86#define DEBUG_TYPE "machine-outliner"
90using namespace outliner;
93STATISTIC(NumOutlined,
"Number of candidates outlined");
94STATISTIC(FunctionsCreated,
"Number of functions created");
97STATISTIC(NumLegalInUnsignedVec,
"Outlinable instructions mapped");
99 "Unoutlinable instructions mapped + number of sentinel values");
100STATISTIC(NumSentinels,
"Sentinel values inserted during mapping");
102 "Invisible instructions skipped during mapping");
104 "Total number of instructions mapped and saved to mapping vector");
106 "Count of hashing attempts made for outlined functions");
108 "Count of unsuccessful hashing attempts for outlined functions");
109STATISTIC(NumRemovedLOHs,
"Total number of Linker Optimization Hints removed");
118 cl::desc(
"Enable the machine outliner on linkonceodr functions"),
127 "Number of times to rerun the outliner after the initial outline"));
132 "The minimum size in bytes before an outlining candidate is accepted"));
136 cl::desc(
"Consider all leaf descendants of internal nodes of the suffix "
137 "tree as candidates for outlining (if false, only leaf children "
142 cl::desc(
"Disable global outlining only by ignoring "
143 "the codegen data generation or use"),
147 "append-content-hash-outlined-name",
cl::Hidden,
148 cl::desc(
"This appends the content hash to the globally outlined function "
149 "name. It's beneficial for enhancing the precision of the stable "
150 "hash and for ordering the outlined functions."),
156struct InstructionMapper {
163 unsigned IllegalInstrNumber = -3;
167 unsigned LegalInstrNumber = 0;
171 InstructionIntegerMap;
187 bool AddedIllegalLastTime =
false;
195 unsigned mapToLegalUnsigned(
197 bool &HaveLegalRange,
unsigned &NumLegalInBlock,
202 AddedIllegalLastTime =
false;
206 if (CanOutlineWithPrevInstr)
207 HaveLegalRange =
true;
208 CanOutlineWithPrevInstr =
true;
220 std::tie(ResultIt, WasInserted) =
221 InstructionIntegerMap.
insert(std::make_pair(&
MI, LegalInstrNumber));
222 unsigned MINumber = ResultIt->second;
231 if (LegalInstrNumber >= IllegalInstrNumber)
235 "Tried to assign DenseMap tombstone or empty key to instruction.");
237 "Tried to assign DenseMap tombstone or empty key to instruction.");
240 ++NumLegalInUnsignedVec;
250 unsigned mapToIllegalUnsigned(
255 CanOutlineWithPrevInstr =
false;
258 if (AddedIllegalLastTime)
259 return IllegalInstrNumber;
262 AddedIllegalLastTime =
true;
263 unsigned MINumber = IllegalInstrNumber;
266 UnsignedVecForMBB.
push_back(IllegalInstrNumber);
267 IllegalInstrNumber--;
269 ++NumIllegalInUnsignedVec;
271 assert(LegalInstrNumber < IllegalInstrNumber &&
272 "Instruction mapping overflow!");
275 "IllegalInstrNumber cannot be DenseMap tombstone or empty key!");
278 "IllegalInstrNumber cannot be DenseMap tombstone or empty key!");
296 <<
"' to unsigned vector ***\n");
300 if (!
TII.isMBBSafeToOutlineFrom(
MBB, Flags))
303 auto OutlinableRanges =
TII.getOutlinableRanges(
MBB, Flags);
305 <<
" outlinable range(s)\n");
306 if (OutlinableRanges.empty())
316 unsigned NumLegalInBlock = 0;
320 bool HaveLegalRange =
false;
324 bool CanOutlineWithPrevInstr =
false;
332 for (
auto &OutlinableRange : OutlinableRanges) {
333 auto OutlinableRangeBegin = OutlinableRange.first;
334 auto OutlinableRangeEnd = OutlinableRange.second;
338 << std::distance(OutlinableRangeBegin, OutlinableRangeEnd)
339 <<
" instruction range\n");
341 unsigned NumSkippedInRange = 0;
343 for (; It != OutlinableRangeBegin; ++It) {
347 mapToIllegalUnsigned(It, CanOutlineWithPrevInstr, UnsignedVecForMBB,
352 <<
" instructions outside outlinable range\n");
354 assert(It !=
MBB.
end() &&
"Should still have instructions?");
357 for (; It != OutlinableRangeEnd; ++It) {
359 switch (
TII.getOutliningType(MMI, It, Flags)) {
360 case InstrType::Illegal:
361 mapToIllegalUnsigned(It, CanOutlineWithPrevInstr, UnsignedVecForMBB,
365 case InstrType::Legal:
366 mapToLegalUnsigned(It, CanOutlineWithPrevInstr, HaveLegalRange,
367 NumLegalInBlock, UnsignedVecForMBB,
371 case InstrType::LegalTerminator:
372 mapToLegalUnsigned(It, CanOutlineWithPrevInstr, HaveLegalRange,
373 NumLegalInBlock, UnsignedVecForMBB,
377 mapToIllegalUnsigned(It, CanOutlineWithPrevInstr, UnsignedVecForMBB,
381 case InstrType::Invisible:
385 AddedIllegalLastTime =
false;
391 LLVM_DEBUG(
dbgs() <<
"HaveLegalRange = " << HaveLegalRange <<
"\n");
395 if (HaveLegalRange) {
400 mapToIllegalUnsigned(It, CanOutlineWithPrevInstr, UnsignedVecForMBB,
412 "DenseMapInfo<unsigned>'s empty key isn't -1!");
414 "DenseMapInfo<unsigned>'s tombstone key isn't -2!");
436 bool OutlineFromLinkOnceODRs =
false;
439 unsigned OutlineRepeatedNum = 0;
445 bool RunOnAllFunctions =
true;
453 std::unique_ptr<OutlinedHashTree> LocalHashTree;
481 void emitNotOutliningCheaperRemark(
482 unsigned StringLen, std::vector<Candidate> &CandidatesForRepeatedSeq,
502 findCandidates(InstructionMapper &Mapper,
503 std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList);
511 void findGlobalCandidates(
512 InstructionMapper &Mapper,
513 std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList);
523 std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList,
524 InstructionMapper &Mapper,
unsigned &OutlinedFunctionNum);
528 InstructionMapper &Mapper,
534 void computeAndPublishHashSequence(
MachineFunction &MF,
unsigned CandSize);
537 void initializeOutlinerMode(
const Module &M);
540 void emitOutlinedHashTree(
Module &M);
547 bool doOutline(
Module &M,
unsigned &OutlinedFunctionNum);
561 void populateMapper(InstructionMapper &Mapper,
Module &M);
567 void initSizeRemarkInfo(
const Module &M,
573 emitInstrCountChangedRemark(
const Module &M,
578char MachineOutliner::ID = 0;
582 MachineOutliner *OL =
new MachineOutliner();
583 OL->RunOnAllFunctions = RunOnAllFunctions;
592void MachineOutliner::emitNotOutliningCheaperRemark(
593 unsigned StringLen,
std::vector<
Candidate> &CandidatesForRepeatedSeq,
599 Candidate &
C = CandidatesForRepeatedSeq.front();
603 C.front().getDebugLoc(),
C.getMBB());
604 R <<
"Did not outline " <<
NV(
"Length", StringLen) <<
" instructions"
605 <<
" from " <<
NV(
"NumOccurrences", CandidatesForRepeatedSeq.size())
607 <<
" Bytes from outlining all occurrences ("
608 <<
NV(
"OutliningCost", OF.getOutliningCost()) <<
")"
609 <<
" >= Unoutlined instruction bytes ("
610 <<
NV(
"NotOutliningCost", OF.getNotOutlinedCost()) <<
")"
611 <<
" (Also found at: ";
614 for (
unsigned i = 1, e = CandidatesForRepeatedSeq.size(); i < e; i++) {
616 CandidatesForRepeatedSeq[i].front().
getDebugLoc());
631 R <<
"Saved " <<
NV(
"OutliningBenefit",
OF.getBenefit()) <<
" bytes by "
632 <<
"outlining " <<
NV(
"Length",
OF.getNumInstrs()) <<
" instructions "
633 <<
"from " <<
NV(
"NumOccurrences",
OF.getOccurrenceCount())
638 for (
size_t i = 0, e =
OF.Candidates.size(); i < e; i++) {
641 OF.Candidates[i].front().getDebugLoc());
664 auto &InstrList = Mapper.InstrList;
665 auto &UnsignedVec = Mapper.UnsignedVec;
674 auto getValidInstr = [&](
unsigned Index) ->
const MachineInstr * {
675 if (UnsignedVec[Index] >= Mapper.LegalInstrNumber)
677 return &(*InstrList[Index]);
680 auto getStableHashAndFollow =
685 auto It = CurrNode->Successors.find(StableHash);
686 return (It == CurrNode->Successors.end()) ? nullptr : It->second.get();
689 for (
unsigned I = 0;
I <
Size; ++
I) {
691 if (!
MI ||
MI->isDebugInstr())
693 const HashNode *CurrNode = getStableHashAndFollow(*
MI, RootNode);
697 for (
unsigned J =
I + 1; J <
Size; ++J) {
704 CurrNode = getStableHashAndFollow(*MJ, CurrNode);
714 return MatchedEntries;
717void MachineOutliner::findGlobalCandidates(
718 InstructionMapper &Mapper,
719 std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList) {
720 FunctionList.
clear();
722 auto &MBBFlagsMap = Mapper.MBBFlagsMap;
724 std::vector<Candidate> CandidatesForRepeatedSeq;
726 CandidatesForRepeatedSeq.
clear();
729 auto Length = ME.EndIdx - ME.StartIdx + 1;
731 CandidatesForRepeatedSeq.emplace_back(ME.StartIdx,
Length, StartIt, EndIt,
736 unsigned MinRepeats = 1;
737 std::optional<std::unique_ptr<OutlinedFunction>>
OF =
738 TII->getOutliningCandidateInfo(*MMI, CandidatesForRepeatedSeq,
740 if (!
OF.has_value() ||
OF.value()->Candidates.empty())
743 assert(
OF.value()->Candidates.size() == MinRepeats);
744 FunctionList.emplace_back(std::make_unique<GlobalOutlinedFunction>(
745 std::move(
OF.value()), ME.Count));
749void MachineOutliner::findCandidates(
750 InstructionMapper &Mapper,
751 std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList) {
752 FunctionList.clear();
757 std::vector<Candidate> CandidatesForRepeatedSeq;
758 LLVM_DEBUG(
dbgs() <<
"*** Discarding overlapping candidates *** \n");
760 dbgs() <<
"Searching for overlaps in all repeated sequences...\n");
762 CandidatesForRepeatedSeq.clear();
763 unsigned StringLen = RS.Length;
767 unsigned NumDiscarded = 0;
768 unsigned NumKept = 0;
773 for (
const unsigned &StartIdx : RS.StartIndices) {
795 unsigned EndIdx = StartIdx + StringLen - 1;
796 if (!CandidatesForRepeatedSeq.empty() &&
797 StartIdx <= CandidatesForRepeatedSeq.back().getEndIdx()) {
800 LLVM_DEBUG(
dbgs() <<
" .. DISCARD candidate @ [" << StartIdx <<
", "
801 << EndIdx <<
"]; overlaps with candidate @ ["
802 << CandidatesForRepeatedSeq.back().getStartIdx()
803 <<
", " << CandidatesForRepeatedSeq.back().getEndIdx()
817 CandidatesForRepeatedSeq.emplace_back(StartIdx, StringLen, StartIt, EndIt,
819 Mapper.MBBFlagsMap[
MBB]);
826 unsigned MinRepeats = 2;
831 if (CandidatesForRepeatedSeq.size() < MinRepeats)
837 CandidatesForRepeatedSeq[0].getMF()->getSubtarget().getInstrInfo();
839 std::optional<std::unique_ptr<OutlinedFunction>>
OF =
840 TII->getOutliningCandidateInfo(*MMI, CandidatesForRepeatedSeq,
845 if (!
OF.has_value() ||
OF.value()->Candidates.size() < MinRepeats)
850 emitNotOutliningCheaperRemark(StringLen, CandidatesForRepeatedSeq,
855 FunctionList.emplace_back(std::move(
OF.value()));
859void MachineOutliner::computeAndPublishHashSequence(
MachineFunction &MF,
863 for (
auto &
MBB : MF) {
864 for (
auto &NewMI :
MBB) {
867 OutlinedHashSequence.
clear();
878 MF.getName().str() +
".content." + std::to_string(CombinedHash);
879 MF.getFunction().setName(NewName);
883 if (OutlinerMode == CGDataMode::Write) {
884 StableHashAttempts++;
885 if (!OutlinedHashSequence.
empty())
886 LocalHashTree->insert({OutlinedHashSequence, CandSize});
898 std::string FunctionName =
"OUTLINED_FUNCTION_";
899 if (OutlineRepeatedNum > 0)
900 FunctionName += std::to_string(OutlineRepeatedNum + 1) +
"_";
901 FunctionName += std::to_string(
Name);
907 Function::ExternalLinkage, FunctionName, M);
912 F->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
916 F->addFnAttr(Attribute::OptimizeForSize);
917 F->addFnAttr(Attribute::MinSize);
923 TII.mergeOutliningCandidateAttributes(*
F,
OF.Candidates);
927 OF.Candidates.cbegin(),
OF.Candidates.cend(), UWTableKind::None,
929 return std::max(K, C.getMF()->getFunction().getUWTableKind());
931 F->setUWTableKind(UW);
935 Builder.CreateRetVoid();
946 const std::vector<MCCFIInstruction> &Instrs =
948 for (
auto &
MI : FirstCand) {
949 if (
MI.isDebugInstr())
954 if (
MI.isCFIInstruction()) {
955 unsigned CFIIndex =
MI.getOperand(0).getCFIIndex();
966 if (OutlinerMode != CGDataMode::None)
967 computeAndPublishHashSequence(MF,
OF.Candidates.size());
980 for (
auto &Cand :
OF.Candidates) {
984 CandLiveIns.addLiveOuts(OutlineBB);
987 CandLiveIns.stepBackward(
MI);
996 TII.buildOutlinedFrame(
MBB, MF, OF);
1012 Unit ,
F->getName(),
StringRef(Dummy), Unit ,
1014 DB.createSubroutineType(
DB.getOrCreateTypeArray({})),
1016 DINode::DIFlags::FlagArtificial ,
1018 DISubprogram::SPFlagDefinition | DISubprogram::SPFlagOptimized);
1021 F->setSubprogram(OutlinedSP);
1029bool MachineOutliner::outline(
1030 Module &M, std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList,
1031 InstructionMapper &Mapper,
unsigned &OutlinedFunctionNum) {
1033 LLVM_DEBUG(
dbgs() <<
"NUMBER OF POTENTIAL FUNCTIONS: " << FunctionList.size()
1035 bool OutlinedSomething =
false;
1039 stable_sort(FunctionList, [](
const std::unique_ptr<OutlinedFunction> &LHS,
1040 const std::unique_ptr<OutlinedFunction> &RHS) {
1041 return LHS->getNotOutlinedCost() *
RHS->getOutliningCost() >
1042 RHS->getNotOutlinedCost() *
LHS->getOutliningCost();
1047 auto *UnsignedVecBegin = Mapper.UnsignedVec.begin();
1049 for (
auto &OF : FunctionList) {
1051 auto NumCandidatesBefore =
OF->Candidates.size();
1056 return std::any_of(UnsignedVecBegin + C.getStartIdx(),
1057 UnsignedVecBegin + C.getEndIdx() + 1, [](unsigned I) {
1058 return I == static_cast<unsigned>(-1);
1063 auto NumCandidatesAfter =
OF->Candidates.size();
1064 LLVM_DEBUG(
dbgs() <<
"PRUNED: " << NumCandidatesBefore - NumCandidatesAfter
1065 <<
"/" << NumCandidatesBefore <<
" candidates\n");
1087 NumRemovedLOHs +=
TM->clearLinkerOptimizationHints(MIs);
1094 emitOutlinedFunctionRemark(*OF);
1096 OutlinedFunctionNum++;
1112 auto MBBBeingOutlinedFromName =
1118 << MFBeingOutlinedFromName <<
":"
1119 << MBBBeingOutlinedFromName <<
"\n");
1141 Iter !=
Last; Iter++) {
1151 DefRegs.
insert(MOP.getReg());
1152 if (UseRegs.
count(MOP.getReg()) &&
1153 !InstrUseRegs.
count(MOP.getReg()))
1156 UseRegs.
erase(MOP.getReg());
1157 }
else if (!MOP.isUndef()) {
1160 UseRegs.
insert(MOP.getReg());
1161 InstrUseRegs.
insert(MOP.getReg());
1164 if (
MI->isCandidateForAdditionalCallInfo())
1165 MI->getMF()->eraseAdditionalCallInfo(
MI);
1184 MBB.
erase(std::next(StartIt), std::next(EndIt));
1187 for (
unsigned &
I :
make_range(UnsignedVecBegin +
C.getStartIdx(),
1188 UnsignedVecBegin +
C.getEndIdx() + 1))
1189 I =
static_cast<unsigned>(-1);
1190 OutlinedSomething =
true;
1197 LLVM_DEBUG(
dbgs() <<
"OutlinedSomething = " << OutlinedSomething <<
"\n");
1198 return OutlinedSomething;
1201void MachineOutliner::populateMapper(InstructionMapper &Mapper,
Module &M) {
1208 if (
F.hasFnAttribute(
"nooutline")) {
1209 LLVM_DEBUG(
dbgs() <<
"SKIP: Function has nooutline attribute\n");
1220 LLVM_DEBUG(
dbgs() <<
"SKIP: Function does not have a MachineFunction\n");
1225 if (!RunOnAllFunctions && !
TII->shouldOutlineFromFunctionByDefault(*MF)) {
1226 LLVM_DEBUG(
dbgs() <<
"SKIP: Target does not want to outline from "
1227 "function by default\n");
1233 if (!
TII->isFunctionSafeToOutlineFrom(*MF, OutlineFromLinkOnceODRs)) {
1235 <<
": unsafe to outline from\n");
1242 const unsigned MinMBBSize = 2;
1252 if (
MBB.
size() < MinMBBSize) {
1253 LLVM_DEBUG(
dbgs() <<
" SKIP: MBB size less than minimum size of "
1254 << MinMBBSize <<
"\n");
1266 Mapper.convertToUnsignedVec(
MBB, *
TII);
1270 UnsignedVecSize = Mapper.UnsignedVec.size();
1273void MachineOutliner::initSizeRemarkInfo(
1288void MachineOutliner::emitInstrCountChangedRemark(
1301 std::string Fname = std::string(
F.getName());
1303 unsigned FnCountBefore = 0;
1306 auto It = FunctionToInstrCount.
find(Fname);
1310 if (It != FunctionToInstrCount.
end())
1311 FnCountBefore = It->second;
1314 int64_t FnDelta =
static_cast<int64_t
>(FnCountAfter) -
1315 static_cast<int64_t
>(FnCountBefore);
1326 <<
": MI instruction count changed from "
1339void MachineOutliner::initializeOutlinerMode(
const Module &M) {
1343 if (
auto *IndexWrapperPass =
1344 getAnalysisIfAvailable<ImmutableModuleSummaryIndexWrapperPass>()) {
1345 auto *TheIndex = IndexWrapperPass->getIndex();
1348 if (TheIndex && !TheIndex->hasExportedFunctions(M))
1357 OutlinerMode = CGDataMode::Write;
1359 LocalHashTree = std::make_unique<OutlinedHashTree>();
1362 OutlinerMode = CGDataMode::Read;
1365void MachineOutliner::emitOutlinedHashTree(
Module &M) {
1367 if (!LocalHashTree->empty()) {
1369 dbgs() <<
"Emit outlined hash tree. Size: " << LocalHashTree->size()
1379 std::unique_ptr<MemoryBuffer> Buffer =
1389bool MachineOutliner::runOnModule(
Module &M) {
1399 initializeOutlinerMode(M);
1401 MMI = &getAnalysis<MachineModuleInfoWrapperPass>().getMMI();
1405 unsigned OutlinedFunctionNum = 0;
1407 OutlineRepeatedNum = 0;
1408 if (!doOutline(M, OutlinedFunctionNum))
1412 OutlinedFunctionNum = 0;
1413 OutlineRepeatedNum++;
1414 if (!doOutline(M, OutlinedFunctionNum)) {
1416 dbgs() <<
"Did not outline on iteration " <<
I + 2 <<
" out of "
1423 if (OutlinerMode == CGDataMode::Write)
1424 emitOutlinedHashTree(M);
1429bool MachineOutliner::doOutline(
Module &M,
unsigned &OutlinedFunctionNum) {
1436 dbgs() <<
"Machine Outliner: Running on ";
1437 if (RunOnAllFunctions)
1438 dbgs() <<
"all functions";
1440 dbgs() <<
"target-default functions";
1447 InstructionMapper Mapper(*MMI);
1450 populateMapper(Mapper, M);
1451 std::vector<std::unique_ptr<OutlinedFunction>> FunctionList;
1454 if (OutlinerMode == CGDataMode::Read)
1455 findGlobalCandidates(Mapper, FunctionList);
1457 findCandidates(Mapper, FunctionList);
1468 bool ShouldEmitSizeRemarks =
M.shouldEmitInstrCountChangedRemark();
1470 if (ShouldEmitSizeRemarks)
1471 initSizeRemarkInfo(M, FunctionToInstrCount);
1474 bool OutlinedSomething =
1475 outline(M, FunctionList, Mapper, OutlinedFunctionNum);
1480 if (ShouldEmitSizeRemarks && OutlinedSomething)
1481 emitInstrCountChangedRemark(M, FunctionToInstrCount);
1484 if (!OutlinedSomething)
1485 dbgs() <<
"Stopped outlining at iteration " << OutlineRepeatedNum
1486 <<
" because no changes were found.\n";
1489 return OutlinedSomething;
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file defines the DenseMap class.
const HexagonInstrInfo * TII
static DISubprogram * getSubprogramOrNull(OutlinableGroup &Group)
Get the subprogram if it exists for one of the outlined regions.
Module.h This file contains the declarations for the Module class.
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
Return the first found DebugLoc that has a DILocation, given a range of instructions.
static cl::opt< bool > DisableGlobalOutlining("disable-global-outlining", cl::Hidden, cl::desc("Disable global outlining only by ignoring " "the codegen data generation or use"), cl::init(false))
static cl::opt< unsigned > OutlinerBenefitThreshold("outliner-benefit-threshold", cl::init(1), cl::Hidden, cl::desc("The minimum size in bytes before an outlining candidate is accepted"))
static cl::opt< bool > OutlinerLeafDescendants("outliner-leaf-descendants", cl::init(true), cl::Hidden, cl::desc("Consider all leaf descendants of internal nodes of the suffix " "tree as candidates for outlining (if false, only leaf children " "are considered)"))
static cl::opt< bool > AppendContentHashToOutlinedName("append-content-hash-outlined-name", cl::Hidden, cl::desc("This appends the content hash to the globally outlined function " "name. It's beneficial for enhancing the precision of the stable " "hash and for ordering the outlined functions."), cl::init(true))
static cl::opt< unsigned > OutlinerReruns("machine-outliner-reruns", cl::init(0), cl::Hidden, cl::desc("Number of times to rerun the outliner after the initial outline"))
Number of times to re-run the outliner.
static cl::opt< bool > EnableLinkOnceODROutlining("enable-linkonceodr-outlining", cl::Hidden, cl::desc("Enable the machine outliner on linkonceodr functions"), cl::init(false))
static SmallVector< MatchedEntry > getMatchedEntries(InstructionMapper &Mapper)
Contains all data structures shared between the outliner implemented in MachineOutliner....
Register const TargetRegisterInfo * TRI
This is the interface to build a ModuleSummaryIndex for a module.
static Expected< Function * > createOutlinedFunction(OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder, const OpenMPIRBuilder::TargetKernelDefaultAttrs &DefaultAttrs, StringRef FuncName, SmallVectorImpl< Value * > &Inputs, OpenMPIRBuilder::TargetBodyGenCallbackTy &CBFunc, OpenMPIRBuilder::TargetGenArgAccessorsCallbackTy &ArgAccessorFuncCB)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file defines the SmallSet class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Target-Independent Code Generator Pass Configuration Options pass.
Represent the analysis usage information of a pass.
AnalysisUsage & addUsedIfAvailable()
Add the specified Pass class to the set of analyses used by this pass.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
LLVM Basic Block Representation.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
This class represents a function call, abstracting a target machine's calling convention.
LLVM_ABI DISubprogram * getSubprogram() const
Get the subprogram for this scope.
Subprogram description. Uses SubclassData1.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
@ InternalLinkage
Rename collisions when linking (static functions).
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Legacy wrapper pass to provide the ModuleSummaryIndex object.
This is an important class for using LLVM in a threaded context.
A set of physical registers with utility functions to track liveness when walking backward/forward th...
bool hasAddressTaken() const
Test whether this block is used as something other than the target of a terminator,...
LLVM_ABI DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any debug instructions.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
LLVM_ABI instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
LLVM_ABI StringRef getName() const
Return the name of the corresponding LLVM basic block, or an empty string.
unsigned getInstructionCount() const
Return the number of MachineInstrs in this MachineFunction.
unsigned addFrameInst(const MCCFIInstruction &Inst)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
const std::vector< MCCFIInstruction > & getFrameInstructions() const
Returns a reference to a list of cfi instructions in the function's prologue.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
void setIsOutlined(bool V)
const MachineFunctionProperties & getProperties() const
Get the function properties.
const MachineBasicBlock & front() const
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *BB=nullptr, std::optional< UniqueBBID > BBID=std::nullopt)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
void insert(iterator MBBI, MachineBasicBlock *MBB)
const MachineInstrBuilder & addCFIIndex(unsigned CFIIndex) const
reverse_iterator getReverse() const
Get a reverse iterator to the same node.
Representation of each machine instruction.
const MachineBasicBlock * getParent() const
bool isDebugInstr() const
LLVM_ABI void dropMemRefs(MachineFunction &MF)
Clear this MachineInstr's memory reference descriptor list.
LLVM_ABI const MachineFunction * getMF() const
Return the function that contains the basic block that this instruction belongs to.
void setDebugLoc(DebugLoc DL)
Replace current source information with new such.
This class contains meta information specific to a module.
LLVM_ABI MachineFunction & getOrCreateMachineFunction(Function &F)
Returns the MachineFunction constructed for the IR function F.
LLVM_ABI MachineFunction * getMachineFunction(const Function &F) const
Returns the MachineFunction associated to IR function F if there is one, otherwise nullptr.
MachineOperand class - Representation of each machine instruction operand.
static MachineOperand CreateReg(Register Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isEarlyClobber=false, unsigned SubReg=0, bool isDebug=false, bool isInternalRead=false, bool isRenamable=false)
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLVM_ABI void freezeReservedRegs()
freezeReservedRegs - Called by the register allocator to freeze the set of reserved registers before ...
LLVM_ABI void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV, bool CannotUsePrivateLabel) const
Print the appropriate prefix and the specified global variable's name.
static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as a MemoryBuffer.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
virtual bool runOnModule(Module &M)=0
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
A Module instance is used to store all the information related to an LLVM module.
const HashNode * getRoot() const
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Wrapper class representing virtual and physical registers.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
reference emplace_back(ArgTypes &&... Args)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
iterator find(StringRef Key)
StringRef - Represent a constant reference to a string, i.e.
std::string str() const
str - Get the contents as an std::string.
constexpr bool empty() const
empty - Check if the string is empty.
constexpr size_t size() const
size - Get the string size.
TargetInstrInfo - Interface to description of machine instruction set.
Primary interface to the complete machine description for the target machine.
Target-Independent Code Generator Pass Configuration Options.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
TargetSubtargetInfo - Generic base class for all target subtargets.
virtual const TargetInstrInfo * getInstrInfo() const
Triple - Helper class for working with autoconf configuration names.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
A raw_ostream that writes to an std::string.
A raw_ostream that writes to an SmallVector or SmallString.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
SmallVector< const MachineInstr * > InstrList
bool hasOutlinedHashTree()
const OutlinedHashTree * getOutlinedHashTree()
initializer< Ty > init(const Ty &Val)
DiagnosticInfoOptimizationBase::Argument NV
This is an optimization pass for GlobalISel generic memory operations.
void stable_sort(R &&Range)
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
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 initializeMachineOutlinerPass(PassRegistry &)
auto reverse(ContainerTy &&C)
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI stable_hash stableHashValue(const MachineOperand &MO)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
LLVM_ABI ModulePass * createMachineOutlinerPass(bool RunOnAllFunctions=true)
This pass performs outlining on machine instructions directly before printing assembly.
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
stable_hash stable_hash_combine(ArrayRef< stable_hash > Buffer)
LLVM_ABI void embedBufferInModule(Module &M, MemoryBufferRef Buf, StringRef SectionName, Align Alignment=Align(1))
Embed the memory buffer Buf into the module M as a global using the specified section name.
void addLiveIns(MachineBasicBlock &MBB, const LivePhysRegs &LiveRegs)
Adds registers contained in LiveRegs to the block live-in list of MBB.
LLVM_ABI std::string getCodeGenDataSectionName(CGDataSectKind CGSK, Triple::ObjectFormatType OF, bool AddSegmentInfo=true)
Implement std::hash so that hash_code can be used in STL containers.
MatchedEntry(unsigned StartIdx, unsigned EndIdx, unsigned Count)
An information struct used to provide DenseMap with the various necessary components for a given valu...
Used in the streaming interface as the general argument type.
A HashNode is an entry in an OutlinedHashTree, holding a hash value and a collection of Successors (o...
std::optional< unsigned > Terminals
The number of terminals in the sequence ending at this node.
A repeated substring in the tree.
An individual sequence of instructions to be replaced with a call to an outlined function.
MachineFunction * getMF() const
The information necessary to create an outlined function for some class of candidate.