LLVM 22.0.0git
ConstantsContext.h
Go to the documentation of this file.
1//===-- ConstantsContext.h - Constants-related Context Interals -*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines various helper methods and classes used by
10// LLVMContextImpl for creating and managing constants.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_IR_CONSTANTSCONTEXT_H
15#define LLVM_LIB_IR_CONSTANTSCONTEXT_H
16
17#include "llvm/ADT/ArrayRef.h"
19#include "llvm/ADT/DenseSet.h"
20#include "llvm/ADT/Hashing.h"
22#include "llvm/ADT/StringRef.h"
23#include "llvm/IR/Constant.h"
24#include "llvm/IR/Constants.h"
27#include "llvm/IR/InlineAsm.h"
28#include "llvm/IR/Instruction.h"
32#include "llvm/Support/Debug.h"
35#include <cassert>
36#include <cstddef>
37#include <cstdint>
38#include <utility>
39
40#define DEBUG_TYPE "ir"
41
42namespace llvm {
43
44/// CastConstantExpr - This class is private to Constants.cpp, and is used
45/// behind the scenes to implement cast constant exprs.
46class CastConstantExpr final : public ConstantExpr {
47 constexpr static IntrusiveOperandsAllocMarker AllocMarker{1};
48
49public:
50 CastConstantExpr(unsigned Opcode, Constant *C, Type *Ty)
51 : ConstantExpr(Ty, Opcode, AllocMarker) {
52 Op<0>() = C;
53 }
54
55 // allocate space for exactly one operand
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
61 static bool classof(const ConstantExpr *CE) {
62 return Instruction::isCast(CE->getOpcode());
63 }
64 static bool classof(const Value *V) {
65 return isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V));
66 }
67};
68
69/// BinaryConstantExpr - This class is private to Constants.cpp, and is used
70/// behind the scenes to implement binary constant exprs.
71class BinaryConstantExpr final : public ConstantExpr {
72 constexpr static IntrusiveOperandsAllocMarker AllocMarker{2};
73
74public:
75 BinaryConstantExpr(unsigned Opcode, Constant *C1, Constant *C2,
76 unsigned Flags)
77 : ConstantExpr(C1->getType(), Opcode, AllocMarker) {
78 Op<0>() = C1;
79 Op<1>() = C2;
81 }
82
83 // allocate space for exactly two operands
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 /// Transparently provide more efficient getOperand methods.
89
90 static bool classof(const ConstantExpr *CE) {
91 return Instruction::isBinaryOp(CE->getOpcode());
92 }
93 static bool classof(const Value *V) {
94 return isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V));
95 }
96};
97
98/// ExtractElementConstantExpr - This class is private to
99/// Constants.cpp, and is used behind the scenes to implement
100/// extractelement constant exprs.
102 constexpr static IntrusiveOperandsAllocMarker AllocMarker{2};
103
104public:
106 : ConstantExpr(cast<VectorType>(C1->getType())->getElementType(),
107 Instruction::ExtractElement, AllocMarker) {
108 Op<0>() = C1;
109 Op<1>() = C2;
110 }
111
112 // allocate space for exactly two operands
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 /// Transparently provide more efficient getOperand methods.
118
119 static bool classof(const ConstantExpr *CE) {
120 return CE->getOpcode() == Instruction::ExtractElement;
121 }
122 static bool classof(const Value *V) {
123 return isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V));
124 }
125};
126
127/// InsertElementConstantExpr - This class is private to
128/// Constants.cpp, and is used behind the scenes to implement
129/// insertelement constant exprs.
131 constexpr static IntrusiveOperandsAllocMarker AllocMarker{3};
132
133public:
135 : ConstantExpr(C1->getType(), Instruction::InsertElement, AllocMarker) {
136 Op<0>() = C1;
137 Op<1>() = C2;
138 Op<2>() = C3;
139 }
140
141 // allocate space for exactly three operands
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 /// Transparently provide more efficient getOperand methods.
147
148 static bool classof(const ConstantExpr *CE) {
149 return CE->getOpcode() == Instruction::InsertElement;
150 }
151 static bool classof(const Value *V) {
152 return isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V));
153 }
154};
155
156/// ShuffleVectorConstantExpr - This class is private to
157/// Constants.cpp, and is used behind the scenes to implement
158/// shufflevector constant exprs.
160 constexpr static IntrusiveOperandsAllocMarker AllocMarker{2};
161
162public:
165 cast<VectorType>(C1->getType())->getElementType(),
166 Mask.size(), isa<ScalableVectorType>(C1->getType())),
167 Instruction::ShuffleVector, AllocMarker) {
169 "Invalid shuffle vector instruction operands!");
170 Op<0>() = C1;
171 Op<1>() = C2;
172 ShuffleMask.assign(Mask.begin(), Mask.end());
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 /// Transparently provide more efficient getOperand methods.
185
186 static bool classof(const ConstantExpr *CE) {
187 return CE->getOpcode() == Instruction::ShuffleVector;
188 }
189 static bool classof(const Value *V) {
190 return isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V));
191 }
192};
193
194/// GetElementPtrConstantExpr - This class is private to Constants.cpp, and is
195/// used behind the scenes to implement getelementptr constant exprs.
197 Type *SrcElementTy;
198 Type *ResElementTy;
199 std::optional<ConstantRange> InRange;
200
202 ArrayRef<Constant *> IdxList, Type *DestTy,
203 std::optional<ConstantRange> InRange,
205
206public:
208 Create(Type *SrcElementTy, Constant *C, ArrayRef<Constant *> IdxList,
209 Type *DestTy, unsigned Flags, std::optional<ConstantRange> InRange) {
210 IntrusiveOperandsAllocMarker AllocMarker{unsigned(IdxList.size() + 1)};
211 GetElementPtrConstantExpr *Result = new (AllocMarker)
212 GetElementPtrConstantExpr(SrcElementTy, C, IdxList, DestTy,
213 std::move(InRange), AllocMarker);
214 Result->SubclassOptionalData = Flags;
215 return Result;
216 }
217
218 Type *getSourceElementType() const;
219 Type *getResultElementType() const;
220 std::optional<ConstantRange> getInRange() const;
221
222 /// Transparently provide more efficient getOperand methods.
224
225 static bool classof(const ConstantExpr *CE) {
226 return CE->getOpcode() == Instruction::GetElementPtr;
227 }
228 static bool classof(const Value *V) {
229 return isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V));
230 }
231};
232
233template <>
235 : public FixedNumOperandTraits<CastConstantExpr, 1> {};
237
238template <>
240 : public FixedNumOperandTraits<BinaryConstantExpr, 2> {};
242
243template <>
245 : public FixedNumOperandTraits<ExtractElementConstantExpr, 2> {};
247
248template <>
250 : public FixedNumOperandTraits<InsertElementConstantExpr, 3> {};
252
253template <>
255 : public FixedNumOperandTraits<ShuffleVectorConstantExpr, 2> {};
257
258template <>
260 : public VariadicOperandTraits<GetElementPtrConstantExpr> {};
261
263
264template <class ConstantClass> struct ConstantAggrKeyType;
265struct InlineAsmKeyType;
268
269template <class ConstantClass> struct ConstantInfo;
270template <> struct ConstantInfo<ConstantExpr> {
273};
274template <> struct ConstantInfo<InlineAsm> {
277};
278template <> struct ConstantInfo<ConstantArray> {
281};
282template <> struct ConstantInfo<ConstantStruct> {
285};
286template <> struct ConstantInfo<ConstantVector> {
289};
290template <> struct ConstantInfo<ConstantPtrAuth> {
293};
294
295template <class ConstantClass> struct ConstantAggrKeyType {
297
299
301 : Operands(Operands) {}
302
303 ConstantAggrKeyType(const ConstantClass *C,
305 assert(Storage.empty() && "Expected empty storage");
306 Storage.reserve(C->getNumOperands());
307 for (unsigned I = 0, E = C->getNumOperands(); I != E; ++I)
308 Storage.push_back(C->getOperand(I));
309 Operands = Storage;
310 }
311
312 bool operator==(const ConstantAggrKeyType &X) const {
313 return Operands == X.Operands;
314 }
315
316 bool operator==(const ConstantClass *C) const {
317 if (Operands.size() != C->getNumOperands())
318 return false;
319 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
320 if (Operands[I] != C->getOperand(I))
321 return false;
322 return true;
323 }
324
325 unsigned getHash() const { return hash_combine_range(Operands); }
326
328
329 ConstantClass *create(TypeClass *Ty) const {
331 return new (AllocMarker) ConstantClass(Ty, Operands, AllocMarker);
332 }
333};
334
343
350
352 : AsmString(Asm->getAsmString()), Constraints(Asm->getConstraintString()),
353 FTy(Asm->getFunctionType()), HasSideEffects(Asm->hasSideEffects()),
354 IsAlignStack(Asm->isAlignStack()), AsmDialect(Asm->getDialect()),
355 CanThrow(Asm->canThrow()) {}
356
357 bool operator==(const InlineAsmKeyType &X) const {
358 return HasSideEffects == X.HasSideEffects &&
359 IsAlignStack == X.IsAlignStack && AsmDialect == X.AsmDialect &&
360 AsmString == X.AsmString && Constraints == X.Constraints &&
361 FTy == X.FTy && CanThrow == X.CanThrow;
362 }
363
364 bool operator==(const InlineAsm *Asm) const {
365 return HasSideEffects == Asm->hasSideEffects() &&
366 IsAlignStack == Asm->isAlignStack() &&
367 AsmDialect == Asm->getDialect() &&
368 AsmString == Asm->getAsmString() &&
369 Constraints == Asm->getConstraintString() &&
370 FTy == Asm->getFunctionType() && CanThrow == Asm->canThrow();
371 }
372
373 unsigned getHash() const {
376 }
377
379
382 return new InlineAsm(FTy, std::string(AsmString), std::string(Constraints),
384 }
385};
386
388private:
389 uint8_t Opcode;
390 uint8_t SubclassOptionalData;
392 ArrayRef<int> ShuffleMask;
393 Type *ExplicitTy;
394 std::optional<ConstantRange> InRange;
395
396 static ArrayRef<int> getShuffleMaskIfValid(const ConstantExpr *CE) {
397 if (CE->getOpcode() == Instruction::ShuffleVector)
398 return CE->getShuffleMask();
399 return {};
400 }
401
402 static Type *getSourceElementTypeIfValid(const ConstantExpr *CE) {
403 if (auto *GEPCE = dyn_cast<GetElementPtrConstantExpr>(CE))
404 return GEPCE->getSourceElementType();
405 return nullptr;
406 }
407
408 static std::optional<ConstantRange>
409 getInRangeIfValid(const ConstantExpr *CE) {
410 if (auto *GEPCE = dyn_cast<GetElementPtrConstantExpr>(CE))
411 return GEPCE->getInRange();
412 return std::nullopt;
413 }
414
415public:
417 unsigned short SubclassOptionalData = 0,
418 ArrayRef<int> ShuffleMask = {},
419 Type *ExplicitTy = nullptr,
420 std::optional<ConstantRange> InRange = std::nullopt)
421 : Opcode(Opcode), SubclassOptionalData(SubclassOptionalData), Ops(Ops),
422 ShuffleMask(ShuffleMask), ExplicitTy(ExplicitTy),
423 InRange(std::move(InRange)) {}
424
426 : Opcode(CE->getOpcode()),
427 SubclassOptionalData(CE->getRawSubclassOptionalData()), Ops(Operands),
428 ShuffleMask(getShuffleMaskIfValid(CE)),
429 ExplicitTy(getSourceElementTypeIfValid(CE)),
430 InRange(getInRangeIfValid(CE)) {}
431
434 : Opcode(CE->getOpcode()),
435 SubclassOptionalData(CE->getRawSubclassOptionalData()),
436 ShuffleMask(getShuffleMaskIfValid(CE)),
437 ExplicitTy(getSourceElementTypeIfValid(CE)),
438 InRange(getInRangeIfValid(CE)) {
439 assert(Storage.empty() && "Expected empty storage");
440 for (unsigned I = 0, E = CE->getNumOperands(); I != E; ++I)
441 Storage.push_back(CE->getOperand(I));
442 Ops = Storage;
443 }
444
445 static bool rangesEqual(const std::optional<ConstantRange> &A,
446 const std::optional<ConstantRange> &B) {
447 if (!A.has_value() || !B.has_value())
448 return A.has_value() == B.has_value();
449 return A->getBitWidth() == B->getBitWidth() && A == B;
450 }
451
452 bool operator==(const ConstantExprKeyType &X) const {
453 return Opcode == X.Opcode &&
454 SubclassOptionalData == X.SubclassOptionalData && Ops == X.Ops &&
455 ShuffleMask == X.ShuffleMask && ExplicitTy == X.ExplicitTy &&
456 rangesEqual(InRange, X.InRange);
457 }
458
459 bool operator==(const ConstantExpr *CE) const {
460 if (Opcode != CE->getOpcode())
461 return false;
462 if (SubclassOptionalData != CE->getRawSubclassOptionalData())
463 return false;
464 if (Ops.size() != CE->getNumOperands())
465 return false;
466 for (unsigned I = 0, E = Ops.size(); I != E; ++I)
467 if (Ops[I] != CE->getOperand(I))
468 return false;
469 if (ShuffleMask != getShuffleMaskIfValid(CE))
470 return false;
471 if (ExplicitTy != getSourceElementTypeIfValid(CE))
472 return false;
473 if (!rangesEqual(InRange, getInRangeIfValid(CE)))
474 return false;
475 return true;
476 }
477
478 unsigned getHash() const {
479 return hash_combine(Opcode, SubclassOptionalData, hash_combine_range(Ops),
480 hash_combine_range(ShuffleMask), ExplicitTy);
481 }
482
484
486 switch (Opcode) {
487 default:
488 if (Instruction::isCast(Opcode))
489 return new CastConstantExpr(Opcode, Ops[0], Ty);
490 if (Instruction::isBinaryOp(Opcode))
491 return new BinaryConstantExpr(Opcode, Ops[0], Ops[1],
492 SubclassOptionalData);
493 llvm_unreachable("Invalid ConstantExpr!");
494 case Instruction::ExtractElement:
495 return new ExtractElementConstantExpr(Ops[0], Ops[1]);
496 case Instruction::InsertElement:
497 return new InsertElementConstantExpr(Ops[0], Ops[1], Ops[2]);
498 case Instruction::ShuffleVector:
499 return new ShuffleVectorConstantExpr(Ops[0], Ops[1], ShuffleMask);
500 case Instruction::GetElementPtr:
502 ExplicitTy, Ops[0], Ops.slice(1), Ty, SubclassOptionalData, InRange);
503 }
504 }
505};
506
509
511
513 : Operands(Operands) {}
514
517 assert(Storage.empty() && "Expected empty storage");
518 for (unsigned I = 0, E = C->getNumOperands(); I != E; ++I)
519 Storage.push_back(cast<Constant>(C->getOperand(I)));
520 Operands = Storage;
521 }
522
524 return Operands == X.Operands;
525 }
526
527 bool operator==(const ConstantPtrAuth *C) const {
528 if (Operands.size() != C->getNumOperands())
529 return false;
530 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
531 if (Operands[I] != C->getOperand(I))
532 return false;
533 return true;
534 }
535
536 unsigned getHash() const { return hash_combine_range(Operands); }
537
539
541 return new ConstantPtrAuth(Operands[0], cast<ConstantInt>(Operands[1]),
542 cast<ConstantInt>(Operands[2]), Operands[3]);
543 }
544};
545
546// Free memory for a given constant. Assumes the constant has already been
547// removed from all relevant maps.
548void deleteConstant(Constant *C);
549
550template <class ConstantClass> class ConstantUniqueMap {
551public:
554 using LookupKey = std::pair<TypeClass *, ValType>;
555
556 /// Key and hash together, so that we compute the hash only once and reuse it.
557 using LookupKeyHashed = std::pair<unsigned, LookupKey>;
558
559private:
560 struct MapInfo {
561 using ConstantClassInfo = DenseMapInfo<ConstantClass *>;
562
563 static inline ConstantClass *getEmptyKey() {
564 return ConstantClassInfo::getEmptyKey();
565 }
566
567 static inline ConstantClass *getTombstoneKey() {
568 return ConstantClassInfo::getTombstoneKey();
569 }
570
571 static unsigned getHashValue(const ConstantClass *CP) {
573 return getHashValue(LookupKey(CP->getType(), ValType(CP, Storage)));
574 }
575
576 static bool isEqual(const ConstantClass *LHS, const ConstantClass *RHS) {
577 return LHS == RHS;
578 }
579
580 static unsigned getHashValue(const LookupKey &Val) {
581 return hash_combine(Val.first, Val.second.getHash());
582 }
583
584 static unsigned getHashValue(const LookupKeyHashed &Val) {
585 return Val.first;
586 }
587
588 static bool isEqual(const LookupKey &LHS, const ConstantClass *RHS) {
589 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
590 return false;
591 if (LHS.first != RHS->getType())
592 return false;
593 return LHS.second == RHS;
594 }
595
596 static bool isEqual(const LookupKeyHashed &LHS, const ConstantClass *RHS) {
597 return isEqual(LHS.second, RHS);
598 }
599 };
600
601public:
603
604private:
605 MapTy Map;
606
607public:
608 typename MapTy::iterator begin() { return Map.begin(); }
609 typename MapTy::iterator end() { return Map.end(); }
610
612 for (auto &I : Map)
614 }
615
616private:
617 ConstantClass *create(TypeClass *Ty, ValType V, LookupKeyHashed &HashKey) {
618 ConstantClass *Result = V.create(Ty);
619
620 assert(Result->getType() == Ty && "Type specified is not correct!");
621 Map.insert_as(Result, HashKey);
622
623 return Result;
624 }
625
626public:
627 /// Return the specified constant from the map, creating it if necessary.
628 ConstantClass *getOrCreate(TypeClass *Ty, ValType V) {
629 LookupKey Key(Ty, V);
630 /// Hash once, and reuse it for the lookup and the insertion if needed.
631 LookupKeyHashed Lookup(MapInfo::getHashValue(Key), Key);
632
633 ConstantClass *Result = nullptr;
634
635 auto I = Map.find_as(Lookup);
636 if (I == Map.end())
637 Result = create(Ty, V, Lookup);
638 else
639 Result = *I;
640 assert(Result && "Unexpected nullptr");
641
642 return Result;
643 }
644
645 /// Remove this constant from the map
646 void remove(ConstantClass *CP) {
647 typename MapTy::iterator I = Map.find(CP);
648 assert(I != Map.end() && "Constant not found in constant table!");
649 assert(*I == CP && "Didn't find correct element?");
650 Map.erase(I);
651 }
652
654 ConstantClass *CP, Value *From,
655 Constant *To, unsigned NumUpdated = 0,
656 unsigned OperandNo = ~0u) {
657 LookupKey Key(CP->getType(), ValType(Operands, CP));
658 /// Hash once, and reuse it for the lookup and the insertion if needed.
659 LookupKeyHashed Lookup(MapInfo::getHashValue(Key), Key);
660
661 auto ItMap = Map.find_as(Lookup);
662 if (ItMap != Map.end())
663 return *ItMap;
664
665 // Update to the new value. Optimize for the case when we have a single
666 // operand that we're changing, but handle bulk updates efficiently.
667 remove(CP);
668 if (NumUpdated == 1) {
669 assert(OperandNo < CP->getNumOperands() && "Invalid index");
670 assert(CP->getOperand(OperandNo) != To && "I didn't contain From!");
671 CP->setOperand(OperandNo, To);
672 } else {
673 for (unsigned I = 0, E = CP->getNumOperands(); I != E; ++I)
674 if (CP->getOperand(I) == From)
675 CP->setOperand(I, To);
676 }
677 Map.insert_as(CP, Lookup);
678 return nullptr;
679 }
680
681 void dump() const {
682 LLVM_DEBUG(dbgs() << "Constant.cpp: ConstantUniqueMap\n");
683 }
684};
685
687 for (auto &I : Map)
688 delete I;
689}
690
691} // end namespace llvm
692
693#endif // LLVM_LIB_IR_CONSTANTSCONTEXT_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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")
#define I(x, y, z)
Definition: MD5.cpp:58
mir Rename Register Operands
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)
Macro for generating out-of-class operand accessor definitions.
This file defines the SmallVector class.
#define LLVM_DEBUG(...)
Definition: Debug.h:119
static std::optional< unsigned > getOpcode(ArrayRef< VPValue * > Values)
Returns the opcode of Values or ~0 if they do not all agree.
Definition: VPlanSLP.cpp:247
static bool canThrow(const Value *V)
static int Lookup(ArrayRef< TableEntry > Table, unsigned Opcode)
Value * RHS
Value * LHS
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:147
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.
Definition: ArrayRef.h:191
Class to represent array types.
Definition: DerivedTypes.h:398
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.
Definition: Constants.h:433
A constant value that is initialized with an expression using other constant values.
Definition: Constants.h:1120
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.
Definition: Constants.cpp:2347
A signed pointer, in the ptrauth sense.
Definition: Constants.h:1032
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.
MapTy::iterator begin()
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.
Definition: Constants.h:517
This is an important base class in LLVM.
Definition: Constant.h:43
This class represents an Operation in the Expression.
ExtractElementConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to...
ExtractElementConstantExpr(Constant *C1, Constant *C2)
static bool classof(const ConstantExpr *CE)
static bool classof(const Value *V)
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
Class to represent function types.
Definition: DerivedTypes.h:105
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
Definition: Constants.cpp:2827
static bool classof(const ConstantExpr *CE)
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.
bool isCast() const
Definition: Instruction.h:321
bool isBinaryOp() const
Definition: Instruction.h:317
Class to represent pointers.
Definition: DerivedTypes.h:700
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
Definition: DerivedTypes.h:720
Class to represent scalable SIMD vectors.
Definition: DerivedTypes.h:639
ShuffleVectorConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
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)
bool empty() const
Definition: SmallVector.h:82
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:574
void assign(size_type NumElts, ValueParamT Elt)
Definition: SmallVector.h:705
void reserve(size_type N)
Definition: SmallVector.h:664
void push_back(const T &Elt)
Definition: SmallVector.h:414
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
Class to represent struct types.
Definition: DerivedTypes.h:218
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:128
LLVM Value Representation.
Definition: Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:256
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
Definition: Value.h:85
Base class of all SIMD vector types.
Definition: DerivedTypes.h:430
DenseSetIterator< false > iterator
Definition: DenseSet.h:154
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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.
Definition: STLExtras.h:1702
void deleteConstant(Constant *C)
Definition: Constants.cpp:529
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:207
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...
Definition: Casting.h:548
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition: Casting.h:565
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Definition: Hashing.h:595
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
Definition: Hashing.h:469
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...
Definition: DenseMapInfo.h:54
FixedNumOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
Definition: OperandTraits.h:30
unsigned getHash() const
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.
Definition: User.h:42
Information about how a User object was allocated, to be passed into the User constructor.
Definition: User.h:79
Indicates this User has operands co-allocated.
Definition: User.h:60
VariadicOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
Definition: OperandTraits.h:67