LLVM: lib/CodeGen/Analysis.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

27

28using namespace llvm;

29

30

31

32

34 const unsigned *Indices,

35 const unsigned *IndicesEnd,

36 unsigned CurIndex) {

37

38 if (Indices && Indices == IndicesEnd)

39 return CurIndex;

40

41

44 Type *ET = I.value();

45 if (Indices && *Indices == I.index())

48 }

49 assert(!Indices && "Unexpected out of bound");

50 return CurIndex;

51 }

52

54 Type *EltTy = ATy->getElementType();

55 unsigned NumElts = ATy->getNumElements();

56

57 unsigned EltLinearOffset = ComputeLinearIndex(EltTy, nullptr, nullptr, 0);

58 if (Indices) {

59 assert(*Indices < NumElts && "Unexpected out of bound");

60

61

62 CurIndex += EltLinearOffset* *Indices;

64 }

65 CurIndex += EltLinearOffset*NumElts;

66 return CurIndex;

67 }

68

69 return CurIndex + 1;

70}

71

77 StartingOffset.isZero()) &&

78 "Offset/TypeSize mismatch!");

79

81

82

83

84 const StructLayout *SL = Offsets ? DL.getStructLayout(STy) : nullptr;

86 EE = STy->element_end();

87 EI != EE; ++EI) {

88

92 }

93 return;

94 }

95

97 Type *EltTy = ATy->getElementType();

98 TypeSize EltSize = DL.getTypeAllocSize(EltTy);

99 for (unsigned i = 0, e = ATy->getNumElements(); i != e; ++i)

101 StartingOffset + i * EltSize);

102 return;

103 }

104

105 if (Ty->isVoidTy())

106 return;

107 Types.push_back(Ty);

108 if (Offsets)

109 Offsets->push_back(StartingOffset);

110}

111

112

113

114

115

116

117

118

126 for (Type *Ty : Types) {

128 if (MemVTs)

130 }

131}

132

139 if (FixedOffsets) {

144 } else {

146 }

147}

148

153

155

156

157

158 const StructLayout *SL = Offsets ? DL.getStructLayout(STy) : nullptr;

159 for (unsigned I = 0, E = STy->getNumElements(); I != E; ++I) {

162 StartingOffset + EltOffset);

163 }

164 return;

165 }

166

168 Type *EltTy = ATy->getElementType();

169 uint64_t EltSize = DL.getTypeAllocSize(EltTy).getFixedValue();

170 for (unsigned i = 0, e = ATy->getNumElements(); i != e; ++i)

172 StartingOffset + i * EltSize);

173 return;

174 }

175

176 if (Ty.isVoidTy())

177 return;

178

180 if (Offsets)

181 Offsets->push_back(StartingOffset);

182}

183

184

189

190 if (Var && Var->getName() == "llvm.eh.catch.all.value") {

192 "The EH catch-all value must have an initializer");

196 }

197

199 "TypeInfo must be a global variable or NULL");

200 return GV;

201}

202

203

204

205

206

208 switch (Pred) {

226 }

227}

228

230 switch (CC) {

237 default: return CC;

238 }

239}

240

242 switch (Pred) {

253 default:

255 }

256}

257

259 switch (Pred) {

280 default:

282 }

283}

284

287 return T1 == T2 || (T1->isPointerTy() && T2->isPointerTy()) ||

290}

291

292

293

294

295

296

297

298

299

300

301

302

305 unsigned &DataBits,

308 while (true) {

309

310

312 if (I || I->getNumOperands() == 0) return V;

313 const Value *NoopInput = nullptr;

314

315 Value *Op = I->getOperand(0);

317

319 NoopInput = Op;

321

323 NoopInput = Op;

325

326

327

329 DL.getPointerSizeInBits() ==

331 NoopInput = Op;

333

334

335

337 DL.getPointerSizeInBits() ==

339 NoopInput = Op;

342 DataBits =

344 I->getType()->getPrimitiveSizeInBits().getFixedValue());

345 NoopInput = Op;

347 const Value *ReturnedOp = CB->getReturnedArgOperand();

349 NoopInput = ReturnedOp;

351

353 if (ValLoc.size() >= InsertLoc.size() &&

354 std::equal(InsertLoc.begin(), InsertLoc.end(), ValLoc.rbegin())) {

355

356

357

359 NoopInput = IVI->getInsertedValueOperand();

360 } else {

361

362

363 NoopInput = Op;

364 }

366

367

368

371 NoopInput = Op;

372 }

373

374 if (!NoopInput)

375 return V;

376

377 V = NoopInput;

378 }

379}

380

381

382

383

384

388 bool AllowDifferingSizes,

391

392

393

394

395

396 unsigned BitsRequired = UINT_MAX;

397 RetVal = getNoopInput(RetVal, RetIndices, BitsRequired, TLI, DL);

398

399

400

402 return true;

403

404

405

406

407

408 unsigned BitsProvided = UINT_MAX;

409 CallVal = getNoopInput(CallVal, CallIndices, BitsProvided, TLI, DL);

410

411

412

413 if (CallVal != RetVal || CallIndices != RetIndices)

414 return false;

415

416

417

418

419

420 if (BitsProvided < BitsRequired ||

421 (!AllowDifferingSizes && BitsProvided != BitsRequired))

422 return false;

423

424 return true;

425}

426

427

428

431 return Idx < AT->getNumElements();

432

433 return Idx < cast(T)->getNumElements();

434}

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

455

456

457 while (!Path.empty() && indexReallyValid(SubTypes.back(), Path.back() + 1)) {

458 Path.pop_back();

460 }

461

462

463 if (Path.empty())

464 return false;

465

466

467

468 ++Path.back();

469 Type *DeeperType =

473 return true;

474

476 Path.push_back(0);

477

479 }

480

481 return true;

482}

483

484

485

486

487

488

489

490

491

492

493

496

497

498

501 Path.push_back(0);

502 Next = FirstInner;

503 }

504

505

506

507 if (Path.empty())

508 return true;

509

510

511

513 ->isAggregateType()) {

515 return false;

516 }

517

518 return true;

519}

520

521

522

525 do {

527 return false;

528

529 assert(!Path.empty() && "found a leaf but didn't set the path?");

531 ->isAggregateType());

532

533 return true;

534}

535

536

537

538

539

540

541

542

544 bool ReturnsFirstArg) {

548

549

550

551

552

553

554

555

556

561 return false;

562

563

564

565

567 if (&*BBI == &Call)

568 break;

569

570

571 if (BBI->isDebugOrPseudoInst())

572 continue;

573

574

576 if (II->getIntrinsicID() == Intrinsic::lifetime_end ||

577 II->getIntrinsicID() == Intrinsic::assume ||

578 II->getIntrinsicID() == Intrinsic::experimental_noalias_scope_decl ||

579 II->getIntrinsicID() == Intrinsic::fake_use)

580 continue;

581 if (BBI->mayHaveSideEffects() || BBI->mayReadFromMemory() ||

583 return false;

584 }

585

589 ReturnsFirstArg);

590}

591

595 bool *AllowDifferingSizes) {

596

597 bool DummyADS;

598 bool &ADS = AllowDifferingSizes ? *AllowDifferingSizes : DummyADS;

599 ADS = true;

600

601 AttrBuilder CallerAttrs(F->getContext(), F->getAttributes().getRetAttrs());

602 AttrBuilder CalleeAttrs(F->getContext(),

604

605

606

607 for (const auto &Attr : {Attribute::Alignment, Attribute::Dereferenceable,

608 Attribute::DereferenceableOrNull, Attribute::NoAlias,

609 Attribute::NonNull, Attribute::NoUndef,

610 Attribute::Range, Attribute::NoFPClass}) {

611 CallerAttrs.removeAttribute(Attr);

612 CalleeAttrs.removeAttribute(Attr);

613 }

614

615 if (CallerAttrs.contains(Attribute::ZExt)) {

616 if (!CalleeAttrs.contains(Attribute::ZExt))

617 return false;

618

619 ADS = false;

620 CallerAttrs.removeAttribute(Attribute::ZExt);

621 CalleeAttrs.removeAttribute(Attribute::ZExt);

622 } else if (CallerAttrs.contains(Attribute::SExt)) {

623 if (!CalleeAttrs.contains(Attribute::SExt))

624 return false;

625

626 ADS = false;

627 CallerAttrs.removeAttribute(Attribute::SExt);

628 CalleeAttrs.removeAttribute(Attribute::SExt);

629 }

630

631

632

633

634

635

636

637

638

639

640

641 if (I->use_empty()) {

642 CalleeAttrs.removeAttribute(Attribute::SExt);

643 CalleeAttrs.removeAttribute(Attribute::ZExt);

644 }

645

646

647

648

649 return CallerAttrs == CalleeAttrs;

650}

651

656 bool ReturnsFirstArg) {

657

658

660

661

662

664

665

666 bool AllowDifferingSizes;

668 return false;

669

670

671 if (ReturnsFirstArg)

672 return true;

673

677

679 bool CallEmpty = firstRealType(CallVal->getType(), CallSubTypes, CallPath);

680

681

682

683 if (RetEmpty)

684 return true;

685

686

687

688

689

690

691

692

693

694 do {

695 if (CallEmpty) {

696

697

698

699 Type *SlotType =

702 }

703

704

705

706

709

710

711

713 AllowDifferingSizes, TLI,

714 F->getDataLayout()))

715 return false;

716

717 CallEmpty = nextRealType(CallSubTypes, CallPath);

719

720 return true;

721}

722

726 bool ReturnsFirstArg = false;

728 ReturnsFirstArg = true;

729 return ReturnsFirstArg;

730}

731

736 while (!Worklist.empty()) {

738

739 if (Visiting->isEHPad() && Visiting != MBB)

740 continue;

741

742

743 auto P = EHScopeMembership.insert(std::make_pair(Visiting, EHScope));

744

745

746 if (P.second) {

747 assert(P.first->second == EHScope && "MBB is part of two scopes!");

748 continue;

749 }

750

751

752

754 continue;

755

757 }

758}

759

763

764

766 return EHScopeMembership;

767

771

778 if (MBB.isEHScopeEntry()) {

780 } else if (IsSEH && MBB.isEHPad()) {

782 } else if (MBB.pred_empty()) {

784 }

785

787

788

789

790 if (MBBI == MBB.end() || MBBI->getOpcode() != TII->getCatchReturnOpcode())

791 continue;

792

793

794

799 }

800

801

802 if (EHScopeBlocks.empty())

803 return EHScopeMembership;

804

805

807

810

813

816

817 for (std::pair<const MachineBasicBlock *, int> CatchRetPair :

818 CatchRetSuccessors)

820 CatchRetPair.first);

821 return EHScopeMembership;

822}

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

const TargetInstrInfo & TII

MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL

MachineBasicBlock MachineBasicBlock::iterator MBBI

static bool isNoopBitcast(Type *T1, Type *T2, const TargetLoweringBase &TLI)

Definition Analysis.cpp:285

static bool firstRealType(Type *Next, SmallVectorImpl< Type * > &SubTypes, SmallVectorImpl< unsigned > &Path)

Find the first non-empty, scalar-like type in Next and setup the iterator components.

Definition Analysis.cpp:494

static bool slotOnlyDiscardsData(const Value *RetVal, const Value *CallVal, SmallVectorImpl< unsigned > &RetIndices, SmallVectorImpl< unsigned > &CallIndices, bool AllowDifferingSizes, const TargetLoweringBase &TLI, const DataLayout &DL)

Return true if this scalar return value only has bits discarded on its path from the "tail call" to t...

Definition Analysis.cpp:385

static void collectEHScopeMembers(DenseMap< const MachineBasicBlock *, int > &EHScopeMembership, int EHScope, const MachineBasicBlock *MBB)

Definition Analysis.cpp:732

static bool indexReallyValid(Type *T, unsigned Idx)

For an aggregate type, determine whether a given index is within bounds or not.

Definition Analysis.cpp:429

static bool nextRealType(SmallVectorImpl< Type * > &SubTypes, SmallVectorImpl< unsigned > &Path)

Set the iterator data-structures to the next non-empty, non-aggregate subtype.

Definition Analysis.cpp:523

static bool advanceToNextLeafType(SmallVectorImpl< Type * > &SubTypes, SmallVectorImpl< unsigned > &Path)

Move the given iterators to the next leaf type in depth first traversal.

Definition Analysis.cpp:453

static const Value * getNoopInput(const Value *V, SmallVectorImpl< unsigned > &ValLoc, unsigned &DataBits, const TargetLoweringBase &TLI, const DataLayout &DL)

Look through operations that will be free to find the earliest source of this value.

Definition Analysis.cpp:303

Module.h This file contains the declarations for the Module class.

uint64_t IntrinsicInst * II

This file describes how to lower LLVM code to machine code.

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

reverse_iterator rend() const

size_t size() const

size - Get the array size.

reverse_iterator rbegin() const

Class to represent array types.

LLVM Basic Block Representation.

const Function * getParent() const

Return the enclosing method, or null if none.

InstListType::const_iterator const_iterator

const Instruction * getTerminator() const LLVM_READONLY

Returns the terminator instruction if the block is well formed or null if the block is not well forme...

Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...

Value * getArgOperand(unsigned i) const

This class represents a function call, abstracting a target machine's calling convention.

Predicate

This enumeration lists the possible predicates for CmpInst subclasses.

@ FCMP_OEQ

0 0 0 1 True if ordered and equal

@ FCMP_TRUE

1 1 1 1 Always true (always folded)

@ ICMP_SLT

signed less than

@ ICMP_SLE

signed less or equal

@ FCMP_OLT

0 1 0 0 True if ordered and less than

@ FCMP_ULE

1 1 0 1 True if unordered, less than, or equal

@ FCMP_OGT

0 0 1 0 True if ordered and greater than

@ FCMP_OGE

0 0 1 1 True if ordered and greater than or equal

@ ICMP_UGE

unsigned greater or equal

@ ICMP_UGT

unsigned greater than

@ ICMP_SGT

signed greater than

@ FCMP_ULT

1 1 0 0 True if unordered or less than

@ FCMP_ONE

0 1 1 0 True if ordered and operands are unequal

@ FCMP_UEQ

1 0 0 1 True if unordered or equal

@ ICMP_ULT

unsigned less than

@ FCMP_UGT

1 0 1 0 True if unordered or greater than

@ FCMP_OLE

0 1 0 1 True if ordered and less than or equal

@ FCMP_ORD

0 1 1 1 True if ordered (no nans)

@ ICMP_SGE

signed greater or equal

@ FCMP_UNE

1 1 1 0 True if unordered or not equal

@ ICMP_ULE

unsigned less or equal

@ FCMP_UGE

1 0 1 1 True if unordered, greater than, or equal

@ FCMP_FALSE

0 0 0 0 Always false (always folded)

@ FCMP_UNO

1 0 0 0 True if unordered: isnan(X) | isnan(Y)

const Constant * stripPointerCasts() const

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

std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)

Constant * getPersonalityFn() const

Get the personality function associated with this function.

const Constant * getInitializer() const

getInitializer - Return the initializer for this global variable.

bool hasInitializer() const

Definitions have initializers, declarations don't.

This instruction inserts a struct field of array element value into an aggregate value.

A wrapper class for inspecting calls to intrinsic functions.

bool isEHPad() const

Returns true if the block is a landing pad.

MachineInstrBundleIterator< const MachineInstr > const_iterator

int getNumber() const

MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...

iterator_range< succ_iterator > successors()

bool isEHScopeReturnBlock() const

Convenience function that returns true if the bock ends in a EH scope return instruction.

const TargetSubtargetInfo & getSubtarget() const

getSubtarget - Return the subtarget for which this machine code is being compiled.

Function & getFunction()

Return the LLVM function that this machine code represents.

const MachineBasicBlock & front() const

Return a value (possibly void), from a function.

Value * getReturnValue() const

Convenience accessor. Returns null if there is no return value.

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

void append(ItTy in_start, ItTy in_end)

Add the specified range to the end of the SmallVector.

void push_back(const T &Elt)

reverse_iterator rbegin()

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...

TypeSize getElementOffset(unsigned Idx) const

Class to represent struct types.

Type::subtype_iterator element_iterator

TargetInstrInfo - Interface to description of machine instruction set.

This base class for TargetLowering contains the SelectionDAG-independent parts that can be used from ...

EVT getMemValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const

EVT getValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const

Return the EVT corresponding to this LLVM type.

virtual bool allowTruncateForTailCall(Type *FromTy, Type *ToTy) const

Return true if a truncation from FromTy to ToTy is permitted when deciding whether a call is in tail ...

bool isTypeLegal(EVT VT) const

Return true if the target has native support for the specified value type.

This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...

Primary interface to the complete machine description for the target machine.

virtual const TargetSubtargetInfo * getSubtargetImpl(const Function &) const

Virtual method implemented by subclasses that returns a reference to that target's TargetSubtargetInf...

unsigned GuaranteedTailCallOpt

GuaranteedTailCallOpt - This flag is enabled when -tailcallopt is specified on the commandline.

virtual const TargetInstrInfo * getInstrInfo() const

virtual const TargetLowering * getTargetLowering() const

static constexpr TypeSize getFixed(ScalarTy ExactSize)

static constexpr TypeSize getZero()

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

bool isAggregateType() const

Return true if the type is an aggregate type.

static LLVM_ABI UndefValue * get(Type *T)

Static factory methods - Return an 'undef' object of the specified type.

Value * getOperand(unsigned i) const

unsigned getNumOperands() const

LLVM Value Representation.

Type * getType() const

All values are typed, get the type of this value.

LLVM_ABI StringRef getName() const

Return a constant reference to the value's name.

constexpr bool isScalable() const

Returns whether the quantity is scaled by a runtime quantity (vscale).

constexpr bool isZero() const

const ParentTy * getParent() const

#define llvm_unreachable(msg)

Marks that the current location is not supposed to be reachable.

@ Tail

Attemps to make calls as fast as possible while guaranteeing that tail call optimization can always b...

@ SwiftTail

This follows the Swift calling convention in how arguments are passed but guarantees tail calls will ...

CondCode

ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...

This is an optimization pass for GlobalISel generic memory operations.

ISD::CondCode getICmpCondCode(ICmpInst::Predicate Pred)

getICmpCondCode - Return the ISD condition code corresponding to the given LLVM IR integer condition ...

Definition Analysis.cpp:241

void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty, SmallVectorImpl< EVT > &ValueVTs, SmallVectorImpl< EVT > *MemVTs=nullptr, SmallVectorImpl< TypeSize > *Offsets=nullptr, TypeSize StartingOffset=TypeSize::getZero())

ComputeValueVTs - Given an LLVM IR type, compute a sequence of EVTs that represent all the individual...

Definition Analysis.cpp:119

auto enumerate(FirstRange &&First, RestRanges &&...Rest)

Given two or more input ranges, returns a new range whose values are tuples (A, B,...

decltype(auto) dyn_cast(const From &Val)

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

void append_range(Container &C, Range &&R)

Wrapper function to append range R to container C.

LLVM_ABI bool isSafeToSpeculativelyExecute(const Instruction *I, const Instruction *CtxI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr, const TargetLibraryInfo *TLI=nullptr, bool UseVariableInfo=true, bool IgnoreUBImplyingAttrs=true)

Return true if the instruction does not have any effects besides calculating the result and does not ...

void ComputeValueTypes(const DataLayout &DL, Type *Ty, SmallVectorImpl< Type * > &Types, SmallVectorImpl< TypeSize > *Offsets=nullptr, TypeSize StartingOffset=TypeSize::getZero())

Given an LLVM IR type, compute non-aggregate subtypes.

Definition Analysis.cpp:72

auto reverse(ContainerTy &&C)

bool returnTypeIsEligibleForTailCall(const Function *F, const Instruction *I, const ReturnInst *Ret, const TargetLoweringBase &TLI, bool ReturnsFirstArg=false)

Test if given that the input instruction is in the tail call position if the return type or any attri...

Definition Analysis.cpp:652

void computeValueLLTs(const DataLayout &DL, Type &Ty, SmallVectorImpl< LLT > &ValueTys, SmallVectorImpl< uint64_t > *Offsets=nullptr, uint64_t StartingOffset=0)

computeValueLLTs - Given an LLVM IR type, compute a sequence of LLTs that represent all the individua...

Definition Analysis.cpp:149

ISD::CondCode getFCmpCondCode(FCmpInst::Predicate Pred)

getFCmpCondCode - Return the ISD condition code corresponding to the given LLVM IR floating-point con...

Definition Analysis.cpp:207

LLVM_ABI EHPersonality classifyEHPersonality(const Value *Pers)

See if the given exception handling personality function is one that we understand.

bool isa(const From &Val)

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

bool attributesPermitTailCall(const Function *F, const Instruction *I, const ReturnInst *Ret, const TargetLoweringBase &TLI, bool *AllowDifferingSizes=nullptr)

Test if given that the input instruction is in the tail call position, if there is an attribute misma...

Definition Analysis.cpp:592

FunctionAddr VTableAddr Next

bool isInTailCallPosition(const CallBase &Call, const TargetMachine &TM, bool ReturnsFirstArg=false)

Test if the given instruction is in a position to be optimized with a tail-call.

Definition Analysis.cpp:543

DWARFExpression::Operation Op

ISD::CondCode getFCmpCodeWithoutNaN(ISD::CondCode CC)

getFCmpCodeWithoutNaN - Given an ISD condition code comparing floats, return the equivalent code if w...

Definition Analysis.cpp:229

bool isAsynchronousEHPersonality(EHPersonality Pers)

Returns true if this personality function catches asynchronous exceptions.

bool funcReturnsFirstArgOfCall(const CallInst &CI)

Returns true if the parent of CI returns CI's first argument after calling CI.

Definition Analysis.cpp:723

decltype(auto) cast(const From &Val)

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

GlobalValue * ExtractTypeInfo(Value *V)

ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.

Definition Analysis.cpp:185

unsigned ComputeLinearIndex(Type *Ty, const unsigned *Indices, const unsigned *IndicesEnd, unsigned CurIndex=0)

Compute the linearized index of a member in a nested aggregate/struct/array.

Definition Analysis.cpp:33

DenseMap< const MachineBasicBlock *, int > getEHScopeMembership(const MachineFunction &MF)

Definition Analysis.cpp:761

LLVM_ABI LLT getLLTForType(Type &Ty, const DataLayout &DL)

Construct a low-level type based on an LLVM type.

static LLVM_ABI EVT getEVT(Type *Ty, bool HandleUnknown=false)

Return the value type corresponding to the specified type.