14#ifndef LLVM_LIB_IR_CONSTANTSCONTEXT_H
15#define LLVM_LIB_IR_CONSTANTSCONTEXT_H
39#define DEBUG_TYPE "ir"
53 void *
operator new(
size_t S) {
return User::operator
new(S, 1); }
54 void operator delete(
void *
Ptr) { User::operator
delete(
Ptr); }
62 return isa<ConstantExpr>(V) &&
classof(cast<ConstantExpr>(V));
79 void *
operator new(
size_t S) {
return User::operator
new(S, 2); }
80 void operator delete(
void *
Ptr) { User::operator
delete(
Ptr); }
89 return isa<ConstantExpr>(V) &&
classof(cast<ConstantExpr>(V));
106 void *
operator new(
size_t S) {
return User::operator
new(S, 2); }
107 void operator delete(
void *
Ptr) { User::operator
delete(
Ptr); }
113 return CE->getOpcode() == Instruction::ExtractElement;
116 return isa<ConstantExpr>(V) &&
classof(cast<ConstantExpr>(V));
134 void *
operator new(
size_t S) {
return User::operator
new(S, 3); }
135 void operator delete(
void *
Ptr) { User::operator
delete(
Ptr); }
141 return CE->getOpcode() == Instruction::InsertElement;
144 return isa<ConstantExpr>(V) &&
classof(cast<ConstantExpr>(V));
159 "Invalid shuffle vector instruction operands!");
170 void *
operator new(
size_t S) {
return User::operator
new(S, 2); }
171 void operator delete(
void *
Ptr) {
return User::operator
delete(
Ptr); }
177 return CE->getOpcode() == Instruction::ShuffleVector;
180 return isa<ConstantExpr>(V) &&
classof(cast<ConstantExpr>(V));
189 std::optional<ConstantRange> InRange;
193 std::optional<ConstantRange> InRange);
198 Type *DestTy,
unsigned Flags, std::optional<ConstantRange> InRange) {
202 Result->SubclassOptionalData = Flags;
208 std::optional<ConstantRange>
getInRange()
const;
214 return CE->getOpcode() == Instruction::GetElementPtr;
217 return isa<ConstantExpr>(V) &&
classof(cast<ConstantExpr>(V));
235 void *
operator new(
size_t S) {
return User::operator
new(S, 2); }
236 void operator delete(
void *
Ptr) {
return User::operator
delete(
Ptr); }
242 return CE->getOpcode() == Instruction::ICmp ||
243 CE->getOpcode() == Instruction::FCmp;
246 return isa<ConstantExpr>(V) &&
classof(cast<ConstantExpr>(V));
322 assert(Storage.
empty() &&
"Expected empty storage");
323 for (
unsigned I = 0,
E =
C->getNumOperands();
I !=
E; ++
I)
333 if (
Operands.size() !=
C->getNumOperands())
387 FTy == Asm->getFunctionType() &&
CanThrow == Asm->canThrow();
407 uint8_t SubclassOptionalData;
412 std::optional<ConstantRange> InRange;
415 if (CE->getOpcode() == Instruction::ShuffleVector)
416 return CE->getShuffleMask();
421 if (
auto *GEPCE = dyn_cast<GetElementPtrConstantExpr>(CE))
422 return GEPCE->getSourceElementType();
426 static std::optional<ConstantRange>
428 if (
auto *GEPCE = dyn_cast<GetElementPtrConstantExpr>(CE))
429 return GEPCE->getInRange();
435 unsigned short SubclassData = 0,
436 unsigned short SubclassOptionalData = 0,
438 Type *ExplicitTy =
nullptr,
439 std::optional<ConstantRange> InRange = std::nullopt)
440 : Opcode(Opcode), SubclassOptionalData(SubclassOptionalData),
441 SubclassData(SubclassData), Ops(Ops), ShuffleMask(ShuffleMask),
442 ExplicitTy(ExplicitTy), InRange(
std::
move(InRange)) {}
446 SubclassOptionalData(CE->getRawSubclassOptionalData()),
447 SubclassData(CE->isCompare() ? CE->getPredicate() : 0), Ops(
Operands),
448 ShuffleMask(getShuffleMaskIfValid(CE)),
449 ExplicitTy(getSourceElementTypeIfValid(CE)),
450 InRange(getInRangeIfValid(CE)) {}
455 SubclassOptionalData(CE->getRawSubclassOptionalData()),
456 SubclassData(CE->isCompare() ? CE->getPredicate() : 0),
457 ShuffleMask(getShuffleMaskIfValid(CE)),
458 ExplicitTy(getSourceElementTypeIfValid(CE)),
459 InRange(getInRangeIfValid(CE)) {
460 assert(Storage.
empty() &&
"Expected empty storage");
461 for (
unsigned I = 0,
E = CE->getNumOperands();
I !=
E; ++
I)
467 const std::optional<ConstantRange> &
B) {
468 if (!
A.has_value() || !
B.has_value())
469 return A.has_value() ==
B.has_value();
470 return A->getBitWidth() ==
B->getBitWidth() &&
A ==
B;
474 return Opcode ==
X.Opcode && SubclassData ==
X.SubclassData &&
475 SubclassOptionalData ==
X.SubclassOptionalData && Ops ==
X.Ops &&
476 ShuffleMask ==
X.ShuffleMask && ExplicitTy ==
X.ExplicitTy &&
481 if (Opcode != CE->getOpcode())
483 if (SubclassOptionalData != CE->getRawSubclassOptionalData())
485 if (Ops.
size() != CE->getNumOperands())
487 if (SubclassData != (CE->isCompare() ? CE->getPredicate() : 0))
489 for (
unsigned I = 0,
E = Ops.
size();
I !=
E; ++
I)
490 if (Ops[
I] != CE->getOperand(
I))
492 if (ShuffleMask != getShuffleMaskIfValid(CE))
494 if (ExplicitTy != getSourceElementTypeIfValid(CE))
503 Opcode, SubclassOptionalData, SubclassData,
515 if ((Opcode >= Instruction::BinaryOpsBegin &&
516 Opcode < Instruction::BinaryOpsEnd))
518 SubclassOptionalData);
520 case Instruction::ExtractElement:
522 case Instruction::InsertElement:
524 case Instruction::ShuffleVector:
526 case Instruction::GetElementPtr:
528 ExplicitTy, Ops[0], Ops.
slice(1), Ty, SubclassOptionalData, InRange);
529 case Instruction::ICmp:
532 case Instruction::FCmp:
556 static inline ConstantClass *getEmptyKey() {
557 return ConstantClassInfo::getEmptyKey();
560 static inline ConstantClass *getTombstoneKey() {
561 return ConstantClassInfo::getTombstoneKey();
564 static unsigned getHashValue(
const ConstantClass *CP) {
569 static bool isEqual(
const ConstantClass *
LHS,
const ConstantClass *
RHS) {
573 static unsigned getHashValue(
const LookupKey &Val) {
582 if (
RHS == getEmptyKey() ||
RHS == getTombstoneKey())
584 if (
LHS.first !=
RHS->getType())
611 ConstantClass *Result = V.create(Ty);
613 assert(Result->getType() == Ty &&
"Type specified is not correct!");
614 Map.insert_as(Result, HashKey);
626 ConstantClass *Result =
nullptr;
630 Result = create(Ty, V,
Lookup);
633 assert(Result &&
"Unexpected nullptr");
641 assert(
I != Map.end() &&
"Constant not found in constant table!");
642 assert(*
I == CP &&
"Didn't find correct element?");
648 Constant *To,
unsigned NumUpdated = 0,
649 unsigned OperandNo = ~0u) {
654 auto ItMap = Map.find_as(
Lookup);
655 if (ItMap != Map.end())
661 if (NumUpdated == 1) {
662 assert(OperandNo < CP->getNumOperands() &&
"Invalid index");
663 assert(CP->getOperand(OperandNo) != To &&
"I didn't contain From!");
664 CP->setOperand(OperandNo, To);
666 for (
unsigned I = 0,
E = CP->getNumOperands();
I !=
E; ++
I)
667 if (CP->getOperand(
I) ==
From)
668 CP->setOperand(
I, To);
670 Map.insert_as(CP,
Lookup);
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-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.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
mir Rename Register Operands
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)
Macro for generating out-of-class operand accessor definitions.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
static std::optional< unsigned > getOpcode(ArrayRef< VPValue * > Values)
Returns the opcode of Values or ~0 if they do not all agree.
static bool canThrow(const Value *V)
static int Lookup(ArrayRef< TableEntry > Table, unsigned Opcode)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
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)
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
static bool classof(const Value *V)
CompareConstantExpr(Type *ty, Instruction::OtherOps opc, unsigned short pred, Constant *LHS, Constant *RHS)
static bool classof(const ConstantExpr *CE)
ConstantArray - Constant Array Declarations.
A constant value that is initialized with an expression using other constant values.
static 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.
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)
std::pair< TypeClass *, ValType > LookupKey
Constant Vector Declarations.
This is an important base class in LLVM.
This class represents an Operation in the Expression.
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(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
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 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 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 assign(size_type NumElts, ValueParamT Elt)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - 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 subclass data that can be dropped.
Base class of all SIMD vector types.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
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.
void deleteConstant(Constant *C)
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...
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< ConstantClass >::TypeClass TypeClass
ConstantClass * create(TypeClass *Ty) const
ConstantAggrKeyType(const ConstantClass *C, SmallVectorImpl< Constant * > &Storage)
bool operator==(const ConstantAggrKeyType &X) const
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(unsigned Opcode, ArrayRef< Constant * > Ops, unsigned short SubclassData=0, unsigned short SubclassOptionalData=0, ArrayRef< int > ShuffleMask=std::nullopt, Type *ExplicitTy=nullptr, std::optional< ConstantRange > InRange=std::nullopt)
ConstantExprKeyType(ArrayRef< Constant * > Operands, const ConstantExpr *CE)
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.
VariadicOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...