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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

38#include

39#include

40#include

41using namespace llvm;

42

43#define DEBUG_TYPE "clone-function"

44

45STATISTIC(RemappedAtomMax, "Highest global NextAtomGroup (after mapping)");

46

48 uint64_t CurGroup = DL->getAtomGroup();

49 if (!CurGroup)

50 return;

51

52

53

54 auto [It, Inserted] = VMap.AtomMap.insert({{DL.getInlinedAt(), CurGroup}, 0});

55 if (!Inserted)

56 return;

57

58

59 uint64_t NewGroup = DL->getContext().incNextDILocationAtomGroup();

60 assert(NewGroup > CurGroup && "Next should always be greater than current");

61 It->second = NewGroup;

62

63 RemappedAtomMax = std::max<uint64_t>(NewGroup, RemappedAtomMax);

64}

65

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

69 if (!M)

70 return;

71

74}

75

76

77

81 return [](const Metadata *MD) { return false; };

82

83 DISubprogram *SPClonedWithinModule = F.getSubprogram();

84

85

86 auto ShouldKeep = [SPClonedWithinModule](const DISubprogram *SP) -> bool {

87 return SP != SPClonedWithinModule;

88 };

89

90 return [=](const Metadata *MD) {

91

93 return true;

94

96 return ShouldKeep(SP);

97

98

100 return ShouldKeep(LScope->getSubprogram());

101

102

105 return ShouldKeep(S->getSubprogram());

106

107 return false;

108 };

109}

110

111

118

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

120

121

124 if (I.hasName())

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

126

129

130 VMap[&I] = NewInst;

131

132 if (MapAtoms) {

135 }

136

138 hasCalls = true;

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

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

141 }

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

144 hasDynamicAllocas = true;

145 }

146 }

147 }

148

149 if (CodeInfo) {

153 }

154 return NewBB;

155}

156

160 bool ModuleLevelChanges,

163

164

165 AttributeList NewAttrs = NewFunc->getAttributes();

168

169 const RemapFlags FuncGlobalRefFlags =

171

172

175 FuncGlobalRefFlags, TypeMapper,

176 Materializer));

177

180 FuncGlobalRefFlags, TypeMapper,

181 Materializer));

182 }

183

186 FuncGlobalRefFlags, TypeMapper,

187 Materializer));

188 }

189

191 AttributeList OldAttrs = OldFunc->getAttributes();

192

193

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

196

197 NewArgAttrs[NewArg->getArgNo()] =

198 OldAttrs.getParamAttrs(OldArg.getArgNo());

199 }

200 }

201

203 AttributeList::get(NewFunc->getContext(), OldAttrs.getFnAttrs(),

204 OldAttrs.getRetAttrs(), NewArgAttrs));

205}

206

215 for (const auto &[Kind, MD] : MDs) {

217 Materializer, IdentityMD));

218 }

219}

220

224 const char *NameSuffix,

230 return;

231

232

233

234

235 for (const BasicBlock &BB : OldFunc) {

236

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

239

240

241 VMap[&BB] = CBB;

242

243

244

245

246

247

248

249 if (BB.hasAddressTaken()) {

253 }

254

255

258 }

259

260

261

264 BE = NewFunc.end();

265 BB != BE; ++BB)

266

267

270 IdentityMD);

272 RemapFlag, TypeMapper, Materializer, IdentityMD);

273 }

274}

275

276

277

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

286

287#ifndef NDEBUG

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

290#endif

291

293

295 TypeMapper, Materializer);

296

297

298

300 return;

301

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

306 } else {

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

310

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

314 }

315 }

316

318

319

320

322

324 Materializer, &IdentityMD);

325

327 NameSuffix, CodeInfo, TypeMapper, Materializer,

328 &IdentityMD);

329

330

331

332

334 return;

335

336

337

338

339

340

341

342

343

344

345

348

350

351

352

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

360 }

361}

362

363

364

365

366

367

368

369

372 std::vector<Type *> ArgTypes;

373

374

375

376

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

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

380

381

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

385

386

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

389

390

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

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

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

396 }

397

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 =

426 newFunc->getAttributes().hasFnAttr(Attribute::StrictFP);

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

453 Intrinsic::IITDescriptor Operand = Descriptor[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

473 LLVMContext &Ctx = NewFunc->getContext();

475 CIID, TParams);

479 --NumOperands;

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

483 }

485 FCmpInst::Predicate Pred = CmpI->getPredicate();

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

512 WeakTrackingVH &BBEntry = VMap[BB];

513

514

515 if (BBEntry)

516 return;

517

518

520 Twine NewName(BB->hasName() ? Twine(BB->getName()) + NameSuffix : "");

522

523

524

525

526

527

528

529

530

531

536 }

537

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

539 bool hasMemProfMetadata = false;

540

541

543 auto CloneDbgRecordsToHere =

545

546

547

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

551 DbgCursor = std::next(II);

552 };

553

554

555

557 ++II) {

558

559

560

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

563 continue;

564

567

568 if (HostFuncIsStrictFP) {

569

570

573 }

574

575

576

580

581

582

583

584

588 VMap[&*II] = V;

590 continue;

591 }

592 }

593 }

594

595 if (II->hasName())

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

597 VMap[&*II] = NewInst;

599 hasCalls = true;

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

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

602 }

603

604 CloneDbgRecordsToHere(NewInst, II);

605

606 if (CodeInfo) {

609 if (CB->hasOperandBundles())

611 }

612

615 hasStaticAllocas = true;

616 else

617 hasDynamicAllocas = true;

618 }

619 }

620

621

623 bool TerminatorDone = false;

625 if (BI->isConditional()) {

626

628

632 }

633

634

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

638 NewBI->setDebugLoc(BI->getDebugLoc());

639 VMap[OldTI] = NewBI;

640 ToClone.push_back(Dest);

641 TerminatorDone = true;

642 }

643 }

645

647 if (Cond) {

650 }

651 if (Cond) {

655 NewBI->setDebugLoc(SI->getDebugLoc());

656 VMap[OldTI] = NewBI;

657 ToClone.push_back(Dest);

658 TerminatorDone = true;

659 }

660 }

661

662 if (!TerminatorDone) {

667

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

669

670 VMap[OldTI] = NewInst;

671

672 if (CodeInfo) {

673 CodeInfo->OrigVMap[OldTI] = NewInst;

675 if (CB->hasOperandBundles())

677 }

678

679

681 } else {

682

683

686

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

688 }

689

690 if (CodeInfo) {

696 }

697}

698

699

700

701

705 bool ModuleLevelChanges,

707 const char *NameSuffix,

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

710

713

714#ifndef NDEBUG

715

716

717 if (!StartingInst)

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

720#endif

721

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

723 NameSuffix, CodeInfo);

725 if (StartingInst)

726 StartingBB = StartingInst->getParent();

727 else {

729 StartingInst = &StartingBB->front();

730 }

731

732

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

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

735 while (!CloneWorklist.empty()) {

736 const BasicBlock *BB = CloneWorklist.back();

737 CloneWorklist.pop_back();

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

739 }

740

741

742

743

744

745

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

750 if (!NewBB)

751 continue;

752

753

755

756

757

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

759

760

763 else

764 break;

765 }

766

767

768

771 TypeMapper, Materializer);

772 }

773

774

775

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

777 const PHINode *OPN = PHIToResolve[phino];

781

782

783

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

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

786 ++phino) {

787 OPN = PHIToResolve[phino];

789 for (int64_t pred = NumPreds - 1; pred >= 0; --pred) {

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

798 continue;

799 }

801 }

802 }

803

804

805

806

807

808

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

813

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

816 --PredCount[Pred];

817

818

820 ++PredCount[Pred];

821

822

823

824

827 for (const auto &[Pred, Count] : PredCount) {

830 }

831 }

832 }

833

834

835

836

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

845 VMap[&*OldI] = NV;

847 ++OldI;

848 }

849 }

850 }

851

852

853

854

856 AttributeMask IncompatibleAttrs = AttributeFuncs::typeIncompatible(

859

860

861

863 for (const BasicBlock &BB : *OldFunc) {

866 if (!NewI)

867 continue;

868

870 NewI->replaceAllUsesWith(V);

871

873 NewI->eraseFromParent();

874 } else {

875

876

877 VMap[&I] = NewI;

878 }

879 }

880 }

881 }

882

883

885

886

887

888

889

890

895 ModuleLevelChanges ? RF_None

897 TypeMapper, Materializer);

898 }

899 }

900

901

902

903

904

905

908

909

910 {

914 while (!Worklist.empty()) {

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

918 }

919

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

923 UnreachableBlocks.push_back(&BB);

925 }

926

927

928

929

930

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

935 ++I;

936 continue;

937 }

938

941 ++I;

942 continue;

943 }

944

945

946

948

949

950

952

953

955

956

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

958

959

961

962

963 }

964

965

966

967

969 E = NewFunc->end();

970 I != E; ++I)

973}

974

975

976

977

978

979

980

981

987 ModuleLevelChanges, Returns, NameSuffix, CodeInfo);

988}

989

990

1003

1004

1005

1006

1007

1008

1017

1019 LMap[OrigLoop] = NewLoop;

1020 if (ParentLoop)

1022 else

1024

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

1028

1029 VMap[OrigPH] = NewPH;

1031

1032

1033 if (ParentLoop)

1035

1036

1038

1040 Loop *&NewLoop = LMap[CurLoop];

1041 if (!NewLoop) {

1043

1044

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

1047 Loop *NewParentLoop = LMap[OrigParent];

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

1049

1051 }

1052 }

1053

1056 Loop *&NewLoop = LMap[CurLoop];

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

1058

1060 VMap[BB] = NewBB;

1061

1062

1064

1065

1066

1068

1070 }

1071

1073

1077

1078

1082 }

1083

1084

1087 F->end());

1088

1089 return NewLoop;

1090}

1091

1092

1093

1097

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

1100

1101

1102

1106

1110

1111

1112

1116

1117

1118

1119

1120

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

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

1125 New->cloneDebugInfoFrom(&*BI);

1126 ValueMapping[&*BI] = New;

1127

1128

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

1131 auto I = ValueMapping.find(Inst);

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

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

1134 }

1135

1136

1138 }

1139

1140 return NewBB;

1141}

1142

1147

1148 for (MDNode *ScopeList : NoAliasDeclScopes) {

1149 for (const MDOperand &MDOp : ScopeList->operands()) {

1152

1153 std::string Name;

1154 auto ScopeName = SNANode.getName();

1155 if (!ScopeName.empty())

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

1157 else

1158 Name = std::string(Ext);

1159

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

1163 }

1164 }

1165 }

1166}

1167

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

1172 bool NeedsReplacement = false;

1174 for (const MDOperand &MDOp : ScopeList->operands()) {

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

1178 NeedsReplacement = true;

1179 continue;

1180 }

1182 }

1183 }

1184 if (NeedsReplacement)

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

1186 return nullptr;

1187 };

1188

1190 if (MDNode *NewScopeList = CloneScopeList(Decl->getScopeList()))

1191 Decl->setScopeList(NewScopeList);

1192

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

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

1195 if (MDNode *NewScopeList = CloneScopeList(CSNoAlias))

1196 I->setMetadata(MD_ID, NewScopeList);

1197 };

1198 replaceWhenNeeded(LLVMContext::MD_noalias);

1199 replaceWhenNeeded(LLVMContext::MD_alias_scope);

1200}

1201

1205 if (NoAliasDeclScopes.empty())

1206 return;

1207

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

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

1211

1213

1214 for (BasicBlock *NewBlock : NewBlocks)

1217}

1218

1222 if (NoAliasDeclScopes.empty())

1223 return;

1224

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

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

1228

1230

1234 ++ItEnd;

1237}

1238

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

1245}

1246

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

1253}

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

MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL

Expand Atomic instructions

static const Function * getParent(const Value *V)

static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")

static MetadataPredicate createIdentityMDPredicate(const Function &F, CloneFunctionChangeType Changes)

Definition CloneFunction.cpp:79

static void collectDebugInfoFromInstructions(const Function &F, DebugInfoFinder &DIFinder)

Definition CloneFunction.cpp:66

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

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

This file defines the SmallVector class.

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

#define STATISTIC(VARNAME, DESC)

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

This class stores enough information to efficiently remove some attributes from an existing AttrBuild...

LLVM Basic Block Representation.

iterator begin()

Instruction iterator methods.

const Function * getParent() const

Return the enclosing method, or null if none.

bool hasAddressTaken() const

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

InstListType::const_iterator const_iterator

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

Creates a new BasicBlock.

LLVM_ABI const BasicBlock * getSinglePredecessor() const

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

const Instruction & front() const

LLVM_ABI const DataLayout & getDataLayout() const

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

LLVM_ABI SymbolTableList< BasicBlock >::iterator eraseFromParent()

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

InstListType::iterator iterator

Instruction iterators...

LLVM_ABI LLVMContext & getContext() const

Get the context in which this basic block lives.

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

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

void addFnAttr(Attribute::AttrKind Kind)

Adds the attribute to the function.

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

This is an important base class in LLVM.

Subprogram description. Uses SubclassData1.

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

Utility to find all debug info in a module.

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

Process a single instruction and collect debug info anchors.

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.

static constexpr UpdateKind Delete

static constexpr UpdateKind Insert

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 LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)

This static method is the primary way of constructing a FunctionType.

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

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.

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

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

LLVM_ABI void addMetadata(unsigned KindID, MDNode &MD)

Add a metadata attachment.

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

LLVM_ABI Instruction * clone() const

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

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

const DebugLoc & getDebugLoc() const

Return the debug location for this node as a DebugLoc.

LLVM_ABI void insertBefore(InstListType::iterator InsertPos)

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

LLVM_ABI InstListType::iterator eraseFromParent()

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

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

iterator_range< op_iterator > operands()

LLVM_ABI void addOperand(MDNode *M)

iterator_range< const_block_iterator > blocks() const

void setIncomingBlock(unsigned i, BasicBlock *BB)

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

BasicBlockT * getCaseSuccessor() const

Resolves successor for current case.

CaseHandleImpl< const SwitchInst, const ConstantInt, const BasicBlock > ConstCaseHandle

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

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)

DMAtomT AtomMap

Map {(InlinedAt, old atom number) -> new atom number}.

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.

LLVM_ABI void setName(const Twine &Name)

Change the name of the value.

LLVM_ABI void replaceAllUsesWith(Value *V)

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

LLVM_ABI StringRef getName() const

Return a constant reference to the value's name.

const ParentTy * getParent() const

self_iterator getIterator()

constexpr char Args[]

Key for Kernel::Metadata::mArgs.

@ BasicBlock

Various leaf nodes.

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

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

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

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

LLVM_ABI bool hasConstrainedFPRoundingModeOperand(ID QID)

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

friend class Instruction

Iterator for Instructions in a `BasicBlock.

This is an optimization pass for GlobalISel generic memory operations.

FunctionAddr VTableAddr Value

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

Definition CloneFunction.cpp:157

std::function< bool(const Metadata *)> MetadataPredicate

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

static cl::opt< unsigned long > StopAt("sbvec-stop-at", cl::init(StopAtDisabled), cl::Hidden, cl::desc("Vectorize if the invocation count is < than this. 0 " "disables vectorization."))

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

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

Definition CloneFunction.cpp:112

decltype(auto) dyn_cast(const From &Val)

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

auto successors(const MachineBasicBlock *BB)

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

ConstantFoldInstruction - Try to constant fold the specified instruction.

constexpr from_range_t from_range

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.

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

auto cast_or_null(const Y &Val)

auto pred_size(const MachineBasicBlock *BB)

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

Definition CloneFunction.cpp:1094

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

Clone OldFunc's metadata into NewFunc.

Definition CloneFunction.cpp:207

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)

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

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

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

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

Clones a loop OrigLoop.

Definition CloneFunction.cpp:1009

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

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

Definition CloneFunction.cpp:982

LLVM_ABI raw_ostream & dbgs()

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

FunctionAddr VTableAddr Count

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

Duplicate the specified list of noalias decl scopes.

Definition CloneFunction.cpp:1143

LLVM_ABI Intrinsic::ID getConstrainedIntrinsicID(const Instruction &Instr)

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

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 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 MetadataPredicate *IdentityMD=nullptr)

Clone OldFunc's body into NewFunc.

Definition CloneFunction.cpp:221

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

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

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

Definition CloneFunction.cpp:1168

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

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

DWARFExpression::Operation Op

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

Clone the specified noalias decl scopes.

Definition CloneFunction.cpp:1202

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

Remaps instructions in Blocks using the mapping in VMap.

Definition CloneFunction.cpp:991

ValueMap< const Value *, WeakTrackingVH > ValueToValueMapTy

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

Definition CloneFunction.cpp:278

decltype(auto) cast(const From &Val)

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

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

Look up or compute a value in the value map.

auto predecessors(const MachineBasicBlock *BB)

auto seq(T Begin, T End)

Iterate over an integral type from Begin up to - but not including - End.

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

Delete the specified blocks from BB.

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

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

Definition CloneFunction.cpp:1239

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

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

Definition CloneFunction.cpp:702

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

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

Definition CloneFunction.cpp:370

LLVM_ABI void mapAtomInstance(const DebugLoc &DL, ValueToValueMapTy &VMap)

Mark a cloned instruction as a new instance so that its source loc can be updated when remapped.

Definition CloneFunction.cpp:47

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

Lookup or compute a mapping for a piece of metadata.

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.

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

ArgKind getArgumentKind() const