aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Constants.cpp
diff options
context:
space:
mode:
authorJoshua Cranmer <joshua.cranmer@intel.com>2022-12-20 11:02:11 -0500
committerJoshua Cranmer <joshua.cranmer@intel.com>2022-12-20 11:02:11 -0500
commite6b02214c68df2c9f826e02310c9352ac652e456 (patch)
tree81280c3f2a940610cd7f2e55393ac618a56c4025 /llvm/lib/IR/Constants.cpp
parente43924a75145d2f9e722f74b673145c3e62bfd07 (diff)
downloadllvm-e6b02214c68df2c9f826e02310c9352ac652e456.zip
llvm-e6b02214c68df2c9f826e02310c9352ac652e456.tar.gz
llvm-e6b02214c68df2c9f826e02310c9352ac652e456.tar.bz2
[IR] Add a target extension type to LLVM.
Target-extension types represent types that need to be preserved through optimization, but otherwise are not introspectable by target-independent optimizations. This patch doesn't add any uses of these types by an existing backend, it only provides basic infrastructure such that these types would work correctly. Reviewed By: nikic, barannikov88 Differential Revision: https://reviews.llvm.org/D135202
Diffstat (limited to 'llvm/lib/IR/Constants.cpp')
-rw-r--r--llvm/lib/IR/Constants.cpp23
1 files changed, 22 insertions, 1 deletions
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index b7126ad..9c8e299 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -87,7 +87,7 @@ bool Constant::isNullValue() const {
// constant zero is zero for aggregates, cpnull is null for pointers, none for
// tokens.
return isa<ConstantAggregateZero>(this) || isa<ConstantPointerNull>(this) ||
- isa<ConstantTokenNone>(this);
+ isa<ConstantTokenNone>(this) || isa<ConstantTargetNone>(this);
}
bool Constant::isAllOnesValue() const {
@@ -369,6 +369,8 @@ Constant *Constant::getNullValue(Type *Ty) {
return ConstantAggregateZero::get(Ty);
case Type::TokenTyID:
return ConstantTokenNone::get(Ty->getContext());
+ case Type::TargetExtTyID:
+ return ConstantTargetNone::get(cast<TargetExtType>(Ty));
default:
// Function, Label, or Opaque type?
llvm_unreachable("Cannot create a null constant of that type!");
@@ -1710,6 +1712,25 @@ void ConstantPointerNull::destroyConstantImpl() {
getContext().pImpl->CPNConstants.erase(getType());
}
+//---- ConstantTargetNone::get() implementation.
+//
+
+ConstantTargetNone *ConstantTargetNone::get(TargetExtType *Ty) {
+ assert(Ty->hasProperty(TargetExtType::HasZeroInit) &&
+ "Target extension type not allowed to have a zeroinitializer");
+ std::unique_ptr<ConstantTargetNone> &Entry =
+ Ty->getContext().pImpl->CTNConstants[Ty];
+ if (!Entry)
+ Entry.reset(new ConstantTargetNone(Ty));
+
+ return Entry.get();
+}
+
+/// Remove the constant from the constant table.
+void ConstantTargetNone::destroyConstantImpl() {
+ getContext().pImpl->CTNConstants.erase(getType());
+}
+
UndefValue *UndefValue::get(Type *Ty) {
std::unique_ptr<UndefValue> &Entry = Ty->getContext().pImpl->UVConstants[Ty];
if (!Entry)