LLVM 19.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"
26#include "llvm/IR/InlineAsm.h"
27#include "llvm/IR/Instruction.h"
31#include "llvm/Support/Debug.h"
34#include <cassert>
35#include <cstddef>
36#include <cstdint>
37#include <utility>
38
39#define DEBUG_TYPE "ir"
40
41namespace llvm {
42
43/// CastConstantExpr - This class is private to Constants.cpp, and is used
44/// behind the scenes to implement cast constant exprs.
45class CastConstantExpr final : public ConstantExpr {
46public:
47 CastConstantExpr(unsigned Opcode, Constant *C, Type *Ty)
48 : ConstantExpr(Ty, Opcode, &Op<0>(), 1) {
49 Op<0>() = C;
50 }
51
52 // allocate space for exactly one operand
53 void *operator new(size_t S) { return User::operator new(S, 1); }
54 void operator delete(void *Ptr) { User::operator delete(Ptr); }
55
57
58 static bool classof(const ConstantExpr *CE) {
59 return Instruction::isCast(CE->getOpcode());
60 }
61 static bool classof(const Value *V) {
62 return isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V));
63 }
64};
65
66/// BinaryConstantExpr - This class is private to Constants.cpp, and is used
67/// behind the scenes to implement binary constant exprs.
68class BinaryConstantExpr final : public ConstantExpr {
69public:
70 BinaryConstantExpr(unsigned Opcode, Constant *C1, Constant *C2,
71 unsigned Flags)
72 : ConstantExpr(C1->getType(), Opcode, &Op<0>(), 2) {
73 Op<0>() = C1;
74 Op<1>() = C2;
76 }
77
78 // allocate space for exactly two operands
79 void *operator new(size_t S) { return User::operator new(S, 2); }
80 void operator delete(void *Ptr) { User::operator delete(Ptr); }
81
82 /// Transparently provide more efficient getOperand methods.
84
85 static bool classof(const ConstantExpr *CE) {
86 return Instruction::isBinaryOp(CE->getOpcode());
87 }
88 static bool classof(const Value *V) {
89 return isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V));
90 }
91};
92
93/// ExtractElementConstantExpr - This class is private to
94/// Constants.cpp, and is used behind the scenes to implement
95/// extractelement constant exprs.
97public:
99 : ConstantExpr(cast<VectorType>(C1->getType())->getElementType(),
100 Instruction::ExtractElement, &Op<0>(), 2) {
101 Op<0>() = C1;
102 Op<1>() = C2;
103 }
104
105 // allocate space for exactly two operands
106 void *operator new(size_t S) { return User::operator new(S, 2); }
107 void operator delete(void *Ptr) { User::operator delete(Ptr); }
108
109 /// Transparently provide more efficient getOperand methods.
111
112 static bool classof(const ConstantExpr *CE) {
113 return CE->getOpcode() == Instruction::ExtractElement;
114 }
115 static bool classof(const Value *V) {
116 return isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V));
117 }
118};
119
120/// InsertElementConstantExpr - This class is private to
121/// Constants.cpp, and is used behind the scenes to implement
122/// insertelement constant exprs.
124public:
126 : ConstantExpr(C1->getType(), Instruction::InsertElement,
127 &Op<0>(), 3) {
128 Op<0>() = C1;
129 Op<1>() = C2;
130 Op<2>() = C3;
131 }
132
133 // allocate space for exactly three operands
134 void *operator new(size_t S) { return User::operator new(S, 3); }
135 void operator delete(void *Ptr) { User::operator delete(Ptr); }
136
137 /// Transparently provide more efficient getOperand methods.
139
140 static bool classof(const ConstantExpr *CE) {
141 return CE->getOpcode() == Instruction::InsertElement;
142 }
143 static bool classof(const Value *V) {
144 return isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V));
145 }
146};
147
148/// ShuffleVectorConstantExpr - This class is private to
149/// Constants.cpp, and is used behind the scenes to implement
150/// shufflevector constant exprs.
152public:
155 cast<VectorType>(C1->getType())->getElementType(),
156 Mask.size(), isa<ScalableVectorType>(C1->getType())),
157 Instruction::ShuffleVector, &Op<0>(), 2) {
159 "Invalid shuffle vector instruction operands!");
160 Op<0>() = C1;
161 Op<1>() = C2;
162 ShuffleMask.assign(Mask.begin(), Mask.end());
165 }
166
169
170 void *operator new(size_t S) { return User::operator new(S, 2); }
171 void operator delete(void *Ptr) { return User::operator delete(Ptr); }
172
173 /// Transparently provide more efficient getOperand methods.
175
176 static bool classof(const ConstantExpr *CE) {
177 return CE->getOpcode() == Instruction::ShuffleVector;
178 }
179 static bool classof(const Value *V) {
180 return isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V));
181 }
182};
183
184/// GetElementPtrConstantExpr - This class is private to Constants.cpp, and is
185/// used behind the scenes to implement getelementptr constant exprs.
187 Type *SrcElementTy;
188 Type *ResElementTy;
189 std::optional<ConstantRange> InRange;
190
192 ArrayRef<Constant *> IdxList, Type *DestTy,
193 std::optional<ConstantRange> InRange);
194
195public:
197 Create(Type *SrcElementTy, Constant *C, ArrayRef<Constant *> IdxList,
198 Type *DestTy, unsigned Flags, std::optional<ConstantRange> InRange) {
199 GetElementPtrConstantExpr *Result = new (IdxList.size() + 1)
200 GetElementPtrConstantExpr(SrcElementTy, C, IdxList, DestTy,
201 std::move(InRange));
202 Result->SubclassOptionalData = Flags;
203 return Result;
204 }
205
206 Type *getSourceElementType() const;
207 Type *getResultElementType() const;
208 std::optional<ConstantRange> getInRange() const;
209
210 /// Transparently provide more efficient getOperand methods.
212
213 static bool classof(const ConstantExpr *CE) {
214 return CE->getOpcode() == Instruction::GetElementPtr;
215 }
216 static bool classof(const Value *V) {
217 return isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V));
218 }
219};
220
221// CompareConstantExpr - This class is private to Constants.cpp, and is used
222// behind the scenes to implement ICmp and FCmp constant expressions. This is
223// needed in order to store the predicate value for these instructions.
224class CompareConstantExpr final : public ConstantExpr {
225public:
226 unsigned short predicate;
228 unsigned short pred, Constant* LHS, Constant* RHS)
229 : ConstantExpr(ty, opc, &Op<0>(), 2), predicate(pred) {
230 Op<0>() = LHS;
231 Op<1>() = RHS;
232 }
233
234 // allocate space for exactly two operands
235 void *operator new(size_t S) { return User::operator new(S, 2); }
236 void operator delete(void *Ptr) { return User::operator delete(Ptr); }
237
238 /// Transparently provide more efficient getOperand methods.
240
241 static bool classof(const ConstantExpr *CE) {
242 return CE->getOpcode() == Instruction::ICmp ||
243 CE->getOpcode() == Instruction::FCmp;
244 }
245 static bool classof(const Value *V) {
246 return isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V));
247 }
248};
249
250template <>
252 : public FixedNumOperandTraits<CastConstantExpr, 1> {};
254
255template <>
257 : public FixedNumOperandTraits<BinaryConstantExpr, 2> {};
259
260template <>
262 : public FixedNumOperandTraits<ExtractElementConstantExpr, 2> {};
264
265template <>
267 : public FixedNumOperandTraits<InsertElementConstantExpr, 3> {};
269
270template <>
272 : public FixedNumOperandTraits<ShuffleVectorConstantExpr, 2> {};
274
275template <>
277 : public VariadicOperandTraits<GetElementPtrConstantExpr, 1> {};
278
280
281template <>
283 : public FixedNumOperandTraits<CompareConstantExpr, 2> {};
285
286template <class ConstantClass> struct ConstantAggrKeyType;
287struct InlineAsmKeyType;
289
290template <class ConstantClass> struct ConstantInfo;
291template <> struct ConstantInfo<ConstantExpr> {
294};
295template <> struct ConstantInfo<InlineAsm> {
298};
299template <> struct ConstantInfo<ConstantArray> {
302};
303template <> struct ConstantInfo<ConstantStruct> {
306};
307template <> struct ConstantInfo<ConstantVector> {
310};
311
312template <class ConstantClass> struct ConstantAggrKeyType {
314
316
318 : Operands(Operands) {}
319
320 ConstantAggrKeyType(const ConstantClass *C,
322 assert(Storage.empty() && "Expected empty storage");
323 for (unsigned I = 0, E = C->getNumOperands(); I != E; ++I)
324 Storage.push_back(C->getOperand(I));
325 Operands = Storage;
326 }
327
328 bool operator==(const ConstantAggrKeyType &X) const {
329 return Operands == X.Operands;
330 }
331
332 bool operator==(const ConstantClass *C) const {
333 if (Operands.size() != C->getNumOperands())
334 return false;
335 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
336 if (Operands[I] != C->getOperand(I))
337 return false;
338 return true;
339 }
340
341 unsigned getHash() const {
342 return hash_combine_range(Operands.begin(), Operands.end());
343 }
344
346
347 ConstantClass *create(TypeClass *Ty) const {
348 return new (Operands.size()) ConstantClass(Ty, Operands);
349 }
350};
351
360
367
369 : AsmString(Asm->getAsmString()), Constraints(Asm->getConstraintString()),
370 FTy(Asm->getFunctionType()), HasSideEffects(Asm->hasSideEffects()),
371 IsAlignStack(Asm->isAlignStack()), AsmDialect(Asm->getDialect()),
372 CanThrow(Asm->canThrow()) {}
373
374 bool operator==(const InlineAsmKeyType &X) const {
375 return HasSideEffects == X.HasSideEffects &&
376 IsAlignStack == X.IsAlignStack && AsmDialect == X.AsmDialect &&
377 AsmString == X.AsmString && Constraints == X.Constraints &&
378 FTy == X.FTy && CanThrow == X.CanThrow;
379 }
380
381 bool operator==(const InlineAsm *Asm) const {
382 return HasSideEffects == Asm->hasSideEffects() &&
383 IsAlignStack == Asm->isAlignStack() &&
384 AsmDialect == Asm->getDialect() &&
385 AsmString == Asm->getAsmString() &&
386 Constraints == Asm->getConstraintString() &&
387 FTy == Asm->getFunctionType() && CanThrow == Asm->canThrow();
388 }
389
390 unsigned getHash() const {
393 }
394
396
399 return new InlineAsm(FTy, std::string(AsmString), std::string(Constraints),
401 }
402};
403
405private:
406 uint8_t Opcode;
407 uint8_t SubclassOptionalData;
408 uint16_t SubclassData;
410 ArrayRef<int> ShuffleMask;
411 Type *ExplicitTy;
412 std::optional<ConstantRange> InRange;
413
414 static ArrayRef<int> getShuffleMaskIfValid(const ConstantExpr *CE) {
415 if (CE->getOpcode() == Instruction::ShuffleVector)
416 return CE->getShuffleMask();
417 return std::nullopt;
418 }
419
420 static Type *getSourceElementTypeIfValid(const ConstantExpr *CE) {
421 if (auto *GEPCE = dyn_cast<GetElementPtrConstantExpr>(CE))
422 return GEPCE->getSourceElementType();
423 return nullptr;
424 }
425
426 static std::optional<ConstantRange>
427 getInRangeIfValid(const ConstantExpr *CE) {
428 if (auto *GEPCE = dyn_cast<GetElementPtrConstantExpr>(CE))
429 return GEPCE->getInRange();
430 return std::nullopt;
431 }
432
433public:
435 unsigned short SubclassData = 0,
436 unsigned short SubclassOptionalData = 0,
437 ArrayRef<int> ShuffleMask = std::nullopt,
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)) {}
443
445 : Opcode(CE->getOpcode()),
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)) {}
451
454 : Opcode(CE->getOpcode()),
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)
462 Storage.push_back(CE->getOperand(I));
463 Ops = Storage;
464 }
465
466 static bool rangesEqual(const std::optional<ConstantRange> &A,
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;
471 }
472
473 bool operator==(const ConstantExprKeyType &X) const {
474 return Opcode == X.Opcode && SubclassData == X.SubclassData &&
475 SubclassOptionalData == X.SubclassOptionalData && Ops == X.Ops &&
476 ShuffleMask == X.ShuffleMask && ExplicitTy == X.ExplicitTy &&
477 rangesEqual(InRange, X.InRange);
478 }
479
480 bool operator==(const ConstantExpr *CE) const {
481 if (Opcode != CE->getOpcode())
482 return false;
483 if (SubclassOptionalData != CE->getRawSubclassOptionalData())
484 return false;
485 if (Ops.size() != CE->getNumOperands())
486 return false;
487 if (SubclassData != (CE->isCompare() ? CE->getPredicate() : 0))
488 return false;
489 for (unsigned I = 0, E = Ops.size(); I != E; ++I)
490 if (Ops[I] != CE->getOperand(I))
491 return false;
492 if (ShuffleMask != getShuffleMaskIfValid(CE))
493 return false;
494 if (ExplicitTy != getSourceElementTypeIfValid(CE))
495 return false;
496 if (!rangesEqual(InRange, getInRangeIfValid(CE)))
497 return false;
498 return true;
499 }
500
501 unsigned getHash() const {
502 return hash_combine(
503 Opcode, SubclassOptionalData, SubclassData,
504 hash_combine_range(Ops.begin(), Ops.end()),
505 hash_combine_range(ShuffleMask.begin(), ShuffleMask.end()), ExplicitTy);
506 }
507
509
511 switch (Opcode) {
512 default:
513 if (Instruction::isCast(Opcode))
514 return new CastConstantExpr(Opcode, Ops[0], Ty);
515 if ((Opcode >= Instruction::BinaryOpsBegin &&
516 Opcode < Instruction::BinaryOpsEnd))
517 return new BinaryConstantExpr(Opcode, Ops[0], Ops[1],
518 SubclassOptionalData);
519 llvm_unreachable("Invalid ConstantExpr!");
520 case Instruction::ExtractElement:
521 return new ExtractElementConstantExpr(Ops[0], Ops[1]);
522 case Instruction::InsertElement:
523 return new InsertElementConstantExpr(Ops[0], Ops[1], Ops[2]);
524 case Instruction::ShuffleVector:
525 return new ShuffleVectorConstantExpr(Ops[0], Ops[1], ShuffleMask);
526 case Instruction::GetElementPtr:
528 ExplicitTy, Ops[0], Ops.slice(1), Ty, SubclassOptionalData, InRange);
529 case Instruction::ICmp:
530 return new CompareConstantExpr(Ty, Instruction::ICmp, SubclassData,
531 Ops[0], Ops[1]);
532 case Instruction::FCmp:
533 return new CompareConstantExpr(Ty, Instruction::FCmp, SubclassData,
534 Ops[0], Ops[1]);
535 }
536 }
537};
538
539// Free memory for a given constant. Assumes the constant has already been
540// removed from all relevant maps.
541void deleteConstant(Constant *C);
542
543template <class ConstantClass> class ConstantUniqueMap {
544public:
547 using LookupKey = std::pair<TypeClass *, ValType>;
548
549 /// Key and hash together, so that we compute the hash only once and reuse it.
550 using LookupKeyHashed = std::pair<unsigned, LookupKey>;
551
552private:
553 struct MapInfo {
554 using ConstantClassInfo = DenseMapInfo<ConstantClass *>;
555
556 static inline ConstantClass *getEmptyKey() {
557 return ConstantClassInfo::getEmptyKey();
558 }
559
560 static inline ConstantClass *getTombstoneKey() {
561 return ConstantClassInfo::getTombstoneKey();
562 }
563
564 static unsigned getHashValue(const ConstantClass *CP) {
566 return getHashValue(LookupKey(CP->getType(), ValType(CP, Storage)));
567 }
568
569 static bool isEqual(const ConstantClass *LHS, const ConstantClass *RHS) {
570 return LHS == RHS;
571 }
572
573 static unsigned getHashValue(const LookupKey &Val) {
574 return hash_combine(Val.first, Val.second.getHash());
575 }
576
577 static unsigned getHashValue(const LookupKeyHashed &Val) {
578 return Val.first;
579 }
580
581 static bool isEqual(const LookupKey &LHS, const ConstantClass *RHS) {
582 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
583 return false;
584 if (LHS.first != RHS->getType())
585 return false;
586 return LHS.second == RHS;
587 }
588
589 static bool isEqual(const LookupKeyHashed &LHS, const ConstantClass *RHS) {
590 return isEqual(LHS.second, RHS);
591 }
592 };
593
594public:
596
597private:
598 MapTy Map;
599
600public:
601 typename MapTy::iterator begin() { return Map.begin(); }
602 typename MapTy::iterator end() { return Map.end(); }
603
605 for (auto &I : Map)
607 }
608
609private:
610 ConstantClass *create(TypeClass *Ty, ValType V, LookupKeyHashed &HashKey) {
611 ConstantClass *Result = V.create(Ty);
612
613 assert(Result->getType() == Ty && "Type specified is not correct!");
614 Map.insert_as(Result, HashKey);
615
616 return Result;
617 }
618
619public:
620 /// Return the specified constant from the map, creating it if necessary.
621 ConstantClass *getOrCreate(TypeClass *Ty, ValType V) {
622 LookupKey Key(Ty, V);
623 /// Hash once, and reuse it for the lookup and the insertion if needed.
624 LookupKeyHashed Lookup(MapInfo::getHashValue(Key), Key);
625
626 ConstantClass *Result = nullptr;
627
628 auto I = Map.find_as(Lookup);
629 if (I == Map.end())
630 Result = create(Ty, V, Lookup);
631 else
632 Result = *I;
633 assert(Result && "Unexpected nullptr");
634
635 return Result;
636 }
637
638 /// Remove this constant from the map
639 void remove(ConstantClass *CP) {
640 typename MapTy::iterator I = Map.find(CP);
641 assert(I != Map.end() && "Constant not found in constant table!");
642 assert(*I == CP && "Didn't find correct element?");
643 Map.erase(I);
644 }
645
647 ConstantClass *CP, Value *From,
648 Constant *To, unsigned NumUpdated = 0,
649 unsigned OperandNo = ~0u) {
650 LookupKey Key(CP->getType(), ValType(Operands, CP));
651 /// Hash once, and reuse it for the lookup and the insertion if needed.
652 LookupKeyHashed Lookup(MapInfo::getHashValue(Key), Key);
653
654 auto ItMap = Map.find_as(Lookup);
655 if (ItMap != Map.end())
656 return *ItMap;
657
658 // Update to the new value. Optimize for the case when we have a single
659 // operand that we're changing, but handle bulk updates efficiently.
660 remove(CP);
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);
665 } else {
666 for (unsigned I = 0, E = CP->getNumOperands(); I != E; ++I)
667 if (CP->getOperand(I) == From)
668 CP->setOperand(I, To);
669 }
670 Map.insert_as(CP, Lookup);
671 return nullptr;
672 }
673
674 void dump() const {
675 LLVM_DEBUG(dbgs() << "Constant.cpp: ConstantUniqueMap\n");
676 }
677};
678
680 for (auto &I : Map)
681 delete I;
682}
683
684} // end namespace llvm
685
686#endif // LLVM_LIB_IR_CONSTANTSCONTEXT_H
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...
#define LLVM_DEBUG(X)
Definition: Debug.h:101
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")
hexagon gen pred
#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.
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.
Definition: VPlanSLP.cpp:191
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
iterator end() const
Definition: ArrayRef.h:154
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:165
iterator begin() const
Definition: ArrayRef.h:153
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:195
Class to represent array types.
Definition: DerivedTypes.h:371
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.
Definition: Constants.h:423
A constant value that is initialized with an expression using other constant values.
Definition: Constants.h:1017
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.
Definition: Constants.cpp:2159
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:507
This is an important base class in LLVM.
Definition: Constant.h:41
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:103
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:2715
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:260
bool isBinaryOp() const
Definition: Instruction.h:257
Class to represent pointers.
Definition: DerivedTypes.h:646
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:662
Class to represent scalable SIMD vectors.
Definition: DerivedTypes.h:586
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 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)
bool empty() const
Definition: SmallVector.h:94
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:586
void assign(size_type NumElts, ValueParamT Elt)
Definition: SmallVector.h:717
void push_back(const T &Elt)
Definition: SmallVector.h:426
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Class to represent struct types.
Definition: DerivedTypes.h:216
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
Definition: Value.h:84
Base class of all SIMD vector types.
Definition: DerivedTypes.h:403
#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:1680
void deleteConstant(Constant *C)
Definition: Constants.cpp:512
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
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
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1849
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:613
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
Definition: Hashing.h:491
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
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...
Definition: DenseMapInfo.h:50
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
VariadicOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
Definition: OperandTraits.h:68