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"
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 {
47public:
48 CastConstantExpr(unsigned Opcode, Constant *C, Type *Ty)
49 : ConstantExpr(Ty, Opcode, &Op<0>(), 1) {
50 Op<0>() = C;
51 }
52
53 // allocate space for exactly one operand
54 void *operator new(size_t S) { return User::operator new(S, 1); }
55 void operator delete(void *Ptr) { User::operator delete(Ptr); }
56
58
59 static bool classof(const ConstantExpr *CE) {
60 return Instruction::isCast(CE->getOpcode());
61 }
62 static bool classof(const Value *V) {
63 return isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V));
64 }
65};
66
67/// BinaryConstantExpr - This class is private to Constants.cpp, and is used
68/// behind the scenes to implement binary constant exprs.
69class BinaryConstantExpr final : public ConstantExpr {
70public:
71 BinaryConstantExpr(unsigned Opcode, Constant *C1, Constant *C2,
72 unsigned Flags)
73 : ConstantExpr(C1->getType(), Opcode, &Op<0>(), 2) {
74 Op<0>() = C1;
75 Op<1>() = C2;
77 }
78
79 // allocate space for exactly two operands
80 void *operator new(size_t S) { return User::operator new(S, 2); }
81 void operator delete(void *Ptr) { User::operator delete(Ptr); }
82
83 /// Transparently provide more efficient getOperand methods.
85
86 static bool classof(const ConstantExpr *CE) {
87 return Instruction::isBinaryOp(CE->getOpcode());
88 }
89 static bool classof(const Value *V) {
90 return isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V));
91 }
92};
93
94/// ExtractElementConstantExpr - This class is private to
95/// Constants.cpp, and is used behind the scenes to implement
96/// extractelement constant exprs.
98public:
100 : ConstantExpr(cast<VectorType>(C1->getType())->getElementType(),
101 Instruction::ExtractElement, &Op<0>(), 2) {
102 Op<0>() = C1;
103 Op<1>() = C2;
104 }
105
106 // allocate space for exactly two operands
107 void *operator new(size_t S) { return User::operator new(S, 2); }
108 void operator delete(void *Ptr) { User::operator delete(Ptr); }
109
110 /// Transparently provide more efficient getOperand methods.
112
113 static bool classof(const ConstantExpr *CE) {
114 return CE->getOpcode() == Instruction::ExtractElement;
115 }
116 static bool classof(const Value *V) {
117 return isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V));
118 }
119};
120
121/// InsertElementConstantExpr - This class is private to
122/// Constants.cpp, and is used behind the scenes to implement
123/// insertelement constant exprs.
125public:
127 : ConstantExpr(C1->getType(), Instruction::InsertElement,
128 &Op<0>(), 3) {
129 Op<0>() = C1;
130 Op<1>() = C2;
131 Op<2>() = C3;
132 }
133
134 // allocate space for exactly three operands
135 void *operator new(size_t S) { return User::operator new(S, 3); }
136 void operator delete(void *Ptr) { User::operator delete(Ptr); }
137
138 /// Transparently provide more efficient getOperand methods.
140
141 static bool classof(const ConstantExpr *CE) {
142 return CE->getOpcode() == Instruction::InsertElement;
143 }
144 static bool classof(const Value *V) {
145 return isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V));
146 }
147};
148
149/// ShuffleVectorConstantExpr - This class is private to
150/// Constants.cpp, and is used behind the scenes to implement
151/// shufflevector constant exprs.
153public:
156 cast<VectorType>(C1->getType())->getElementType(),
157 Mask.size(), isa<ScalableVectorType>(C1->getType())),
158 Instruction::ShuffleVector, &Op<0>(), 2) {
160 "Invalid shuffle vector instruction operands!");
161 Op<0>() = C1;
162 Op<1>() = C2;
163 ShuffleMask.assign(Mask.begin(), Mask.end());
166 }
167
170
171 void *operator new(size_t S) { return User::operator new(S, 2); }
172 void operator delete(void *Ptr) { return User::operator delete(Ptr); }
173
174 /// Transparently provide more efficient getOperand methods.
176
177 static bool classof(const ConstantExpr *CE) {
178 return CE->getOpcode() == Instruction::ShuffleVector;
179 }
180 static bool classof(const Value *V) {
181 return isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V));
182 }
183};
184
185/// GetElementPtrConstantExpr - This class is private to Constants.cpp, and is
186/// used behind the scenes to implement getelementptr constant exprs.
188 Type *SrcElementTy;
189 Type *ResElementTy;
190 std::optional<ConstantRange> InRange;
191
193 ArrayRef<Constant *> IdxList, Type *DestTy,
194 std::optional<ConstantRange> InRange);
195
196public:
198 Create(Type *SrcElementTy, Constant *C, ArrayRef<Constant *> IdxList,
199 Type *DestTy, unsigned Flags, std::optional<ConstantRange> InRange) {
200 GetElementPtrConstantExpr *Result = new (IdxList.size() + 1)
201 GetElementPtrConstantExpr(SrcElementTy, C, IdxList, DestTy,
202 std::move(InRange));
203 Result->SubclassOptionalData = Flags;
204 return Result;
205 }
206
207 Type *getSourceElementType() const;
208 Type *getResultElementType() const;
209 std::optional<ConstantRange> getInRange() const;
210
211 /// Transparently provide more efficient getOperand methods.
213
214 static bool classof(const ConstantExpr *CE) {
215 return CE->getOpcode() == Instruction::GetElementPtr;
216 }
217 static bool classof(const Value *V) {
218 return isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V));
219 }
220};
221
222template <>
224 : public FixedNumOperandTraits<CastConstantExpr, 1> {};
226
227template <>
229 : public FixedNumOperandTraits<BinaryConstantExpr, 2> {};
231
232template <>
234 : public FixedNumOperandTraits<ExtractElementConstantExpr, 2> {};
236
237template <>
239 : public FixedNumOperandTraits<InsertElementConstantExpr, 3> {};
241
242template <>
244 : public FixedNumOperandTraits<ShuffleVectorConstantExpr, 2> {};
246
247template <>
249 : public VariadicOperandTraits<GetElementPtrConstantExpr, 1> {};
250
252
253template <class ConstantClass> struct ConstantAggrKeyType;
254struct InlineAsmKeyType;
257
258template <class ConstantClass> struct ConstantInfo;
259template <> struct ConstantInfo<ConstantExpr> {
262};
263template <> struct ConstantInfo<InlineAsm> {
266};
267template <> struct ConstantInfo<ConstantArray> {
270};
271template <> struct ConstantInfo<ConstantStruct> {
274};
275template <> struct ConstantInfo<ConstantVector> {
278};
279template <> struct ConstantInfo<ConstantPtrAuth> {
282};
283
284template <class ConstantClass> struct ConstantAggrKeyType {
286
288
290 : Operands(Operands) {}
291
292 ConstantAggrKeyType(const ConstantClass *C,
294 assert(Storage.empty() && "Expected empty storage");
295 for (unsigned I = 0, E = C->getNumOperands(); I != E; ++I)
296 Storage.push_back(C->getOperand(I));
297 Operands = Storage;
298 }
299
300 bool operator==(const ConstantAggrKeyType &X) const {
301 return Operands == X.Operands;
302 }
303
304 bool operator==(const ConstantClass *C) const {
305 if (Operands.size() != C->getNumOperands())
306 return false;
307 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
308 if (Operands[I] != C->getOperand(I))
309 return false;
310 return true;
311 }
312
313 unsigned getHash() const {
314 return hash_combine_range(Operands.begin(), Operands.end());
315 }
316
318
319 ConstantClass *create(TypeClass *Ty) const {
320 return new (Operands.size()) ConstantClass(Ty, Operands);
321 }
322};
323
332
339
341 : AsmString(Asm->getAsmString()), Constraints(Asm->getConstraintString()),
342 FTy(Asm->getFunctionType()), HasSideEffects(Asm->hasSideEffects()),
343 IsAlignStack(Asm->isAlignStack()), AsmDialect(Asm->getDialect()),
344 CanThrow(Asm->canThrow()) {}
345
346 bool operator==(const InlineAsmKeyType &X) const {
347 return HasSideEffects == X.HasSideEffects &&
348 IsAlignStack == X.IsAlignStack && AsmDialect == X.AsmDialect &&
349 AsmString == X.AsmString && Constraints == X.Constraints &&
350 FTy == X.FTy && CanThrow == X.CanThrow;
351 }
352
353 bool operator==(const InlineAsm *Asm) const {
354 return HasSideEffects == Asm->hasSideEffects() &&
355 IsAlignStack == Asm->isAlignStack() &&
356 AsmDialect == Asm->getDialect() &&
357 AsmString == Asm->getAsmString() &&
358 Constraints == Asm->getConstraintString() &&
359 FTy == Asm->getFunctionType() && CanThrow == Asm->canThrow();
360 }
361
362 unsigned getHash() const {
365 }
366
368
371 return new InlineAsm(FTy, std::string(AsmString), std::string(Constraints),
373 }
374};
375
377private:
378 uint8_t Opcode;
379 uint8_t SubclassOptionalData;
381 ArrayRef<int> ShuffleMask;
382 Type *ExplicitTy;
383 std::optional<ConstantRange> InRange;
384
385 static ArrayRef<int> getShuffleMaskIfValid(const ConstantExpr *CE) {
386 if (CE->getOpcode() == Instruction::ShuffleVector)
387 return CE->getShuffleMask();
388 return std::nullopt;
389 }
390
391 static Type *getSourceElementTypeIfValid(const ConstantExpr *CE) {
392 if (auto *GEPCE = dyn_cast<GetElementPtrConstantExpr>(CE))
393 return GEPCE->getSourceElementType();
394 return nullptr;
395 }
396
397 static std::optional<ConstantRange>
398 getInRangeIfValid(const ConstantExpr *CE) {
399 if (auto *GEPCE = dyn_cast<GetElementPtrConstantExpr>(CE))
400 return GEPCE->getInRange();
401 return std::nullopt;
402 }
403
404public:
406 unsigned short SubclassOptionalData = 0,
407 ArrayRef<int> ShuffleMask = std::nullopt,
408 Type *ExplicitTy = nullptr,
409 std::optional<ConstantRange> InRange = std::nullopt)
410 : Opcode(Opcode), SubclassOptionalData(SubclassOptionalData), Ops(Ops),
411 ShuffleMask(ShuffleMask), ExplicitTy(ExplicitTy),
412 InRange(std::move(InRange)) {}
413
415 : Opcode(CE->getOpcode()),
416 SubclassOptionalData(CE->getRawSubclassOptionalData()), Ops(Operands),
417 ShuffleMask(getShuffleMaskIfValid(CE)),
418 ExplicitTy(getSourceElementTypeIfValid(CE)),
419 InRange(getInRangeIfValid(CE)) {}
420
423 : Opcode(CE->getOpcode()),
424 SubclassOptionalData(CE->getRawSubclassOptionalData()),
425 ShuffleMask(getShuffleMaskIfValid(CE)),
426 ExplicitTy(getSourceElementTypeIfValid(CE)),
427 InRange(getInRangeIfValid(CE)) {
428 assert(Storage.empty() && "Expected empty storage");
429 for (unsigned I = 0, E = CE->getNumOperands(); I != E; ++I)
430 Storage.push_back(CE->getOperand(I));
431 Ops = Storage;
432 }
433
434 static bool rangesEqual(const std::optional<ConstantRange> &A,
435 const std::optional<ConstantRange> &B) {
436 if (!A.has_value() || !B.has_value())
437 return A.has_value() == B.has_value();
438 return A->getBitWidth() == B->getBitWidth() && A == B;
439 }
440
441 bool operator==(const ConstantExprKeyType &X) const {
442 return Opcode == X.Opcode &&
443 SubclassOptionalData == X.SubclassOptionalData && Ops == X.Ops &&
444 ShuffleMask == X.ShuffleMask && ExplicitTy == X.ExplicitTy &&
445 rangesEqual(InRange, X.InRange);
446 }
447
448 bool operator==(const ConstantExpr *CE) const {
449 if (Opcode != CE->getOpcode())
450 return false;
451 if (SubclassOptionalData != CE->getRawSubclassOptionalData())
452 return false;
453 if (Ops.size() != CE->getNumOperands())
454 return false;
455 for (unsigned I = 0, E = Ops.size(); I != E; ++I)
456 if (Ops[I] != CE->getOperand(I))
457 return false;
458 if (ShuffleMask != getShuffleMaskIfValid(CE))
459 return false;
460 if (ExplicitTy != getSourceElementTypeIfValid(CE))
461 return false;
462 if (!rangesEqual(InRange, getInRangeIfValid(CE)))
463 return false;
464 return true;
465 }
466
467 unsigned getHash() const {
468 return hash_combine(
469 Opcode, SubclassOptionalData,
470 hash_combine_range(Ops.begin(), Ops.end()),
471 hash_combine_range(ShuffleMask.begin(), ShuffleMask.end()), ExplicitTy);
472 }
473
475
477 switch (Opcode) {
478 default:
479 if (Instruction::isCast(Opcode))
480 return new CastConstantExpr(Opcode, Ops[0], Ty);
481 if ((Opcode >= Instruction::BinaryOpsBegin &&
482 Opcode < Instruction::BinaryOpsEnd))
483 return new BinaryConstantExpr(Opcode, Ops[0], Ops[1],
484 SubclassOptionalData);
485 llvm_unreachable("Invalid ConstantExpr!");
486 case Instruction::ExtractElement:
487 return new ExtractElementConstantExpr(Ops[0], Ops[1]);
488 case Instruction::InsertElement:
489 return new InsertElementConstantExpr(Ops[0], Ops[1], Ops[2]);
490 case Instruction::ShuffleVector:
491 return new ShuffleVectorConstantExpr(Ops[0], Ops[1], ShuffleMask);
492 case Instruction::GetElementPtr:
494 ExplicitTy, Ops[0], Ops.slice(1), Ty, SubclassOptionalData, InRange);
495 }
496 }
497};
498
501
503
505 : Operands(Operands) {}
506
509 assert(Storage.empty() && "Expected empty storage");
510 for (unsigned I = 0, E = C->getNumOperands(); I != E; ++I)
511 Storage.push_back(cast<Constant>(C->getOperand(I)));
512 Operands = Storage;
513 }
514
516 return Operands == X.Operands;
517 }
518
519 bool operator==(const ConstantPtrAuth *C) const {
520 if (Operands.size() != C->getNumOperands())
521 return false;
522 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
523 if (Operands[I] != C->getOperand(I))
524 return false;
525 return true;
526 }
527
528 unsigned getHash() const {
529 return hash_combine_range(Operands.begin(), Operands.end());
530 }
531
533
535 return new ConstantPtrAuth(Operands[0], cast<ConstantInt>(Operands[1]),
536 cast<ConstantInt>(Operands[2]), Operands[3]);
537 }
538};
539
540// Free memory for a given constant. Assumes the constant has already been
541// removed from all relevant maps.
542void deleteConstant(Constant *C);
543
544template <class ConstantClass> class ConstantUniqueMap {
545public:
548 using LookupKey = std::pair<TypeClass *, ValType>;
549
550 /// Key and hash together, so that we compute the hash only once and reuse it.
551 using LookupKeyHashed = std::pair<unsigned, LookupKey>;
552
553private:
554 struct MapInfo {
555 using ConstantClassInfo = DenseMapInfo<ConstantClass *>;
556
557 static inline ConstantClass *getEmptyKey() {
558 return ConstantClassInfo::getEmptyKey();
559 }
560
561 static inline ConstantClass *getTombstoneKey() {
562 return ConstantClassInfo::getTombstoneKey();
563 }
564
565 static unsigned getHashValue(const ConstantClass *CP) {
567 return getHashValue(LookupKey(CP->getType(), ValType(CP, Storage)));
568 }
569
570 static bool isEqual(const ConstantClass *LHS, const ConstantClass *RHS) {
571 return LHS == RHS;
572 }
573
574 static unsigned getHashValue(const LookupKey &Val) {
575 return hash_combine(Val.first, Val.second.getHash());
576 }
577
578 static unsigned getHashValue(const LookupKeyHashed &Val) {
579 return Val.first;
580 }
581
582 static bool isEqual(const LookupKey &LHS, const ConstantClass *RHS) {
583 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
584 return false;
585 if (LHS.first != RHS->getType())
586 return false;
587 return LHS.second == RHS;
588 }
589
590 static bool isEqual(const LookupKeyHashed &LHS, const ConstantClass *RHS) {
591 return isEqual(LHS.second, RHS);
592 }
593 };
594
595public:
597
598private:
599 MapTy Map;
600
601public:
602 typename MapTy::iterator begin() { return Map.begin(); }
603 typename MapTy::iterator end() { return Map.end(); }
604
606 for (auto &I : Map)
608 }
609
610private:
611 ConstantClass *create(TypeClass *Ty, ValType V, LookupKeyHashed &HashKey) {
612 ConstantClass *Result = V.create(Ty);
613
614 assert(Result->getType() == Ty && "Type specified is not correct!");
615 Map.insert_as(Result, HashKey);
616
617 return Result;
618 }
619
620public:
621 /// Return the specified constant from the map, creating it if necessary.
622 ConstantClass *getOrCreate(TypeClass *Ty, ValType V) {
623 LookupKey Key(Ty, V);
624 /// Hash once, and reuse it for the lookup and the insertion if needed.
625 LookupKeyHashed Lookup(MapInfo::getHashValue(Key), Key);
626
627 ConstantClass *Result = nullptr;
628
629 auto I = Map.find_as(Lookup);
630 if (I == Map.end())
631 Result = create(Ty, V, Lookup);
632 else
633 Result = *I;
634 assert(Result && "Unexpected nullptr");
635
636 return Result;
637 }
638
639 /// Remove this constant from the map
640 void remove(ConstantClass *CP) {
641 typename MapTy::iterator I = Map.find(CP);
642 assert(I != Map.end() && "Constant not found in constant table!");
643 assert(*I == CP && "Didn't find correct element?");
644 Map.erase(I);
645 }
646
648 ConstantClass *CP, Value *From,
649 Constant *To, unsigned NumUpdated = 0,
650 unsigned OperandNo = ~0u) {
651 LookupKey Key(CP->getType(), ValType(Operands, CP));
652 /// Hash once, and reuse it for the lookup and the insertion if needed.
653 LookupKeyHashed Lookup(MapInfo::getHashValue(Key), Key);
654
655 auto ItMap = Map.find_as(Lookup);
656 if (ItMap != Map.end())
657 return *ItMap;
658
659 // Update to the new value. Optimize for the case when we have a single
660 // operand that we're changing, but handle bulk updates efficiently.
661 remove(CP);
662 if (NumUpdated == 1) {
663 assert(OperandNo < CP->getNumOperands() && "Invalid index");
664 assert(CP->getOperand(OperandNo) != To && "I didn't contain From!");
665 CP->setOperand(OperandNo, To);
666 } else {
667 for (unsigned I = 0, E = CP->getNumOperands(); I != E; ++I)
668 if (CP->getOperand(I) == From)
669 CP->setOperand(I, To);
670 }
671 Map.insert_as(CP, Lookup);
672 return nullptr;
673 }
674
675 void dump() const {
676 LLVM_DEBUG(dbgs() << "Constant.cpp: ConstantUniqueMap\n");
677 }
678};
679
681 for (auto &I : Map)
682 delete I;
683}
684
685} // end namespace llvm
686
687#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")
#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)
ConstantArray - Constant Array Declarations.
Definition: Constants.h:424
A constant value that is initialized with an expression using other constant values.
Definition: Constants.h:1084
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:2264
A signed pointer, in the ptrauth sense.
Definition: Constants.h:1012
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:508
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:2734
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:282
bool isBinaryOp() const
Definition: Instruction.h:279
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:593
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
Definition: Hashing.h:471
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
ConstantExprKeyType(unsigned Opcode, ArrayRef< Constant * > Ops, unsigned short SubclassOptionalData=0, ArrayRef< int > ShuffleMask=std::nullopt, Type *ExplicitTy=nullptr, std::optional< ConstantRange > InRange=std::nullopt)
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:52
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