LLVM: include/llvm/IR/Operator.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef LLVM_IR_OPERATOR_H

15#define LLVM_IR_OPERATOR_H

16

26#include

27#include

28

29namespace llvm {

30

31

32

34public:

35

36

39

40 void *operator new(size_t s) = delete;

41

42

45 return I->getOpcode();

47 }

48

49

50

53 return I->getOpcode();

55 return CE->getOpcode();

56 return Instruction::UserOp1;

57 }

58

64

65

66

68

69

70

71

73};

74

75

76

77

79public:

80 enum {

84 };

85

86private:

89

90 void setHasNoUnsignedWrap(bool B) {

93 }

94 void setHasNoSignedWrap(bool B) {

97 }

98

99public:

100

102

103

104

108

109

110

114

115

117 unsigned NoWrapKind = 0;

120

123

124 return NoWrapKind;

125 }

126

127

129

131 return I->getOpcode() == Instruction::Add ||

132 I->getOpcode() == Instruction::Sub ||

133 I->getOpcode() == Instruction::Mul ||

134 I->getOpcode() == Instruction::Shl;

135 }

137 return CE->getOpcode() == Instruction::Add ||

138 CE->getOpcode() == Instruction::Sub;

139 }

144};

145

146template <>

149

151

152

153

155public:

156 enum {

158 };

159

160private:

163

164 void setIsExact(bool B) {

166 }

167

168public:

169

171

172

176

178 return OpC == Instruction::SDiv ||

179 OpC == Instruction::UDiv ||

180 OpC == Instruction::AShr ||

181 OpC == Instruction::LShr;

182 }

183

190};

191

192template <>

195

197

198

199

201private:

203

204

205 void setFast(bool B) {

206 setHasAllowReassoc(B);

207 setHasNoNaNs(B);

208 setHasNoInfs(B);

209 setHasNoSignedZeros(B);

210 setHasAllowReciprocal(B);

211 setHasAllowContract(B);

212 setHasApproxFunc(B);

213 }

214

215 void setHasAllowReassoc(bool B) {

216 SubclassOptionalData =

217 (SubclassOptionalData & ~FastMathFlags::AllowReassoc) |

219 }

220

221 void setHasNoNaNs(bool B) {

222 SubclassOptionalData =

223 (SubclassOptionalData & ~FastMathFlags::NoNaNs) |

225 }

226

227 void setHasNoInfs(bool B) {

228 SubclassOptionalData =

231 }

232

233 void setHasNoSignedZeros(bool B) {

234 SubclassOptionalData =

235 (SubclassOptionalData & ~FastMathFlags::NoSignedZeros) |

237 }

238

239 void setHasAllowReciprocal(bool B) {

240 SubclassOptionalData =

241 (SubclassOptionalData & ~FastMathFlags::AllowReciprocal) |

243 }

244

245 void setHasAllowContract(bool B) {

246 SubclassOptionalData =

247 (SubclassOptionalData & ~FastMathFlags::AllowContract) |

249 }

250

251 void setHasApproxFunc(bool B) {

252 SubclassOptionalData =

253 (SubclassOptionalData & ~FastMathFlags::ApproxFunc) |

255 }

256

257

258

260 SubclassOptionalData |= FMF.Flags;

261 }

262

263

264

266 SubclassOptionalData = FMF.Flags;

267 }

268

269

270

271 static bool isComposedOfHomogeneousFloatingPointTypes(Type *Ty) {

273 if (!StructTy->isLiteral() || !StructTy->containsHomogeneousTypes())

274 return false;

275 Ty = StructTy->elements().front();

277 do {

278 Ty = ArrayTy->getElementType();

280 }

281 return Ty->isFPOrFPVectorTy();

282 };

283

284public:

285

295

296

300

301

305

306

310

311

315

316

320

321

325

326

327

331

332

336

337

338

339

340 LLVM_ABI float getFPAccuracy() const;

341

342

343

345 return Ty->isFPOrFPVectorTy() ||

346 isComposedOfHomogeneousFloatingPointTypes(Ty);

347 }

348

350 unsigned Opcode;

352 Opcode = I->getOpcode();

353 else

354 return false;

355

356 switch (Opcode) {

357 case Instruction::FNeg:

358 case Instruction::FAdd:

359 case Instruction::FSub:

360 case Instruction::FMul:

361 case Instruction::FDiv:

362 case Instruction::FRem:

363 case Instruction::FPTrunc:

364 case Instruction::FPExt:

365

366

367

368

369

370 case Instruction::FCmp:

371 return true;

372 case Instruction::PHI:

373 case Instruction::Select:

374 case Instruction::Call: {

376 }

377 default:

378 return false;

379 }

380 }

381};

382

383

384template<typename SuperClass, unsigned Opc>

386public:

388 return I->getOpcode() == Opc;

389 }

391 return CE->getOpcode() == Opc;

392 }

397};

398

400 : public ConcreteOperator<OverflowingBinaryOperator, Instruction::Add> {

401};

403 : public ConcreteOperator<OverflowingBinaryOperator, Instruction::Sub> {

404};

406 : public ConcreteOperator<OverflowingBinaryOperator, Instruction::Mul> {

407};

409 : public ConcreteOperator<OverflowingBinaryOperator, Instruction::Shl> {

410};

411

418

420 : public ConcreteOperator<Operator, Instruction::GetElementPtr> {

421public:

422

424

428

429

431

435

439

440

441

443

448

452

456

466

467

471

474

475

479

483

487

488

489

490

494 if (C->isZero())

495 continue;

496 return false;

497 }

498 return true;

499 }

500

501

502

503

507 return false;

508 }

509 return true;

510 }

511

517

518

520

521

522

523

524

525

526

527

528

529

530

531

532

533

534

535

536

537

541

546

547

548

552 APInt &ConstantOffset) const;

553};

554

555template <>

558

560

565

566public:

567

569

576

580

581

585

586

590};

591

592template <>

595

597

602

603public:

604

606

609

613

614

616

617

621};

622

623template <>

626

628

633

634public:

635

637

641

645};

646

647template <>

650

652

657

658public:

659

661

663

665

669

671 return getType()->getPointerAddressSpace();

672 }

673};

674

675template <>

678

680

681}

682

683#endif

MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL

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

Move duplicate certain instructions close to their use

This file implements a map that provides insertion order iteration.

#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)

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

static SymbolRef::Type getType(const Symbol *Sym)

Class for arbitrary precision integers.

Definition Operator.h:413

Definition Operator.h:400

Definition Operator.h:654

const Value * getPointerOperand() const

Definition Operator.h:664

friend class AddrSpaceCastInst

Definition Operator.h:655

unsigned getDestAddressSpace() const

Definition Operator.h:670

DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)

Transparently provide more efficient getOperand methods.

unsigned getSrcAddressSpace() const

Definition Operator.h:666

friend class ConstantExpr

Definition Operator.h:656

Value * getPointerOperand()

Definition Operator.h:662

ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...

Definition Operator.h:630

Type * getDestTy() const

Definition Operator.h:642

friend class ConstantExpr

Definition Operator.h:632

DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)

Transparently provide more efficient getOperand methods.

Type * getSrcTy() const

Definition Operator.h:638

friend class BitCastInst

Definition Operator.h:631

A helper template for defining operators for individual opcodes.

Definition Operator.h:385

static bool classof(const Value *V)

Definition Operator.h:393

static bool classof(const ConstantExpr *CE)

Definition Operator.h:390

static bool classof(const Instruction *I)

Definition Operator.h:387

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

This is the shared class of boolean and integer constants.

A parsed version of the target data layout string in and methods for querying it.

Utility class for floating point operations which can have information about relaxed accuracy require...

Definition Operator.h:200

bool hasAllowReassoc() const

Test if this operation may be simplified with reassociative transforms.

Definition Operator.h:297

bool isFast() const

Test if this operation allows all non-strict floating-point transforms.

Definition Operator.h:286

static bool classof(const Value *V)

Definition Operator.h:349

bool hasNoNaNs() const

Test if this operation's arguments and results are assumed not-NaN.

Definition Operator.h:302

friend class Instruction

Iterator for Instructions in a `BasicBlock.

Definition Operator.h:202

FastMathFlags getFastMathFlags() const

Convenience function for getting all the fast-math flags.

Definition Operator.h:333

bool hasAllowReciprocal() const

Test if this operation can use reciprocal multiply instead of division.

Definition Operator.h:317

bool hasNoSignedZeros() const

Test if this operation can ignore the sign of zero.

Definition Operator.h:312

static bool isSupportedFloatingPointType(Type *Ty)

Returns true if Ty is a supported floating-point type for phi, select, or call FPMathOperators.

Definition Operator.h:344

bool hasAllowContract() const

Test if this operation can be floating-point contracted (FMA).

Definition Operator.h:322

bool hasNoInfs() const

Test if this operation's arguments and results are assumed not-infinite.

Definition Operator.h:307

bool hasApproxFunc() const

Test if this operation allows approximations of math library functions or intrinsics.

Definition Operator.h:328

Convenience struct for specifying and reasoning about fast-math flags.

Represents flags for the getelementptr instruction/expression.

static GEPNoWrapFlags fromRaw(unsigned Flags)

bool hasNoUnsignedSignedWrap() const

bool hasNoUnsignedWrap() const

Definition Operator.h:420

bool hasNoUnsignedSignedWrap() const

Definition Operator.h:432

const_op_iterator idx_end() const

Definition Operator.h:447

const Value * getPointerOperand() const

Definition Operator.h:460

LLVM_ABI std::optional< ConstantRange > getInRange() const

Returns the offset of the index with an inrange attachment, or std::nullopt if none.

const_op_iterator idx_begin() const

Definition Operator.h:445

LLVM_ABI bool collectOffset(const DataLayout &DL, unsigned BitWidth, SmallMapVector< Value *, APInt, 4 > &VariableOffsets, APInt &ConstantOffset) const

Collect the offset of this GEP as a map of Values to their associated APInt multipliers,...

bool isInBounds() const

Test whether this is an inbounds GEP, as defined by LangRef.html.

Definition Operator.h:430

Type * getPointerOperandType() const

Method to return the pointer operand as a PointerType.

Definition Operator.h:468

unsigned getNumIndices() const

Definition Operator.h:480

unsigned countNonConstantIndices() const

Definition Operator.h:512

bool hasNoUnsignedWrap() const

Definition Operator.h:436

bool hasAllZeroIndices() const

Return true if all of the indices of this GEP are zeros.

Definition Operator.h:491

op_iterator idx_end()

Definition Operator.h:446

DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)

Transparently provide more efficient getOperand methods.

LLVM_ABI Type * getResultElementType() const

LLVM_ABI Type * getSourceElementType() const

op_iterator idx_begin()

Definition Operator.h:444

Value * getPointerOperand()

Definition Operator.h:457

GEPNoWrapFlags getNoWrapFlags() const

Definition Operator.h:425

bool hasAllConstantIndices() const

Return true if all of the indices of this GEP are constant integers.

Definition Operator.h:504

LLVM_ABI Align getMaxPreservedAlignment(const DataLayout &DL) const

Compute the maximum alignment that this GEP is garranteed to preserve.

iterator_range< op_iterator > indices()

Definition Operator.h:449

bool hasIndices() const

Definition Operator.h:484

iterator_range< const_op_iterator > indices() const

Definition Operator.h:453

LLVM_ABI bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset, function_ref< bool(Value &, APInt &)> ExternalAnalysis=nullptr) const

Accumulate the constant address offset of this GEP if possible.

unsigned getPointerAddressSpace() const

Method to return the address space of the pointer operand.

Definition Operator.h:476

static unsigned getPointerOperandIndex()

Definition Operator.h:463

LLVM_ABI bool isCommutative() const LLVM_READONLY

Return true if the instruction is commutative:

Definition Operator.h:416

Definition Operator.h:406

This is a utility class that provides an abstraction for the common functionality between Instruction...

Definition Operator.h:33

static bool classof(const ConstantExpr *)

Definition Operator.h:60

static bool classof(const Instruction *)

Definition Operator.h:59

LLVM_ABI bool hasPoisonGeneratingFlags() const

Return true if this operator has flags which may cause this operator to evaluate to poison despite ha...

unsigned getOpcode() const

Return the opcode for this Instruction or ConstantExpr.

Definition Operator.h:43

static bool classof(const Value *V)

Definition Operator.h:61

static unsigned getOpcode(const Value *V)

If V is an Instruction or ConstantExpr, return its opcode.

Definition Operator.h:51

LLVM_ABI bool hasPoisonGeneratingAnnotations() const

Return true if this operator has poison-generating flags, return attributes or metadata.

Utility class for integer operators which may exhibit overflow - Add, Sub, Mul, and Shl.

Definition Operator.h:78

static bool classof(const Value *V)

Definition Operator.h:140

@ NoUnsignedWrap

Definition Operator.h:82

@ NoSignedWrap

Definition Operator.h:83

@ AnyWrap

Definition Operator.h:81

DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)

Transparently provide more efficient getOperand methods.

bool hasNoSignedWrap() const

Test whether this operation is known to never undergo signed overflow, aka the nsw property.

Definition Operator.h:111

unsigned getNoWrapKind() const

Returns the no-wrap kind of the operation.

Definition Operator.h:116

friend class ConstantExpr

Definition Operator.h:88

friend class Instruction

Iterator for Instructions in a `BasicBlock.

Definition Operator.h:87

bool hasNoUnsignedWrap() const

Test whether this operation is known to never undergo unsigned overflow, aka the nuw property.

Definition Operator.h:105

bool isCommutative() const

Return true if the instruction is commutative.

Definition Operator.h:128

static bool classof(const ConstantExpr *CE)

Definition Operator.h:136

static bool classof(const Instruction *I)

Definition Operator.h:130

A udiv, sdiv, lshr, or ashr instruction, which can be marked as "exact", indicating that no bits are ...

Definition Operator.h:154

bool isExact() const

Test whether this division is known to be exact, with zero remainder.

Definition Operator.h:173

DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)

Transparently provide more efficient getOperand methods.

static bool isPossiblyExactOpcode(unsigned OpC)

Definition Operator.h:177

friend class ConstantExpr

Definition Operator.h:162

friend class Instruction

Iterator for Instructions in a `BasicBlock.

Definition Operator.h:161

@ IsExact

Definition Operator.h:157

static bool classof(const Value *V)

Definition Operator.h:187

static bool classof(const Instruction *I)

Definition Operator.h:184

Definition Operator.h:599

static unsigned getPointerOperandIndex()

Definition Operator.h:610

Value * getPointerOperand()

Definition Operator.h:607

friend class PtrToAddr

Definition Operator.h:600

DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)

Transparently provide more efficient getOperand methods.

friend class ConstantExpr

Definition Operator.h:601

Type * getPointerOperandType() const

Method to return the pointer operand as a PointerType.

Definition Operator.h:615

const Value * getPointerOperand() const

Definition Operator.h:608

unsigned getPointerAddressSpace() const

Method to return the address space of the pointer operand.

Definition Operator.h:618

Definition Operator.h:562

DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)

Transparently provide more efficient getOperand methods.

friend class ConstantExpr

Definition Operator.h:564

friend class PtrToInt

Definition Operator.h:563

Type * getPointerOperandType() const

Method to return the pointer operand as a PointerType.

Definition Operator.h:582

static unsigned getPointerOperandIndex()

Definition Operator.h:577

unsigned getPointerAddressSpace() const

Method to return the address space of the pointer operand.

Definition Operator.h:587

const Value * getPointerOperand() const

Definition Operator.h:573

Value * getPointerOperand()

Definition Operator.h:570

Definition Operator.h:409

Definition Operator.h:403

The instances of the Type class are immutable: once they are created, they are never changed.

LLVM_ABI unsigned getPointerAddressSpace() const

Get the address space of this pointer or pointer vector type.

A Use represents the edge between a Value definition and its users.

User(Type *ty, unsigned vty, AllocInfo AllocInfo)

const Use * const_op_iterator

Value * getOperand(unsigned i) const

unsigned getNumOperands() const

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.

An efficient, type-erasing, non-owning reference to a callable.

A range adaptor for a pair of iterators.

@ C

The default llvm calling convention, compatible with C.

This is an optimization pass for GlobalISel generic memory operations.

decltype(auto) dyn_cast(const From &Val)

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

iterator_range< T > make_range(T x, T y)

Convenience function for iterating over sub-ranges.

const Value * getPointerOperand(const Value *V)

A helper function that returns the pointer operand of a load, store or GEP instruction.

bool isa(const From &Val)

isa - Return true if the parameter to the template is an instance of one of the template type argu...

constexpr unsigned BitWidth

auto count_if(R &&Range, UnaryPredicate P)

Wrapper function around std::count_if to count the number of times an element satisfying a given pred...

decltype(auto) cast(const From &Val)

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

This struct is a compact representation of a valid (non-zero power of two) alignment.

FixedNumOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...

Compile-time customization of User operands.

A MapVector that performs no allocations if smaller than a certain size.

VariadicOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...