LLVM: lib/IR/ConstantsContext.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef LLVM_LIB_IR_CONSTANTSCONTEXT_H
15#define LLVM_LIB_IR_CONSTANTSCONTEXT_H
16
35#include
36#include
37#include
38#include
39
40#define DEBUG_TYPE "ir"
41
42namespace llvm {
43
44
45
48
49public:
53 }
54
55
56 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
57 void operator delete(void *Ptr) { User::operator delete(Ptr); }
58
60
63 }
65 return isa(V) && classof(cast(V));
66 }
67};
68
69
70
73
74public:
76 unsigned Flags)
81 }
82
83
84 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
85 void operator delete(void *Ptr) { User::operator delete(Ptr); }
86
87
89
92 }
94 return isa(V) && classof(cast(V));
95 }
96};
97
98
99
100
103
104public:
107 Instruction::ExtractElement, AllocMarker) {
110 }
111
112
113 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
114 void operator delete(void *Ptr) { User::operator delete(Ptr); }
115
116
118
120 return CE->getOpcode() == Instruction::ExtractElement;
121 }
123 return isa(V) && classof(cast(V));
124 }
125};
126
127
128
129
132
133public:
139 }
140
141
142 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
143 void operator delete(void *Ptr) { User::operator delete(Ptr); }
144
145
147
149 return CE->getOpcode() == Instruction::InsertElement;
150 }
152 return isa(V) && classof(cast(V));
153 }
154};
155
156
157
158
161
162public:
167 Instruction::ShuffleVector, AllocMarker) {
169 "Invalid shuffle vector instruction operands!");
175 }
176
179
180 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
181 void operator delete(void *Ptr) { return User::operator delete(Ptr); }
182
183
185
187 return CE->getOpcode() == Instruction::ShuffleVector;
188 }
190 return isa(V) && classof(cast(V));
191 }
192};
193
194
195
197 Type *SrcElementTy;
198 Type *ResElementTy;
199 std::optional InRange;
200
203 std::optional InRange,
205
206public:
209 Type *DestTy, unsigned Flags, std::optional InRange) {
213 std::move(InRange), AllocMarker);
214 Result->SubclassOptionalData = Flags;
215 return Result;
216 }
217
220 std::optional getInRange() const;
221
222
224
226 return CE->getOpcode() == Instruction::GetElementPtr;
227 }
229 return isa(V) && classof(cast(V));
230 }
231};
232
233template <>
237
238template <>
242
243template <>
247
248template <>
252
253template <>
257
258template <>
261
263
268
273};
277};
281};
285};
289};
293};
294
297
299
302
305 assert(Storage.empty() && "Expected empty storage");
306 Storage.reserve(C->getNumOperands());
307 for (unsigned I = 0, E = C->getNumOperands(); I != E; ++I)
310 }
311
314 }
315
317 if (Operands.size() != C->getNumOperands())
318 return false;
319 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
321 return false;
322 return true;
323 }
324
327 }
328
330
333 return new (AllocMarker) ConstantClass(Ty, Operands, AllocMarker);
334 }
335};
336
345
352
355 FTy(Asm->getFunctionType()), HasSideEffects(Asm->hasSideEffects()),
358
364 }
365
370 AsmString == Asm->getAsmString() &&
371 Constraints == Asm->getConstraintString() &&
372 FTy == Asm->getFunctionType() && CanThrow == Asm->canThrow();
373 }
374
378 }
379
381
386 }
387};
388
390private:
392 uint8_t SubclassOptionalData;
395 Type *ExplicitTy;
396 std::optional InRange;
397
399 if (CE->getOpcode() == Instruction::ShuffleVector)
400 return CE->getShuffleMask();
401 return {};
402 }
403
404 static Type *getSourceElementTypeIfValid(const ConstantExpr *CE) {
405 if (auto *GEPCE = dyn_cast(CE))
406 return GEPCE->getSourceElementType();
407 return nullptr;
408 }
409
410 static std::optional
412 if (auto *GEPCE = dyn_cast(CE))
413 return GEPCE->getInRange();
414 return std::nullopt;
415 }
416
417public:
419 unsigned short SubclassOptionalData = 0,
421 Type *ExplicitTy = nullptr,
422 std::optional InRange = std::nullopt)
423 : Opcode(Opcode), SubclassOptionalData(SubclassOptionalData), Ops(Ops),
424 ShuffleMask(ShuffleMask), ExplicitTy(ExplicitTy),
425 InRange(std::move(InRange)) {}
426
429 SubclassOptionalData(CE->getRawSubclassOptionalData()), Ops(Operands),
430 ShuffleMask(getShuffleMaskIfValid(CE)),
431 ExplicitTy(getSourceElementTypeIfValid(CE)),
432 InRange(getInRangeIfValid(CE)) {}
433
437 SubclassOptionalData(CE->getRawSubclassOptionalData()),
438 ShuffleMask(getShuffleMaskIfValid(CE)),
439 ExplicitTy(getSourceElementTypeIfValid(CE)),
440 InRange(getInRangeIfValid(CE)) {
441 assert(Storage.empty() && "Expected empty storage");
442 for (unsigned I = 0, E = CE->getNumOperands(); I != E; ++I)
443 Storage.push_back(CE->getOperand(I));
444 Ops = Storage;
445 }
446
447 static bool rangesEqual(const std::optional &A,
448 const std::optional &B) {
449 if (.has_value() ||
.has_value())
450 return A.has_value() == B.has_value();
451 return A->getBitWidth() == B->getBitWidth() && A == B;
452 }
453
455 return Opcode == X.Opcode &&
456 SubclassOptionalData == X.SubclassOptionalData && Ops == X.Ops &&
457 ShuffleMask == X.ShuffleMask && ExplicitTy == X.ExplicitTy &&
459 }
460
462 if (Opcode != CE->getOpcode())
463 return false;
464 if (SubclassOptionalData != CE->getRawSubclassOptionalData())
465 return false;
466 if (Ops.size() != CE->getNumOperands())
467 return false;
468 for (unsigned I = 0, E = Ops.size(); I != E; ++I)
469 if (Ops[I] != CE->getOperand(I))
470 return false;
471 if (ShuffleMask != getShuffleMaskIfValid(CE))
472 return false;
473 if (ExplicitTy != getSourceElementTypeIfValid(CE))
474 return false;
475 if ((InRange, getInRangeIfValid(CE)))
476 return false;
477 return true;
478 }
479
482 Opcode, SubclassOptionalData,
485 }
486
488
490 switch (Opcode) {
491 default:
496 SubclassOptionalData);
498 case Instruction::ExtractElement:
500 case Instruction::InsertElement:
502 case Instruction::ShuffleVector:
504 case Instruction::GetElementPtr:
506 ExplicitTy, Ops[0], Ops.slice(1), Ty, SubclassOptionalData, InRange);
507 }
508 }
509};
510
513
515
518
521 assert(Storage.empty() && "Expected empty storage");
522 for (unsigned I = 0, E = C->getNumOperands(); I != E; ++I)
523 Storage.push_back(cast(C->getOperand(I)));
525 }
526
529 }
530
532 if (Operands.size() != C->getNumOperands())
533 return false;
534 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
536 return false;
537 return true;
538 }
539
542 }
543
545
549 }
550};
551
552
553
555
557public:
560 using LookupKey = std::pair<TypeClass *, ValType>;
561
562
564
565private:
566 struct MapInfo {
568
569 static inline ConstantClass *getEmptyKey() {
570 return ConstantClassInfo::getEmptyKey();
571 }
572
573 static inline ConstantClass *getTombstoneKey() {
574 return ConstantClassInfo::getTombstoneKey();
575 }
576
577 static unsigned getHashValue(const ConstantClass *CP) {
579 return getHashValue(LookupKey(CP->getType(), ValType(CP, Storage)));
580 }
581
582 static bool isEqual(const ConstantClass *LHS, const ConstantClass *RHS) {
584 }
585
586 static unsigned getHashValue(const LookupKey &Val) {
587 return hash_combine(Val.first, Val.second.getHash());
588 }
589
590 static unsigned getHashValue(const LookupKeyHashed &Val) {
591 return Val.first;
592 }
593
595 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
596 return false;
597 if (LHS.first != RHS->getType())
598 return false;
600 }
601
604 }
605 };
606
607public:
609
610private:
612
613public:
616
618 for (auto &I : Map)
620 }
621
622private:
624 ConstantClass *Result = V.create(Ty);
625
626 assert(Result->getType() == Ty && "Type specified is not correct!");
627 Map.insert_as(Result, HashKey);
628
629 return Result;
630 }
631
632public:
633
636
638
639 ConstantClass *Result = nullptr;
640
641 auto I = Map.find_as(Lookup);
642 if (I == Map.end())
643 Result = create(Ty, V, Lookup);
644 else
645 Result = *I;
646 assert(Result && "Unexpected nullptr");
647
648 return Result;
649 }
650
651
654 assert(I != Map.end() && "Constant not found in constant table!");
655 assert(*I == CP && "Didn't find correct element?");
656 Map.erase(I);
657 }
658
661 Constant *To, unsigned NumUpdated = 0,
662 unsigned OperandNo = ~0u) {
664
666
667 auto ItMap = Map.find_as(Lookup);
668 if (ItMap != Map.end())
669 return *ItMap;
670
671
672
674 if (NumUpdated == 1) {
675 assert(OperandNo < CP->getNumOperands() && "Invalid index");
676 assert(CP->getOperand(OperandNo) != To && "I didn't contain From!");
677 CP->setOperand(OperandNo, To);
678 } else {
679 for (unsigned I = 0, E = CP->getNumOperands(); I != E; ++I)
680 if (CP->getOperand(I) == From)
681 CP->setOperand(I, To);
682 }
683 Map.insert_as(CP, Lookup);
684 return nullptr;
685 }
686
688 LLVM_DEBUG(dbgs() << "Constant.cpp: ConstantUniqueMap\n");
689 }
690};
691
693 for (auto &I : Map)
694 delete I;
695}
696
697}
698
699#endif
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)
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.
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)
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 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.
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 - Return true if the parameter to the template is an instance of one of the template type argu...
decltype(auto) cast(const From &Val)
cast - 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.
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(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)
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
typename 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...