LLVM: lib/Transforms/Scalar/CorrelatedValuePropagation.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

42#include

43#include

44#include

45

46using namespace llvm;

47

48#define DEBUG_TYPE "correlated-value-propagation"

49

50STATISTIC(NumPhis, "Number of phis propagated");

51STATISTIC(NumPhiCommon, "Number of phis deleted via common incoming value");

52STATISTIC(NumSelects, "Number of selects propagated");

53STATISTIC(NumCmps, "Number of comparisons propagated");

54STATISTIC(NumReturns, "Number of return values propagated");

55STATISTIC(NumDeadCases, "Number of switch cases removed");

57 "Number of sdivs/srems whose width was decreased");

58STATISTIC(NumSDivs, "Number of sdiv converted to udiv");

60 "Number of udivs/urems whose width was decreased");

61STATISTIC(NumAShrsConverted, "Number of ashr converted to lshr");

62STATISTIC(NumAShrsRemoved, "Number of ashr removed");

63STATISTIC(NumSRems, "Number of srem converted to urem");

64STATISTIC(NumSExt, "Number of sext converted to zext");

65STATISTIC(NumSIToFP, "Number of sitofp converted to uitofp");

66STATISTIC(NumSICmps, "Number of signed icmp preds simplified to unsigned");

67STATISTIC(NumAnd, "Number of ands removed");

68STATISTIC(NumNW, "Number of no-wrap deductions");

69STATISTIC(NumNSW, "Number of no-signed-wrap deductions");

70STATISTIC(NumNUW, "Number of no-unsigned-wrap deductions");

71STATISTIC(NumAddNW, "Number of no-wrap deductions for add");

72STATISTIC(NumAddNSW, "Number of no-signed-wrap deductions for add");

73STATISTIC(NumAddNUW, "Number of no-unsigned-wrap deductions for add");

74STATISTIC(NumSubNW, "Number of no-wrap deductions for sub");

75STATISTIC(NumSubNSW, "Number of no-signed-wrap deductions for sub");

76STATISTIC(NumSubNUW, "Number of no-unsigned-wrap deductions for sub");

77STATISTIC(NumMulNW, "Number of no-wrap deductions for mul");

78STATISTIC(NumMulNSW, "Number of no-signed-wrap deductions for mul");

79STATISTIC(NumMulNUW, "Number of no-unsigned-wrap deductions for mul");

80STATISTIC(NumShlNW, "Number of no-wrap deductions for shl");

81STATISTIC(NumShlNSW, "Number of no-signed-wrap deductions for shl");

82STATISTIC(NumShlNUW, "Number of no-unsigned-wrap deductions for shl");

83STATISTIC(NumAbs, "Number of llvm.abs intrinsics removed");

84STATISTIC(NumOverflows, "Number of overflow checks removed");

86 "Number of saturating arithmetics converted to normal arithmetics");

87STATISTIC(NumNonNull, "Number of function pointer arguments marked non-null");

88STATISTIC(NumCmpIntr, "Number of llvm.[us]cmp intrinsics removed");

89STATISTIC(NumMinMax, "Number of llvm.[us]{min,max} intrinsics removed");

91 "Number of llvm.s{min,max} intrinsics simplified to unsigned");

93 "Number of bound udiv's/urem's expanded");

94STATISTIC(NumNNeg, "Number of zext/uitofp non-negative deductions");

95

98 return C;

99

100

101

103 if (C)

104 return nullptr;

105

106 Value *Op0 = C->getOperand(0);

108 if (!Op1)

109 return nullptr;

110

111 return LVI->getPredicateAt(C->getPredicate(), Op0, Op1, At,

112 false);

113}

114

117 return false;

118

125 I->getParent(), I);

126 else

128

130 if (!CI)

131 continue;

132

135 ++NumSelects;

136 }

137

140

142}

143

144

145

146

147

148

149

150

151

152

153

154

157

159 Value *CommonValue = nullptr;

160 for (unsigned i = 0, e = P->getNumIncomingValues(); i != e; ++i) {

163 IncomingConstants.push_back(std::make_pair(IncomingConstant, i));

164 } else if (!CommonValue) {

165

167 } else if (Incoming != CommonValue) {

168

169 return false;

170 }

171 }

172

173 if (!CommonValue || IncomingConstants.empty())

174 return false;

175

176

179 if (!DT->dominates(CommonInst, ToBB))

180 return false;

181

182

183

184

185 for (auto &IncomingConstant : IncomingConstants) {

186 Constant *C = IncomingConstant.first;

187 BasicBlock *IncomingBB = P->getIncomingBlock(IncomingConstant.second);

189 return false;

190 }

191

192

193

194

196 return false;

197

198

199

200 P->replaceAllUsesWith(CommonValue);

201 P->eraseFromParent();

202 ++NumPhiCommon;

203 return true;

204}

205

210 return C;

211

212

213

214

215

217 if (SI)

218 return nullptr;

219

220

221

222 Value *Condition = SI->getCondition();

225 if (C->isOneValue())

226 return SI->getTrueValue();

227 if (C->isZeroValue())

228 return SI->getFalseValue();

229 }

230 }

231

232

233

234

235

236

237

241 Res && Res->isZero())

242 return SI->getTrueValue();

243

244

245

249 Res && Res->isZero())

250 return SI->getFalseValue();

251

252 return nullptr;

253}

254

258

260 for (unsigned i = 0, e = P->getNumIncomingValues(); i < e; ++i) {

263

265 if (V) {

266 P->setIncomingValue(i, V);

268 }

269 }

270

272 P->replaceAllUsesWith(V);

273 P->eraseFromParent();

275 }

276

279

281 ++NumPhis;

282

284}

285

287

288 if (!Cmp->getOperand(0)->getType()->isIntOrIntVectorTy())

289 return false;

290

291 if (!Cmp->isSigned() && (!Cmp->isUnsigned() || Cmp->hasSameSign()))

292 return false;

293

295

297 false),

299 false);

300

301 if (Cmp->isSigned()) {

304 Cmp->getPredicate(), CR1, CR2);

305

307 return false;

308

309 ++NumSICmps;

310 Cmp->setPredicate(UnsignedPred);

312 }

313

315 Cmp->setSameSign();

317 }

318

320}

321

322

323

324

325

327 Value *Op0 = Cmp->getOperand(0);

328 Value *Op1 = Cmp->getOperand(1);

330 true);

331 if (!Res)

332 return false;

333

334 ++NumCmps;

335 Cmp->replaceAllUsesWith(Res);

336 Cmp->eraseFromParent();

337 return true;

338}

339

342 return true;

343

346 return true;

347

348 return false;

349}

350

351

352

353

354

355

356

357

360 DomTreeUpdater DTU(*DT, DomTreeUpdater::UpdateStrategy::Lazy);

363

364

368 SuccessorsCount[Succ]++;

369

370 {

371

375 unsigned ReachableCaseCount = 0;

376

377 for (auto CI = SI->case_begin(), CE = SI->case_end(); CI != CE;) {

379 std::optional Predicate = std::nullopt;

386

389 true));

390 if (Res && Res->isZero())

392 else if (Res && Res->isOne())

394 }

395

397

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

400 CI = SI.removeCase(CI);

401 CE = SI->case_end();

402

403

404

405 Cond = SI->getCondition();

406

407 ++NumDeadCases;

409 if (--SuccessorsCount[Succ] == 0)

411 continue;

412 }

414

415

416

417 SI->setCondition(Case);

418 NumDeadCases += SI->getNumCases();

420 break;

421 }

422

423

424 ++CI;

425 ++ReachableCaseCount;

426 }

427

428

429 if (SI->defaultDestUnreachable() &&

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

437

439 SI->setDefaultDest(NewUnreachableBB);

440

441 if (SuccessorsCount[DefaultDest] == 1)

444

445 ++NumDeadCases;

447 }

448 }

449

451

452

454 nullptr, &DTU);

456}

457

458

466 return NWRegion.contains(LRange);

467}

468

470 bool NewNSW, bool NewNUW) {

471 Statistic *OpcNW, *OpcNSW, *OpcNUW;

472 switch (Opcode) {

473 case Instruction::Add:

474 OpcNW = &NumAddNW;

475 OpcNSW = &NumAddNSW;

476 OpcNUW = &NumAddNUW;

477 break;

478 case Instruction::Sub:

479 OpcNW = &NumSubNW;

480 OpcNSW = &NumSubNSW;

481 OpcNUW = &NumSubNUW;

482 break;

483 case Instruction::Mul:

484 OpcNW = &NumMulNW;

485 OpcNSW = &NumMulNSW;

486 OpcNUW = &NumMulNUW;

487 break;

488 case Instruction::Shl:

489 OpcNW = &NumShlNW;

490 OpcNSW = &NumShlNSW;

491 OpcNUW = &NumShlNUW;

492 break;

493 default:

495 }

496

498 if (NewNSW) {

499 ++NumNW;

500 ++*OpcNW;

501 ++NumNSW;

502 ++*OpcNSW;

503 if (Inst)

504 Inst->setHasNoSignedWrap();

505 }

506 if (NewNUW) {

507 ++NumNW;

508 ++*OpcNW;

509 ++NumNUW;

510 ++*OpcNUW;

511 if (Inst)

512 Inst->setHasNoUnsignedWrap();

513 }

514}

515

517

518

519

520

522 Value *X = II->getArgOperand(0);

526 II->getOperandUse(0), IsIntMinPoison);

527

528

530 ++NumAbs;

531 II->replaceAllUsesWith(X);

532 II->eraseFromParent();

533 return true;

534 }

535

536

537 if (Range.getSignedMax().isNonPositive()) {

539 Value *NegX = B.CreateNeg(X, II->getName(),

540 IsIntMinPoison);

541 ++NumAbs;

542 II->replaceAllUsesWith(NegX);

543 II->eraseFromParent();

544

545

548

549 return true;

550 }

551

552

553

554 if (!IsIntMinPoison && Range.contains(IntMin)) {

555 ++NumNSW;

556 ++NumSubNSW;

558 return true;

559 }

560 return false;

561}

562

568

570 ++NumCmpIntr;

573 return true;

574 }

576 ++NumCmpIntr;

579 return true;

580 }

582 ++NumCmpIntr;

585 return true;

586 }

587

588 return false;

589}

590

591

592

596 false);

598 false);

599 if (LHS_CR.icmp(Pred, RHS_CR)) {

600 ++NumMinMax;

603 return true;

604 }

605 if (RHS_CR.icmp(Pred, LHS_CR)) {

606 ++NumMinMax;

609 return true;

610 }

611

614 RHS_CR)) {

615 ++NumSMinMax;

618 MM->getIntrinsicID() == Intrinsic::smin ? Intrinsic::umin

619 : Intrinsic::umax,

622 return true;

623 }

624

625 return false;

626}

627

628

634

638

643 Value *NewI = B.CreateInsertValue(Struct, NewOp, 0);

646 ++NumOverflows;

647

648

651

652 return true;

653}

654

657 bool NSW = SI->isSigned();

658 bool NUW = SI->isSigned();

660 Opcode, SI->getLHS(), SI->getRHS(), SI->getName(), SI->getIterator());

663

664 SI->replaceAllUsesWith(BinOp);

665 SI->eraseFromParent();

666 ++NumSaturating;

667

668

671

672 return true;

673}

674

675

677

680 }

681

684 }

685

688 }

689

693 }

694

698 }

699

701

702

703

704

705

706

707

708

710 for (const Use &ConstU : DeoptBundle->Inputs) {

711 Use &U = const_cast<Use&>(ConstU);

712 Value *V = U.get();

713 if (V->getType()->isVectorTy()) continue;

715

717 if (C) continue;

718 U.set(C);

720 }

721 }

722

724 unsigned ArgNo = 0;

725

728

729

730

735 false));

736 Res && Res->isZero())

738 ArgNo++;

739 }

740

741 assert(ArgNo == CB.arg_size() && "Call arguments not processed correctly.");

742

743 if (ArgNos.empty())

745

746 NumNonNull += ArgNos.size();

749 AS = AS.addParamAttribute(Ctx, ArgNos,

752

753 return true;

754}

755

757

765

766

767

770 assert(Instr->getOpcode() == Instruction::SDiv ||

771 Instr->getOpcode() == Instruction::SRem);

772

773

774

775 unsigned OrigWidth = Instr->getType()->getScalarSizeInBits();

776

777

778

779 unsigned MinSignedBits =

781

782

783

786 ++MinSignedBits;

787

788

789 unsigned NewWidth = std::max(PowerOf2Ceil(MinSignedBits), 8);

790

791

792

793 if (NewWidth >= OrigWidth)

794 return false;

795

796 ++NumSDivSRemsNarrowed;

798 auto *TruncTy = Instr->getType()->getWithNewBitWidth(NewWidth);

799 auto *LHS = B.CreateTruncOrBitCast(Instr->getOperand(0), TruncTy,

800 Instr->getName() + ".lhs.trunc");

801 auto *RHS = B.CreateTruncOrBitCast(Instr->getOperand(1), TruncTy,

802 Instr->getName() + ".rhs.trunc");

803 auto *BO = B.CreateBinOp(Instr->getOpcode(), LHS, RHS, Instr->getName());

804 auto *Sext = B.CreateSExt(BO, Instr->getType(), Instr->getName() + ".sext");

806 if (BinOp->getOpcode() == Instruction::SDiv)

807 BinOp->setIsExact(Instr->isExact());

808

809 Instr->replaceAllUsesWith(Sext);

810 Instr->eraseFromParent();

811 return true;

812}

813

816 Type *Ty = Instr->getType();

817 assert(Instr->getOpcode() == Instruction::UDiv ||

818 Instr->getOpcode() == Instruction::URem);

819 bool IsRem = Instr->getOpcode() == Instruction::URem;

820

821 Value *X = Instr->getOperand(0);

822 Value *Y = Instr->getOperand(1);

823

824

825

828 Instr->eraseFromParent();

829 ++NumUDivURemsNarrowedExpanded;

830 return true;

831 }

832

833

834

835

836

837

838

839

840

841

842

843

844

845

846

847

848

849

850

851

852

853

854

855

856

858 return false;

859

861 Value *ExpandedOp;

863

864 if (IsRem)

865 ExpandedOp = B.CreateNUWSub(X, Y);

866 else

867 ExpandedOp = ConstantInt::get(Instr->getType(), 1);

868 } else if (IsRem) {

869

870

873 FrozenX = B.CreateFreeze(X, X->getName() + ".frozen");

876 FrozenY = B.CreateFreeze(Y, Y->getName() + ".frozen");

877 auto *AdjX = B.CreateNUWSub(FrozenX, FrozenY, Instr->getName() + ".urem");

879 Instr->getName() + ".cmp");

880 ExpandedOp = B.CreateSelect(Cmp, FrozenX, AdjX);

881 } else {

882 auto *Cmp =

884 ExpandedOp = B.CreateZExt(Cmp, Ty, Instr->getName() + ".udiv");

885 }

887 Instr->replaceAllUsesWith(ExpandedOp);

888 Instr->eraseFromParent();

889 ++NumUDivURemsNarrowedExpanded;

890 return true;

891}

892

893

894

897 assert(Instr->getOpcode() == Instruction::UDiv ||

898 Instr->getOpcode() == Instruction::URem);

899

900

901

902

903

904

906

907 unsigned NewWidth = std::max(PowerOf2Ceil(MaxActiveBits), 8);

908

909

910

911 if (NewWidth >= Instr->getType()->getScalarSizeInBits())

912 return false;

913

914 ++NumUDivURemsNarrowed;

916 auto *TruncTy = Instr->getType()->getWithNewBitWidth(NewWidth);

917 auto *LHS = B.CreateTruncOrBitCast(Instr->getOperand(0), TruncTy,

918 Instr->getName() + ".lhs.trunc");

919 auto *RHS = B.CreateTruncOrBitCast(Instr->getOperand(1), TruncTy,

920 Instr->getName() + ".rhs.trunc");

921 auto *BO = B.CreateBinOp(Instr->getOpcode(), LHS, RHS, Instr->getName());

922 auto *Zext = B.CreateZExt(BO, Instr->getType(), Instr->getName() + ".zext");

924 if (BinOp->getOpcode() == Instruction::UDiv)

925 BinOp->setIsExact(Instr->isExact());

926

927 Instr->replaceAllUsesWith(Zext);

928 Instr->eraseFromParent();

929 return true;

930}

931

933 assert(Instr->getOpcode() == Instruction::UDiv ||

934 Instr->getOpcode() == Instruction::URem);

936 false);

937

939 true);

941 return true;

942

944}

945

949

953 return true;

954 }

955

956 struct Operand {

959 };

963 return false;

964

965

966 ++NumSRems;

967

968

969 for (Operand &Op : Ops) {

971 continue;

975 Op.V = BO;

976 }

977

978 auto *URem = BinaryOperator::CreateURem(Ops[0].V, Ops[1].V, SDI->getName(),

981

982 auto *Res = URem;

983

984

989 }

990

993

994

996

997 return true;

998}

999

1000

1001

1002

1003

1004

1008

1009

1014 return true;

1015 }

1016

1017 struct Operand {

1020 };

1024 return false;

1025

1026

1027 ++NumSDivs;

1028

1029

1030 for (Operand &Op : Ops) {

1032 continue;

1036 Op.V = BO;

1037 }

1038

1039 auto *UDiv = BinaryOperator::CreateUDiv(Ops[0].V, Ops[1].V, SDI->getName(),

1042 UDiv->setIsExact(SDI->isExact());

1043

1044 auto *Res = UDiv;

1045

1046

1051 }

1052

1055

1056

1058

1059 return true;

1060}

1061

1063 assert(Instr->getOpcode() == Instruction::SDiv ||

1064 Instr->getOpcode() == Instruction::SRem);

1067

1070 if (Instr->getOpcode() == Instruction::SDiv)

1072 return true;

1073

1074 if (Instr->getOpcode() == Instruction::SRem) {

1076 return true;

1077 }

1078

1080}

1081

1088 if (NegOneOrZero.contains(LRange)) {

1089

1090 ++NumAShrsRemoved;

1093 return true;

1094 }

1095

1097 return false;

1098

1099 ++NumAShrsConverted;

1100 auto *BO = BinaryOperator::CreateLShr(SDI->getOperand(0), SDI->getOperand(1),

1102 BO->takeName(SDI);

1104 BO->setIsExact(SDI->isExact());

1107

1108 return true;

1109}

1110

1115 return false;

1116

1117 ++NumSExt;

1120 ZExt->takeName(SDI);

1122 ZExt->setNonNeg();

1125

1126 return true;

1127}

1128

1130 if (I->hasNonNeg())

1131 return false;

1132

1133 const Use &Base = I->getOperandUse(0);

1136 return false;

1137

1138 ++NumNNeg;

1139 I->setNonNeg();

1140

1141 return true;

1142}

1143

1147

1151

1156 return false;

1157

1158 ++NumSIToFP;

1161 UIToFP->takeName(SIToFP);

1162 UIToFP->setDebugLoc(SIToFP->getDebugLoc());

1163 UIToFP->setNonNeg();

1166

1167 return true;

1168}

1169

1172

1175 if (NSW && NUW)

1176 return false;

1177

1180 false);

1182 false);

1183

1185 bool NewNUW = false, NewNSW = false;

1186 if (!NUW) {

1188 Opcode, RRange, OBO::NoUnsignedWrap);

1189 NewNUW = NUWRange.contains(LRange);

1191 }

1192 if (!NSW) {

1194 Opcode, RRange, OBO::NoSignedWrap);

1195 NewNSW = NSWRange.contains(LRange);

1197 }

1198

1200

1202}

1203

1206

1207

1208

1212 return false;

1213

1214

1215

1219 return false;

1220

1223 NumAnd++;

1224 return true;

1225}

1226

1229 return false;

1230

1235

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

1239 ++NumNUW;

1241 }

1242 }

1243

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

1247 ++NumNSW;

1249 }

1250 }

1251

1253}

1254

1257 bool FnChanged = false;

1258 std::optional RetRange;

1259 if (F.hasExactDefinition() && F.getReturnType()->isIntOrIntVectorTy())

1260 RetRange =

1261 ConstantRange::getEmpty(F.getReturnType()->getScalarSizeInBits());

1262

1263

1264

1265

1266

1267

1269 bool BBChanged = false;

1271 switch (II.getOpcode()) {

1272 case Instruction::Select:

1274 break;

1275 case Instruction::PHI:

1277 break;

1278 case Instruction::ICmp:

1279 case Instruction::FCmp:

1281 break;

1282 case Instruction::Call:

1283 case Instruction::Invoke:

1285 break;

1286 case Instruction::SRem:

1287 case Instruction::SDiv:

1289 break;

1290 case Instruction::UDiv:

1291 case Instruction::URem:

1293 break;

1294 case Instruction::AShr:

1296 break;

1297 case Instruction::SExt:

1299 break;

1300 case Instruction::ZExt:

1302 break;

1303 case Instruction::UIToFP:

1305 break;

1306 case Instruction::SIToFP:

1308 break;

1309 case Instruction::Add:

1310 case Instruction::Sub:

1311 case Instruction::Mul:

1312 case Instruction::Shl:

1314 break;

1315 case Instruction::And:

1317 break;

1318 case Instruction::Trunc:

1320 break;

1321 }

1322 }

1323

1324 Instruction *Term = BB->getTerminator();

1325 switch (Term->getOpcode()) {

1326 case Instruction::Switch:

1328 break;

1329 case Instruction::Ret: {

1331

1332

1333

1334 auto *RetVal = RI->getReturnValue();

1335 if (!RetVal) break;

1336 if (RetRange && !RetRange->isFullSet())

1337 RetRange =

1339 false));

1340

1341 if (isa(RetVal)) break;

1343 ++NumReturns;

1344 RI->replaceUsesOfWith(RetVal, C);

1345 BBChanged = true;

1346 }

1347 }

1348 }

1349

1350 FnChanged |= BBChanged;

1351 }

1352

1353

1354 if (RetRange && !RetRange->isFullSet()) {

1355 Attribute RangeAttr = F.getRetAttribute(Attribute::Range);

1356 if (RangeAttr.isValid())

1357 RetRange = RetRange->intersectWith(RangeAttr.getRange());

1358

1359

1360 if (!RetRange->isEmptySet() && !RetRange->isSingleElement()) {

1361 F.addRangeRetAttr(*RetRange);

1362 FnChanged = true;

1363 }

1364 }

1365 return FnChanged;

1366}

1367

1372

1374

1378 } else {

1379#if defined(EXPENSIVE_CHECKS)

1380 assert(DT->verify(DominatorTree::VerificationLevel::Full));

1381#else

1382 assert(DT->verify(DominatorTree::VerificationLevel::Fast));

1383#endif

1384

1387 }

1388

1389

1390

1391

1392

1394 return PA;

1395}

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

This file contains the simple types necessary to represent the attributes associated with functions a...

static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")

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

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

This file builds on the ADT/GraphTraits.h file to build generic depth first graph iterator.

static bool runImpl(Function &F, const TargetLowering &TLI, const LibcallLoweringInfo &Libcalls, AssumptionCache *AC)

This is the interface for a simple mod/ref and alias analysis over globals.

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

This header defines various interfaces for pass management in LLVM.

const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]

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

uint64_t IntrinsicInst * II

const SmallVectorImpl< MachineOperand > & Cond

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)

static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")

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

Class for arbitrary precision integers.

static APInt getAllOnes(unsigned numBits)

Return an APInt of a specified width with all bits set.

static APInt getSignedMinValue(unsigned numBits)

Gets minimum signed value of APInt for a specific bit width.

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.

PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)

Get the result of an analysis pass for a given IR unit.

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.

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.

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

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

This class represents an intrinsic that is based on a binary operation.

LLVM_ABI unsigned getNoWrapKind() const

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

LLVM_ABI bool isSigned() const

Whether the intrinsic is signed or unsigned.

LLVM_ABI Instruction::BinaryOps getBinaryOp() const

Returns the binary operation underlying the intrinsic.

static LLVM_ABI BinaryOperator * CreateNeg(Value *Op, const Twine &Name="", InsertPosition InsertBefore=nullptr)

Helper functions to construct and inspect unary operations (NEG and NOT) via binary operators SUB and...

BinaryOps getOpcode() const

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.

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.

LLVM_ABI bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const

Determine whether the argument or parameter has the given attribute.

void setAttributes(AttributeList A)

Set the attributes for this call.

LLVM_ABI Intrinsic::ID getIntrinsicID() const

Returns the intrinsic ID of the intrinsic called or Intrinsic::not_intrinsic if the called function i...

iterator_range< User::op_iterator > args()

Iteration adapter for range-for loops.

unsigned arg_size() const

AttributeList getAttributes() const

Return the attributes for this call.

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

Create a ZExt or BitCast cast instruction.

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

Type * getDestTy() const

Return the destination type, as a convenience.

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_UGE

unsigned greater or equal

@ ICMP_ULT

unsigned less than

@ ICMP_ULE

unsigned less or equal

Predicate getNonStrictPredicate() const

For example, SGT -> SGE, SLT -> SLE, ULT -> ULE, UGT -> UGE.

This class represents a ucmp/scmp intrinsic.

static CmpInst::Predicate getGTPredicate(Intrinsic::ID ID)

static CmpInst::Predicate getLTPredicate(Intrinsic::ID ID)

This is the shared class of boolean and integer constants.

static LLVM_ABI ConstantInt * getTrue(LLVMContext &Context)

static ConstantInt * getSigned(IntegerType *Ty, int64_t V)

Return a ConstantInt with the specified value for the specified type.

static LLVM_ABI ConstantInt * getFalse(LLVMContext &Context)

const APInt & getValue() const

Return the constant as an APInt value reference.

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 unsigned getActiveBits() const

Compute the maximal number of active bits needed to represent every value in this range.

static LLVM_ABI CmpInst::Predicate getEquivalentPredWithFlippedSignedness(CmpInst::Predicate Pred, const ConstantRange &CR1, const ConstantRange &CR2)

If the comparison between constant ranges this and Other is insensitive to the signedness of the comp...

const APInt * getSingleElement() const

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

LLVM_ABI bool isAllNegative() const

Return true if all values in this range are negative.

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

Does the predicate Pred hold between ranges this and Other?

LLVM_ABI bool isSizeLargerThan(uint64_t MaxSize) const

Compare set size of this range with Value.

LLVM_ABI ConstantRange abs(bool IntMinIsPoison=false) const

Calculate absolute value range.

LLVM_ABI ConstantRange uadd_sat(const ConstantRange &Other) const

Perform an unsigned saturating addition of two constant ranges.

bool isSingleElement() const

Return true if this set contains exactly one member.

LLVM_ABI bool isAllNonNegative() const

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

LLVM_ABI ConstantRange sdiv(const ConstantRange &Other) const

Return a new range representing the possible values resulting from a signed division of a value in th...

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.

static LLVM_ABI bool areInsensitiveToSignednessOfICmpPredicate(const ConstantRange &CR1, const ConstantRange &CR2)

Return true iff CR1 ult CR2 is equivalent to CR1 slt CR2.

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 unsigned getMinSignedBits() const

Compute the maximal number of bits needed to represent every value in this signed range.

uint32_t getBitWidth() const

Get the bit width of this ConstantRange.

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.

static DebugLoc getTemporary()

Analysis pass which computes a DominatorTree.

static constexpr UpdateKind Delete

static constexpr UpdateKind Insert

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

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

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

void applyUpdatesPermissive(ArrayRef< UpdateT > Updates)

Submit updates to all available trees.

void applyUpdates(ArrayRef< UpdateT > Updates)

Submit updates to all available trees.

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

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

LLVM_ABI bool hasNoUnsignedWrap() const LLVM_READONLY

Determine whether the no unsigned wrap flag is set.

LLVM_ABI bool hasNoSignedWrap() const LLVM_READONLY

Determine whether the no signed wrap flag is set.

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.

void setDebugLoc(DebugLoc Loc)

Set the debug location information for this instruction.

A wrapper class for inspecting calls to intrinsic functions.

Intrinsic::ID getIntrinsicID() const

Return the intrinsic ID of this intrinsic.

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

Analysis to compute lazy value information.

This pass computes, caches, and vends lazy value constraint information.

ConstantRange getConstantRangeAtUse(const Use &U, bool UndefAllowed)

Return the ConstantRange constraint that is known to hold for the value at a specific use-site.

ConstantRange getConstantRange(Value *V, Instruction *CxtI, bool UndefAllowed)

Return the ConstantRange constraint that is known to hold for the specified value at the specified in...

Constant * getPredicateOnEdge(CmpInst::Predicate Pred, Value *V, Constant *C, BasicBlock *FromBB, BasicBlock *ToBB, Instruction *CxtI=nullptr)

Determine whether the specified value comparison with a constant is known to be true or false on the ...

Constant * getConstantOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB, Instruction *CxtI=nullptr)

Determine whether the specified value is known to be a constant on the specified edge.

Constant * getConstant(Value *V, Instruction *CxtI)

Determine whether the specified value is known to be a constant at the specified instruction.

Constant * getPredicateAt(CmpInst::Predicate Pred, Value *V, Constant *C, Instruction *CxtI, bool UseBlockValue)

Determine whether the specified value comparison with a constant is known to be true or false at the ...

This class represents min/max intrinsics.

static ICmpInst::Predicate getPredicate(Intrinsic::ID ID)

Returns the comparison predicate underlying the intrinsic.

static bool isSigned(Intrinsic::ID ID)

Whether the intrinsic is signed or unsigned.

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

static LLVM_ABI PoisonValue * get(Type *T)

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

Instruction that can have a nneg flag (zext/uitofp).

A set of analyses that are preserved following a run of a transformation pass.

static PreservedAnalyses all()

Construct a special preserved set that preserves all passes.

PreservedAnalyses & abandon()

Mark an analysis as abandoned.

PreservedAnalyses & preserve()

Mark an analysis as preserved.

This class represents a sign extension of integer types.

This class represents a cast from signed integer to floating point.

Represents a saturating add/sub intrinsic.

This class represents the LLVM 'select' instruction.

const Value * getFalseValue() const

const Value * getCondition() const

const Value * getTrueValue() const

void push_back(const T &Elt)

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

Class to represent struct types.

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

This class represents a truncation of integer types.

void setHasNoSignedWrap(bool B)

void setHasNoUnsignedWrap(bool B)

bool hasNoSignedWrap() const

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

bool hasNoUnsignedWrap() const

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

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

bool isVectorTy() const

True if this is an instance of VectorType.

LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY

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

This class represents a cast unsigned integer to floating point.

This function has undefined behavior.

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

const Use & getOperandUse(unsigned i) const

Value * getOperand(unsigned i) const

LLVM Value Representation.

Type * getType() const

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

LLVM_ABI void replaceAllUsesWith(Value *V)

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

LLVM_ABI LLVMContext & getContext() const

All values hold a context through their type.

iterator_range< use_iterator > uses()

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.

This class represents zero extension of integer types.

self_iterator getIterator()

#define llvm_unreachable(msg)

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

@ C

The default llvm calling convention, compatible with C.

cst_pred_ty< is_lowbit_mask > m_LowBitMask()

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

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

This is an optimization pass for GlobalISel generic memory operations.

LLVM_ABI bool ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions=false, const TargetLibraryInfo *TLI=nullptr, DomTreeUpdater *DTU=nullptr)

If a terminator instruction is predicated on a constant value, convert it into an unconditional branc...

decltype(auto) dyn_cast(const From &Val)

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

auto successors(const MachineBasicBlock *BB)

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 bool isGuaranteedNotToBeUndef(const Value *V, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, unsigned Depth=0)

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

uint64_t PowerOf2Ceil(uint64_t A)

Returns the power of two which is greater than or equal to the given value.

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 isa(const From &Val)

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

DWARFExpression::Operation Op

decltype(auto) cast(const From &Val)

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

iterator_range< df_iterator< T > > depth_first(const T &G)

AnalysisManager< Function > FunctionAnalysisManager

Convenience typedef for the Function analysis manager.

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

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

LLVM_ABI const SimplifyQuery getBestSimplifyQuery(Pass &, Function &)

Incoming for lane maks phi as machine instruction, incoming register Reg and incoming block Block are...