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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

34#include

35#include

36#include

37

38using namespace llvm;

40

41#define DEBUG_TYPE "sccp"

42

43

44

46

47

52

53namespace llvm {

54

59

63

66 if (!Const)

67 return false;

68

69

70

71

76

77

78 if (F)

80

81 LLVM_DEBUG(dbgs() << " Can\'t treat the result of call " << *CB

82 << " as a constant\n");

83 return false;

84 }

85

86 LLVM_DEBUG(dbgs() << " Constant: " << *Const << " = " << *V << '\n');

87

88

89 V->replaceAllUsesWith(Const);

90 return true;

91}

92

93

94

95

99 return Const->toConstantRange();

101 unsigned Bitwidth = Op->getType()->getScalarSizeInBits();

102 return ConstantRange::getFull(Bitwidth);

103 }

105 false);

106}

107

108

113 auto GetRange = [&Solver, &InsertedValues](Value *Op) {

114 return getRange(Op, Solver, InsertedValues);

115 };

116

119 return false;

120

121 auto RangeA = GetRange(Inst.getOperand(0));

122 auto RangeB = GetRange(Inst.getOperand(1));

127 if (NUWRange.contains(RangeA)) {

130 }

131 }

136 if (NSWRange.contains(RangeA)) {

139 }

140 }

143 if (Range.isAllNonNegative()) {

146 }

148 if (TI->hasNoSignedWrap() && TI->hasNoUnsignedWrap())

149 return false;

150

152 uint64_t DestWidth = TI->getDestTy()->getScalarSizeInBits();

153 if (!TI->hasNoUnsignedWrap()) {

154 if (Range.getActiveBits() <= DestWidth) {

155 TI->setHasNoUnsignedWrap(true);

157 }

158 }

159 if (!TI->hasNoSignedWrap()) {

160 if (Range.getMinSignedBits() <= DestWidth) {

161 TI->setHasNoSignedWrap(true);

163 }

164 }

166 if (GEP->hasNoUnsignedWrap() || GEP->hasNoUnsignedSignedWrap())

167 return false;

168

170 [&](Value *V) { return GetRange(V).isAllNonNegative(); })) {

171 GEP->setNoWrapFlags(GEP->getNoWrapFlags() |

174 }

175 }

176

178}

179

180

184

185 auto isNonNegative = [&Solver, &InsertedValues](Value *V) {

187 };

188

191 case Instruction::SIToFP:

192 case Instruction::SExt: {

193

195 if (!isNonNegative(Op0))

196 return false;

198 ? Instruction::ZExt

199 : Instruction::UIToFP,

202 break;

203 }

204 case Instruction::AShr: {

205

207 if (!isNonNegative(Op0))

208 return false;

209 NewInst = BinaryOperator::CreateLShr(Op0, Inst.getOperand(1), "", Inst.getIterator());

211 break;

212 }

213 case Instruction::SDiv:

214 case Instruction::SRem: {

215

217 if (!isNonNegative(Op0) || !isNonNegative(Op1))

218 return false;

219 auto NewOpcode = Inst.getOpcode() == Instruction::SDiv ? Instruction::UDiv

220 : Instruction::URem;

222 if (Inst.getOpcode() == Instruction::SDiv)

224 break;

225 }

226 default:

227 return false;

228 }

229

230

231 assert(NewInst && "Expected replacement instruction");

233 InsertedValues.insert(NewInst);

238 return true;

239}

240

241

245 auto GetRange = [&Solver, &InsertedValues](Value *Op) {

246 return getRange(Op, Solver, InsertedValues);

247 };

248

250 const APInt *RHSC;

251

255 return X;

256 }

257

258

260 Value *LHS = Cmp->getOperand(0);

261 Value *RHS = Cmp->getOperand(1);

262 unsigned BitWidth = LHS->getType()->getScalarSizeInBits();

263

265 return nullptr;

268 return nullptr;

271 return nullptr;

276 if (!RHSLower.icmp(Pred, LRange) || !LRange.icmp(Pred, RHSUpper))

277 return nullptr;

278

280 Value *Sub = Builder.CreateSub(LHS, RHS, Inst.getName(), false,

281 Cmp->isSigned());

283 if (Sub->getType() != Inst.getType()) {

284 Sub = Builder.CreateSExtOrTrunc(Sub, Inst.getType());

286 }

287 return Sub;

288 }

289

290

293 auto MatchTwoInstructionExactRangeCheck =

294 [&]() -> std::optional {

295 const APInt *RHSC;

296 if (match(ICmp->getOperand(1), m_APInt(RHSC)))

297 return std::nullopt;

298

299 Value *LHS = ICmp->getOperand(0);

304

305 if (ICmp->isEquality()) {

306 const APInt *Mask;

308 RHSC->countr_zero() >= Mask->countr_zero()) {

311 }

312 }

313 return std::nullopt;

314 };

315

316 if (auto CR = MatchTwoInstructionExactRangeCheck()) {

318

320 return nullptr;

321 auto ConvertCRToICmp =

322 [&](const std::optional &NewCR) -> Value * {

325

326 if (NewCR && NewCR->getEquivalentICmp(Pred, RHS)) {

329 Builder.CreateICmp(Pred, X, ConstantInt::get(X->getType(), RHS));

330 InsertedValues.insert(NewICmp);

331 return NewICmp;

332 }

333 return nullptr;

334 };

335

336

337

338

339 if (auto *V = ConvertCRToICmp(CR->exactIntersectWith(LRange)))

340 return V;

341

342 if (auto *V = ConvertCRToICmp(CR->exactUnionWith(LRange.inverse())))

343 return V;

344 }

345 }

346

347 return nullptr;

348}

349

354 bool MadeChanges = false;

356 if (Inst.getType()->isVoidTy())

357 continue;

360 Inst.eraseFromParent();

361

362 MadeChanges = true;

363 ++InstRemovedStat;

365 MadeChanges = true;

366 ++InstReplacedStat;

368 MadeChanges = true;

370 Inst.replaceAllUsesWith(V);

371 Inst.eraseFromParent();

372 ++InstRemovedStat;

373 MadeChanges = true;

374 }

375 }

376 return MadeChanges;

377}

378

380 BasicBlock *&NewUnreachableBB) const {

382 bool HasNonFeasibleEdges = false;

385 FeasibleSuccessors.insert(Succ);

386 else

387 HasNonFeasibleEdges = true;

388 }

389

390

391 if (!HasNonFeasibleEdges)

392 return false;

393

394

398 "Terminator must be a br, switch or indirectbr");

399

400 if (FeasibleSuccessors.size() == 0) {

401

405 Succ->removePredecessor(BB);

406 if (SeenSuccs.insert(Succ).second)

408 }

412 } else if (FeasibleSuccessors.size() == 1) {

413

414 BasicBlock *OnlyFeasibleSuccessor = *FeasibleSuccessors.begin();

416 bool HaveSeenOnlyFeasibleSuccessor = false;

418 if (Succ == OnlyFeasibleSuccessor && !HaveSeenOnlyFeasibleSuccessor) {

419

420

421 HaveSeenOnlyFeasibleSuccessor = true;

422 continue;

423 }

424

425 Succ->removePredecessor(BB);

427 }

428

433 } else if (FeasibleSuccessors.size() > 1) {

436

437

438

439 BasicBlock *DefaultDest = SI->getDefaultDest();

440 if (!FeasibleSuccessors.contains(DefaultDest)) {

441 if (!NewUnreachableBB) {

442 NewUnreachableBB =

444 DefaultDest->getParent(), DefaultDest);

445 auto *UI =

448 }

449

451 SI->setDefaultDest(NewUnreachableBB);

454 }

455

456 for (auto CI = SI->case_begin(); CI != SI->case_end();) {

457 if (FeasibleSuccessors.contains(CI->getCaseSuccessor())) {

458 ++CI;

459 continue;

460 }

461

462 BasicBlock *Succ = CI->getCaseSuccessor();

465 SI.removeCase(CI);

466

467 }

468

470 } else {

471 llvm_unreachable("Must have at least one feasible successor");

472 }

473 return true;

474}

475

478

480

482 return;

483

484

485 Attribute OldAttr = F->getAttributeAtIndex(AttrIndex, Attribute::Range);

489 F->addAttributeAtIndex(

490 AttrIndex, Attribute::get(F->getContext(), Attribute::Range, CR));

491 return;

492 }

493

496 F->hasAttributeAtIndex(AttrIndex, Attribute::NonNull)) {

497 F->addAttributeAtIndex(AttrIndex,

499 }

500}

501

506

510 continue;

512 if (A.getType()->isStructTy())

513 inferAttribute(F, AttributeList::FirstArgIndex + A.getArgNo(),

515 }

516}

517

518

519

523

525

528 ValueState;

529

530

531

533

534

535

536

537

539

540

541

542

544

545

546

548 TrackedMultipleRetVals;

549

550

551

553

554

555

557

558

560

561

562

563

565

566

567

569

570

571

572

574

575

577

578

579

580 using Edge = std::pair<BasicBlock *, BasicBlock *>;

582

584

586

588

590

591private:

594 }

595

596

598

599

600 void pushUsersToWorkList(Value *V);

601

602

603

605

606

607

608

610 bool MayIncludeUndef = false);

611

613 assert(!V->getType()->isStructTy() && "structs should use mergeInValue");

614 return markConstant(ValueState[V], V, C);

615 }

616

618

621 }

622

623

624

625

626

629

630

631

632

634

635

636

640 false, false});

641

642

643

644

646 assert(!V->getType()->isStructTy() && "Should use getStructValueState");

647

648 auto I = ValueState.try_emplace(V);

650

651 if (I.second)

652 return LV;

653

656

657

658 return LV;

659 }

660

661

662

663

665 assert(V->getType()->isStructTy() && "Should use getValueState");

667 "Invalid element #");

668

669 auto I = StructValueState.insert(

672

673 if (I.second)

674 return LV;

675

677 Constant *Elt = C->getAggregateElement(i);

678

679 if (!Elt)

681 else

682 LV.markConstant(Elt);

683 }

684

685

686 return LV;

687 }

688

689

690

694

695 while (!ToInvalidate.empty()) {

697

698 if (!Invalidated.insert(Inst).second)

699 continue;

700

701 if (!BBExecutable.count(Inst->getParent()))

702 continue;

703

704 Value *V = nullptr;

705

706

708 Function *F = RetInst->getParent()->getParent();

709 if (auto It = TrackedRetVals.find(F); It != TrackedRetVals.end()) {

711 V = F;

712 } else if (MRVFunctionsTracked.count(F)) {

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

716 V = F;

717 }

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

720 if (auto It = StructValueState.find({Inst, I});

721 It != StructValueState.end()) {

723 V = Inst;

724 }

725 }

726 } else if (auto It = ValueState.find(Inst); It != ValueState.end()) {

728 V = Inst;

729 }

730

731 if (V) {

732 LLVM_DEBUG(dbgs() << "Invalidated lattice for " << *V << "\n");

733

737

738 auto It = AdditionalUsers.find(V);

739 if (It != AdditionalUsers.end())

740 for (User *U : It->second)

743 }

744 }

745 }

746

747

748

750

751

752

754

755

756 void addAdditionalUser(Value *V, User *U) { AdditionalUsers[V].insert(U); }

757

759 void handleCallOverdefined(CallBase &CB);

760 void handleCallResult(CallBase &CB);

761 void handleCallArguments(CallBase &CB);

765

766private:

768

769

770

771

772 void visitPHINode(PHINode &I);

773

774

775

778

784 void visitCmpInst(CmpInst &I);

787

789 markOverdefined(&CPI);

790 visitTerminator(CPI);

791 }

792

793

794

798 void visitAllocaInst(AllocaInst &AI);

799

801 visitCallBase(II);

802 visitTerminator(II);

803 }

804

805 void visitCallBrInst(CallBrInst &CBI) {

806 visitCallBase(CBI);

807 visitTerminator(CBI);

808 }

809

810 void visitCallBase(CallBase &CB);

811 void visitResumeInst(ResumeInst &I) {

812 }

813 void visitUnreachableInst(UnreachableInst &I) {

814 }

815 void visitFenceInst(FenceInst &I) {

816 }

817

818 void visitInstruction(Instruction &I);

819

820public:

822 FnPredicateInfo.insert({&F, std::make_unique(

823 F, DT, AC, PredicateInfoAllocator)});

824 }

825

827 auto It = FnPredicateInfo.find(&F);

828 if (It == FnPredicateInfo.end())

829 return;

830

834 if (BC->getType() == BC->getOperand(0)->getType()) {

835 if (It->second->getPredicateInfoFor(&Inst)) {

836 Value *Op = BC->getOperand(0);

837 Inst.replaceAllUsesWith(Op);

838 Inst.eraseFromParent();

839 }

840 }

841 }

842 }

843 }

844 }

845

847

849

851 auto It = FnPredicateInfo.find(I->getParent()->getParent());

852 if (It == FnPredicateInfo.end())

853 return nullptr;

854 return It->second->getPredicateInfoFor(I);

855 }

856

860 : DL(DL), GetTLI(GetTLI), Ctx(Ctx) {}

861

869

871

873 MRVFunctionsTracked.insert(F);

874 for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i)

875 TrackedMultipleRetVals.try_emplace(std::make_pair(F, i));

876 } else if (F->getReturnType()->isVoidTy())

877 TrackedRetVals.try_emplace(F);

878 }

879

881 MustPreserveReturnsInFunctions.insert(F);

882 }

883

885 return MustPreserveReturnsInFunctions.count(F);

886 }

887

889 TrackingIncomingArguments.insert(F);

890 }

891

893 return TrackingIncomingArguments.count(F);

894 }

895

897 return TrackingIncomingArguments;

898 }

899

901

903

905

907 return BBExecutable.count(BB);

908 }

909

911

913 std::vector StructValues;

915 assert(STy && "getStructLatticeValueFor() can be called only on structs");

916 for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {

917 auto I = StructValueState.find(std::make_pair(V, i));

918 assert(I != StructValueState.end() && "Value not in valuemap!");

919 StructValues.push_back(I->second);

920 }

921 return StructValues;

922 }

923

925

926

927

929

931 (void)F;

932 assert(F->getReturnType()->isVoidTy() &&

933 (TrackedRetVals.count(F) || MRVFunctionsTracked.count(F)) &&

934 "All non void specializations should be tracked");

935 invalidate(Call);

936 handleCallResult(*Call);

937 }

938

940 assert(!V->getType()->isStructTy() &&

941 "Should use getStructLatticeValueFor");

943 ValueState.find(V);

944 assert(I != ValueState.end() &&

945 "V not found in ValueState nor Paramstate map!");

946 return I->second;

947 }

948

950 return TrackedRetVals;

951 }

952

955 return TrackedGlobals;

956 }

957

959 return MRVFunctionsTracked;

960 }

961

964 for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i)

965 markOverdefined(getStructValueState(V, i), V);

966 else

967 markOverdefined(ValueState[V], V);

968 }

969

971 if (A->getType()->isIntOrIntVectorTy()) {

972 if (std::optional Range = A->getRange())

974 }

975 if (A->hasNonNullAttr())

977

979 }

980

982 if (A->getType()->isStructTy())

983 return (void)markOverdefined(A);

985 }

986

988

990

992

995

997 for (auto &BB : *F)

998 BBExecutable.erase(&BB);

999 }

1000

1002 bool ResolvedUndefs = true;

1003 while (ResolvedUndefs) {

1005 ResolvedUndefs = false;

1008 }

1009 }

1010

1012 bool ResolvedUndefs = true;

1013 while (ResolvedUndefs) {

1015 ResolvedUndefs = false;

1018 }

1019 }

1020

1022 bool ResolvedUndefs = true;

1023 while (ResolvedUndefs) {

1025 ResolvedUndefs = false;

1026 for (Value *V : Invalidated)

1029 }

1030 Invalidated.clear();

1031 }

1032};

1033

1034}

1035

1037 if (!BBExecutable.insert(BB).second)

1038 return false;

1040 BBWorkList.push_back(BB);

1041 return true;

1042}

1043

1044void SCCPInstVisitor::pushToWorkList(Instruction *I) {

1045

1046

1047

1048

1049 if (CurI && I->getParent() == CurI->getParent() && I->comesBefore(CurI))

1050 return;

1051

1052

1053 if (BBVisited.contains(I->getParent()))

1054 InstWorkList.insert(I);

1055}

1056

1057void SCCPInstVisitor::pushUsersToWorkList(Value *V) {

1060 pushToWorkList(UI);

1061

1062 auto Iter = AdditionalUsers.find(V);

1063 if (Iter != AdditionalUsers.end()) {

1064

1065

1067 for (User *U : Iter->second)

1071 pushToWorkList(UI);

1072 }

1073}

1074

1077 LLVM_DEBUG(dbgs() << "updated " << IV << ": " << *V << '\n');

1078 pushUsersToWorkList(V);

1079}

1080

1082 Constant *C, bool MayIncludeUndef) {

1083 if (IV.markConstant(C, MayIncludeUndef))

1084 return false;

1085 LLVM_DEBUG(dbgs() << "markConstant: " << *C << ": " << *V << '\n');

1086 pushUsersToWorkList(V);

1087 return true;

1088}

1089

1092 if (IV.markNotConstant(C))

1093 return false;

1094 LLVM_DEBUG(dbgs() << "markNotConstant: " << *C << ": " << *V << '\n');

1095 pushUsersToWorkList(V);

1096 return true;

1097}

1098

1101 if (IV.markConstantRange(CR))

1102 return false;

1103 LLVM_DEBUG(dbgs() << "markConstantRange: " << CR << ": " << *V << '\n');

1104 pushUsersToWorkList(V);

1105 return true;

1106}

1107

1109 if (IV.markOverdefined())

1110 return false;

1111

1114 << "Function '" << F->getName() << "'\n";

1115 else dbgs() << *V << '\n');

1116

1117 pushUsersToWorkList(V);

1118 return true;

1119}

1120

1122 for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {

1123 const auto &It = TrackedMultipleRetVals.find(std::make_pair(F, i));

1124 assert(It != TrackedMultipleRetVals.end());

1126 return false;

1127 }

1128 return true;

1129}

1130

1132 Type *Ty) const {

1135 assert(C->getType() == Ty && "Type mismatch");

1136 return C;

1137 }

1138

1143 }

1144 return nullptr;

1145}

1146

1149 if (V->getType()->isStructTy()) {

1152 return nullptr;

1153 std::vector<Constant *> ConstVals;

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

1160 }

1162 } else {

1165 return nullptr;

1168 }

1169 assert(Const && "Constant is nullptr here!");

1170 return Const;

1171}

1172

1175 assert(!Args.empty() && "Specialization without arguments");

1176 assert(F->arg_size() == Args[0].Formal->getParent()->arg_size() &&

1177 "Functions should have the same number of arguments");

1178

1179 auto Iter = Args.begin();

1182 for (auto End = F->arg_end(); NewArg != End; ++NewArg, ++OldArg) {

1183

1186

1187

1188

1189 if (Iter != Args.end() && Iter->Formal == &*OldArg) {

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

1193 NewValue.markConstant(Iter->Actual->getAggregateElement(I));

1194 }

1195 } else {

1196 ValueState[&*NewArg].markConstant(Iter->Actual);

1197 }

1198 ++Iter;

1199 } else {

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

1203 NewValue = StructValueState[{&*OldArg, I}];

1204 }

1205 } else {

1207 NewValue = ValueState[&*OldArg];

1208 }

1209 }

1210 }

1211}

1212

1213void SCCPInstVisitor::visitInstruction(Instruction &I) {

1214

1215

1216 LLVM_DEBUG(dbgs() << "SCCP: Don't know how to handle: " << I << '\n');

1217 markOverdefined(&I);

1218}

1219

1223 if (IV.mergeIn(MergeWithV, Opts)) {

1224 pushUsersToWorkList(V);

1225 LLVM_DEBUG(dbgs() << "Merged " << MergeWithV << " into " << *V << " : "

1226 << IV << "\n");

1227 return true;

1228 }

1229 return false;

1230}

1231

1232bool SCCPInstVisitor::markEdgeExecutable(BasicBlock *Source, BasicBlock *Dest) {

1233 if (!KnownFeasibleEdges.insert(Edge(Source, Dest)).second)

1234 return false;

1235

1237

1238

1239

1241 << " -> " << Dest->getName() << '\n');

1242

1243 for (PHINode &PN : Dest->phis())

1244 pushToWorkList(&PN);

1245 }

1246 return true;

1247}

1248

1249

1250

1251void SCCPInstVisitor::getFeasibleSuccessors(Instruction &TI,

1255 if (BI->isUnconditional()) {

1256 Succs[0] = true;

1257 return;

1258 }

1259

1260 const ValueLatticeElement &BCValue = getValueState(BI->getCondition());

1261 ConstantInt *CI = getConstantInt(BCValue, BI->getCondition()->getType());

1262 if (!CI) {

1263

1264

1266 Succs[0] = Succs[1] = true;

1267 return;

1268 }

1269

1270

1271 Succs[CI->isZero()] = true;

1272 return;

1273 }

1274

1275

1276

1279 return;

1280 }

1281

1283 if (SI->getNumCases()) {

1284 Succs[0] = true;

1285 return;

1286 }

1287 const ValueLatticeElement &SCValue = getValueState(SI->getCondition());

1288 if (ConstantInt *CI =

1290 Succs[SI->findCaseValue(CI)->getSuccessorIndex()] = true;

1291 return;

1292 }

1293

1294

1295

1298 unsigned ReachableCaseCount = 0;

1299 for (const auto &Case : SI->cases()) {

1300 const APInt &CaseValue = Case.getCaseValue()->getValue();

1302 Succs[Case.getSuccessorIndex()] = true;

1303 ++ReachableCaseCount;

1304 }

1305 }

1306

1307 Succs[SI->case_default()->getSuccessorIndex()] =

1309 return;

1310 }

1311

1312

1315 return;

1316 }

1317

1318

1319

1321

1322 const ValueLatticeElement &IBRValue = getValueState(IBR->getAddress());

1324 getConstant(IBRValue, IBR->getAddress()->getType()));

1325 if (!Addr) {

1326

1329 return;

1330 }

1331

1334 "Block address of a different function ?");

1335 for (unsigned i = 0; i < IBR->getNumSuccessors(); ++i) {

1336

1337 if (IBR->getDestination(i) == T) {

1338 Succs[i] = true;

1339 return;

1340 }

1341 }

1342

1343

1344

1345 return;

1346 }

1347

1348 LLVM_DEBUG(dbgs() << "Unknown terminator instruction: " << TI << '\n');

1349 llvm_unreachable("SCCP: Don't know how to handle this terminator!");

1350}

1351

1352

1353

1355

1356

1357

1358 return KnownFeasibleEdges.count(Edge(From, To));

1359}

1360

1361

1362

1363

1364

1365

1366

1367

1368

1369

1370

1371

1372

1373

1374

1375

1376

1377

1378void SCCPInstVisitor::visitPHINode(PHINode &PN) {

1379

1380

1382 return (void)markOverdefined(&PN);

1383

1384 if (isInstFullyOverDefined(PN))

1385 return;

1389 continue;

1390 FeasibleIncomingIndices.push_back(i);

1391 }

1392

1393

1394

1395

1396

1397

1399 for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {

1402 continue;

1403 for (unsigned j : FeasibleIncomingIndices) {

1408 break;

1409 }

1410 ValueLatticeElement &PhiStateRef = getStructValueState(&PN, i);

1411 mergeInValue(PhiStateRef, &PN, PhiState,

1412 ValueLatticeElement::MergeOptions().setMaxWidenSteps(

1413 FeasibleIncomingIndices.size() + 1));

1415 std::max((unsigned)FeasibleIncomingIndices.size(),

1417 }

1418 } else {

1419 ValueLatticeElement PhiState = getValueState(&PN);

1420 for (unsigned i : FeasibleIncomingIndices) {

1421 const ValueLatticeElement &IV = getValueState(PN.getIncomingValue(i));

1424 break;

1425 }

1426

1427

1428

1429

1430

1431 ValueLatticeElement &PhiStateRef = ValueState[&PN];

1432 mergeInValue(PhiStateRef, &PN, PhiState,

1433 ValueLatticeElement::MergeOptions().setMaxWidenSteps(

1434 FeasibleIncomingIndices.size() + 1));

1436 std::max((unsigned)FeasibleIncomingIndices.size(),

1438 }

1439}

1440

1441void SCCPInstVisitor::visitReturnInst(ReturnInst &I) {

1442 if (I.getNumOperands() == 0)

1443 return;

1444

1445 Function *F = I.getParent()->getParent();

1446 Value *ResultOp = I.getOperand(0);

1447

1448

1449 if (!TrackedRetVals.empty() && !ResultOp->getType()->isStructTy()) {

1450 auto TFRVI = TrackedRetVals.find(F);

1451 if (TFRVI != TrackedRetVals.end()) {

1452 mergeInValue(TFRVI->second, F, getValueState(ResultOp));

1453 return;

1454 }

1455 }

1456

1457

1458 if (!TrackedMultipleRetVals.empty()) {

1460 if (MRVFunctionsTracked.count(F))

1461 for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i)

1462 mergeInValue(TrackedMultipleRetVals[std::make_pair(F, i)], F,

1463 getStructValueState(ResultOp, i));

1464 }

1465}

1466

1467void SCCPInstVisitor::visitTerminator(Instruction &TI) {

1469 getFeasibleSuccessors(TI, SuccFeasible);

1470

1472

1473

1474 for (unsigned i = 0, e = SuccFeasible.size(); i != e; ++i)

1475 if (SuccFeasible[i])

1477}

1478

1479void SCCPInstVisitor::visitCastInst(CastInst &I) {

1480

1481

1482 if (ValueState[&I].isOverdefined())

1483 return;

1484

1486 if (BC->getType() == BC->getOperand(0)->getType()) {

1488 handlePredicate(&I, I.getOperand(0), PI);

1489 return;

1490 }

1491 }

1492 }

1493

1494 const ValueLatticeElement &OpSt = getValueState(I.getOperand(0));

1496 return;

1497

1498 if (Constant *OpC = getConstant(OpSt, I.getOperand(0)->getType())) {

1499

1500 if (Constant *C =

1502 return (void)markConstant(&I, C);

1503 }

1504

1505

1506 if (I.getDestTy()->isIntOrIntVectorTy() &&

1507 I.getSrcTy()->isIntOrIntVectorTy() &&

1508 I.getOpcode() != Instruction::BitCast) {

1509 ConstantRange OpRange =

1511 auto &LV = getValueState(&I);

1512

1513 Type *DestTy = I.getDestTy();

1514 ConstantRange Res = ConstantRange::getEmpty(DestTy->getScalarSizeInBits());

1517 Trunc->getNoWrapKind());

1518 else

1521 } else

1522 markOverdefined(&I);

1523}

1524

1525void SCCPInstVisitor::handleExtractOfWithOverflow(ExtractValueInst &EVI,

1527 unsigned Idx) {

1530

1531 addAdditionalUser(LHS, &EVI);

1532 addAdditionalUser(RHS, &EVI);

1533

1534 const ValueLatticeElement &L = getValueState(LHS);

1535 if (L.isUnknownOrUndef())

1536 return;

1537 ConstantRange LR = L.asConstantRange(Ty, false);

1538

1539 const ValueLatticeElement &R = getValueState(RHS);

1540 if (R.isUnknownOrUndef())

1541 return;

1542

1543 ConstantRange RR = R.asConstantRange(Ty, false);

1544 if (Idx == 0) {

1547 } else {

1548 assert(Idx == 1 && "Index can only be 0 or 1");

1553 markOverdefined(&EVI);

1554 }

1555}

1556

1557void SCCPInstVisitor::visitExtractValueInst(ExtractValueInst &EVI) {

1558

1559

1561 return (void)markOverdefined(&EVI);

1562

1563

1564

1565 if (ValueState[&EVI].isOverdefined())

1566 return (void)markOverdefined(&EVI);

1567

1568

1570 return (void)markOverdefined(&EVI);

1571

1576 return handleExtractOfWithOverflow(EVI, WO, i);

1577 ValueLatticeElement EltVal = getStructValueState(AggVal, i);

1578 mergeInValue(ValueState[&EVI], &EVI, EltVal);

1579 } else {

1580

1581 return (void)markOverdefined(&EVI);

1582 }

1583}

1584

1585void SCCPInstVisitor::visitInsertValueInst(InsertValueInst &IVI) {

1587 if (!STy)

1588 return (void)markOverdefined(&IVI);

1589

1590

1591

1592 if (ValueState[&IVI].isOverdefined())

1593 return (void)markOverdefined(&IVI);

1594

1595

1596

1598 return (void)markOverdefined(&IVI);

1599

1601 unsigned Idx = *IVI.idx_begin();

1602

1603

1604 for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {

1605

1606 if (i != Idx) {

1607 ValueLatticeElement EltVal = getStructValueState(Aggr, i);

1608 mergeInValue(getStructValueState(&IVI, i), &IVI, EltVal);

1609 continue;

1610 }

1611

1614

1615 markOverdefined(getStructValueState(&IVI, i), &IVI);

1616 else {

1617 ValueLatticeElement InVal = getValueState(Val);

1618 mergeInValue(getStructValueState(&IVI, i), &IVI, InVal);

1619 }

1620 }

1621}

1622

1623void SCCPInstVisitor::visitSelectInst(SelectInst &I) {

1624

1625

1626 if (I.getType()->isStructTy())

1627 return (void)markOverdefined(&I);

1628

1629

1630

1631 if (ValueState[&I].isOverdefined())

1632 return (void)markOverdefined(&I);

1633

1634 const ValueLatticeElement &CondValue = getValueState(I.getCondition());

1636 return;

1637

1638 if (ConstantInt *CondCB =

1639 getConstantInt(CondValue, I.getCondition()->getType())) {

1640 Value *OpVal = CondCB->isZero() ? I.getFalseValue() : I.getTrueValue();

1641 const ValueLatticeElement &OpValState = getValueState(OpVal);

1642

1643

1644 assert(ValueState.contains(&I) && "&I is not in ValueState map.");

1645 mergeInValue(ValueState[&I], &I, OpValState);

1646 return;

1647 }

1648

1649

1650

1651

1652 ValueLatticeElement TVal = getValueState(I.getTrueValue());

1653 ValueLatticeElement FVal = getValueState(I.getFalseValue());

1654

1655 ValueLatticeElement &State = ValueState[&I];

1659 pushUsersToWorkListMsg(State, &I);

1660}

1661

1662

1663void SCCPInstVisitor::visitUnaryOperator(Instruction &I) {

1664 ValueLatticeElement V0State = getValueState(I.getOperand(0));

1665

1666 ValueLatticeElement &IV = ValueState[&I];

1667

1668

1669 if (IV.isOverdefined())

1670 return (void)markOverdefined(&I);

1671

1672

1674 return;

1675

1678 I.getOpcode(), getConstant(V0State, I.getType()), DL))

1679 return (void)markConstant(IV, &I, C);

1680

1681 markOverdefined(&I);

1682}

1683

1684void SCCPInstVisitor::visitFreezeInst(FreezeInst &I) {

1685

1686

1687 if (I.getType()->isStructTy())

1688 return (void)markOverdefined(&I);

1689

1690 ValueLatticeElement V0State = getValueState(I.getOperand(0));

1691 ValueLatticeElement &IV = ValueState[&I];

1692

1693

1694 if (IV.isOverdefined())

1695 return (void)markOverdefined(&I);

1696

1697

1699 return;

1700

1703 return (void)markConstant(IV, &I, getConstant(V0State, I.getType()));

1704

1705 markOverdefined(&I);

1706}

1707

1708

1709void SCCPInstVisitor::visitBinaryOperator(Instruction &I) {

1710 ValueLatticeElement V1State = getValueState(I.getOperand(0));

1711 ValueLatticeElement V2State = getValueState(I.getOperand(1));

1712

1713 ValueLatticeElement &IV = ValueState[&I];

1714 if (IV.isOverdefined())

1715 return;

1716

1717

1719 return;

1720

1722 return (void)markOverdefined(&I);

1723

1724

1725

1728 ? getConstant(V1State, I.getOperand(0)->getType())

1729 : I.getOperand(0);

1731 ? getConstant(V2State, I.getOperand(1)->getType())

1732 : I.getOperand(1);

1735 if (C) {

1736

1737

1738

1739

1740

1741 ValueLatticeElement NewV;

1743 return (void)mergeInValue(ValueState[&I], &I, NewV);

1744 }

1745 }

1746

1747

1748 if (I.getType()->isIntOrIntVectorTy())

1749 return markOverdefined(&I);

1750

1751

1752 ConstantRange A =

1753 V1State.asConstantRange(I.getType(), false);

1754 ConstantRange B =

1755 V2State.asConstantRange(I.getType(), false);

1756

1758 ConstantRange R = ConstantRange::getEmpty(I.getType()->getScalarSizeInBits());

1760 R = A.overflowingBinaryOp(BO->getOpcode(), B, OBO->getNoWrapKind());

1761 else

1762 R = A.binaryOp(BO->getOpcode(), B);

1764

1765

1766

1767

1768}

1769

1770

1771void SCCPInstVisitor::visitCmpInst(CmpInst &I) {

1772

1773

1774 if (ValueState[&I].isOverdefined())

1775 return (void)markOverdefined(&I);

1776

1777 Value *Op1 = I.getOperand(0);

1778 Value *Op2 = I.getOperand(1);

1779

1780

1781

1782 auto V1State = getValueState(Op1);

1783 auto V2State = getValueState(Op2);

1784

1786 if (C) {

1787 ValueLatticeElement CV;

1789 mergeInValue(ValueState[&I], &I, CV);

1790 return;

1791 }

1792

1793

1796 return;

1797

1798 markOverdefined(&I);

1799}

1800

1801

1802

1804 if (ValueState[&I].isOverdefined())

1805 return (void)markOverdefined(&I);

1806

1807 const ValueLatticeElement &PtrState = getValueState(I.getPointerOperand());

1809 return;

1810

1811

1813 if (I.hasNoUnsignedWrap() ||

1814 (I.isInBounds() &&

1816 return (void)markNotNull(ValueState[&I], &I);

1817 return (void)markOverdefined(&I);

1818 }

1819

1821 Operands.reserve(I.getNumOperands());

1822

1823 for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i) {

1824 const ValueLatticeElement &State = getValueState(I.getOperand(i));

1826 return;

1827

1828 if (Constant *C = getConstant(State, I.getOperand(i)->getType())) {

1830 continue;

1831 }

1832

1833 return (void)markOverdefined(&I);

1834 }

1835

1837 markConstant(&I, C);

1838 else

1839 markOverdefined(&I);

1840}

1841

1842void SCCPInstVisitor::visitAllocaInst(AllocaInst &I) {

1844 return (void)markNotNull(ValueState[&I], &I);

1845

1846 markOverdefined(&I);

1847}

1848

1849void SCCPInstVisitor::visitStoreInst(StoreInst &SI) {

1850

1851 if (SI.getOperand(0)->getType()->isStructTy())

1852 return;

1853

1855 return;

1856

1858 auto I = TrackedGlobals.find(GV);

1859 if (I == TrackedGlobals.end())

1860 return;

1861

1862

1863 mergeInValue(I->second, GV, getValueState(SI.getOperand(0)),

1864 ValueLatticeElement::MergeOptions().setCheckWiden(false));

1865 if (I->second.isOverdefined())

1866 TrackedGlobals.erase(I);

1867}

1868

1871 if (CB->getType()->isIntOrIntVectorTy())

1872 if (std::optional Range = CB->getRange())

1874 if (CB->getType()->isPointerTy() && CB->isReturnNonNull())

1877 }

1878

1879 if (I->getType()->isIntOrIntVectorTy())

1880 if (MDNode *Ranges = I->getMetadata(LLVMContext::MD_range))

1883 if (I->hasMetadata(LLVMContext::MD_nonnull))

1886

1888}

1889

1890

1891

1892void SCCPInstVisitor::visitLoadInst(LoadInst &I) {

1893

1894

1895 if (I.getType()->isStructTy() || I.isVolatile())

1896 return (void)markOverdefined(&I);

1897

1898

1899

1900 if (ValueState[&I].isOverdefined())

1901 return (void)markOverdefined(&I);

1902

1903 const ValueLatticeElement &PtrVal = getValueState(I.getOperand(0));

1905 return;

1906

1909 ValueLatticeElement &IV = ValueState[&I];

1910

1911

1914 return (void)markOverdefined(IV, &I);

1915 else

1916 return;

1917 }

1918

1919

1921 if (!TrackedGlobals.empty()) {

1922

1923 auto It = TrackedGlobals.find(GV);

1924 if (It != TrackedGlobals.end()) {

1926 return;

1927 }

1928 }

1929 }

1930

1931

1933 return (void)markConstant(IV, &I, C);

1934 }

1935

1936

1938}

1939

1940void SCCPInstVisitor::visitCallBase(CallBase &CB) {

1941 handleCallResult(CB);

1942 handleCallArguments(CB);

1943}

1944

1945void SCCPInstVisitor::handleCallOverdefined(CallBase &CB) {

1947

1948

1950 return;

1951

1952

1954 return (void)markOverdefined(&CB);

1955

1956

1957

1960 for (const Use &A : CB.args()) {

1961 if (A.get()->getType()->isStructTy())

1962 return markOverdefined(&CB);

1963 if (A.get()->getType()->isMetadataTy())

1964 continue;

1965 const ValueLatticeElement &State = getValueState(A);

1966

1968 return;

1970 return (void)markOverdefined(&CB);

1973 }

1974

1976 return (void)markOverdefined(&CB);

1977

1978

1979

1981 return (void)markConstant(&CB, C);

1982 }

1983

1984

1986}

1987

1988void SCCPInstVisitor::handleCallArguments(CallBase &CB) {

1990

1991

1992

1993 if (TrackingIncomingArguments.count(F)) {

1995

1996

1999 ++AI, ++CAI) {

2000

2001

2002 if (AI->hasByValAttr() && F->onlyReadsMemory()) {

2003 markOverdefined(&*AI);

2004 continue;

2005 }

2006

2008 for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {

2009 ValueLatticeElement CallArg = getStructValueState(*CAI, i);

2010 mergeInValue(getStructValueState(&*AI, i), &*AI, CallArg,

2012 }

2013 } else {

2014 ValueLatticeElement CallArg =

2017 }

2018 }

2019 }

2020}

2021

2022void SCCPInstVisitor::handlePredicate(Instruction *I, Value *CopyOf,

2024 ValueLatticeElement CopyOfVal = getValueState(CopyOf);

2025 const std::optional &Constraint = PI->getConstraint();

2026 if (!Constraint) {

2027 mergeInValue(ValueState[I], I, CopyOfVal);

2028 return;

2029 }

2030

2032 Value *OtherOp = Constraint->OtherOp;

2033

2034

2035 if (getValueState(OtherOp).isUnknown()) {

2036 addAdditionalUser(OtherOp, I);

2037 return;

2038 }

2039

2040 ValueLatticeElement CondVal = getValueState(OtherOp);

2041 ValueLatticeElement &IV = ValueState[I];

2043 auto ImposedCR =

2044 ConstantRange::getFull(DL.getTypeSizeInBits(CopyOf->getType()));

2045

2046

2050

2051

2052

2054 true);

2055

2056 if (CopyOfCR.isEmptySet())

2057 CopyOfCR = ConstantRange::getFull(CopyOfCR.getBitWidth());

2058 auto NewCR = ImposedCR.intersectWith(CopyOfCR);

2059

2060

2061

2062 if (!CopyOfCR.contains(NewCR) && CopyOfCR.getSingleMissingElement())

2063 NewCR = CopyOfCR;

2064

2065

2066

2067

2068

2069

2070 addAdditionalUser(OtherOp, I);

2071 mergeInValue(

2073 return;

2076

2077

2078 addAdditionalUser(OtherOp, I);

2079 mergeInValue(IV, I, CondVal);

2080 return;

2082

2083 addAdditionalUser(OtherOp, I);

2085 return;

2086 }

2087

2088 return (void)mergeInValue(IV, I, CopyOfVal);

2089}

2090

2091void SCCPInstVisitor::handleCallResult(CallBase &CB) {

2093

2095 if (II->getIntrinsicID() == Intrinsic::vscale) {

2098 return (void)mergeInValue(ValueState[II], II,

2100 }

2101 if (II->getIntrinsicID() == Intrinsic::experimental_get_vector_length) {

2102 Value *CountArg = II->getArgOperand(0);

2103 Value *VF = II->getArgOperand(1);

2105

2106

2109

2110 ConstantRange Count = getValueState(CountArg)

2111 .asConstantRange(CountArg->getType(), false)

2113 ConstantRange MaxLanes = getValueState(VF)

2114 .asConstantRange(VF->getType(), false)

2116 if (Scalable)

2117 MaxLanes =

2119

2120

2121 ConstantRange Result(

2124

2125

2128

2129 Result = Result.truncate(II->getType()->getScalarSizeInBits());

2130 return (void)mergeInValue(ValueState[II], II,

2132 }

2133

2135

2136

2137

2140 const ValueLatticeElement &State = getValueState(Op);

2142 return;

2145 }

2146

2147 ConstantRange Result =

2149 return (void)mergeInValue(ValueState[II], II,

2151 }

2152 }

2153

2154

2155

2156

2157 if (F || F->isDeclaration())

2158 return handleCallOverdefined(CB);

2159

2160

2162 if (!MRVFunctionsTracked.count(F))

2163 return handleCallOverdefined(CB);

2164

2165

2166

2167 for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i)

2168 mergeInValue(getStructValueState(&CB, i), &CB,

2169 TrackedMultipleRetVals[std::make_pair(F, i)],

2171 } else {

2172 auto TFRVI = TrackedRetVals.find(F);

2173 if (TFRVI == TrackedRetVals.end())

2174 return handleCallOverdefined(CB);

2175

2176

2178 }

2179}

2180

2181bool SCCPInstVisitor::isInstFullyOverDefined(Instruction &Inst) {

2182

2183

2184

2186 for (unsigned i = 0, e = STy->getNumElements(); i < e; ++i) {

2187 if (!getStructValueState(&Inst, i).isOverdefined())

2188 return false;

2189 }

2190 return true;

2191 }

2192

2193 return getValueState(&Inst).isOverdefined();

2194}

2195

2197

2198 while (!BBWorkList.empty() || !InstWorkList.empty()) {

2199

2200 while (!InstWorkList.empty()) {

2201 Instruction *I = InstWorkList.pop_back_val();

2202 Invalidated.erase(I);

2203

2204 LLVM_DEBUG(dbgs() << "\nPopped off I-WL: " << *I << '\n');

2205

2207 }

2208

2209

2210 while (!BBWorkList.empty()) {

2211 BasicBlock *BB = BBWorkList.pop_back_val();

2212 BBVisited.insert(BB);

2213

2214 LLVM_DEBUG(dbgs() << "\nPopped off BBWL: " << *BB << '\n');

2216 CurI = &I;

2218 }

2219 CurI = nullptr;

2220 }

2221 }

2222}

2223

2225

2226 if (I.getType()->isVoidTy())

2227 return false;

2228

2230

2231

2232

2235 if (MRVFunctionsTracked.count(F))

2236 return false;

2237

2238

2239

2241 return false;

2242

2243

2244 for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {

2247 markOverdefined(LV, &I);

2248 return true;

2249 }

2250 }

2251 return false;

2252 }

2253

2256 return false;

2257

2258

2259

2260

2261

2262

2265 if (TrackedRetVals.count(F))

2266 return false;

2267

2269

2270

2271

2272 return false;

2273 }

2274

2275 markOverdefined(&I);

2276 return true;

2277}

2278

2279

2280

2281

2282

2283

2284

2285

2286

2287

2288

2289

2290

2291

2293 bool MadeChange = false;

2295 if (!BBExecutable.count(&BB))

2296 continue;

2297

2300 }

2301

2303 << "\nResolved undefs in " << F.getName() << '\n');

2304

2305 return MadeChange;

2306}

2307

2308

2309

2310

2311

2317

2319

2322 Visitor->addPredicateInfo(F, DT, AC);

2323}

2324

2326 Visitor->removeSSACopies(F);

2327}

2328

2330 return Visitor->markBlockExecutable(BB);

2331}

2332

2334 return Visitor->getPredicateInfoFor(I);

2335}

2336

2338 Visitor->trackValueOfGlobalVariable(GV);

2339}

2340

2342 Visitor->addTrackedFunction(F);

2343}

2344

2346 Visitor->addToMustPreserveReturnsInFunctions(F);

2347}

2348

2350 return Visitor->mustPreserveReturn(F);

2351}

2352

2354 Visitor->addArgumentTrackedFunction(F);

2355}

2356

2358 return Visitor->isArgumentTrackedFunction(F);

2359}

2360

2363 return Visitor->getArgumentTrackedFunctions();

2364}

2365

2367

2369 return Visitor->resolvedUndefsIn(F);

2370}

2371

2373 Visitor->solveWhileResolvedUndefsIn(M);

2374}

2375

2376void

2378 Visitor->solveWhileResolvedUndefsIn(WorkList);

2379}

2380

2382 Visitor->solveWhileResolvedUndefs();

2383}

2384

2386 return Visitor->isBlockExecutable(BB);

2387}

2388

2390 return Visitor->isEdgeFeasible(From, To);

2391}

2392

2393std::vector

2395 return Visitor->getStructLatticeValueFor(V);

2396}

2397

2399 return Visitor->removeLatticeValueFor(V);

2400}

2401

2403 Visitor->resetLatticeValueFor(Call);

2404}

2405

2407 return Visitor->getLatticeValueFor(V);

2408}

2409

2412 return Visitor->getTrackedRetVals();

2413}

2414

2417 return Visitor->getTrackedGlobals();

2418}

2419

2421 return Visitor->getMRVFunctionsTracked();

2422}

2423

2425

2427 Visitor->trackValueOfArgument(V);

2428}

2429

2431 return Visitor->isStructLatticeConstant(F, STy);

2432}

2433

2435 Type *Ty) const {

2436 return Visitor->getConstant(LV, Ty);

2437}

2438

2440 return Visitor->getConstantOrNull(V);

2441}

2442

2445 Visitor->setLatticeValueForSpecializationArguments(F, Args);

2446}

2447

2449 Visitor->markFunctionUnreachable(F);

2450}

2451

2453

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

MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL

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

ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))

uint64_t IntrinsicInst * II

static ValueLatticeElement::MergeOptions getMaxWidenStepsOpts()

Returns MergeOptions with MaxWidenSteps set to MaxNumRangeExtensions.

Definition SCCPSolver.cpp:48

static const unsigned MaxNumRangeExtensions

Definition SCCPSolver.cpp:45

static ValueLatticeElement getValueFromMetadata(const Instruction *I)

Definition SCCPSolver.cpp:1869

std::pair< BasicBlock *, BasicBlock * > Edge

This file implements a set that has insertion order iteration characteristics.

static ConstantInt * getConstantInt(Value *V, const DataLayout &DL)

Extract ConstantInt from value, looking through IntToPtr and PointerNullValue.

static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")

static const uint32_t IV[8]

Class for arbitrary precision integers.

unsigned countr_zero() const

Count the number of trailing zero bits.

bool ule(const APInt &RHS) const

Unsigned less or equal comparison.

static APInt getZero(unsigned numBits)

Get the '0' value for the specified bit-width.

an instruction to allocate memory on the stack

This class represents an incoming formal argument to a Function.

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

Functions, function parameters, and return types can have attributes to indicate how they should be t...

LLVM_ABI const ConstantRange & getRange() const

Returns the value of the range attribute.

static LLVM_ABI Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)

Return a uniquified Attribute object.

bool isValid() const

Return true if the attribute is any kind of attribute.

LLVM Basic Block Representation.

iterator_range< const_phi_iterator > phis() const

Returns a range that iterates over the phis in the basic block.

const Function * getParent() const

Return the enclosing method, or null if none.

static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)

Creates a new BasicBlock.

LLVM_ABI LLVMContext & getContext() const

Get the context in which this basic block lives.

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

LLVM_ABI void removePredecessor(BasicBlock *Pred, bool KeepOneInputPHIs=false)

Update PHI nodes in this BasicBlock before removal of predecessor Pred.

LLVM_ABI unsigned getNoWrapKind() const

Returns one of OBO::NoSignedWrap or OBO::NoUnsignedWrap.

LLVM_ABI Instruction::BinaryOps getBinaryOp() const

Returns the binary operation underlying the intrinsic.

static LLVM_ABI BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), InsertPosition InsertBefore=nullptr)

Construct a binary instruction, given the opcode and the two operands.

Function * getFunction() const

BasicBlock * getBasicBlock() const

static BranchInst * Create(BasicBlock *IfTrue, InsertPosition InsertBefore=nullptr)

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

std::optional< OperandBundleUse > getOperandBundle(StringRef Name) const

Return an operand bundle by name, if present.

Function * getCalledFunction() const

Returns the function called, or null if this is an indirect function invocation or the function signa...

User::op_iterator arg_begin()

Return the iterator pointing to the beginning of the argument list.

LLVM_ABI bool isMustTailCall() const

Tests if this call site must be tail call optimized.

iterator_range< User::op_iterator > args()

Iteration adapter for range-for loops.

CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...

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

This is the base class for all instructions that perform data casts.

static LLVM_ABI CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)

Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...

This class is the base class for the comparison instructions.

Predicate

This enumeration lists the possible predicates for CmpInst subclasses.

@ ICMP_SLE

signed less or equal

@ ICMP_ULE

unsigned less or equal

This is the shared class of boolean and integer constants.

bool isZero() const

This is just a convenience method to make client code smaller for a common code.

static LLVM_ABI ConstantInt * getFalse(LLVMContext &Context)

static LLVM_ABI ConstantPointerNull * get(PointerType *T)

Static factory methods - Return objects of the specified value.

This class represents a range of values.

LLVM_ABI ConstantRange multiply(const ConstantRange &Other) const

Return a new range representing the possible values resulting from a multiplication of a value in thi...

LLVM_ABI ConstantRange add(const ConstantRange &Other) const

Return a new range representing the possible values resulting from an addition of a value in this ran...

const APInt * getSingleElement() const

If this set contains a single element, return it, otherwise return null.

LLVM_ABI ConstantRange castOp(Instruction::CastOps CastOp, uint32_t BitWidth) const

Return a new range representing the possible values resulting from an application of the specified ca...

LLVM_ABI bool isFullSet() const

Return true if this set contains all of the elements possible for this data-type.

LLVM_ABI bool icmp(CmpInst::Predicate Pred, const ConstantRange &Other) const

Does the predicate Pred hold between ranges this and Other?

static LLVM_ABI ConstantRange intrinsic(Intrinsic::ID IntrinsicID, ArrayRef< ConstantRange > Ops)

Compute range of intrinsic result for the given operand ranges.

LLVM_ABI bool isSizeLargerThan(uint64_t MaxSize) const

Compare set size of this range with Value.

static LLVM_ABI bool isIntrinsicSupported(Intrinsic::ID IntrinsicID)

Returns true if ConstantRange calculations are supported for intrinsic with IntrinsicID.

bool isSingleElement() const

Return true if this set contains exactly one member.

LLVM_ABI ConstantRange truncate(uint32_t BitWidth, unsigned NoWrapKind=0) const

Return a new range in the specified integer type, which must be strictly smaller than the current typ...

LLVM_ABI bool isAllNonNegative() const

Return true if all values in this range are non-negative.

static LLVM_ABI ConstantRange makeAllowedICmpRegion(CmpInst::Predicate Pred, const ConstantRange &Other)

Produce the smallest range such that all values that may satisfy the given predicate with any value c...

const APInt & getUpper() const

Return the upper value for this range.

static LLVM_ABI ConstantRange makeExactICmpRegion(CmpInst::Predicate Pred, const APInt &Other)

Produce the exact range such that all values in the returned range satisfy the given predicate with a...

LLVM_ABI ConstantRange inverse() const

Return a new range that is the logical not of the current set.

LLVM_ABI bool contains(const APInt &Val) const

Return true if the specified value is in the set.

LLVM_ABI APInt getUnsignedMax() const

Return the largest unsigned value contained in the ConstantRange.

LLVM_ABI ConstantRange intersectWith(const ConstantRange &CR, PreferredRangeType Type=Smallest) const

Return the range that results from the intersection of this range with another range.

static LLVM_ABI ConstantRange makeGuaranteedNoWrapRegion(Instruction::BinaryOps BinOp, const ConstantRange &Other, unsigned NoWrapKind)

Produce the largest range containing all X such that "X BinOp Y" is guaranteed not to wrap (overflow)...

LLVM_ABI ConstantRange binaryOp(Instruction::BinaryOps BinOp, const ConstantRange &Other) const

Return a new range representing the possible values resulting from an application of the specified bi...

LLVM_ABI ConstantRange sub(const ConstantRange &Other) const

Return a new range representing the possible values resulting from a subtraction of a value in this r...

static LLVM_ABI Constant * get(StructType *T, ArrayRef< Constant * > V)

This is an important base class in LLVM.

static LLVM_ABI Constant * getNullValue(Type *Ty)

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

LLVM_ABI bool isNullValue() const

Return true if this is the value that would be returned by getNullValue.

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

static DebugLoc getTemporary()

DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT, true > const_iterator

Implements a dense probed hash-table based set.

static constexpr UpdateKind Delete

static constexpr UpdateKind Insert

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

This class represents a freeze function that returns random concrete value if an operand is either a ...

static GEPNoWrapFlags noUnsignedWrap()

void applyUpdatesPermissive(ArrayRef< UpdateT > Updates)

Submit updates to all available trees.

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

Module * getParent()

Get the module that this global value is contained inside of...

Type * getValueType() const

const Constant * getInitializer() const

getInitializer - Return the initializer for this global variable.

This provides a uniform API for creating instructions and inserting them into a basic block: either a...

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

Value * getInsertedValueOperand()

Value * getAggregateOperand()

unsigned getNumIndices() const

idx_iterator idx_begin() const

Base class for instruction visitors.

void visit(Iterator Start, Iterator End)

LLVM_ABI void setHasNoUnsignedWrap(bool b=true)

Set or clear the nuw flag on this instruction, which must be an operator which supports this flag.

LLVM_ABI bool hasNoUnsignedWrap() const LLVM_READONLY

Determine whether the no unsigned wrap flag is set.

LLVM_ABI unsigned getNumSuccessors() const LLVM_READONLY

Return the number of successors that this instruction has.

LLVM_ABI bool hasNoSignedWrap() const LLVM_READONLY

Determine whether the no signed wrap flag is set.

LLVM_ABI void setHasNoSignedWrap(bool b=true)

Set or clear the nsw flag on this instruction, which must be an operator which supports this flag.

const DebugLoc & getDebugLoc() const

Return the debug location for this node as a DebugLoc.

LLVM_ABI InstListType::iterator eraseFromParent()

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

LLVM_ABI bool isExact() const LLVM_READONLY

Determine whether the exact flag is set.

LLVM_ABI BasicBlock * getSuccessor(unsigned Idx) const LLVM_READONLY

Return the specified successor. This instruction must be a terminator.

LLVM_ABI void setNonNeg(bool b=true)

Set or clear the nneg flag on this instruction, which must be a zext instruction.

LLVM_ABI bool hasNonNeg() const LLVM_READONLY

Determine whether the the nneg flag is set.

unsigned getOpcode() const

Returns a member of one of the enums like Instruction::Add.

LLVM_ABI void setIsExact(bool b=true)

Set or clear the exact flag on this instruction, which must be an operator which supports this flag.

void setDebugLoc(DebugLoc Loc)

Set the debug location information for this instruction.

bool isSpecialTerminator() const

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

@ OB_clang_arc_attachedcall

An instruction for reading from memory.

This class implements a map that also provides access to all stored values in a deterministic order.

A Module instance is used to store all the information related to an LLVM module.

BasicBlock * getIncomingBlock(unsigned i) const

Return incoming basic block number i.

Value * getIncomingValue(unsigned i) const

Return incoming value number x.

unsigned getNumIncomingValues() const

Return the number of incoming edges.

LLVM_ABI std::optional< PredicateConstraint > getConstraint() const

Fetch condition in the form of PredicateConstraint, if possible.

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

Helper class for SCCPSolver.

Definition SCCPSolver.cpp:520

const MapVector< Function *, ValueLatticeElement > & getTrackedRetVals() const

Definition SCCPSolver.cpp:949

const PredicateBase * getPredicateInfoFor(Instruction *I)

Definition SCCPSolver.cpp:850

std::vector< ValueLatticeElement > getStructLatticeValueFor(Value *V) const

Definition SCCPSolver.cpp:912

bool resolvedUndef(Instruction &I)

Definition SCCPSolver.cpp:2224

void markFunctionUnreachable(Function *F)

Definition SCCPSolver.cpp:996

bool markBlockExecutable(BasicBlock *BB)

Definition SCCPSolver.cpp:1036

bool resolvedUndefsIn(Function &F)

While solving the dataflow for a function, we don't compute a result for operations with an undef ope...

Definition SCCPSolver.cpp:2292

Constant * getConstant(const ValueLatticeElement &LV, Type *Ty) const

Definition SCCPSolver.cpp:1131

SCCPInstVisitor(const DataLayout &DL, std::function< const TargetLibraryInfo &(Function &)> GetTLI, LLVMContext &Ctx)

Definition SCCPSolver.cpp:857

const DenseMap< GlobalVariable *, ValueLatticeElement > & getTrackedGlobals() const

Definition SCCPSolver.cpp:954

const ValueLatticeElement & getLatticeValueFor(Value *V) const

Definition SCCPSolver.cpp:939

void removeLatticeValueFor(Value *V)

Definition SCCPSolver.cpp:924

void trackValueOfArgument(Argument *A)

Definition SCCPSolver.cpp:981

void visitCallInst(CallInst &I)

Definition SCCPSolver.cpp:846

void markOverdefined(Value *V)

Definition SCCPSolver.cpp:962

bool isArgumentTrackedFunction(Function *F)

Definition SCCPSolver.cpp:892

void addTrackedFunction(Function *F)

Definition SCCPSolver.cpp:870

void solveWhileResolvedUndefs()

Definition SCCPSolver.cpp:1021

void solveWhileResolvedUndefsIn(Module &M)

Definition SCCPSolver.cpp:1001

void trackValueOfGlobalVariable(GlobalVariable *GV)

Definition SCCPSolver.cpp:862

Constant * getConstantOrNull(Value *V) const

Definition SCCPSolver.cpp:1147

void removeSSACopies(Function &F)

Definition SCCPSolver.cpp:826

const SmallPtrSet< Function *, 16 > & getMRVFunctionsTracked() const

Definition SCCPSolver.cpp:958

const SmallPtrSetImpl< Function * > & getArgumentTrackedFunctions() const

Definition SCCPSolver.cpp:896

void resetLatticeValueFor(CallBase *Call)

Invalidate the Lattice Value of Call and its users after specializing the call.

Definition SCCPSolver.cpp:928

void solve()

Definition SCCPSolver.cpp:2196

ValueLatticeElement getArgAttributeVL(Argument *A)

Definition SCCPSolver.cpp:970

void addPredicateInfo(Function &F, DominatorTree &DT, AssumptionCache &AC)

Definition SCCPSolver.cpp:821

void addToMustPreserveReturnsInFunctions(Function *F)

Definition SCCPSolver.cpp:880

void addArgumentTrackedFunction(Function *F)

Definition SCCPSolver.cpp:888

bool isStructLatticeConstant(Function *F, StructType *STy)

Definition SCCPSolver.cpp:1121

void solveWhileResolvedUndefsIn(SmallVectorImpl< Function * > &WorkList)

Definition SCCPSolver.cpp:1011

bool isBlockExecutable(BasicBlock *BB) const

Definition SCCPSolver.cpp:906

bool mustPreserveReturn(Function *F)

Definition SCCPSolver.cpp:884

void setLatticeValueForSpecializationArguments(Function *F, const SmallVectorImpl< ArgInfo > &Args)

Definition SCCPSolver.cpp:1173

bool isEdgeFeasible(BasicBlock *From, BasicBlock *To) const

Definition SCCPSolver.cpp:1354

SCCPSolver - This interface class is a general purpose solver for Sparse Conditional Constant Propaga...

LLVM_ABI void visitCall(CallInst &I)

Definition SCCPSolver.cpp:2454

LLVM_ABI void resetLatticeValueFor(CallBase *Call)

Invalidate the Lattice Value of Call and its users after specializing the call.

Definition SCCPSolver.cpp:2402

LLVM_ABI void trackValueOfGlobalVariable(GlobalVariable *GV)

trackValueOfGlobalVariable - Clients can use this method to inform the SCCPSolver that it should trac...

Definition SCCPSolver.cpp:2337

LLVM_ABI bool tryToReplaceWithConstant(Value *V)

Definition SCCPSolver.cpp:64

LLVM_ABI void inferArgAttributes() const

Definition SCCPSolver.cpp:507

LLVM_ABI bool isStructLatticeConstant(Function *F, StructType *STy)

Definition SCCPSolver.cpp:2430

LLVM_ABI void addPredicateInfo(Function &F, DominatorTree &DT, AssumptionCache &AC)

Definition SCCPSolver.cpp:2320

LLVM_ABI void solve()

Solve - Solve for constants and executable blocks.

Definition SCCPSolver.cpp:2366

LLVM_ABI void visit(Instruction *I)

Definition SCCPSolver.cpp:2452

LLVM_ABI void trackValueOfArgument(Argument *V)

trackValueOfArgument - Mark the specified argument overdefined unless it have range attribute.

Definition SCCPSolver.cpp:2426

LLVM_ABI const DenseMap< GlobalVariable *, ValueLatticeElement > & getTrackedGlobals() const

getTrackedGlobals - Get and return the set of inferred initializers for global variables.

Definition SCCPSolver.cpp:2416

LLVM_ABI void addTrackedFunction(Function *F)

addTrackedFunction - If the SCCP solver is supposed to track calls into and out of the specified func...

Definition SCCPSolver.cpp:2341

LLVM_ABI void solveWhileResolvedUndefsIn(Module &M)

Definition SCCPSolver.cpp:2372

LLVM_ABI const PredicateBase * getPredicateInfoFor(Instruction *I)

Definition SCCPSolver.cpp:2333

LLVM_ABI const SmallPtrSetImpl< Function * > & getArgumentTrackedFunctions() const

Definition SCCPSolver.cpp:2362

LLVM_ABI const SmallPtrSet< Function *, 16 > & getMRVFunctionsTracked() const

getMRVFunctionsTracked - Get the set of functions which return multiple values tracked by the pass.

Definition SCCPSolver.cpp:2420

LLVM_ABI bool resolvedUndefsIn(Function &F)

resolvedUndefsIn - While solving the dataflow for a function, we assume that branches on undef values...

Definition SCCPSolver.cpp:2368

LLVM_ABI void addArgumentTrackedFunction(Function *F)

Definition SCCPSolver.cpp:2353

LLVM_ABI void solveWhileResolvedUndefs()

Definition SCCPSolver.cpp:2381

LLVM_ABI void removeLatticeValueFor(Value *V)

Definition SCCPSolver.cpp:2398

LLVM_ABI std::vector< ValueLatticeElement > getStructLatticeValueFor(Value *V) const

Definition SCCPSolver.cpp:2394

LLVM_ABI Constant * getConstantOrNull(Value *V) const

Return either a Constant or nullptr for a given Value.

Definition SCCPSolver.cpp:2439

LLVM_ABI bool simplifyInstsInBlock(BasicBlock &BB, SmallPtrSetImpl< Value * > &InsertedValues, Statistic &InstRemovedStat, Statistic &InstReplacedStat)

Definition SCCPSolver.cpp:350

LLVM_ABI Constant * getConstant(const ValueLatticeElement &LV, Type *Ty) const

Helper to return a Constant if LV is either a constant or a constant range with a single element.

Definition SCCPSolver.cpp:2434

LLVM_ABI const ValueLatticeElement & getLatticeValueFor(Value *V) const

Definition SCCPSolver.cpp:2406

LLVM_ABI void addToMustPreserveReturnsInFunctions(Function *F)

Add function to the list of functions whose return cannot be modified.

Definition SCCPSolver.cpp:2345

LLVM_ABI bool removeNonFeasibleEdges(BasicBlock *BB, DomTreeUpdater &DTU, BasicBlock *&NewUnreachableBB) const

Definition SCCPSolver.cpp:379

LLVM_ABI bool isBlockExecutable(BasicBlock *BB) const

Definition SCCPSolver.cpp:2385

LLVM_ABI void inferReturnAttributes() const

Definition SCCPSolver.cpp:502

LLVM_ABI bool markBlockExecutable(BasicBlock *BB)

markBlockExecutable - This method can be used by clients to mark all of the blocks that are known to ...

Definition SCCPSolver.cpp:2329

LLVM_ABI void setLatticeValueForSpecializationArguments(Function *F, const SmallVectorImpl< ArgInfo > &Args)

Set the Lattice Value for the arguments of a specialization F.

Definition SCCPSolver.cpp:2443

static LLVM_ABI bool isConstant(const ValueLatticeElement &LV)

Definition SCCPSolver.cpp:55

LLVM_ABI const MapVector< Function *, ValueLatticeElement > & getTrackedRetVals() const

getTrackedRetVals - Get the inferred return value map.

Definition SCCPSolver.cpp:2411

LLVM_ABI bool isEdgeFeasible(BasicBlock *From, BasicBlock *To) const

Definition SCCPSolver.cpp:2389

LLVM_ABI bool mustPreserveReturn(Function *F)

Returns true if the return of the given function cannot be modified.

Definition SCCPSolver.cpp:2349

static LLVM_ABI bool isOverdefined(const ValueLatticeElement &LV)

Definition SCCPSolver.cpp:60

LLVM_ABI void markFunctionUnreachable(Function *F)

Mark all of the blocks in function F non-executable.

Definition SCCPSolver.cpp:2448

LLVM_ABI bool isArgumentTrackedFunction(Function *F)

Returns true if the given function is in the solver's set of argument-tracked functions.

Definition SCCPSolver.cpp:2357

LLVM_ABI SCCPSolver(const DataLayout &DL, std::function< const TargetLibraryInfo &(Function &)> GetTLI, LLVMContext &Ctx)

Definition SCCPSolver.cpp:2312

LLVM_ABI void markOverdefined(Value *V)

markOverdefined - Mark the specified value overdefined.

Definition SCCPSolver.cpp:2424

LLVM_ABI void removeSSACopies(Function &F)

Definition SCCPSolver.cpp:2325

This class represents the LLVM 'select' instruction.

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

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

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

bool contains(ConstPtrType Ptr) const

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

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

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

void assign(size_type NumElts, ValueParamT Elt)

void reserve(size_type N)

void push_back(const T &Elt)

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

An instruction for storing to memory.

Class to represent struct types.

unsigned getNumElements() const

Random access to the elements.

A wrapper class to simplify modification of SwitchInst cases along with their prof branch_weights met...

Provides information about what library functions are available for the current target.

This class represents a truncation of integer types.

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

bool isPointerTy() const

True if this is an instance of PointerType.

bool isSingleValueType() const

Return true if the type is a valid type for a register in codegen.

bool isStructTy() const

True if this is an instance of StructType.

LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY

If this is a vector type, return the getPrimitiveSizeInBits value for the element type.

bool isVoidTy() const

Return true if this is 'void'.

static LLVM_ABI UndefValue * get(Type *T)

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

This function has undefined behavior.

Value * getOperand(unsigned i) const

This class represents lattice values for constants.

static ValueLatticeElement getRange(ConstantRange CR, bool MayIncludeUndef=false)

bool isOverdefined() const

LLVM_ABI Constant * getCompare(CmpInst::Predicate Pred, Type *Ty, const ValueLatticeElement &Other, const DataLayout &DL) const

true, false or undef constants, or nullptr if the comparison cannot be evaluated.

bool isConstantRangeIncludingUndef() const

static ValueLatticeElement getNot(Constant *C)

ConstantRange asConstantRange(unsigned BW, bool UndefAllowed=false) const

bool isNotConstant() const

void setNumRangeExtensions(unsigned N)

const ConstantRange & getConstantRange(bool UndefAllowed=true) const

Returns the constant range for this value.

bool isConstantRange(bool UndefAllowed=true) const

Returns true if this value is a constant range.

unsigned getNumRangeExtensions() const

Constant * getNotConstant() const

LLVM_ABI ValueLatticeElement intersect(const ValueLatticeElement &Other) const

Combine two sets of facts about the same value into a single set of facts.

bool isUnknownOrUndef() const

Constant * getConstant() const

bool mergeIn(const ValueLatticeElement &RHS, MergeOptions Opts=MergeOptions())

Updates this object to approximate both this object and RHS.

bool markConstant(Constant *V, bool MayIncludeUndef=false)

static ValueLatticeElement getOverdefined()

LLVM Value Representation.

Type * getType() const

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

LLVM_ABI std::string getNameOrAsOperand() const

LLVM_ABI void replaceAllUsesWith(Value *V)

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

iterator_range< user_iterator > users()

LLVM_ABI StringRef getName() const

Return a constant reference to the value's name.

LLVM_ABI void takeName(Value *V)

Transfer the name from V to this value.

Represents an op.with.overflow intrinsic.

const ParentTy * getParent() const

self_iterator getIterator()

#define llvm_unreachable(msg)

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

const APInt & umin(const APInt &A, const APInt &B)

Determine the smaller of two APInts considered to be unsigned.

@ C

The default llvm calling convention, compatible with C.

@ BasicBlock

Various leaf nodes.

OneUse_match< SubPat > m_OneUse(const SubPat &SP)

cst_pred_ty< is_lowbit_mask > m_LowBitMask()

Match an integer or vector with only the low bit(s) set.

BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)

ap_match< APInt > m_APInt(const APInt *&Res)

Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.

bool match(Val *V, const Pattern &P)

cst_pred_ty< is_negated_power2 > m_NegatedPower2()

Match a integer or vector negated power-of-2.

match_combine_or< BinaryOp_match< LHS, RHS, Instruction::Add >, DisjointOr_match< LHS, RHS > > m_AddLike(const LHS &L, const RHS &R)

Match either "add" or "or disjoint".

class_match< Value > m_Value()

Match an arbitrary value and ignore it.

This is an optimization pass for GlobalISel generic memory operations.

FunctionAddr VTableAddr Value

bool all_of(R &&range, UnaryPredicate P)

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

static bool replaceSignedInst(SCCPSolver &Solver, SmallPtrSetImpl< Value * > &InsertedValues, Instruction &Inst)

Try to replace signed instructions with their unsigned equivalent.

Definition SCCPSolver.cpp:181

LLVM_ABI bool canConstantFoldCallTo(const CallBase *Call, const Function *F)

canConstantFoldCallTo - Return true if its even possible to fold a call to the specified function.

decltype(auto) dyn_cast(const From &Val)

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

auto successors(const MachineBasicBlock *BB)

static ConstantRange getRange(Value *Op, SCCPSolver &Solver, const SmallPtrSetImpl< Value * > &InsertedValues)

Helper for getting ranges from Solver.

Definition SCCPSolver.cpp:96

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

LLVM_ABI Constant * ConstantFoldCall(const CallBase *Call, Function *F, ArrayRef< Constant * > Operands, const TargetLibraryInfo *TLI=nullptr, bool AllowNonDeterministic=true)

ConstantFoldCall - Attempt to constant fold a call to the specified function with the specified argum...

LLVM_ABI ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)

Parse out a conservative ConstantRange from !range metadata.

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

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

auto dyn_cast_or_null(const Y &Val)

bool any_of(R &&range, UnaryPredicate P)

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

LLVM_ABI Constant * ConstantFoldUnaryOpOperand(unsigned Opcode, Constant *Op, const DataLayout &DL)

Attempt to constant fold a unary operation with the specified operand.

LLVM_ABI bool NullPointerIsDefined(const Function *F, unsigned AS=0)

Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...

LLVM_ABI raw_ostream & dbgs()

dbgs() - This returns a reference to a raw_ostream for debugging messages.

LLVM_ABI bool wouldInstructionBeTriviallyDead(const Instruction *I, const TargetLibraryInfo *TLI=nullptr)

Return true if the result produced by the instruction would have no side effects if it was not used.

FunctionAddr VTableAddr Count

LLVM_ABI ConstantRange getVScaleRange(const Function *F, unsigned BitWidth)

Determine the possible constant range of vscale with the given bit width, based on the vscale_range f...

LLVM_ABI Constant * ConstantFoldCastOperand(unsigned Opcode, Constant *C, Type *DestTy, const DataLayout &DL)

Attempt to constant fold a cast with the specified operand.

class LLVM_GSL_OWNER SmallVector

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

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 Value * simplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS, const SimplifyQuery &Q)

Given operands for a BinaryOperator, fold the result or return null.

@ Sub

Subtraction of integers.

DWARFExpression::Operation Op

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

Return true if this function can prove that V does not have undef bits and is never poison.

constexpr unsigned BitWidth

OutputIt move(R &&Range, OutputIt Out)

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

decltype(auto) cast(const From &Val)

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

LLVM_ABI Constant * ConstantFoldLoadFromConstPtr(Constant *C, Type *Ty, APInt Offset, const DataLayout &DL)

Return the value that a load from C with offset Offset would produce if it is constant and determinab...

BumpPtrAllocatorImpl<> BumpPtrAllocator

The standard BumpPtrAllocator which just uses the default template parameters.

LLVM_ABI Constant * ConstantFoldInstOperands(const Instruction *I, ArrayRef< Constant * > Ops, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, bool AllowNonDeterministic=true)

ConstantFoldInstOperands - Attempt to constant fold an instruction with the specified operands.

static bool refineInstruction(SCCPSolver &Solver, const SmallPtrSetImpl< Value * > &InsertedValues, Instruction &Inst)

Try to use Inst's value range from Solver to infer the NUW flag.

Definition SCCPSolver.cpp:109

static void inferAttribute(Function *F, unsigned AttrIndex, const ValueLatticeElement &Val)

Definition SCCPSolver.cpp:476

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

Struct to control some aspects related to merging constant ranges.

MergeOptions & setMaxWidenSteps(unsigned Steps=1)