14#ifndef LLVM_LIB_IR_CONSTANTSCONTEXT_H
15#define LLVM_LIB_IR_CONSTANTSCONTEXT_H
41#define DEBUG_TYPE "ir"
57 void *
operator new(
size_t S) {
return User::operator
new(S, AllocMarker); }
58 void operator delete(
void *Ptr) { User::operator
delete(Ptr, AllocMarker); }
86 void *
operator new(
size_t S) {
return User::operator
new(S, AllocMarker); }
87 void operator delete(
void *Ptr) { User::operator
delete(Ptr, AllocMarker); }
115 void *
operator new(
size_t S) {
return User::operator
new(S, AllocMarker); }
116 void operator delete(
void *Ptr) { User::operator
delete(Ptr, AllocMarker); }
122 return CE->getOpcode() == Instruction::ExtractElement;
144 void *
operator new(
size_t S) {
return User::operator
new(S, AllocMarker); }
145 void operator delete(
void *Ptr) { User::operator
delete(Ptr, AllocMarker); }
151 return CE->getOpcode() == Instruction::InsertElement;
171 "Invalid shuffle vector instruction operands!");
182 void *
operator new(
size_t S) {
return User::operator
new(S, AllocMarker); }
183 void operator delete(
void *Ptr) {
184 return User::operator
delete(Ptr, AllocMarker);
191 return CE->getOpcode() == Instruction::ShuffleVector;
203 std::optional<ConstantRange> InRange;
207 std::optional<ConstantRange> InRange,
211 static GetElementPtrConstantExpr *
213 Type *DestTy,
unsigned Flags, std::optional<ConstantRange> InRange) {
215 GetElementPtrConstantExpr *Result =
new (AllocMarker)
216 GetElementPtrConstantExpr(SrcElementTy,
C, IdxList, DestTy,
217 std::move(InRange), AllocMarker);
219 Result->SubclassOptionalData = Flags;
225 std::optional<ConstantRange>
getInRange()
const;
231 return CE->getOpcode() == Instruction::GetElementPtr;
310 assert(Storage.
empty() &&
"Expected empty storage");
311 Storage.
reserve(
C->getNumOperands());
312 for (
unsigned I = 0,
E =
C->getNumOperands();
I !=
E; ++
I)
322 if (
Operands.size() !=
C->getNumOperands())
336 return new (AllocMarker) ConstantClass(Ty,
Operands, AllocMarker);
375 FTy == Asm->getFunctionType() &&
CanThrow == Asm->canThrow();
399 std::optional<ConstantRange> InRange;
402 if (CE->getOpcode() == Instruction::ShuffleVector)
403 return CE->getShuffleMask();
409 return GEPCE->getSourceElementType();
413 static std::optional<ConstantRange>
416 return GEPCE->getInRange();
422 unsigned short SubclassOptionalData = 0,
424 Type *ExplicitTy =
nullptr,
425 std::optional<ConstantRange>
InRange = std::nullopt)
426 : Opcode(Opcode), SubclassOptionalData(SubclassOptionalData),
Ops(
Ops),
427 ShuffleMask(ShuffleMask), ExplicitTy(ExplicitTy),
431 : Opcode(CE->getOpcode()),
432 SubclassOptionalData(CE->getRawSubclassOptionalData()), Ops(
Operands),
433 ShuffleMask(getShuffleMaskIfValid(CE)),
434 ExplicitTy(getSourceElementTypeIfValid(CE)),
435 InRange(getInRangeIfValid(CE)) {}
439 : Opcode(CE->getOpcode()),
440 SubclassOptionalData(CE->getRawSubclassOptionalData()),
441 ShuffleMask(getShuffleMaskIfValid(CE)),
442 ExplicitTy(getSourceElementTypeIfValid(CE)),
443 InRange(getInRangeIfValid(CE)) {
444 assert(Storage.
empty() &&
"Expected empty storage");
445 for (
unsigned I = 0,
E = CE->getNumOperands();
I !=
E; ++
I)
451 const std::optional<ConstantRange> &
B) {
452 if (!
A.has_value() || !
B.has_value())
453 return A.has_value() ==
B.has_value();
454 return A->getBitWidth() ==
B->getBitWidth() &&
A ==
B;
458 return Opcode ==
X.Opcode &&
459 SubclassOptionalData ==
X.SubclassOptionalData && Ops ==
X.Ops &&
460 ShuffleMask ==
X.ShuffleMask && ExplicitTy ==
X.ExplicitTy &&
465 if (Opcode != CE->getOpcode())
467 if (SubclassOptionalData != CE->getRawSubclassOptionalData())
469 if (Ops.size() != CE->getNumOperands())
471 for (
unsigned I = 0,
E = Ops.size();
I !=
E; ++
I)
472 if (Ops[
I] != CE->getOperand(
I))
474 if (ShuffleMask != getShuffleMaskIfValid(CE))
476 if (ExplicitTy != getSourceElementTypeIfValid(CE))
497 SubclassOptionalData);
499 case Instruction::ExtractElement:
501 case Instruction::InsertElement:
503 case Instruction::ShuffleVector:
505 case Instruction::GetElementPtr:
507 ExplicitTy, Ops[0], Ops.slice(1), Ty, SubclassOptionalData, InRange);
522 assert(Storage.
empty() &&
"Expected empty storage");
523 for (
unsigned I = 0,
E =
C->getNumOperands();
I !=
E; ++
I)
533 if (
Operands.size() !=
C->getNumOperands())
561 GV->setMayHaveConstantUsers();
577 static unsigned getHashValue(
const ConstantClass *CP) {
582 static bool isEqual(
const ConstantClass *
LHS,
const ConstantClass *
RHS) {
586 static unsigned getHashValue(
const LookupKey &Val) {
595 if (
LHS.first !=
RHS->getType())
622 ConstantClass *Result =
V.create(Ty);
624 assert(Result->getType() == Ty &&
"Type specified is not correct!");
625 if constexpr (std::is_base_of_v<User, ConstantClass>)
626 for (
Value *
Op : Result->operand_values())
628 Map.insert_as(Result, HashKey);
640 ConstantClass *Result =
nullptr;
644 Result = create(Ty,
V,
Lookup);
647 assert(Result &&
"Unexpected nullptr");
655 assert(
I != Map.end() &&
"Constant not found in constant table!");
656 assert(*
I == CP &&
"Didn't find correct element?");
661 ConstantClass *CP,
Value *From,
662 Constant *To,
unsigned NumUpdated = 0,
663 unsigned OperandNo = ~0u) {
668 auto ItMap = Map.find_as(
Lookup);
669 if (ItMap != Map.end())
676 if (NumUpdated == 1) {
677 assert(OperandNo < CP->getNumOperands() &&
"Invalid index");
678 assert(CP->getOperand(OperandNo) != To &&
"I didn't contain From!");
679 CP->setOperand(OperandNo, To);
681 for (
unsigned I = 0,
E = CP->getNumOperands();
I !=
E; ++
I)
682 if (CP->getOperand(
I) == From)
683 CP->setOperand(
I, To);
685 Map.insert_as(CP,
Lookup);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines DenseMapInfo traits for DenseMap.
This file defines the DenseSet and SmallDenseSet classes.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
static bool InRange(int64_t Value, unsigned short Shift, int LBound, int HBound)
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)
Macro for generating out-of-class operand accessor definitions.
This file defines the SmallVector class.
static bool canThrow(const Value *V)
static int Lookup(ArrayRef< TableEntry > Table, unsigned Opcode)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
Class to represent array types.
BinaryConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to impleme...
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
static bool classof(const ConstantExpr *CE)
static bool classof(const Value *V)
BinaryConstantExpr(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags)
CastConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to implement...
static bool classof(const Value *V)
static bool classof(const ConstantExpr *CE)
CastConstantExpr(unsigned Opcode, Constant *C, Type *Ty)
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
ConstantArray - Constant Array Declarations.
A constant value that is initialized with an expression using other constant values.
ConstantExpr(Type *ty, unsigned Opcode, AllocInfo AllocInfo)
static LLVM_ABI Constant * get(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags=0, Type *OnlyIfReducedTy=nullptr)
get - Return a binary or shift operator constant expression, folding if possible.
A signed pointer, in the ptrauth sense.
typename ConstantInfo< ConstantClass >::ValType ValType
typename ConstantInfo< ConstantClass >::TypeClass TypeClass
ConstantClass * getOrCreate(TypeClass *Ty, ValType V)
Return the specified constant from the map, creating it if necessary.
std::pair< unsigned, LookupKey > LookupKeyHashed
Key and hash together, so that we compute the hash only once and reuse it.
void remove(ConstantClass *CP)
Remove this constant from the map.
ConstantClass * replaceOperandsInPlace(ArrayRef< Constant * > Operands, ConstantClass *CP, Value *From, Constant *To, unsigned NumUpdated=0, unsigned OperandNo=~0u)
DenseSet< ConstantClass *, MapInfo > MapTy
std::pair< TypeClass *, ValType > LookupKey
Constant Vector Declarations.
This is an important base class in LLVM.
static constexpr unsigned ConstantSubclassBits
Bits reserved in SubclassOptionalData, not to be used for ConstantExpr flags.
Implements a dense probed hash-table based set.
Class to represent function types.
GetElementPtrConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
std::optional< ConstantRange > getInRange() const
static bool classof(const ConstantExpr *CE)
Type * getResultElementType() const
Type * getSourceElementType() const
static bool classof(const Value *V)
static GetElementPtrConstantExpr * Create(Type *SrcElementTy, Constant *C, ArrayRef< Constant * > IdxList, Type *DestTy, unsigned Flags, std::optional< ConstantRange > InRange)
InsertElementConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
static bool classof(const ConstantExpr *CE)
InsertElementConstantExpr(Constant *C1, Constant *C2, Constant *C3)
static bool classof(const Value *V)
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
Class to represent pointers.
static PointerType * getUnqual(LLVMContext &C)
This constructs an opaque pointer to an object in the default address space (address space zero).
Class to represent scalable SIMD vectors.
ShuffleVectorConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
Constant * ShuffleMaskForBitcode
SmallVector< int, 4 > ShuffleMask
static bool classof(const ConstantExpr *CE)
ShuffleVectorConstantExpr(Constant *C1, Constant *C2, ArrayRef< int > Mask)
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
static bool classof(const Value *V)
static LLVM_ABI bool isValidOperands(const Value *V1, const Value *V2, const Value *Mask)
Return true if a shufflevector instruction can be formed with the specified operands.
static LLVM_ABI Constant * convertShuffleMaskForBitcode(ArrayRef< int > Mask, Type *ResultTy)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void reserve(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Class to represent struct types.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
unsigned char SubclassOptionalData
Hold arbitary subclass data.
Base class of all SIMD vector types.
DenseSetIterator< false > iterator
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
bool isEqual(const GCNRPTracker::LiveRegSet &S1, const GCNRPTracker::LiveRegSet &S2)
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
void noteConstantOperand(Value *Op)
Record that a uniqued constant uses Op, so that Constant::removeDeadConstantUsers on a global operand...
void deleteConstant(Constant *C)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
DWARFExpression::Operation Op
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
Implement std::hash so that hash_code can be used in STL containers.
bool operator==(const ConstantClass *C) const
ArrayRef< Constant * > Operands
ConstantAggrKeyType(ArrayRef< Constant * > Operands)
ConstantAggrKeyType(ArrayRef< Constant * > Operands, const ConstantClass *)
typename ConstantInfo< ConstantArray >::TypeClass TypeClass
ConstantClass * create(TypeClass *Ty) const
ConstantAggrKeyType(const ConstantClass *C, SmallVectorImpl< Constant * > &Storage)
bool operator==(const ConstantAggrKeyType &X) const
ConstantExprKeyType(unsigned Opcode, ArrayRef< Constant * > Ops, unsigned short SubclassOptionalData=0, ArrayRef< int > ShuffleMask={}, Type *ExplicitTy=nullptr, std::optional< ConstantRange > InRange=std::nullopt)
ConstantExprKeyType(const ConstantExpr *CE, SmallVectorImpl< Constant * > &Storage)
ConstantInfo< ConstantExpr >::TypeClass TypeClass
static bool rangesEqual(const std::optional< ConstantRange > &A, const std::optional< ConstantRange > &B)
ConstantExpr * create(TypeClass *Ty) const
bool operator==(const ConstantExprKeyType &X) const
bool operator==(const ConstantExpr *CE) const
ConstantExprKeyType(ArrayRef< Constant * > Operands, const ConstantExpr *CE)
ConstantAggrKeyType< ConstantArray > ValType
ConstantExprKeyType ValType
ConstantPtrAuthKeyType ValType
ConstantAggrKeyType< ConstantStruct > ValType
ConstantAggrKeyType< ConstantVector > ValType
bool operator==(const ConstantPtrAuthKeyType &X) const
ArrayRef< Constant * > Operands
ConstantPtrAuthKeyType(ArrayRef< Constant * > Operands, const ConstantPtrAuth *)
ConstantPtrAuthKeyType(const ConstantPtrAuth *C, SmallVectorImpl< Constant * > &Storage)
ConstantPtrAuthKeyType(ArrayRef< Constant * > Operands)
bool operator==(const ConstantPtrAuth *C) const
ConstantPtrAuth * create(TypeClass *Ty) const
ConstantInfo< ConstantPtrAuth >::TypeClass TypeClass
An information struct used to provide DenseMap with the various necessary components for a given valu...
FixedNumOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
bool operator==(const InlineAsmKeyType &X) const
ConstantInfo< InlineAsm >::TypeClass TypeClass
InlineAsm * create(TypeClass *Ty) const
bool operator==(const InlineAsm *Asm) const
InlineAsmKeyType(const InlineAsm *Asm, SmallVectorImpl< Constant * > &)
InlineAsmKeyType(StringRef AsmString, StringRef Constraints, FunctionType *FTy, bool HasSideEffects, bool IsAlignStack, InlineAsm::AsmDialect AsmDialect, bool canThrow)
InlineAsm::AsmDialect AsmDialect
Compile-time customization of User operands.
Information about how a User object was allocated, to be passed into the User constructor.
Indicates this User has operands co-allocated.
VariadicOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...