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:

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

67};

68

69

70

73

74public:

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

96};

97

98

99

100

103

104public:

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 }

125};

126

127

128

129

132

133public:

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 }

154};

155

156

157

158

161

162public:

167 Instruction::ShuffleVector, AllocMarker) {

169 "Invalid shuffle vector instruction operands!");

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

185

187 return CE->getOpcode() == Instruction::ShuffleVector;

188 }

192};

193

194

195

197 Type *SrcElementTy;

198 Type *ResElementTy;

199 std::optional InRange;

200

201 GetElementPtrConstantExpr(Type *SrcElementTy, Constant *C,

203 std::optional InRange,

205

206public:

207 static GetElementPtrConstantExpr *

209 Type *DestTy, unsigned Flags, std::optional InRange) {

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

220 std::optional getInRange() const;

221

222

224

226 return CE->getOpcode() == Instruction::GetElementPtr;

227 }

231};

232

233template <>

237

238template <>

242

243template <>

247

248template <>

252

253template <>

257

258template <>

261

263

268

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

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

326

328

331 return new (AllocMarker) ConstantClass(Ty, Operands, AllocMarker);

332 }

333};

334

343

350

356

363

368 AsmString == Asm->getAsmString() &&

369 Constraints == Asm->getConstraintString() &&

370 FTy == Asm->getFunctionType() && CanThrow == Asm->canThrow();

371 }

372

377

379

385};

386

388private:

390 uint8_t SubclassOptionalData;

393 Type *ExplicitTy;

394 std::optional InRange;

395

397 if (CE->getOpcode() == Instruction::ShuffleVector)

398 return CE->getShuffleMask();

399 return {};

400 }

401

402 static Type *getSourceElementTypeIfValid(const ConstantExpr *CE) {

404 return GEPCE->getSourceElementType();

405 return nullptr;

406 }

407

408 static std::optional

411 return GEPCE->getInRange();

412 return std::nullopt;

413 }

414

415public:

417 unsigned short SubclassOptionalData = 0,

419 Type *ExplicitTy = nullptr,

420 std::optional InRange = std::nullopt)

421 : Opcode(Opcode), SubclassOptionalData(SubclassOptionalData), Ops(Ops),

422 ShuffleMask(ShuffleMask), ExplicitTy(ExplicitTy),

424

427 SubclassOptionalData(CE->getRawSubclassOptionalData()), Ops(Operands),

428 ShuffleMask(getShuffleMaskIfValid(CE)),

429 ExplicitTy(getSourceElementTypeIfValid(CE)),

430 InRange(getInRangeIfValid(CE)) {}

431

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 &A,

446 const std::optional &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

453 return Opcode == X.Opcode &&

454 SubclassOptionalData == X.SubclassOptionalData && Ops == X.Ops &&

455 ShuffleMask == X.ShuffleMask && ExplicitTy == X.ExplicitTy &&

457 }

458

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

482

484

486 switch (Opcode) {

487 default:

492 SubclassOptionalData);

494 case Instruction::ExtractElement:

496 case Instruction::InsertElement:

498 case Instruction::ShuffleVector:

500 case Instruction::GetElementPtr:

502 ExplicitTy, Ops[0], Ops.slice(1), Ty, SubclassOptionalData, InRange);

503 }

504 }

505};

506

509

511

514

517 assert(Storage.empty() && "Expected empty storage");

518 for (unsigned I = 0, E = C->getNumOperands(); I != E; ++I)

521 }

522

526

528 if (Operands.size() != C->getNumOperands())

529 return false;

530 for (unsigned I = 0, E = Operands.size(); I != E; ++I)

532 return false;

533 return true;

534 }

535

537

539

545};

546

547

548

550

552public:

555 using LookupKey = std::pair<TypeClass *, ValType>;

556

557

559

560private:

561 struct MapInfo {

563

564 static inline ConstantClass *getEmptyKey() {

565 return ConstantClassInfo::getEmptyKey();

566 }

567

568 static inline ConstantClass *getTombstoneKey() {

569 return ConstantClassInfo::getTombstoneKey();

570 }

571

572 static unsigned getHashValue(const ConstantClass *CP) {

574 return getHashValue(LookupKey(CP->getType(), ValType(CP, Storage)));

575 }

576

577 static bool isEqual(const ConstantClass *LHS, const ConstantClass *RHS) {

579 }

580

581 static unsigned getHashValue(const LookupKey &Val) {

582 return hash_combine(Val.first, Val.second.getHash());

583 }

584

585 static unsigned getHashValue(const LookupKeyHashed &Val) {

586 return Val.first;

587 }

588

590 if (RHS == getEmptyKey() || RHS == getTombstoneKey())

591 return false;

592 if (LHS.first != RHS->getType())

593 return false;

594 return LHS.second == RHS;

595 }

596

599 }

600 };

601

602public:

604

605private:

607

608public:

611

613 for (auto &I : Map)

615 }

616

617private:

619 ConstantClass *Result = V.create(Ty);

620

621 assert(Result->getType() == Ty && "Type specified is not correct!");

622 Map.insert_as(Result, HashKey);

623

624 return Result;

625 }

626

627public:

628

631

633

634 ConstantClass *Result = nullptr;

635

636 auto I = Map.find_as(Lookup);

637 if (I == Map.end())

638 Result = create(Ty, V, Lookup);

639 else

640 Result = *I;

641 assert(Result && "Unexpected nullptr");

642

643 return Result;

644 }

645

646

649 assert(I != Map.end() && "Constant not found in constant table!");

650 assert(*I == CP && "Didn't find correct element?");

651 Map.erase(I);

652 }

653

655 ConstantClass *CP, Value *From,

656 Constant *To, unsigned NumUpdated = 0,

657 unsigned OperandNo = ~0u) {

659

661

662 auto ItMap = Map.find_as(Lookup);

663 if (ItMap != Map.end())

664 return *ItMap;

665

666

667

669 if (NumUpdated == 1) {

670 assert(OperandNo < CP->getNumOperands() && "Invalid index");

671 assert(CP->getOperand(OperandNo) != To && "I didn't contain From!");

672 CP->setOperand(OperandNo, To);

673 } else {

674 for (unsigned I = 0, E = CP->getNumOperands(); I != E; ++I)

675 if (CP->getOperand(I) == From)

676 CP->setOperand(I, To);

677 }

678 Map.insert_as(CP, Lookup);

679 return nullptr;

680 }

681

685};

686

688 for (auto &I : Map)

689 delete I;

690}

691

692}

693

694#endif

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")

static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")

static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")

static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-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.

const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]

static bool InRange(int64_t Value, unsigned short Shift, int LBound, int HBound)

#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)

Macro for generating out-of-class operand accessor definitions.

This file defines the SmallVector class.

static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton 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.

Class to represent array types.

BinaryConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to impleme...

Definition ConstantsContext.h:71

DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)

Transparently provide more efficient getOperand methods.

static bool classof(const ConstantExpr *CE)

Definition ConstantsContext.h:90

static bool classof(const Value *V)

Definition ConstantsContext.h:93

BinaryConstantExpr(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags)

Definition ConstantsContext.h:75

CastConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to implement...

Definition ConstantsContext.h:46

static bool classof(const Value *V)

Definition ConstantsContext.h:64

static bool classof(const ConstantExpr *CE)

Definition ConstantsContext.h:61

CastConstantExpr(unsigned Opcode, Constant *C, Type *Ty)

Definition ConstantsContext.h:50

DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)

ConstantArray - Constant Array Declarations.

A constant value that is initialized with an expression using other constant values.

ConstantExpr(Type *ty, unsigned Opcode, AllocInfo AllocInfo)

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.

A signed pointer, in the ptrauth sense.

Definition ConstantsContext.h:551

typename ConstantInfo< ConstantClass >::ValType ValType

Definition ConstantsContext.h:553

typename ConstantInfo< ConstantClass >::TypeClass TypeClass

Definition ConstantsContext.h:554

ConstantClass * getOrCreate(TypeClass *Ty, ValType V)

Return the specified constant from the map, creating it if necessary.

Definition ConstantsContext.h:629

std::pair< unsigned, LookupKey > LookupKeyHashed

Key and hash together, so that we compute the hash only once and reuse it.

Definition ConstantsContext.h:558

void freeConstants()

Definition ConstantsContext.h:612

MapTy::iterator begin()

Definition ConstantsContext.h:609

MapTy::iterator end()

Definition ConstantsContext.h:610

void dump() const

Definition ConstantsContext.h:682

void remove(ConstantClass *CP)

Remove this constant from the map.

Definition ConstantsContext.h:647

ConstantClass * replaceOperandsInPlace(ArrayRef< Constant * > Operands, ConstantClass *CP, Value *From, Constant *To, unsigned NumUpdated=0, unsigned OperandNo=~0u)

Definition ConstantsContext.h:654

DenseSet< ConstantClass *, MapInfo > MapTy

Definition ConstantsContext.h:603

std::pair< TypeClass *, ValType > LookupKey

Definition ConstantsContext.h:555

Constant Vector Declarations.

This is an important base class in LLVM.

Implements a dense probed hash-table based set.

Class to represent function types.

GetElementPtrConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...

Definition ConstantsContext.h:196

DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)

Transparently provide more efficient getOperand methods.

std::optional< ConstantRange > getInRange() const

static bool classof(const ConstantExpr *CE)

Definition ConstantsContext.h:225

Type * getResultElementType() const

Type * getSourceElementType() const

static bool classof(const Value *V)

Definition ConstantsContext.h:228

static GetElementPtrConstantExpr * Create(Type *SrcElementTy, Constant *C, ArrayRef< Constant * > IdxList, Type *DestTy, unsigned Flags, std::optional< ConstantRange > InRange)

Definition ConstantsContext.h:208

InsertElementConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...

Definition ConstantsContext.h:130

static bool classof(const ConstantExpr *CE)

Definition ConstantsContext.h:148

InsertElementConstantExpr(Constant *C1, Constant *C2, Constant *C3)

Definition ConstantsContext.h:134

static bool classof(const Value *V)

Definition ConstantsContext.h:151

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 ...

Definition ConstantsContext.h:159

Constant * ShuffleMaskForBitcode

Definition ConstantsContext.h:178

SmallVector< int, 4 > ShuffleMask

Definition ConstantsContext.h:177

static bool classof(const ConstantExpr *CE)

Definition ConstantsContext.h:186

ShuffleVectorConstantExpr(Constant *C1, Constant *C2, ArrayRef< int > Mask)

Definition ConstantsContext.h:163

DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)

Transparently provide more efficient getOperand methods.

static bool classof(const Value *V)

Definition ConstantsContext.h:189

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)

This class consists of common code factored out of the SmallVector class to reduce code duplication b...

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.

DenseSetIterator< false > iterator

#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.

decltype(auto) dyn_cast(const From &Val)

dyn_cast - Return the argument parameter cast to the specified type.

void deleteConstant(Constant *C)

LLVM_ABI 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...

LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key

DWARFExpression::Operation Op

OutputIt move(R &&Range, OutputIt Out)

Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.

decltype(auto) cast(const From &Val)

cast - Return the argument parameter cast to the specified type.

hash_code hash_combine(const Ts &...args)

Combine values into a single hash_code.

hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)

Compute a hash_code for a sequence of values.

Implement std::hash so that hash_code can be used in STL containers.

Definition ConstantsContext.h:295

bool operator==(const ConstantClass *C) const

Definition ConstantsContext.h:316

unsigned getHash() const

Definition ConstantsContext.h:325

ArrayRef< Constant * > Operands

Definition ConstantsContext.h:296

ConstantAggrKeyType(ArrayRef< Constant * > Operands)

Definition ConstantsContext.h:298

ConstantAggrKeyType(ArrayRef< Constant * > Operands, const ConstantClass *)

Definition ConstantsContext.h:300

typename ConstantInfo< ConstantArray >::TypeClass TypeClass

Definition ConstantsContext.h:327

ConstantClass * create(TypeClass *Ty) const

Definition ConstantsContext.h:329

ConstantAggrKeyType(const ConstantClass *C, SmallVectorImpl< Constant * > &Storage)

Definition ConstantsContext.h:303

bool operator==(const ConstantAggrKeyType &X) const

Definition ConstantsContext.h:312

Definition ConstantsContext.h:387

ConstantExprKeyType(unsigned Opcode, ArrayRef< Constant * > Ops, unsigned short SubclassOptionalData=0, ArrayRef< int > ShuffleMask={}, Type *ExplicitTy=nullptr, std::optional< ConstantRange > InRange=std::nullopt)

Definition ConstantsContext.h:416

ConstantExprKeyType(const ConstantExpr *CE, SmallVectorImpl< Constant * > &Storage)

Definition ConstantsContext.h:432

unsigned getHash() const

Definition ConstantsContext.h:478

ConstantInfo< ConstantExpr >::TypeClass TypeClass

Definition ConstantsContext.h:483

static bool rangesEqual(const std::optional< ConstantRange > &A, const std::optional< ConstantRange > &B)

Definition ConstantsContext.h:445

ConstantExpr * create(TypeClass *Ty) const

Definition ConstantsContext.h:485

bool operator==(const ConstantExprKeyType &X) const

Definition ConstantsContext.h:452

bool operator==(const ConstantExpr *CE) const

Definition ConstantsContext.h:459

ConstantExprKeyType(ArrayRef< Constant * > Operands, const ConstantExpr *CE)

Definition ConstantsContext.h:425

ConstantAggrKeyType< ConstantArray > ValType

Definition ConstantsContext.h:279

ArrayType TypeClass

Definition ConstantsContext.h:280

Type TypeClass

Definition ConstantsContext.h:272

ConstantExprKeyType ValType

Definition ConstantsContext.h:271

Type TypeClass

Definition ConstantsContext.h:292

ConstantPtrAuthKeyType ValType

Definition ConstantsContext.h:291

ConstantAggrKeyType< ConstantStruct > ValType

Definition ConstantsContext.h:283

StructType TypeClass

Definition ConstantsContext.h:284

ConstantAggrKeyType< ConstantVector > ValType

Definition ConstantsContext.h:287

VectorType TypeClass

Definition ConstantsContext.h:288

InlineAsmKeyType ValType

Definition ConstantsContext.h:275

PointerType TypeClass

Definition ConstantsContext.h:276

Definition ConstantsContext.h:269

Definition ConstantsContext.h:507

bool operator==(const ConstantPtrAuthKeyType &X) const

Definition ConstantsContext.h:523

ArrayRef< Constant * > Operands

Definition ConstantsContext.h:508

ConstantPtrAuthKeyType(ArrayRef< Constant * > Operands, const ConstantPtrAuth *)

Definition ConstantsContext.h:512

unsigned getHash() const

Definition ConstantsContext.h:536

ConstantPtrAuthKeyType(const ConstantPtrAuth *C, SmallVectorImpl< Constant * > &Storage)

Definition ConstantsContext.h:515

ConstantPtrAuthKeyType(ArrayRef< Constant * > Operands)

Definition ConstantsContext.h:510

bool operator==(const ConstantPtrAuth *C) const

Definition ConstantsContext.h:527

ConstantPtrAuth * create(TypeClass *Ty) const

Definition ConstantsContext.h:540

ConstantInfo< ConstantPtrAuth >::TypeClass TypeClass

Definition ConstantsContext.h:538

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...

Definition ConstantsContext.h:335

unsigned getHash() const

Definition ConstantsContext.h:373

bool HasSideEffects

Definition ConstantsContext.h:339

bool operator==(const InlineAsmKeyType &X) const

Definition ConstantsContext.h:357

bool IsAlignStack

Definition ConstantsContext.h:340

bool CanThrow

Definition ConstantsContext.h:342

ConstantInfo< InlineAsm >::TypeClass TypeClass

Definition ConstantsContext.h:378

StringRef AsmString

Definition ConstantsContext.h:336

InlineAsm * create(TypeClass *Ty) const

Definition ConstantsContext.h:380

bool operator==(const InlineAsm *Asm) const

Definition ConstantsContext.h:364

InlineAsmKeyType(const InlineAsm *Asm, SmallVectorImpl< Constant * > &)

Definition ConstantsContext.h:351

StringRef Constraints

Definition ConstantsContext.h:337

InlineAsmKeyType(StringRef AsmString, StringRef Constraints, FunctionType *FTy, bool HasSideEffects, bool IsAlignStack, InlineAsm::AsmDialect AsmDialect, bool canThrow)

Definition ConstantsContext.h:344

InlineAsm::AsmDialect AsmDialect

Definition ConstantsContext.h:341

FunctionType * FTy

Definition ConstantsContext.h:338

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...