LLVM: lib/Transforms/Utils/PromoteMemoryToRegister.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

51#include

52#include

53#include

54#include

55#include

56

57using namespace llvm;

58

59#define DEBUG_TYPE "mem2reg"

60

61STATISTIC(NumLocalPromoted, "Number of alloca's promoted within one block");

62STATISTIC(NumSingleStore, "Number of alloca's promoted with a single store");

63STATISTIC(NumDeadAlloca, "Number of dead alloca's removed");

64STATISTIC(NumPHIInsert, "Number of PHI nodes inserted");

65

67

68 for (const User *U : AI->users()) {

70

71

72 if (LI->isVolatile() || LI->getType() != AI->getAllocatedType())

73 return false;

75 if (SI->getValueOperand() == AI ||

77 return false;

78

79

80 if (SI->isVolatile())

81 return false;

83 if (II->isLifetimeStartOrEnd() && II->isDroppable() &&

84 II->getIntrinsicID() != Intrinsic::fake_use)

85 return false;

88 return false;

90 if (!GEPI->hasAllZeroIndices())

91 return false;

93 return false;

96 return false;

97 } else {

98 return false;

99 }

100 }

101

102 return true;

103}

104

105namespace {

106

107static void createDebugValue(DIBuilder &DIB, Value *NewValue,

111

112

113

114 (void)DIB;

116 *InsertBefore);

117}

118

119

120class AssignmentTrackingInfo {

121

122

123

125

126public:

127 void init(AllocaInst *AI) {

128 SmallSet<DebugVariable, 2> Vars;

130 if (Vars.insert(DebugVariable(DVR)).second)

131 DVRAssigns.push_back(DVR);

132 }

133 }

134

135

136

137 void updateForDeletedStore(

138 StoreInst *ToDelete, DIBuilder &DIB,

139 SmallPtrSet<DbgVariableRecord *, 8> *DVRAssignsToDelete) const {

140

141

142 if (DVRAssigns.empty())

143 return;

144

145

146

147

148

149

150

151 SmallSet<DebugVariableAggregate, 2> VarHasDbgAssignForStore;

152 auto InsertValueForAssign = [&](auto *DbgAssign, auto *&AssignList) {

153 VarHasDbgAssignForStore.insert(DebugVariableAggregate(DbgAssign));

154 AssignList->insert(DbgAssign);

155 createDebugValue(DIB, DbgAssign->getValue(), DbgAssign->getVariable(),

156 DbgAssign->getExpression(), DbgAssign->getDebugLoc(),

157 DbgAssign);

158 };

160 InsertValueForAssign(Assign, DVRAssignsToDelete);

161

162

163

164

165

166

167

168

169

170 auto ConvertUnlinkedAssignToValue = [&](DbgVariableRecord *Assign) {

171 if (VarHasDbgAssignForStore.contains(DebugVariableAggregate(Assign)))

172 return;

174 };

175 for_each(DVRAssigns, ConvertUnlinkedAssignToValue);

176 }

177

178

179

180 void updateForNewPhi(PHINode *NewPhi, DIBuilder &DIB) const {

181

182

183

184 for (auto *DVR : DVRAssigns)

186 }

187

188 void clear() { DVRAssigns.clear(); }

189 bool empty() { return DVRAssigns.empty(); }

190};

191

192struct AllocaInfo {

193 using DPUserVec = SmallVector<DbgVariableRecord *, 1>;

194

197

198 StoreInst *OnlyStore;

200 bool OnlyUsedInOneBlock;

201

202

203 DPUserVec DPUsers;

204

205 AssignmentTrackingInfo AssignmentTracking;

206

207 void clear() {

208 DefiningBlocks.clear();

209 UsingBlocks.clear();

210 OnlyStore = nullptr;

211 OnlyBlock = nullptr;

212 OnlyUsedInOneBlock = true;

213 DPUsers.clear();

214 AssignmentTracking.clear();

215 }

216

217

218

219 void AnalyzeAlloca(AllocaInst *AI) {

220 clear();

221

222

223

224

225 for (User *U : AI->users()) {

227

229

230 DefiningBlocks.push_back(SI->getParent());

231 OnlyStore = SI;

232 } else {

234

235

236 UsingBlocks.push_back(LI->getParent());

237 }

238

239 if (OnlyUsedInOneBlock) {

240 if (!OnlyBlock)

241 OnlyBlock = User->getParent();

242 else if (OnlyBlock != User->getParent())

243 OnlyUsedInOneBlock = false;

244 }

245 }

248 std::copy_if(AllDPUsers.begin(), AllDPUsers.end(),

249 std::back_inserter(DPUsers),

250 [](DbgVariableRecord *DVR) { return !DVR->isDbgAssign(); });

251 AssignmentTracking.init(AI);

252 }

253};

254

255template class VectorWithUndo {

258

259public:

260 void undo(size_t S) {

261 assert(S <= Undo.size());

262 while (S < Undo.size()) {

263 Vals[Undo.back().first] = Undo.back().second;

264 Undo.pop_back();

265 }

266 }

267

268 void resize(size_t Sz) { Vals.resize(Sz); }

269

270 size_t undoSize() const { return Undo.size(); }

271

272 const T &operator[](size_t Idx) const { return Vals[Idx]; }

273

274 void set(size_t Idx, const T &Val) {

275 if (Vals[Idx] == Val)

276 return;

277 Undo.emplace_back(Idx, Vals[Idx]);

278 Vals[Idx] = Val;

279 }

280

281 void init(size_t Idx, const T &Val) {

282 assert(Undo.empty());

283 Vals[Idx] = Val;

284 }

285};

286

287

288struct RenamePassData {

289 RenamePassData(BasicBlock *B, BasicBlock *P, size_t V, size_t L)

290 : BB(B), Pred(P), UndoVals(V), UndoLocs(L) {}

291

294

295 size_t UndoVals;

296 size_t UndoLocs;

297};

298

299

300

301

302

303

304class LargeBlockInfo {

305

306

307

308

309

310 DenseMap<const Instruction *, unsigned> InstNumbers;

311

312public:

313

314

315 static bool isInterestingInstruction(const Instruction *I) {

318 }

319

320

321 unsigned getInstructionIndex(const Instruction *I) {

322 assert(isInterestingInstruction(I) &&

323 "Not a load/store to/from an alloca?");

324

325

326 DenseMap<const Instruction *, unsigned>::iterator It = InstNumbers.find(I);

327 if (It != InstNumbers.end())

328 return It->second;

329

330

331

332

334 unsigned InstNo = 0;

335 for (const Instruction &BBI : *BB)

336 if (isInterestingInstruction(&BBI))

337 InstNumbers[&BBI] = InstNo++;

338 It = InstNumbers.find(I);

339

340 assert(It != InstNumbers.end() && "Didn't insert instruction?");

341 return It->second;

342 }

343

344 void deleteValue(const Instruction *I) { InstNumbers.erase(I); }

345

346 void clear() { InstNumbers.clear(); }

347};

348

349struct PromoteMem2Reg {

350

351 std::vector<AllocaInst *> Allocas;

352

353 DominatorTree &DT;

354 DIBuilder DIB;

355

356

357 AssumptionCache *AC;

358

359 const SimplifyQuery SQ;

360

361

362 DenseMap<AllocaInst *, unsigned> AllocaLookup;

363

364

365

366

367

368

369 DenseMap<std::pair<unsigned, unsigned>, PHINode *> NewPhiNodes;

370

371

372

373 DenseMap<PHINode *, unsigned> PhiToAllocaMap;

374

375

376

377

379

380

381

383

384

385 SmallPtrSet<DbgVariableRecord *, 8> DVRAssignsToDelete;

386

387

388 BitVector Visited;

389

390

391

392 SmallVector BBNumPreds;

393

394

395 VectorWithUndo<Value *> IncomingVals;

396

397

398 VectorWithUndo IncomingLocs;

399

400

402

403

404 bool NoSignedZeros = false;

405

406public:

408 AssumptionCache *AC)

409 : Allocas(Allocas.begin(), Allocas.end()), DT(DT),

411 AC(AC), SQ(DT.getRoot()->getDataLayout(),

412 nullptr, &DT, AC) {}

413

414 void run();

415

416private:

417 void RemoveFromAllocasList(unsigned &AllocaIdx) {

418 Allocas[AllocaIdx] = Allocas.back();

419 Allocas.pop_back();

420 --AllocaIdx;

421 }

422

423 unsigned getNumPreds(const BasicBlock *BB) {

424

425 unsigned &NP = BBNumPreds[BB->getNumber()];

426 if (NP == 0)

428 return NP - 1;

429 }

430

432 const SmallPtrSetImpl<BasicBlock *> &DefBlocks,

433 SmallPtrSetImpl<BasicBlock *> &LiveInBlocks);

434 void RenamePass(BasicBlock *BB, BasicBlock *Pred);

435 bool QueuePhiNode(BasicBlock *BB, unsigned AllocaIdx, unsigned &Version);

436

437

438 void cleanUpDbgAssigns() {

439 for (auto *DVR : DVRAssignsToDelete)

440 DVR->eraseFromParent();

441 DVRAssignsToDelete.clear();

442 }

443

444 void pushToWorklist(BasicBlock *BB, BasicBlock *Pred) {

445 Worklist.emplace_back(BB, Pred, IncomingVals.undoSize(),

446 IncomingLocs.undoSize());

447 }

448

449 RenamePassData popFromWorklist() {

450 RenamePassData R = Worklist.back();

451 Worklist.pop_back();

452 IncomingVals.undo(R.UndoVals);

453 IncomingLocs.undo(R.UndoLocs);

454 return R;

455 }

456};

457

458}

459

460

471

476

481 return;

482 }

483

484

485

486

487

488 if (AC && LI->getMetadata(LLVMContext::MD_nonnull) &&

489 LI->getMetadata(LLVMContext::MD_noundef) &&

492}

493

495

496

497

501 continue;

502

503

504 if (I->isDroppable()) {

505 I->dropDroppableUse(U);

506 continue;

507 }

508

509 if (I->getType()->isVoidTy()) {

510

511

512

515

516

519 continue;

520 }

522 }

523 }

524 I->eraseFromParent();

525 }

526}

527

528

529

530

531

532

533

534

535

542

543

544

545

546 bool RequireDominatingStore =

549 int StoreIndex = -1;

550

551

552 Info.UsingBlocks.clear();

553

556 if (UserInst == OnlyStore)

557 continue;

559

560

561

562

563

564 if (RequireDominatingStore) {

565 if (LI->getParent() == StoreBB) {

566

567

568

569 if (StoreIndex == -1)

570 StoreIndex = LBI.getInstructionIndex(OnlyStore);

571

572 if (unsigned(StoreIndex) > LBI.getInstructionIndex(LI)) {

573

574 Info.UsingBlocks.push_back(StoreBB);

575 continue;

576 }

578

579

580

582 continue;

583 }

584 }

585

586

587

588

589 if (ReplVal == LI)

591

595 LBI.deleteValue(LI);

596 }

597

598

599 if (Info.UsingBlocks.empty())

600 return false;

601

603

604 Info.AssignmentTracking.updateForDeletedStore(Info.OnlyStore, DIB,

605 DVRAssignsToDelete);

606

607

608

619 }

620 }

621

622

624

625

626 Info.OnlyStore->eraseFromParent();

627 LBI.deleteValue(Info.OnlyStore);

628

630 return true;

631}

632

633

634

635

636

637

638

639

640

641

642

643

644

645

646

647

648

650 AllocaInst *AI, const AllocaInfo &Info, LargeBlockInfo &LBI,

653

654

655

656

657

658

660 StoresByIndexTy StoresByIndex;

661

664 StoresByIndex.push_back(std::make_pair(LBI.getInstructionIndex(SI), SI));

665

666

667

669

670

671

674 if (!LI)

675 continue;

676

677 unsigned LoadIdx = LBI.getInstructionIndex(LI);

678

679

681 StoresByIndex,

682 std::make_pair(LoadIdx, static_cast<StoreInst *>(nullptr)),

685 if (I == StoresByIndex.begin()) {

686 if (StoresByIndex.empty())

687

689 else

690

691

692 return false;

693 } else {

694

695

696 ReplVal = std::prev(I)->second->getOperand(0);

697 }

698

700

701

702

703 if (ReplVal == LI)

705

708 LBI.deleteValue(LI);

709 }

710

711

715

716 Info.AssignmentTracking.updateForDeletedStore(SI, DIB, DVRAssignsToDelete);

717

721 }

722 }

723

724 SI->eraseFromParent();

725 LBI.deleteValue(SI);

726 }

727

728

731

732

737 }

738

739 ++NumLocalPromoted;

740 return true;

741}

742

743void PromoteMem2Reg::run() {

745

746 AllocaATInfo.resize(Allocas.size());

747 AllocaDPUsers.resize(Allocas.size());

748

749 AllocaInfo Info;

750 LargeBlockInfo LBI;

752

753 NoSignedZeros = F.getFnAttribute("no-signed-zeros-fp-math").getValueAsBool();

754

755 for (unsigned AllocaNum = 0; AllocaNum != Allocas.size(); ++AllocaNum) {

756 AllocaInst *AI = Allocas[AllocaNum];

757

760 "All allocas should be in the same function, which is same as DF!");

761

763

765

767

768

769 RemoveFromAllocasList(AllocaNum);

770 ++NumDeadAlloca;

771 continue;

772 }

773

774

775

776 Info.AnalyzeAlloca(AI);

777

778

779

780 if (Info.DefiningBlocks.size() == 1) {

782 &DVRAssignsToDelete)) {

783

784 RemoveFromAllocasList(AllocaNum);

785 ++NumSingleStore;

786 continue;

787 }

788 }

789

790

791

792 if (Info.OnlyUsedInOneBlock &&

794 &DVRAssignsToDelete)) {

795

796 RemoveFromAllocasList(AllocaNum);

797 continue;

798 }

799

800

801 if (BBNumPreds.empty())

802 BBNumPreds.resize(F.getMaxBlockNumber());

803

804

805 if (Info.AssignmentTracking.empty())

806 AllocaATInfo[AllocaNum] = Info.AssignmentTracking;

807 if (Info.DPUsers.empty())

808 AllocaDPUsers[AllocaNum] = Info.DPUsers;

809

810

811 AllocaLookup[Allocas[AllocaNum]] = AllocaNum;

812

813

815 Info.DefiningBlocks);

816

817

818

819 SmallPtrSet<BasicBlock *, 32> LiveInBlocks;

821

822

823

824

825

826 IDF.setLiveInBlocks(LiveInBlocks);

827 IDF.setDefiningBlocks(DefBlocks);

829 IDF.calculate(PHIBlocks);

830 llvm::sort(PHIBlocks, [](BasicBlock *A, BasicBlock *B) {

831 return A->getNumber() < B->getNumber();

832 });

833

835 for (BasicBlock *BB : PHIBlocks)

836 QueuePhiNode(BB, AllocaNum, CurrentVersion);

837 }

838

839 if (Allocas.empty()) {

840 cleanUpDbgAssigns();

841 return;

842 }

843 LBI.clear();

844

845

846

847

848 IncomingVals.resize(Allocas.size());

849 for (unsigned i = 0, e = Allocas.size(); i != e; ++i)

850 IncomingVals.init(i, UndefValue::get(Allocas[i]->getAllocatedType()));

851

852

853

854

855 IncomingLocs.resize(Allocas.size());

856 for (unsigned i = 0, e = Allocas.size(); i != e; ++i)

858

859

860 Visited.resize(F.getMaxBlockNumber(), false);

861

862

863 pushToWorklist(&F.front(), nullptr);

864

865 do {

866 RenamePassData RPD = popFromWorklist();

867 RenamePass(RPD.BB, RPD.Pred);

868 } while (!Worklist.empty());

869

870

871 for (Instruction *A : Allocas) {

872

874

875

876

877 if (A->use_empty())

879 A->eraseFromParent();

880 }

881

882

883 for (auto &DbgUsers : AllocaDPUsers) {

884 for (DbgVariableRecord *DbgItem : DbgUsers)

885 if (DbgItem->isAddressOfVariable() ||

886 DbgItem->getExpression()->startsWithDeref())

887 DbgItem->eraseFromParent();

888 }

889

890

891

892

893

894 bool EliminatedAPHI = true;

895 while (EliminatedAPHI) {

896 EliminatedAPHI = false;

897

898

899

900

901

902 for (DenseMap<std::pair<unsigned, unsigned>, PHINode *>::iterator

903 I = NewPhiNodes.begin(),

904 E = NewPhiNodes.end();

905 I != E;) {

906 PHINode *PN = I->second;

907

908

912 NewPhiNodes.erase(I++);

913 EliminatedAPHI = true;

914 continue;

915 }

916 ++I;

917 }

918 }

919

920

921

922

923

924

925 for (const auto &PhiNode : NewPhiNodes) {

926

927

928 PHINode *SomePHI = PhiNode.second;

930 if (&BB->front() != SomePHI)

931 continue;

932

933

934

935

937 continue;

938

939

940 SmallVector<BasicBlock *, 16> Preds(predecessors(BB));

941

942

943

944

946 return A->getNumber() < B->getNumber();

947 };

949

950

951

953

957 "PHI node has entry for a block which is not a predecessor!");

958

959

960 Preds.erase(EntIt);

961 }

962

963

964

965

966

972 for (BasicBlock *Pred : Preds)

974 }

975 }

976

977 NewPhiNodes.clear();

978 cleanUpDbgAssigns();

979}

980

981

982

983

984

985

986void PromoteMem2Reg::ComputeLiveInBlocks(

987 AllocaInst *AI, AllocaInfo &Info,

988 const SmallPtrSetImpl<BasicBlock *> &DefBlocks,

989 SmallPtrSetImpl<BasicBlock *> &LiveInBlocks) {

990

991

992

993 SmallVector<BasicBlock *, 64> LiveInBlockWorklist(Info.UsingBlocks.begin(),

994 Info.UsingBlocks.end());

995

996

997

998

999 for (unsigned i = 0, e = LiveInBlockWorklist.size(); i != e; ++i) {

1000 BasicBlock *BB = LiveInBlockWorklist[i];

1001 if (!DefBlocks.count(BB))

1002 continue;

1003

1004

1005

1008 if (SI->getOperand(1) != AI)

1009 continue;

1010

1011

1012

1013 LiveInBlockWorklist[i] = LiveInBlockWorklist.back();

1014 LiveInBlockWorklist.pop_back();

1015 --i;

1016 --e;

1017 break;

1018 }

1019

1021

1022

1024 break;

1025 }

1026 }

1027

1028

1029

1030 while (!LiveInBlockWorklist.empty()) {

1031 BasicBlock *BB = LiveInBlockWorklist.pop_back_val();

1032

1033

1034

1035 if (!LiveInBlocks.insert(BB).second)

1036 continue;

1037

1038

1039

1040

1042

1043 if (DefBlocks.count(P))

1044 continue;

1045

1046

1047 LiveInBlockWorklist.push_back(P);

1048 }

1049 }

1050}

1051

1052

1053

1054

1055bool PromoteMem2Reg::QueuePhiNode(BasicBlock *BB, unsigned AllocaNo,

1057

1058 PHINode *&PN = NewPhiNodes[std::make_pair(BB->getNumber(), AllocaNo)];

1059

1060

1061 if (PN)

1062 return false;

1063

1064

1065

1066 PN = PHINode::Create(Allocas[AllocaNo]->getAllocatedType(), getNumPreds(BB),

1067 Allocas[AllocaNo]->getName() + "." + Twine(Version++));

1069 ++NumPHIInsert;

1070 PhiToAllocaMap[PN] = AllocaNo;

1071 return true;

1072}

1073

1074

1075

1077 bool ApplyMergedLoc) {

1078 if (ApplyMergedLoc)

1080 else

1082}

1083

1084

1085

1086

1087

1088

1089void PromoteMem2Reg::RenamePass(BasicBlock *BB, BasicBlock *Pred) {

1090

1091

1093

1094

1095 if (PhiToAllocaMap.count(APN)) {

1096

1097

1098

1099

1100

1101

1102 unsigned NewPHINumOperands = APN->getNumOperands();

1103

1105 assert(NumEdges && "Must be at least one edge from Pred to BB!");

1106

1107

1109 do {

1110 unsigned AllocaNo = PhiToAllocaMap[APN];

1111

1112

1114 APN->getNumIncomingValues() > 0);

1115

1116

1117 for (unsigned i = 0; i != NumEdges; ++i)

1118 APN->addIncoming(IncomingVals[AllocaNo], Pred);

1119

1120

1121

1122

1123

1124

1126 APN->setHasNoSignedZeros(true);

1127

1128

1129 IncomingVals.set(AllocaNo, APN);

1130 AllocaATInfo[AllocaNo].updateForNewPhi(APN, DIB);

1131 for (DbgVariableRecord *DbgItem : AllocaDPUsers[AllocaNo])

1132 if (DbgItem->isAddressOfVariable())

1134

1135

1136 ++PNI;

1138 if (!APN)

1139 break;

1140

1141

1142

1143 } while (APN->getNumOperands() == NewPHINumOperands);

1144 }

1145 }

1146

1147

1149 return;

1151

1153 Instruction *I = &*II++;

1154

1157 if (!Src)

1158 continue;

1159

1160 DenseMap<AllocaInst *, unsigned>::iterator AI = AllocaLookup.find(Src);

1161 if (AI == AllocaLookup.end())

1162 continue;

1163

1164 Value *V = IncomingVals[AI->second];

1166

1167

1171

1172

1174 if (!Dest)

1175 continue;

1176

1177 DenseMap<AllocaInst *, unsigned>::iterator ai = AllocaLookup.find(Dest);

1178 if (ai == AllocaLookup.end())

1179 continue;

1180

1181

1182 unsigned AllocaNo = ai->second;

1183 IncomingVals.set(AllocaNo, SI->getOperand(0));

1184

1185

1186 IncomingLocs.set(AllocaNo, SI->getDebugLoc());

1187 AllocaATInfo[AllocaNo].updateForDeletedStore(SI, DIB,

1188 &DVRAssignsToDelete);

1189 for (DbgVariableRecord *DbgItem : AllocaDPUsers[ai->second])

1190 if (DbgItem->isAddressOfVariable())

1192 SI->eraseFromParent();

1193 }

1194 }

1195

1196

1197

1198

1199 SmallPtrSet<BasicBlock *, 8> VisitedSuccs;

1200

1202 if (VisitedSuccs.insert(S).second)

1203 pushToWorklist(S, BB);

1204}

1205

1208

1209 if (Allocas.empty())

1210 return;

1211

1212 PromoteMem2Reg(Allocas, DT, AC).run();

1213}

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

MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL

Function Alias Analysis false

static const Function * getParent(const Value *V)

This file implements the BitVector class.

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")

Analysis containing CSE Info

This file contains the declarations for the subclasses of Constant, which represent the different fla...

static DeltaTreeNode * getRoot(void *Root)

This file defines the DenseMap class.

This file provides various utilities for inspecting and working with the control flow graph in LLVM I...

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

uint64_t IntrinsicInst * II

static StringRef getName(Value *V)

static void ComputeLiveInBlocks(const SmallPtrSetImpl< BasicBlock * > &UsingBlocks, const SmallPtrSetImpl< BasicBlock * > &DefBlocks, SmallPtrSetImpl< BasicBlock * > &LiveInBlocks, PredIteratorCache &PredCache)

Given sets of UsingBlocks and DefBlocks, compute the set of LiveInBlocks.

This file defines the SmallPtrSet class.

This file defines the SmallVector class.

This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...

#define STATISTIC(VARNAME, DESC)

This class represents a conversion between pointers from one address space to another.

an instruction to allocate memory on the stack

Type * getAllocatedType() const

Return the type that is being allocated by the instruction.

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

bool empty() const

empty - Check if the array is empty.

A cache of @llvm.assume calls within a function.

LLVM_ABI void registerAssumption(AssumeInst *CI)

Add an @llvm.assume intrinsic to this function's cache.

LLVM Basic Block Representation.

unsigned getNumber() const

iterator begin()

Instruction iterator methods.

const Function * getParent() const

Return the enclosing method, or null if none.

const Instruction & front() const

InstListType::iterator iterator

Instruction iterators...

This class represents a no-op cast from one type to another.

bool test(unsigned Idx) const

void resize(unsigned N, bool t=false)

resize - Grow or shrink the bitvector.

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

static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)

static LLVM_ABI ConstantInt * getTrue(LLVMContext &Context)

static LLVM_ABI Constant * getNullValue(Type *Ty)

Constructor to create a '0' constant of arbitrary type.

LLVM_ABI bool startsWithDeref() const

Return whether the first element a DW_OP_deref.

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

LLVM_ABI void eraseFromParent()

Record of a variable value-assignment, aka a non instruction representation of the dbg....

bool isValueOfVariable() const

Determine if this describes the value of a local variable.

bool isAddressOfVariable() const

Does this describe the address of a local variable.

DIExpression * getExpression() const

static LLVM_ABI DbgVariableRecord * createDbgVariableRecord(Value *Location, DILocalVariable *DV, DIExpression *Expr, const DILocation *DI)

static DebugLoc getCompilerGenerated()

iterator find(const_arg_type_t< KeyT > Val)

bool erase(const KeyT &Val)

size_type count(const_arg_type_t< KeyT > Val) const

Return 1 if the specified key is in the map, 0 otherwise.

Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.

LLVM_ABI bool dominates(const BasicBlock *BB, const Use &U) const

Return true if the (end of the) basic block BB dominates the use U.

Class representing an expression and its matching format.

an instruction for type-safe pointer arithmetic to access elements of arrays and structs

This instruction compares its operands according to the predicate given to the constructor.

const DebugLoc & getDebugLoc() const

Return the debug location for this node as a DebugLoc.

LLVM_ABI const Module * getModule() const

Return the module owning the function this instruction belongs to or nullptr it the function does not...

bool hasMetadata() const

Return true if this instruction has any metadata attached to it.

LLVM_ABI void insertBefore(InstListType::iterator InsertPos)

Insert an unlinked instruction into a basic block immediately before the specified position.

LLVM_ABI InstListType::iterator eraseFromParent()

This method unlinks 'this' from the containing basic block and deletes it.

Instruction * user_back()

Specialize the methods defined in Value, as we know that an instruction can only be used by other ins...

MDNode * getMetadata(unsigned KindID) const

Get the metadata of given kind attached to this Instruction.

void setDebugLoc(DebugLoc Loc)

Set the debug location information for this instruction.

LLVM_ABI void applyMergedLocation(DebugLoc LocA, DebugLoc LocB)

Merge 2 debug locations and apply it to the Instruction.

LLVM_ABI void insertAfter(Instruction *InsertPos)

Insert an unlinked instruction into a basic block immediately after the specified instruction.

A wrapper class for inspecting calls to intrinsic functions.

This is an important class for using LLVM in a threaded context.

An instruction for reading from memory.

Value * getPointerOperand()

void addIncoming(Value *V, BasicBlock *BB)

Add an incoming value to the end of the PHI list.

BasicBlock * getIncomingBlock(unsigned i) const

Return incoming basic block number i.

unsigned getNumIncomingValues() const

Return the number of incoming edges.

static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)

Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...

static PointerType * getUnqual(Type *ElementType)

This constructs a pointer to an object of the specified type in the default address space (address sp...

static LLVM_ABI PoisonValue * get(Type *T)

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

size_type count(ConstPtrType Ptr) const

count - Return 1 if the specified pointer is in the set, 0 otherwise.

std::pair< iterator, bool > insert(PtrType Ptr)

Inserts Ptr if and only if there is no element in the container equal to Ptr.

SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.

bool contains(const T &V) const

Check if the SmallSet contains the given element.

std::pair< const_iterator, bool > insert(const T &V)

insert - Insert an element into the set if it isn't already there.

typename SuperClass::iterator iterator

void push_back(const T &Elt)

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

An instruction for storing to memory.

static LLVM_ABI UndefValue * get(Type *T)

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

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

LLVM_ABI bool isDroppable() const

A droppable user is a user for which uses can be dropped without affecting correctness and should be ...

Value * getOperand(unsigned i) const

LLVM Value Representation.

Type * getType() const

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

LLVM_ABI void replaceAllUsesWith(Value *V)

Change all uses of this to point to a new Value.

iterator_range< user_iterator > users()

static LLVM_ABI void dropDroppableUse(Use &U)

Remove the droppable use U.

LLVM_ABI LLVMContext & getContext() const

All values hold a context through their type.

iterator_range< use_iterator > uses()

const ParentTy * getParent() const

self_iterator getIterator()

@ BasicBlock

Various leaf nodes.

LLVM_ABI Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > Tys={})

Look up the Function declaration of the intrinsic id in the Module M.

SmallVector< DbgVariableRecord * > getDVRAssignmentMarkers(const Instruction *Inst)

Return a range of dbg_assign records for which Inst performs the assignment they encode.

LLVM_ABI void deleteAssignmentMarkers(const Instruction *Inst)

Delete the llvm.dbg.assign intrinsics linked to Inst.

initializer< Ty > init(const Ty &Val)

PointerTypeMap run(const Module &M)

Compute the PointerTypeMap for the module M.

@ User

could "use" a pointer

friend class Instruction

Iterator for Instructions in a `BasicBlock.

LLVM_ABI iterator begin() const

This is an optimization pass for GlobalISel generic memory operations.

FunctionAddr VTableAddr Value

UnaryFunction for_each(R &&Range, UnaryFunction F)

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

LLVM_ABI void PromoteMemToReg(ArrayRef< AllocaInst * > Allocas, DominatorTree &DT, AssumptionCache *AC=nullptr)

Promote the specified list of alloca instructions into scalar registers, inserting PHI nodes as appro...

Definition PromoteMemoryToRegister.cpp:1206

decltype(auto) dyn_cast(const From &Val)

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

auto successors(const MachineBasicBlock *BB)

LLVM_ABI bool onlyUsedByLifetimeMarkersOrDroppableInsts(const Value *V)

Return true if the only users of this pointer are lifetime markers or droppable instructions.

LLVM_ABI void InsertDebugValueAtStoreLoc(DbgVariableRecord *DVR, StoreInst *SI, DIBuilder &Builder)

===------------------------------------------------------------------—===// Dbg Intrinsic utilities

constexpr from_range_t from_range

iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)

Make a range that does early increment to allow mutation of the underlying range without disrupting i...

auto pred_size(const MachineBasicBlock *BB)

LLVM_ABI bool isAllocaPromotable(const AllocaInst *AI)

Return true if this alloca is legal for promotion.

Definition PromoteMemoryToRegister.cpp:66

LLVM_ABI Value * simplifyInstruction(Instruction *I, const SimplifyQuery &Q)

See if we can compute a simplified version of this instruction.

FunctionAddr VTableAddr uintptr_t uintptr_t Version

auto reverse(ContainerTy &&C)

void sort(IteratorTy Start, IteratorTy End)

LLVM_ABI void ConvertDebugDeclareToDebugValue(DbgVariableRecord *DVR, StoreInst *SI, DIBuilder &Builder)

Inserts a dbg.value record before a store to an alloca'd value that has an associated dbg....

class LLVM_GSL_OWNER SmallVector

Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...

IDFCalculator< false > ForwardIDFCalculator

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_ABI bool isKnownNonZero(const Value *V, const SimplifyQuery &Q, unsigned Depth=0)

Return true if the given value is known to be non-zero when defined.

LLVM_ABI bool onlyUsedByLifetimeMarkers(const Value *V)

Return true if the only users of this pointer are lifetime markers.

auto lower_bound(R &&Range, T &&Value)

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

auto count(R &&Range, const E &Element)

Wrapper function around std::count to count the number of times an element Element occurs in the give...

ArrayRef(const T &OneElt) -> ArrayRef< T >

decltype(auto) cast(const From &Val)

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

auto predecessors(const MachineBasicBlock *BB)

LLVM_ABI bool isGuaranteedNotToBePoison(const Value *V, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, unsigned Depth=0)

Returns true if V cannot be poison, but may be undef.

LLVM_ABI void findDbgUsers(Value *V, SmallVectorImpl< DbgVariableRecord * > &DbgVariableRecords)

Finds the debug info records describing a value.

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

Function object to check whether the first component of a container supported by std::get (like std::...