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()) {

69 if (const LoadInst *LI = dyn_cast(U)) {

70

71

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

73 return false;

74 } else if (const StoreInst *SI = dyn_cast(U)) {

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

77 return false;

78

79

80 if (SI->isVolatile())

81 return false;

82 } else if (const IntrinsicInst *II = dyn_cast(U)) {

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

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

85 return false;

86 } else if (const BitCastInst *BCI = dyn_cast(U)) {

88 return false;

89 } else if (const GetElementPtrInst *GEPI = dyn_cast(U)) {

90 if (!GEPI->hasAllZeroIndices())

91 return false;

93 return false;

94 } else if (const AddrSpaceCastInst *ASCI = dyn_cast(U)) {

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}

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

122 DIB.insertDbgValueIntrinsic(NewValue, Variable, Expression, DI, InsertBefore);

123}

124

125

126class AssignmentTrackingInfo {

127

128

129

132

133public:

139 }

143 }

144 }

145

146

147

148 void updateForDeletedStore(

152

153

154 if (DbgAssigns.empty() && DVRAssigns.empty())

155 return;

156

157

158

159

160

161

162

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

166 AssignList->insert(DbgAssign);

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

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

169 DbgAssign);

170 };

172 InsertValueForAssign(Assign, DbgAssignsToDelete);

174 InsertValueForAssign(Assign, DVRAssignsToDelete);

175

176

177

178

179

180

181

182

183

184 auto ConvertUnlinkedAssignToValue = [&](auto *Assign) {

186 return;

188 };

189 for_each(DbgAssigns, ConvertUnlinkedAssignToValue);

190 for_each(DVRAssigns, ConvertUnlinkedAssignToValue);

191 }

192

193

194

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

196

197

198

199 for (auto *DAI : DbgAssigns)

201 for (auto *DVR : DVRAssigns)

203 }

204

205 void clear() {

206 DbgAssigns.clear();

207 DVRAssigns.clear();

208 }

209 bool empty() { return DbgAssigns.empty() && DVRAssigns.empty(); }

210};

211

212struct AllocaInfo {

215

218

221 bool OnlyUsedInOneBlock;

222

223

224 DbgUserVec DbgUsers;

225 DPUserVec DPUsers;

226

227 AssignmentTrackingInfo AssignmentTracking;

228

229 void clear() {

230 DefiningBlocks.clear();

231 UsingBlocks.clear();

232 OnlyStore = nullptr;

233 OnlyBlock = nullptr;

234 OnlyUsedInOneBlock = true;

235 DbgUsers.clear();

236 DPUsers.clear();

237 AssignmentTracking.clear();

238 }

239

240

241

243 clear();

244

245

246

247

250

252

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

254 OnlyStore = SI;

255 } else {

257

258

260 }

261

262 if (OnlyUsedInOneBlock) {

263 if (!OnlyBlock)

264 OnlyBlock = User->getParent();

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

266 OnlyUsedInOneBlock = false;

267 }

268 }

269 DbgUserVec AllDbgUsers;

272 std::copy_if(AllDbgUsers.begin(), AllDbgUsers.end(),

274 return !isa(DII);

275 });

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

277 std::back_inserter(DPUsers),

279 AssignmentTracking.init(AI);

280 }

281};

282

283

284struct RenamePassData {

285 using ValVector = std::vector<Value *>;

286 using LocationVector = std::vector;

287

290

293 ValVector Values;

295};

296

297

298

299

300

301

302class LargeBlockInfo {

303

304

305

306

307

309

310public:

311

312

313 static bool isInterestingInstruction(const Instruction *I) {

314 return (isa(I) && isa(I->getOperand(0))) ||

315 (isa(I) && isa(I->getOperand(1)));

316 }

317

318

319 unsigned getInstructionIndex(const Instruction *I) {

320 assert(isInterestingInstruction(I) &&

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

322

323

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

326 return It->second;

327

328

329

330

332 unsigned InstNo = 0;

334 if (isInterestingInstruction(&BBI))

335 InstNumbers[&BBI] = InstNo++;

336 It = InstNumbers.find(I);

337

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

339 return It->second;

340 }

341

343

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

345};

346

347struct PromoteMem2Reg {

348

349 std::vector<AllocaInst *> Allocas;

350

353

354

356

358

359

361

362

363

364

365

366

368

369

370

372

373

374

375

378

379

380

382

383

386

387

389

390

391

393

394

396

397public:

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

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

403 nullptr, &DT, AC) {}

404

405 void run();

406

407private:

408 void RemoveFromAllocasList(unsigned &AllocaIdx) {

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

410 Allocas.pop_back();

411 --AllocaIdx;

412 }

413

414 unsigned getNumPreds(const BasicBlock *BB) {

415

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

417 if (NP == 0)

419 return NP - 1;

420 }

421

426 RenamePassData::ValVector &IncVals,

427 RenamePassData::LocationVector &IncLocs,

428 std::vector &Worklist);

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

430

431

432 void cleanUpDbgAssigns() {

433 for (auto *DAI : DbgAssignsToDelete)

434 DAI->eraseFromParent();

435 DbgAssignsToDelete.clear();

436 for (auto *DVR : DVRAssignsToDelete)

437 DVR->eraseFromParent();

438 DVRAssignsToDelete.clear();

439 }

440};

441

442}

443

444

454}

455

459 if (isa(Val) && LI->hasMetadata(LLVMContext::MD_noundef)) {

460

465 return;

466 }

467

468

469

470

471

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

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

476}

477

479

480

481

483 Instruction *I = cast(U.getUser());

484 if (isa(I) || isa(I))

485 continue;

486

487

488 if (I->isDroppable()) {

489 I->dropDroppableUse(U);

490 continue;

491 }

492

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

494

495

496

498 Instruction *Inst = cast(UU.getUser());

499

500

503 continue;

504 }

506 }

507 }

508 I->eraseFromParent();

509 }

510}

511

512

513

514

515

516

517

518

519

520static bool

528

529

530

531

532 bool RequireDominatingStore =

535 int StoreIndex = -1;

536

537

538 Info.UsingBlocks.clear();

539

541 Instruction *UserInst = cast(U);

542 if (UserInst == OnlyStore)

543 continue;

544 LoadInst *LI = cast(UserInst);

545

546

547

548

549

550 if (RequireDominatingStore) {

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

552

553

554

555 if (StoreIndex == -1)

556 StoreIndex = LBI.getInstructionIndex(OnlyStore);

557

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

559

560 Info.UsingBlocks.push_back(StoreBB);

561 continue;

562 }

564

565

566

568 continue;

569 }

570 }

571

572

573

574

575 if (ReplVal == LI)

577

581 LBI.deleteValue(LI);

582 }

583

584

585 if (Info.UsingBlocks.empty())

586 return false;

587

589

590 Info.AssignmentTracking.updateForDeletedStore(

591 Info.OnlyStore, DIB, DbgAssignsToDelete, DVRAssignsToDelete);

592

593

594

595 auto ConvertDebugInfoForStore = [&](auto &Container) {

596 for (auto *DbgItem : Container) {

597 if (DbgItem->isAddressOfVariable()) {

599 DbgItem->eraseFromParent();

600 } else if (DbgItem->isValueOfVariable() &&

601 DbgItem->getExpression()->startsWithDeref()) {

603 DbgItem->eraseFromParent();

604 } else if (DbgItem->getExpression()->startsWithDeref()) {

605 DbgItem->eraseFromParent();

606 }

607 }

608 };

609 ConvertDebugInfoForStore(Info.DbgUsers);

610 ConvertDebugInfoForStore(Info.DPUsers);

611

612

614

615

616 Info.OnlyStore->eraseFromParent();

617 LBI.deleteValue(Info.OnlyStore);

618

620 return true;

621}

622

623

624

625

626

627

628

629

630

631

632

633

634

635

636

637

638

639static bool

645

646

647

648

649

650

652 StoresByIndexTy StoresByIndex;

653

655 if (StoreInst *SI = dyn_cast(U))

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

657

658

659

661

662

663

665 LoadInst *LI = dyn_cast(U);

666 if (!LI)

667 continue;

668

669 unsigned LoadIdx = LBI.getInstructionIndex(LI);

670

671

673 StoresByIndex,

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

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

678 if (StoresByIndex.empty())

679

681 else

682

683

684 return false;

685 } else {

686

687

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

689 }

690

692

693

694

695 if (ReplVal == LI)

697

700 LBI.deleteValue(LI);

701 }

702

703

707

708 Info.AssignmentTracking.updateForDeletedStore(SI, DIB, DbgAssignsToDelete,

709 DVRAssignsToDelete);

710

711 auto DbgUpdateForStore = [&](auto &Container) {

712 for (auto *DbgItem : Container) {

713 if (DbgItem->isAddressOfVariable()) {

715 }

716 }

717 };

718 DbgUpdateForStore(Info.DbgUsers);

719 DbgUpdateForStore(Info.DPUsers);

720

721 SI->eraseFromParent();

722 LBI.deleteValue(SI);

723 }

724

725

728

729

730 auto DbgUpdateForAlloca = [&](auto &Container) {

731 for (auto *DbgItem : Container)

732 if (DbgItem->isAddressOfVariable() ||

733 DbgItem->getExpression()->startsWithDeref())

734 DbgItem->eraseFromParent();

735 };

736 DbgUpdateForAlloca(Info.DbgUsers);

737 DbgUpdateForAlloca(Info.DPUsers);

738

739 ++NumLocalPromoted;

740 return true;

741}

742

743void PromoteMem2Reg::run() {

745

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

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

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

749

750 AllocaInfo Info;

751 LargeBlockInfo LBI;

753

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

755

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

758

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

762

764

766

768

769

770 RemoveFromAllocasList(AllocaNum);

771 ++NumDeadAlloca;

772 continue;

773 }

774

775

776

777 Info.AnalyzeAlloca(AI);

778

779

780

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

783 &DbgAssignsToDelete, &DVRAssignsToDelete)) {

784

785 RemoveFromAllocasList(AllocaNum);

786 ++NumSingleStore;

787 continue;

788 }

789 }

790

791

792

793 if (Info.OnlyUsedInOneBlock &&

795 &DbgAssignsToDelete, &DVRAssignsToDelete)) {

796

797 RemoveFromAllocasList(AllocaNum);

798 continue;

799 }

800

801

802 if (BBNumPreds.empty())

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

804

805

806 if (Info.DbgUsers.empty())

807 AllocaDbgUsers[AllocaNum] = Info.DbgUsers;

808 if (Info.AssignmentTracking.empty())

809 AllocaATInfo[AllocaNum] = Info.AssignmentTracking;

810 if (Info.DPUsers.empty())

811 AllocaDPUsers[AllocaNum] = Info.DPUsers;

812

813

814 AllocaLookup[Allocas[AllocaNum]] = AllocaNum;

815

816

818 Info.DefiningBlocks.end());

819

820

821

824

825

826

827

828

829 IDF.setLiveInBlocks(LiveInBlocks);

830 IDF.setDefiningBlocks(DefBlocks);

832 IDF.calculate(PHIBlocks);

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

835 });

836

839 QueuePhiNode(BB, AllocaNum, CurrentVersion);

840 }

841

842 if (Allocas.empty()) {

843 cleanUpDbgAssigns();

844 return;

845 }

846 LBI.clear();

847

848

849

850

851 RenamePassData::ValVector Values(Allocas.size());

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

853 Values[i] = UndefValue::get(Allocas[i]->getAllocatedType());

854

855

856

857 RenamePassData::LocationVector Locations(Allocas.size());

858

859

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

861

862

863

864 std::vector RenamePassWorkList;

865 RenamePassWorkList.emplace_back(&F.front(), nullptr, std::move(Values),

866 std::move(Locations));

867 do {

868 RenamePassData RPD = std::move(RenamePassWorkList.back());

869 RenamePassWorkList.pop_back();

870

871 RenamePass(RPD.BB, RPD.Pred, RPD.Values, RPD.Locations, RenamePassWorkList);

872 } while (!RenamePassWorkList.empty());

873

874

876

878

879

880

881 if (A->use_empty())

883 A->eraseFromParent();

884 }

885

886

887 auto RemoveDbgDeclares = [&](auto &Container) {

888 for (auto &DbgUsers : Container) {

889 for (auto *DbgItem : DbgUsers)

890 if (DbgItem->isAddressOfVariable() ||

891 DbgItem->getExpression()->startsWithDeref())

892 DbgItem->eraseFromParent();

893 }

894 };

895 RemoveDbgDeclares(AllocaDbgUsers);

896 RemoveDbgDeclares(AllocaDPUsers);

897

898

899

900

901

902 bool EliminatedAPHI = true;

903 while (EliminatedAPHI) {

904 EliminatedAPHI = false;

905

906

907

908

909

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

911 I = NewPhiNodes.begin(),

912 E = NewPhiNodes.end();

913 I != E;) {

915

916

920 NewPhiNodes.erase(I++);

921 EliminatedAPHI = true;

922 continue;

923 }

924 ++I;

925 }

926 }

927

928

929

930

931

932

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

934 I = NewPhiNodes.begin(),

935 E = NewPhiNodes.end();

936 I != E; ++I) {

937

938

939 PHINode *SomePHI = I->second;

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

942 continue;

943

944

945

946

948 continue;

949

950

952

953

954

955

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

958 };

960

961

962

964

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

969

970

971 Preds.erase(EntIt);

972 }

973

974

975

976

977

980 while ((SomePHI = dyn_cast(BBI++)) &&

985 }

986 }

987

988 NewPhiNodes.clear();

989 cleanUpDbgAssigns();

990}

991

992

993

994

995

996

997void PromoteMem2Reg::ComputeLiveInBlocks(

1001

1002

1003

1005 Info.UsingBlocks.end());

1006

1007

1008

1009

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

1011 BasicBlock *BB = LiveInBlockWorklist[i];

1012 if (!DefBlocks.count(BB))

1013 continue;

1014

1015

1016

1018 if (StoreInst *SI = dyn_cast(I)) {

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

1020 continue;

1021

1022

1023

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

1025 LiveInBlockWorklist.pop_back();

1026 --i;

1027 --e;

1028 break;

1029 }

1030

1031 if (LoadInst *LI = dyn_cast(I))

1032

1033

1035 break;

1036 }

1037 }

1038

1039

1040

1041 while (!LiveInBlockWorklist.empty()) {

1042 BasicBlock *BB = LiveInBlockWorklist.pop_back_val();

1043

1044

1045

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

1047 continue;

1048

1049

1050

1051

1053

1054 if (DefBlocks.count(P))

1055 continue;

1056

1057

1058 LiveInBlockWorklist.push_back(P);

1059 }

1060 }

1061}

1062

1063

1064

1065

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

1067 unsigned &Version) {

1068

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

1070

1071

1072 if (PN)

1073 return false;

1074

1075

1076

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

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

1080 ++NumPHIInsert;

1081 PhiToAllocaMap[PN] = AllocaNo;

1082 return true;

1083}

1084

1085

1086

1088 bool ApplyMergedLoc) {

1089 if (ApplyMergedLoc)

1091 else

1093}

1094

1095

1096

1097

1098

1099

1101 RenamePassData::ValVector &IncomingVals,

1102 RenamePassData::LocationVector &IncomingLocs,

1103 std::vector &Worklist) {

1104NextIteration:

1105

1106

1107 if (PHINode *APN = dyn_cast(BB->begin())) {

1108

1109

1110 if (PhiToAllocaMap.count(APN)) {

1111

1112

1113

1114

1115

1116

1117 unsigned NewPHINumOperands = APN->getNumOperands();

1118

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

1121

1122

1124 do {

1125 unsigned AllocaNo = PhiToAllocaMap[APN];

1126

1127

1129 APN->getNumIncomingValues() > 0);

1130

1131

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

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

1134

1135

1136

1137

1138

1139

1140 if (isa(APN) && NoSignedZeros)

1141 APN->setHasNoSignedZeros(true);

1142

1143

1144 IncomingVals[AllocaNo] = APN;

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

1146 auto ConvertDbgDeclares = [&](auto &Container) {

1147 for (auto *DbgItem : Container)

1148 if (DbgItem->isAddressOfVariable())

1150 };

1151 ConvertDbgDeclares(AllocaDbgUsers[AllocaNo]);

1152 ConvertDbgDeclares(AllocaDPUsers[AllocaNo]);

1153

1154

1155 ++PNI;

1156 APN = dyn_cast(PNI);

1157 if (!APN)

1158 break;

1159

1160

1161

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

1163 }

1164 }

1165

1166

1168 return;

1170

1172 Instruction *I = &*II++;

1173

1174 if (LoadInst *LI = dyn_cast(I)) {

1176 if (!Src)

1177 continue;

1178

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

1181 continue;

1182

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

1185

1186

1189 } else if (StoreInst *SI = dyn_cast(I)) {

1190

1191

1192 AllocaInst *Dest = dyn_cast(SI->getPointerOperand());

1193 if (!Dest)

1194 continue;

1195

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

1198 continue;

1199

1200

1201 unsigned AllocaNo = ai->second;

1202 IncomingVals[AllocaNo] = SI->getOperand(0);

1203

1204

1205 IncomingLocs[AllocaNo] = SI->getDebugLoc();

1206 AllocaATInfo[AllocaNo].updateForDeletedStore(SI, DIB, &DbgAssignsToDelete,

1207 &DVRAssignsToDelete);

1208 auto ConvertDbgDeclares = [&](auto &Container) {

1209 for (auto *DbgItem : Container)

1210 if (DbgItem->isAddressOfVariable())

1212 };

1213 ConvertDbgDeclares(AllocaDbgUsers[ai->second]);

1214 ConvertDbgDeclares(AllocaDPUsers[ai->second]);

1215 SI->eraseFromParent();

1216 }

1217 }

1218

1219

1221 if (I == E)

1222 return;

1223

1224

1226

1227

1228 VisitedSuccs.insert(*I);

1229 Pred = BB;

1230 BB = *I;

1231 ++I;

1232

1233 for (; I != E; ++I)

1234 if (VisitedSuccs.insert(*I).second)

1235 Worklist.emplace_back(*I, Pred, IncomingVals, IncomingLocs);

1236

1237 goto NextIteration;

1238}

1239

1242

1243 if (Allocas.empty())

1244 return;

1245

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

1247}

MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL

static const Function * getParent(const Value *V)

This file implements the BitVector class.

static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")

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

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)

assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())

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.

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 Instruction & front() const

const Function * getParent() const

Return the enclosing method, or null if none.

InstListType::iterator iterator

Instruction iterators...

const Instruction & back() const

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 ConstantInt * getTrue(LLVMContext &Context)

static Constant * getNullValue(Type *Ty)

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

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

This represents the llvm.dbg.assign instruction.

This is the common base class for debug info intrinsics for variables.

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

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

Identifies a unique instance of a whole variable (discards/ignores fragment information).

Identifies a unique instance of a variable.

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.

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.

void insertBefore(Instruction *InsertPos)

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

const DebugLoc & getDebugLoc() const

Return the debug location for this node as a DebugLoc.

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.

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 applyMergedLocation(DILocation *LocA, DILocation *LocB)

Merge 2 debug locations and apply it to the Instruction.

void setDebugLoc(DebugLoc Loc)

Set the debug location information for this instruction.

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 PoisonValue * get(Type *T)

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

A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...

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.

SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...

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.

Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...

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

Value * getOperand(unsigned i) const

bool isDroppable() const

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

LLVM Value Representation.

Type * getType() const

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

void replaceAllUsesWith(Value *V)

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

iterator_range< user_iterator > users()

static void dropDroppableUse(Use &U)

Remove the droppable use U.

LLVMContext & getContext() const

All values hold a context through their type.

iterator_range< use_iterator > uses()

const ParentTy * getParent() const

self_iterator getIterator()

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

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

AssignmentMarkerRange getAssignmentMarkers(DIAssignID *ID)

Return a range of dbg.assign intrinsics which use \ID as an operand.

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

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.

const_iterator begin(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)

Get begin iterator over path.

const_iterator end(StringRef path LLVM_LIFETIME_BOUND)

Get end iterator over path.

This is an optimization pass for GlobalISel generic memory operations.

UnaryFunction for_each(R &&Range, UnaryFunction F)

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

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

void findDbgUsers(SmallVectorImpl< DbgVariableIntrinsic * > &DbgInsts, Value *V, SmallVectorImpl< DbgVariableRecord * > *DbgVariableRecords=nullptr)

Finds the debug info intrinsics describing a value.

auto successors(const MachineBasicBlock *BB)

bool onlyUsedByLifetimeMarkersOrDroppableInsts(const Value *V)

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

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

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

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)

bool isAllocaPromotable(const AllocaInst *AI)

Return true if this alloca is legal for promotion.

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

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

void sort(IteratorTy Start, IteratorTy End)

void ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII, StoreInst *SI, DIBuilder &Builder)

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

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.

RNSuccIterator< NodeRef, BlockT, RegionT > succ_begin(NodeRef Node)

bool onlyUsedByLifetimeMarkers(const Value *V)

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

RNSuccIterator< NodeRef, BlockT, RegionT > succ_end(NodeRef Node)

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

OutputIt move(R &&Range, OutputIt Out)

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

auto predecessors(const MachineBasicBlock *BB)

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.

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

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