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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

37#include

38#include

39using namespace llvm;

40

41#define DEBUG_TYPE "clone-function"

42

43

51

52 bool hasCalls = false, hasDynamicAllocas = false, hasMemProfMetadata = false;

53

54

57 if (I.hasName())

58 NewInst->setName(I.getName() + NameSuffix);

59

62

63 VMap[&I] = NewInst;

64

65 if (isa(I) && I.isDebugOrPseudoInst()) {

66 hasCalls = true;

67 hasMemProfMetadata |= I.hasMetadata(LLVMContext::MD_memprof);

68 hasMemProfMetadata |= I.hasMetadata(LLVMContext::MD_callsite);

69 }

70 if (const AllocaInst *AI = dyn_cast(&I)) {

71 if (!AI->isStaticAlloca()) {

72 hasDynamicAllocas = true;

73 }

74 }

75 }

76

77 if (CodeInfo) {

81 }

82 return NewBB;

83}

84

88 bool ModuleLevelChanges,

91

92

96

99

100

103 FuncGlobalRefFlags, TypeMapper,

104 Materializer));

105

108 FuncGlobalRefFlags, TypeMapper,

109 Materializer));

110 }

111

114 FuncGlobalRefFlags, TypeMapper,

115 Materializer));

116 }

117

120

121

122 for (const Argument &OldArg : OldFunc->args()) {

123 if (Argument *NewArg = dyn_cast(VMap[&OldArg])) {

124

125 NewArgAttrs[NewArg->getArgNo()] =

127 }

128 }

129

133}

134

138 DISubprogram *SPClonedWithinModule = nullptr;

139 if (Changes < CloneFunctionChangeType::DifferentModule) {

140 SPClonedWithinModule = F.getSubprogram();

141 }

142 if (SPClonedWithinModule)

144

145 const Module *M = F.getParent();

146 if (Changes != CloneFunctionChangeType::ClonedModule && M) {

147

150 }

151

152 return SPClonedWithinModule;

153}

154

160

161 if (Changes < CloneFunctionChangeType::DifferentModule &&

163

165 if (ISP != SPClonedWithinModule)

167 }

168

169

171 auto *LScope = dyn_cast(S);

172 if (LScope && LScope->getSubprogram() != SPClonedWithinModule)

174 }

175

178

181 } else {

182 assert(!SPClonedWithinModule &&

183 "Subprogram should be in DIFinder->subprogram_count()...");

184 }

185

186 return MD;

187}

188

197 for (auto MD : MDs) {

199 *MapMetadata(MD.second, VMap, RemapFlag, TypeMapper,

200 Materializer, IdentityMD));

201 }

202}

203

207 const char *NameSuffix,

213 return;

214

215

216

217

218 for (const BasicBlock &BB : OldFunc) {

219

220

222 CloneBasicBlock(&BB, VMap, NameSuffix, &NewFunc, CodeInfo);

223

224

225 VMap[&BB] = CBB;

226

227

228

229

230

231

232

233 if (BB.hasAddressTaken()) {

237 }

238

239

242 }

243

244

245

247 BB = cast(VMap[&OldFunc.front()])->getIterator(),

248 BE = NewFunc.end();

249 BB != BE; ++BB)

250

251

254 IdentityMD);

256 RemapFlag, TypeMapper, Materializer, IdentityMD);

257 }

258}

259

260

261

270 assert(NameSuffix && "NameSuffix cannot be null!");

271

272#ifndef NDEBUG

274 assert(VMap.count(&I) && "No mapping from source argument specified!");

275#endif

276

277 bool ModuleLevelChanges = Changes > CloneFunctionChangeType::LocalChangesOnly;

278

280 TypeMapper, Materializer);

281

282

283

285 return;

286

287

288

289

290

291

293

294

295

296 if (Changes < CloneFunctionChangeType::DifferentModule) {

297

298

301 "Expected NewFunc to have the same parent, or no parent");

302 } else {

303

304

307 "Expected NewFunc to have different parents, or no parent");

308

309 if (Changes == CloneFunctionChangeType::DifferentModule) {

311 "Need parent of new function to maintain debug info invariants");

312 }

313 }

314

317

320

321

322

323 const auto RemapFlag = RF_None;

324

326 Materializer, &IdentityMD);

327

329 NameSuffix, CodeInfo, TypeMapper, Materializer,

330 &IdentityMD);

331

332

333

334

335 if (Changes != CloneFunctionChangeType::DifferentModule)

336 return;

337

338

339

340

341

342

343

344

345

346

347

348 auto *NewModule = NewFunc->getParent();

350

352 for (auto *Operand : NMD->operands())

353 Visited.insert(Operand);

357 if (Visited.insert(MappedUnit).second)

358 NMD->addOperand(MappedUnit);

359 }

360}

361

362

363

364

365

366

367

368

371 std::vector<Type *> ArgTypes;

372

373

374

375

377 if (VMap.count(&I) == 0)

378 ArgTypes.push_back(I.getType());

379

380

382 FunctionType::get(F->getFunctionType()->getReturnType(), ArgTypes,

383 F->getFunctionType()->isVarArg());

384

385

387 F->getName(), F->getParent());

389

390

393 if (VMap.count(&I) == 0) {

394 DestI->setName(I.getName());

395 VMap[&I] = &*DestI++;

396 }

397

399 CloneFunctionInto(NewF, F, VMap, CloneFunctionChangeType::LocalChangesOnly,

400 Returns, "", CodeInfo);

401

402 return NewF;

403}

404

405namespace {

406

407struct PruningFunctionCloner {

411 bool ModuleLevelChanges;

412 const char *NameSuffix;

414 bool HostFuncIsStrictFP;

415

417

418public:

419 PruningFunctionCloner(Function *newFunc, const Function *oldFunc,

422 : NewFunc(newFunc), OldFunc(oldFunc), VMap(valueMap),

423 ModuleLevelChanges(moduleLevelChanges), NameSuffix(nameSuffix),

424 CodeInfo(codeInfo) {

425 HostFuncIsStrictFP =

427 }

428

429

430

432 std::vector<const BasicBlock *> &ToClone);

433};

434}

435

440 if (HostFuncIsStrictFP) {

443

444

445

446

447

448

452 for (unsigned I = 0, E = Descriptor.size(); I != E; ++I) {

454 switch (Operand.Kind) {

457 Intrinsic::IITDescriptor::AK_MatchType) {

458 if (I == 0)

460 else

462 }

463 break;

465 ++I;

466 break;

467 default:

468 break;

469 }

470 }

471

472

475 CIID, TParams);

478 if (isa(OldInst))

479 --NumOperands;

480 for (unsigned I = 0; I < NumOperands; ++I) {

483 }

484 if (const auto *CmpI = dyn_cast(&OldInst)) {

486 StringRef PredName = FCmpInst::getPredicateName(Pred);

488 }

489

490

491

492

494 Args.push_back(

496 Args.push_back(

498

500 }

501 }

502 if (!NewInst)

503 NewInst = II->clone();

504 return NewInst;

505}

506

507

508

509void PruningFunctionCloner::CloneBlock(

511 std::vector<const BasicBlock *> &ToClone) {

513

514

515 if (BBEntry)

516 return;

517

518

523

524

525

526

527

528

529

530

531

532

537 }

538

539 bool hasCalls = false, hasDynamicAllocas = false, hasStaticAllocas = false;

540 bool hasMemProfMetadata = false;

541

542

544 auto CloneDbgRecordsToHere =

547 return;

548

549

550

551

552 for (; DbgCursor != II; ++DbgCursor)

553 NewInst->cloneDebugInfoFrom(&*DbgCursor, std::nullopt, false);

554 NewInst->cloneDebugInfoFrom(&*II);

555 DbgCursor = std::next(II);

556 };

557

558

559

561 ++II) {

562

563

564

565 if (auto *IntrInst = dyn_cast(II))

566 if (IntrInst->getIntrinsicID() == Intrinsic::fake_use)

567 continue;

568

571

572 if (HostFuncIsStrictFP) {

573

574

575 if (auto *Call = dyn_cast(NewInst))

576 Call->addFnAttr(Attribute::StrictFP);

577 }

578

579

580

581

582 if (!isa(NewInst) && !isa(NewInst)) {

585

586

587

588

589

593 VMap[&*II] = V;

595 continue;

596 }

597 }

598 }

599

600 if (II->hasName())

601 NewInst->setName(II->getName() + NameSuffix);

602 VMap[&*II] = NewInst;

603 if (isa(II) && II->isDebugOrPseudoInst()) {

604 hasCalls = true;

605 hasMemProfMetadata |= II->hasMetadata(LLVMContext::MD_memprof);

606 hasMemProfMetadata |= II->hasMetadata(LLVMContext::MD_callsite);

607 }

608

609 CloneDbgRecordsToHere(NewInst, II);

610

611 if (CodeInfo) {

613 if (auto *CB = dyn_cast(&*II))

614 if (CB->hasOperandBundles())

616 }

617

618 if (const AllocaInst *AI = dyn_cast(II)) {

619 if (isa(AI->getArraySize()))

620 hasStaticAllocas = true;

621 else

622 hasDynamicAllocas = true;

623 }

624 }

625

626

628 bool TerminatorDone = false;

629 if (const BranchInst *BI = dyn_cast(OldTI)) {

630 if (BI->isConditional()) {

631

632 ConstantInt *Cond = dyn_cast(BI->getCondition());

633

636 Cond = dyn_cast_or_null(V);

637 }

638

639

641 BasicBlock *Dest = BI->getSuccessor(Cond->getZExtValue());

643 ToClone.push_back(Dest);

644 TerminatorDone = true;

645 }

646 }

647 } else if (const SwitchInst *SI = dyn_cast(OldTI)) {

648

650 if (Cond) {

652 Cond = dyn_cast_or_null(V);

653 }

654 if (Cond) {

658 ToClone.push_back(Dest);

659 TerminatorDone = true;

660 }

661 }

662

663 if (!TerminatorDone) {

668

669 CloneDbgRecordsToHere(NewInst, OldTI->getIterator());

670

671 VMap[OldTI] = NewInst;

672

673 if (CodeInfo) {

674 CodeInfo->OrigVMap[OldTI] = NewInst;

675 if (auto *CB = dyn_cast(OldTI))

676 if (CB->hasOperandBundles())

678 }

679

680

682 } else {

683

684

687

688 CloneDbgRecordsToHere(NewInst, OldTI->getIterator());

689 }

690

691 if (CodeInfo) {

697 }

698}

699

700

701

702

706 bool ModuleLevelChanges,

708 const char *NameSuffix,

710 assert(NameSuffix && "NameSuffix cannot be null!");

711

714

715#ifndef NDEBUG

716

717

718 if (!StartingInst)

720 assert(VMap.count(&II) && "No mapping from source argument specified!");

721#endif

722

723 PruningFunctionCloner PFC(NewFunc, OldFunc, VMap, ModuleLevelChanges,

724 NameSuffix, CodeInfo);

726 if (StartingInst)

727 StartingBB = StartingInst->getParent();

728 else {

730 StartingInst = &StartingBB->front();

731 }

732

733

735 for (const auto &BB : *OldFunc) {

736 for (const auto &I : BB) {

737 if (const auto *DVI = dyn_cast(&I))

739 }

740 }

741

742

743 std::vector<const BasicBlock *> CloneWorklist;

744 PFC.CloneBlock(StartingBB, StartingInst->getIterator(), CloneWorklist);

745 while (!CloneWorklist.empty()) {

747 CloneWorklist.pop_back();

748 PFC.CloneBlock(BB, BB->begin(), CloneWorklist);

749 }

750

751

752

753

754

755

757 for (const BasicBlock &BI : *OldFunc) {

759 BasicBlock *NewBB = cast_or_null(V);

760 if (!NewBB)

761 continue;

762

763

765

766

767

768 for (const PHINode &PN : BI.phis()) {

769

770

771 if (isa(VMap[&PN]))

773 else

774 break;

775 }

776

777

778

781 TypeMapper, Materializer);

782 }

783

784

785

786 for (unsigned phino = 0, e = PHIToResolve.size(); phino != e;) {

787 const PHINode *OPN = PHIToResolve[phino];

790 BasicBlock *NewBB = cast(VMap[OldBB]);

791

792

793

794 for (; phino != PHIToResolve.size() &&

795 PHIToResolve[phino]->getParent() == OldBB;

796 ++phino) {

797 OPN = PHIToResolve[phino];

798 PHINode *PN = cast(VMap[OPN]);

799 for (unsigned pred = 0, e = NumPreds; pred != e; ++pred) {

801 if (BasicBlock *MappedBlock = cast_or_null(V)) {

805 assert(InVal && "Unknown input value?");

808 } else {

810 --pred;

811 --e;

812 }

813 }

814 }

815

816

817

818

819

820

824 assert(NumPreds < PN->getNumIncomingValues());

825

826 std::map<BasicBlock *, unsigned> PredCount;

828 --PredCount[Pred];

829

830

833

834

835

836

838 for (; (PN = dyn_cast(I)); ++I) {

839 for (const auto &PCI : PredCount) {

841 for (unsigned NumToRemove = PCI.second; NumToRemove; --NumToRemove)

843 }

844 }

845 }

846

847

848

849

850 PN = cast(NewBB->begin());

854 while ((PN = dyn_cast(I++))) {

857 assert(VMap[&*OldI] == PN && "VMap mismatch");

858 VMap[&*OldI] = NV;

860 ++OldI;

861 }

862 }

863 }

864

865

866

867

872

873

874

876 for (const auto &BB : *OldFunc) {

877 for (const auto &I : BB) {

878 auto *NewI = dyn_cast_or_null(VMap.lookup(&I));

879 if (!NewI)

880 continue;

881

883 NewI->replaceAllUsesWith(V);

884

886 NewI->eraseFromParent();

887 } else {

888

889

890 VMap[&I] = NewI;

891 }

892 }

893 }

894 }

895

896

898

899

900

901

902

903

904 for (const auto *DVI : DbgIntrinsics) {

906 cast_or_null(VMap.lookup(DVI)))

909 TypeMapper, Materializer);

910 }

911

912

913

914 Function::iterator Begin = cast(VMap[StartingBB])->getIterator();

918 ModuleLevelChanges ? RF_None

920 TypeMapper, Materializer);

921 }

922 }

923

924

925

926

927

928

931

932

933 {

937 while (!Worklist.empty()) {

939 if (ReachableBlocks.insert(BB).second)

941 }

942

945 if (!ReachableBlocks.contains(&BB))

946 UnreachableBlocks.push_back(&BB);

948 }

949

950

951

952

953

955 while (I != NewFunc->end()) {

956 BranchInst *BI = dyn_cast(I->getTerminator());

958 ++I;

959 continue;

960 }

961

964 ++I;

965 continue;

966 }

967

968

969

971

972

973

975

976

978

979

980 I->splice(I->end(), Dest);

981

982

984

985

986 }

987

988

989

990

991 for (Function::iterator I = cast(VMap[StartingBB])->getIterator(),

992 E = NewFunc->end();

993 I != E; ++I)

994 if (ReturnInst *RI = dyn_cast(I->getTerminator()))

996}

997

998

999

1000

1001

1002

1003

1004

1010 ModuleLevelChanges, Returns, NameSuffix, CodeInfo);

1011}

1012

1013

1016

1017 for (auto *BB : Blocks) {

1018 for (auto &Inst : *BB) {

1023 }

1024 }

1025}

1026

1027

1028

1029

1030

1031

1040

1042 LMap[OrigLoop] = NewLoop;

1043 if (ParentLoop)

1045 else

1047

1049 assert(OrigPH && "No preheader");

1051

1052 VMap[OrigPH] = NewPH;

1053 Blocks.push_back(NewPH);

1054

1055

1056 if (ParentLoop)

1058

1059

1061

1063 Loop *&NewLoop = LMap[CurLoop];

1064 if (!NewLoop) {

1066

1067

1069 assert(OrigParent && "Could not find the original parent loop");

1070 Loop *NewParentLoop = LMap[OrigParent];

1071 assert(NewParentLoop && "Could not find the new parent loop");

1072

1074 }

1075 }

1076

1079 Loop *&NewLoop = LMap[CurLoop];

1080 assert(NewLoop && "Expecting new loop to be allocated");

1081

1083 VMap[BB] = NewBB;

1084

1085

1087

1088

1089

1091

1092 Blocks.push_back(NewBB);

1093 }

1094

1096

1099 LMap[CurLoop]->moveToHeader(cast(VMap[BB]));

1100

1101

1104 cast(VMap[IDomBB]));

1105 }

1106

1107

1110 F->end());

1111

1112 return NewLoop;

1113}

1114

1115

1116

1120

1122 "There must be a single edge between PredBB and BB!");

1123

1124

1125

1127 for (; PHINode *PN = dyn_cast(BI); ++BI)

1129

1133

1134

1135

1136 DTU.applyUpdates({{DominatorTree::Delete, PredBB, BB},

1137 {DominatorTree::Insert, PredBB, NewBB},

1138 {DominatorTree::Insert, NewBB, BB}});

1139

1140

1141

1142

1143

1144 for (; StopAt != &*BI && BB->getTerminator() != &*BI; ++BI) {

1146 New->setName(BI->getName());

1147 New->insertBefore(NewTerm->getIterator());

1148 New->cloneDebugInfoFrom(&*BI);

1149 ValueMapping[&*BI] = New;

1150

1151

1152 for (unsigned i = 0, e = New->getNumOperands(); i != e; ++i)

1153 if (Instruction *Inst = dyn_cast(New->getOperand(i))) {

1154 auto I = ValueMapping.find(Inst);

1155 if (I != ValueMapping.end())

1156 New->setOperand(i, I->second);

1157 }

1158

1159

1161 }

1162

1163 return NewBB;

1164}

1165

1170

1171 for (auto *ScopeList : NoAliasDeclScopes) {

1172 for (const auto &MDOperand : ScopeList->operands()) {

1175

1176 std::string Name;

1177 auto ScopeName = SNANode.getName();

1178 if (!ScopeName.empty())

1179 Name = (Twine(ScopeName) + ":" + Ext).str();

1180 else

1181 Name = std::string(Ext);

1182

1185 ClonedScopes.insert(std::make_pair(MD, NewScope));

1186 }

1187 }

1188 }

1189}

1190

1194 auto CloneScopeList = [&](const MDNode *ScopeList) -> MDNode * {

1195 bool NeedsReplacement = false;

1197 for (const auto &MDOp : ScopeList->operands()) {

1198 if (MDNode *MD = dyn_cast(MDOp)) {

1199 if (auto *NewMD = ClonedScopes.lookup(MD)) {

1201 NeedsReplacement = true;

1202 continue;

1203 }

1205 }

1206 }

1207 if (NeedsReplacement)

1208 return MDNode::get(Context, NewScopeList);

1209 return nullptr;

1210 };

1211

1212 if (auto *Decl = dyn_cast(I))

1213 if (auto *NewScopeList = CloneScopeList(Decl->getScopeList()))

1214 Decl->setScopeList(NewScopeList);

1215

1216 auto replaceWhenNeeded = [&](unsigned MD_ID) {

1217 if (const MDNode *CSNoAlias = I->getMetadata(MD_ID))

1218 if (auto *NewScopeList = CloneScopeList(CSNoAlias))

1219 I->setMetadata(MD_ID, NewScopeList);

1220 };

1221 replaceWhenNeeded(LLVMContext::MD_noalias);

1222 replaceWhenNeeded(LLVMContext::MD_alias_scope);

1223}

1224

1228 if (NoAliasDeclScopes.empty())

1229 return;

1230

1232 LLVM_DEBUG(dbgs() << "cloneAndAdaptNoAliasScopes: cloning "

1233 << NoAliasDeclScopes.size() << " node(s)\n");

1234

1236

1237 for (BasicBlock *NewBlock : NewBlocks)

1240}

1241

1245 if (NoAliasDeclScopes.empty())

1246 return;

1247

1249 LLVM_DEBUG(dbgs() << "cloneAndAdaptNoAliasScopes: cloning "

1250 << NoAliasDeclScopes.size() << " node(s)\n");

1251

1253

1257 ++ItEnd;

1260}

1261

1266 if (auto *Decl = dyn_cast(&I))

1267 NoAliasDeclScopes.push_back(Decl->getScopeList());

1268}

1269

1274 if (auto *Decl = dyn_cast(&I))

1275 NoAliasDeclScopes.push_back(Decl->getScopeList());

1276}

MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL

Expand Atomic instructions

static const Function * getParent(const Value *V)

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

DenseMap< Block *, BlockRelaxAux > Blocks

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

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

uint64_t IntrinsicInst * II

const SmallVectorImpl< MachineOperand > & Cond

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

This file defines the SmallVector class.

This is a simple wrapper around an MDNode which provides a higher-level interface by hiding the detai...

const MDNode * getDomain() const

Get the MDNode for this AliasScopeNode's domain.

StringRef getName() const

an instruction to allocate memory on the stack

This class represents an incoming formal argument to a Function.

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

size_t size() const

size - Get the array size.

bool empty() const

empty - Check if the array is empty.

AttributeSet getFnAttrs() const

The function attributes are returned.

static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute > > Attrs)

Create an AttributeList with the specified parameters in it.

AttributeSet getRetAttrs() const

The attributes for the ret value are returned.

bool hasFnAttr(Attribute::AttrKind Kind) const

Return true if the attribute exists for the function.

AttributeSet getParamAttrs(unsigned ArgNo) const

The attributes for the argument or parameter at the given index are returned.

LLVM Basic Block Representation.

iterator begin()

Instruction iterator methods.

bool hasAddressTaken() const

Returns true if there are any uses of this basic block other than direct branches,...

InstListType::const_iterator const_iterator

const Instruction & front() const

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

Creates a new BasicBlock.

const BasicBlock * getSinglePredecessor() const

Return the predecessor of this block if it has a single predecessor block.

const Function * getParent() const

Return the enclosing method, or null if none.

const DataLayout & getDataLayout() const

Get the data layout of the module this basic block belongs to.

SymbolTableList< BasicBlock >::iterator eraseFromParent()

Unlink 'this' from the containing function and delete it.

InstListType::iterator iterator

Instruction iterators...

LLVMContext & getContext() const

Get the context in which this basic block lives.

bool IsNewDbgInfoFormat

Flag recording whether or not this block stores debug-info in the form of intrinsic instructions (fal...

void moveBefore(BasicBlock *MovePos)

Unlink this basic block from its current function and insert it into the function that MovePos 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...

const Instruction & back() const

static BlockAddress * get(Function *F, BasicBlock *BB)

Return a BlockAddress for the specified function and basic block.

Conditional or Unconditional Branch instruction.

bool isConditional() const

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

BasicBlock * getSuccessor(unsigned i) const

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

Predicate

This enumeration lists the possible predicates for CmpInst subclasses.

This is the shared class of boolean and integer constants.

This is an important base class in LLVM.

Base class for scope-like contexts.

This class represents an Operation in the Expression.

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

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

Utility to find all debug info in a module.

void processInstruction(const Module &M, const Instruction &I)

Process a single instruction and collect debug info anchors.

unsigned subprogram_count() const

void processSubprogram(DISubprogram *SP)

Process subprogram.

iterator_range< subprogram_iterator > subprograms() const

iterator_range< type_iterator > types() const

iterator_range< scope_iterator > scopes() const

iterator_range< compile_unit_iterator > compile_units() const

ValueT lookup(const_arg_type_t< KeyT > Val) const

lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...

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

DomTreeNodeBase * getIDom() const

void changeImmediateDominator(DomTreeNodeBase< NodeT > *N, DomTreeNodeBase< NodeT > *NewIDom)

changeImmediateDominator - This method is used to update the dominator tree information when a node's...

DomTreeNodeBase< NodeT > * addNewBlock(NodeT *BB, NodeT *DomBB)

Add a new node to the dominator tree information.

DomTreeNodeBase< NodeT > * getNode(const NodeT *BB) const

getNode - return the (Post)DominatorTree node for the specified basic block.

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

Class to represent function types.

static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)

const BasicBlock & getEntryBlock() const

BasicBlockListType::iterator iterator

void setPrefixData(Constant *PrefixData)

const DataLayout & getDataLayout() const

Get the data layout of the module this function belongs to.

const BasicBlock & front() const

iterator_range< arg_iterator > args()

bool IsNewDbgInfoFormat

Is this function using intrinsics to record the position of debugging information,...

bool hasPrefixData() const

Check whether this function has prefix data.

bool hasPersonalityFn() const

Check whether this function has a personality function.

Constant * getPrologueData() const

Get the prologue data associated with this function.

Constant * getPersonalityFn() const

Get the personality function associated with this function.

void setPersonalityFn(Constant *Fn)

AttributeList getAttributes() const

Return the attribute list for this Function.

void setAttributes(AttributeList Attrs)

Set the attribute list for this Function.

LLVMContext & getContext() const

getContext - Return a reference to the LLVMContext associated with this function.

void setPrologueData(Constant *PrologueData)

void removeRetAttrs(const AttributeMask &Attrs)

removes the attributes from the return value list of attributes.

void setIsNewDbgInfoFormat(bool NewVal)

Type * getReturnType() const

Returns the type of the ret val.

Constant * getPrefixData() const

Get the prefix data associated with this function.

bool hasPrologueData() const

Check whether this function has prologue data.

void copyAttributesFrom(const Function *Src)

copyAttributesFrom - copy all additional attributes (those not needed to create a Function) from the ...

void applyUpdates(ArrayRef< UpdateT > Updates)

Submit updates to all available trees.

void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const

Appends all metadata attached to this value to MDs, sorting by KindID.

void addMetadata(unsigned KindID, MDNode &MD)

Add a metadata attachment.

bool isDeclaration() const

Return true if the primary definition of this global value is outside of the current translation unit...

Module * getParent()

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

Instruction * clone() const

Create a copy of 'this' instruction that is identical in all ways except the following:

iterator_range< simple_ilist< DbgRecord >::iterator > cloneDebugInfoFrom(const Instruction *From, std::optional< simple_ilist< DbgRecord >::iterator > FromHere=std::nullopt, bool InsertAtHead=false)

Clone any debug-info attached to From onto this instruction.

void insertBefore(Instruction *InsertPos)

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

InstListType::iterator eraseFromParent()

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

InstListType::iterator insertInto(BasicBlock *ParentBB, InstListType::iterator It)

Inserts an unlinked instruction into ParentBB at position It and returns the iterator of the inserted...

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

SmallVector< const LoopT *, 4 > getLoopsInPreorder() const

Return all loops in the loop nest rooted by the loop in preorder, with siblings in forward program or...

BlockT * getHeader() const

void addBasicBlockToLoop(BlockT *NewBB, LoopInfoBase< BlockT, LoopT > &LI)

This method is used by other analyses to update loop information.

void addChildLoop(LoopT *NewChild)

Add the specified loop to be a child of this loop.

BlockT * getLoopPreheader() const

If there is a preheader for this loop, return it.

ArrayRef< BlockT * > getBlocks() const

Get a list of the basic blocks which make up this loop.

LoopT * getParentLoop() const

Return the parent loop if it exists or nullptr for top level loops.

void addTopLevelLoop(LoopT *New)

This adds the specified loop to the collection of top-level loops.

LoopT * AllocateLoop(ArgsTy &&...Args)

LoopT * getLoopFor(const BlockT *BB) const

Return the inner most loop that BB lives in.

Represents a single loop in the control flow graph.

MDNode * createAnonymousAliasScope(MDNode *Domain, StringRef Name=StringRef())

Return metadata appropriate for an alias scope root node.

static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)

Tracking metadata reference owned by Metadata.

static MDString * get(LLVMContext &Context, StringRef Str)

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

NamedMDNode * getOrInsertNamedMetadata(StringRef Name)

Return the named MDNode in the module with the specified name.

void setIncomingBlock(unsigned i, BasicBlock *BB)

Value * removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty=true)

Remove an incoming value.

void setIncomingValue(unsigned i, Value *V)

Value * getIncomingValueForBlock(const BasicBlock *BB) const

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.

static PoisonValue * get(Type *T)

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

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

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.

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

void push_back(const T &Elt)

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

StringRef - Represent a constant reference to a string, i.e.

A handle to a particular switch case.

BasicBlockT * getCaseSuccessor() const

Resolves successor for current case.

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

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

Value * getOperand(unsigned i) const

unsigned getNumOperands() const

This is a class that can be implemented by clients to remap types when cloning constants and instruct...

ValueT lookup(const KeyT &Val) const

lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...

size_type count(const KeyT &Val) const

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

iterator find(const KeyT &Val)

This is a class that can be implemented by clients to materialize Values on demand.

LLVM Value Representation.

Type * getType() const

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

void setName(const Twine &Name)

Change the name of the value.

void replaceAllUsesWith(Value *V)

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

StringRef getName() const

Return a constant reference to the value's name.

Value handle that is nullable, but tries to track the Value.

const ParentTy * getParent() const

self_iterator getIterator()

constexpr char Args[]

Key for Kernel::Metadata::mArgs.

AttributeMask typeIncompatible(Type *Ty, AttributeSet AS, AttributeSafetyKind ASK=ASK_ALL)

Which attributes cannot be applied to a type.

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

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

void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl< IITDescriptor > &T)

Return the IIT table descriptor for the specified intrinsic into an array of IITDescriptors.

bool hasConstrainedFPRoundingModeOperand(ID QID)

Returns true if the intrinsic ID is for one of the "Constrained Floating-Point Intrinsics" that take ...

This is an optimization pass for GlobalISel generic memory operations.

void CloneFunctionAttributesInto(Function *NewFunc, const Function *OldFunc, ValueToValueMapTy &VMap, bool ModuleLevelChanges, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)

Clone OldFunc's attributes into NewFunc, transforming values based on the mappings in VMap.

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

auto successors(const MachineBasicBlock *BB)

Metadata * MapMetadata(const Metadata *MD, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr, const MetadataSetTy *IdentityMD=nullptr)

Lookup or compute a mapping for a piece of metadata.

iterator_range< T > make_range(T x, T y)

Convenience function for iterating over sub-ranges.

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

Wrapper function to append range R to container C.

void remapDebugVariable(ValueToValueMapTy &Mapping, Instruction *Inst)

Remap the operands of the debug records attached to Inst, and the operands of Inst itself if it's a d...

void RemapDbgRecordRange(Module *M, iterator_range< DbgRecordIterator > Range, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr, const MetadataSetTy *IdentityMD=nullptr)

Remap the Values used in the DbgRecords Range using the value map VM.

auto pred_size(const MachineBasicBlock *BB)

BasicBlock * DuplicateInstructionsInSplitBetween(BasicBlock *BB, BasicBlock *PredBB, Instruction *StopAt, ValueToValueMapTy &ValueMapping, DomTreeUpdater &DTU)

Split edge between BB and PredBB and duplicate all non-Phi instructions from BB between its beginning...

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

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

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

Return true if the result produced by the instruction is not used, and the instruction will return.

Loop * cloneLoopWithPreheader(BasicBlock *Before, BasicBlock *LoopDomBB, Loop *OrigLoop, ValueToValueMapTy &VMap, const Twine &NameSuffix, LoopInfo *LI, DominatorTree *DT, SmallVectorImpl< BasicBlock * > &Blocks)

Clones a loop OrigLoop.

RemapFlags

These are flags that the value mapping APIs allow.

@ RF_IgnoreMissingLocals

If this flag is set, the remapper ignores missing function-local entries (Argument,...

@ RF_NoModuleLevelChanges

If this flag is set, the remapper knows that only local values within a function (such as an instruct...

void CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc, ValueToValueMapTy &VMap, bool ModuleLevelChanges, SmallVectorImpl< ReturnInst * > &Returns, const char *NameSuffix="", ClonedCodeInfo *CodeInfo=nullptr)

This works exactly like CloneFunctionInto, except that it does some simple constant prop and DCE on t...

raw_ostream & dbgs()

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

Value * MapValue(const Value *V, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr, const MetadataSetTy *IdentityMD=nullptr)

Look up or compute a value in the value map.

void RemapInstruction(Instruction *I, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr, const MetadataSetTy *IdentityMD=nullptr)

Convert the instruction operands from referencing the current values into those specified by VM.

void cloneNoAliasScopes(ArrayRef< MDNode * > NoAliasDeclScopes, DenseMap< MDNode *, MDNode * > &ClonedScopes, StringRef Ext, LLVMContext &Context)

Duplicate the specified list of noalias decl scopes.

Intrinsic::ID getConstrainedIntrinsicID(const Instruction &Instr)

Returns constrained intrinsic id to represent the given instruction in strictfp function.

MetadataSetTy FindDebugInfoToIdentityMap(CloneFunctionChangeType Changes, DebugInfoFinder &DIFinder, DISubprogram *SPClonedWithinModule)

Based on Changes and DIFinder return debug info that needs to be identity mapped during Metadata clon...

void CloneFunctionMetadataInto(Function &NewFunc, const Function &OldFunc, ValueToValueMapTy &VMap, RemapFlags RemapFlag, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr, const MetadataSetTy *IdentityMD=nullptr)

Clone OldFunc's metadata into NewFunc.

BasicBlock * CloneBasicBlock(const BasicBlock *BB, ValueToValueMapTy &VMap, const Twine &NameSuffix="", Function *F=nullptr, ClonedCodeInfo *CodeInfo=nullptr)

Return a copy of the specified basic block, but without embedding the block into a particular functio...

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

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

void adaptNoAliasScopes(llvm::Instruction *I, const DenseMap< MDNode *, MDNode * > &ClonedScopes, LLVMContext &Context)

Adapt the metadata for the specified instruction according to the provided mapping.

Constant * ConstantFoldInstruction(Instruction *I, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)

ConstantFoldInstruction - Try to constant fold the specified instruction.

void cloneAndAdaptNoAliasScopes(ArrayRef< MDNode * > NoAliasDeclScopes, ArrayRef< BasicBlock * > NewBlocks, LLVMContext &Context, StringRef Ext)

Clone the specified noalias decl scopes.

void remapInstructionsInBlocks(ArrayRef< BasicBlock * > Blocks, ValueToValueMapTy &VMap)

Remaps instructions in Blocks using the mapping in VMap.

void CloneFunctionInto(Function *NewFunc, const Function *OldFunc, ValueToValueMapTy &VMap, CloneFunctionChangeType Changes, SmallVectorImpl< ReturnInst * > &Returns, const char *NameSuffix="", ClonedCodeInfo *CodeInfo=nullptr, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)

Clone OldFunc into NewFunc, transforming the old arguments into references to VMap values.

auto predecessors(const MachineBasicBlock *BB)

DISubprogram * CollectDebugInfoForCloning(const Function &F, CloneFunctionChangeType Changes, DebugInfoFinder &DIFinder)

Collect debug information such as types, compile units, and other subprograms that are reachable from...

void DeleteDeadBlocks(ArrayRef< BasicBlock * > BBs, DomTreeUpdater *DTU=nullptr, bool KeepOneInputPHIs=false)

Delete the specified blocks from BB.

void identifyNoAliasScopesToClone(ArrayRef< BasicBlock * > BBs, SmallVectorImpl< MDNode * > &NoAliasDeclScopes)

Find the 'llvm.experimental.noalias.scope.decl' intrinsics in the specified basic blocks and extract ...

BasicBlock * SplitEdge(BasicBlock *From, BasicBlock *To, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, const Twine &BBName="")

Split the edge connecting the specified blocks, and return the newly created basic block between From...

void CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc, const Instruction *StartingInst, ValueToValueMapTy &VMap, bool ModuleLevelChanges, SmallVectorImpl< ReturnInst * > &Returns, const char *NameSuffix="", ClonedCodeInfo *CodeInfo=nullptr)

This works like CloneAndPruneFunctionInto, except that it does not clone the entire function.

Function * CloneFunction(Function *F, ValueToValueMapTy &VMap, ClonedCodeInfo *CodeInfo=nullptr)

Return a copy of the specified function and add it to that function's module.

void CloneFunctionBodyInto(Function &NewFunc, const Function &OldFunc, ValueToValueMapTy &VMap, RemapFlags RemapFlag, SmallVectorImpl< ReturnInst * > &Returns, const char *NameSuffix="", ClonedCodeInfo *CodeInfo=nullptr, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr, const MetadataSetTy *IdentityMD=nullptr)

Clone OldFunc's body into NewFunc.

This struct can be used to capture information about code being cloned, while it is being cloned.

bool ContainsDynamicAllocas

This is set to true if the cloned code contains a 'dynamic' alloca.

bool ContainsCalls

This is set to true if the cloned code contains a normal call instruction.

bool ContainsMemProfMetadata

This is set to true if there is memprof related metadata (memprof or callsite metadata) in the cloned...

DenseMap< const Value *, const Value * > OrigVMap

Like VMap, but maps only unsimplified instructions.

std::vector< WeakTrackingVH > OperandBundleCallSites

All cloned call sites that have operand bundles attached are appended to this vector.

This is a type descriptor which explains the type requirements of an intrinsic.

enum llvm::Intrinsic::IITDescriptor::IITDescriptorKind Kind

ArgKind getArgumentKind() const