84#define DEBUG_TYPE "machine-outliner"
88using namespace outliner;
91STATISTIC(NumOutlined,
"Number of candidates outlined");
92STATISTIC(FunctionsCreated,
"Number of functions created");
95STATISTIC(NumLegalInUnsignedVec,
"Outlinable instructions mapped");
97 "Unoutlinable instructions mapped + number of sentinel values");
98STATISTIC(NumSentinels,
"Sentinel values inserted during mapping");
100 "Invisible instructions skipped during mapping");
102 "Total number of instructions mapped and saved to mapping vector");
104 "Count of hashing attempts made for outlined functions");
106 "Count of unsuccessful hashing attempts for outlined functions");
115 cl::desc(
"Enable the machine outliner on linkonceodr functions"),
124 "Number of times to rerun the outliner after the initial outline"));
129 "The minimum size in bytes before an outlining candidate is accepted"));
133 cl::desc(
"Consider all leaf descendants of internal nodes of the suffix "
134 "tree as candidates for outlining (if false, only leaf children "
139 cl::desc(
"Disable global outlining only by ignoring "
140 "the codegen data generation or use"),
144 "append-content-hash-outlined-name",
cl::Hidden,
145 cl::desc(
"This appends the content hash to the globally outlined function "
146 "name. It's beneficial for enhancing the precision of the stable "
147 "hash and for ordering the outlined functions."),
153struct InstructionMapper {
160 unsigned IllegalInstrNumber = -3;
164 unsigned LegalInstrNumber = 0;
168 InstructionIntegerMap;
184 bool AddedIllegalLastTime =
false;
192 unsigned mapToLegalUnsigned(
194 bool &HaveLegalRange,
unsigned &NumLegalInBlock,
199 AddedIllegalLastTime =
false;
203 if (CanOutlineWithPrevInstr)
204 HaveLegalRange =
true;
205 CanOutlineWithPrevInstr =
true;
217 std::tie(ResultIt, WasInserted) =
218 InstructionIntegerMap.
insert(std::make_pair(&
MI, LegalInstrNumber));
219 unsigned MINumber = ResultIt->second;
228 if (LegalInstrNumber >= IllegalInstrNumber)
232 "Tried to assign DenseMap tombstone or empty key to instruction.");
234 "Tried to assign DenseMap tombstone or empty key to instruction.");
237 ++NumLegalInUnsignedVec;
247 unsigned mapToIllegalUnsigned(
252 CanOutlineWithPrevInstr =
false;
255 if (AddedIllegalLastTime)
256 return IllegalInstrNumber;
259 AddedIllegalLastTime =
true;
260 unsigned MINumber = IllegalInstrNumber;
263 UnsignedVecForMBB.
push_back(IllegalInstrNumber);
264 IllegalInstrNumber--;
266 ++NumIllegalInUnsignedVec;
268 assert(LegalInstrNumber < IllegalInstrNumber &&
269 "Instruction mapping overflow!");
272 "IllegalInstrNumber cannot be DenseMap tombstone or empty key!");
275 "IllegalInstrNumber cannot be DenseMap tombstone or empty key!");
293 <<
"' to unsigned vector ***\n");
297 if (!
TII.isMBBSafeToOutlineFrom(
MBB, Flags))
300 auto OutlinableRanges =
TII.getOutlinableRanges(
MBB, Flags);
302 <<
" outlinable range(s)\n");
303 if (OutlinableRanges.empty())
313 unsigned NumLegalInBlock = 0;
317 bool HaveLegalRange =
false;
321 bool CanOutlineWithPrevInstr =
false;
329 for (
auto &OutlinableRange : OutlinableRanges) {
330 auto OutlinableRangeBegin = OutlinableRange.first;
331 auto OutlinableRangeEnd = OutlinableRange.second;
335 << std::distance(OutlinableRangeBegin, OutlinableRangeEnd)
336 <<
" instruction range\n");
338 unsigned NumSkippedInRange = 0;
340 for (; It != OutlinableRangeBegin; ++It) {
344 mapToIllegalUnsigned(It, CanOutlineWithPrevInstr, UnsignedVecForMBB,
349 <<
" instructions outside outlinable range\n");
351 assert(It !=
MBB.
end() &&
"Should still have instructions?");
354 for (; It != OutlinableRangeEnd; ++It) {
356 switch (
TII.getOutliningType(MMI, It, Flags)) {
357 case InstrType::Illegal:
358 mapToIllegalUnsigned(It, CanOutlineWithPrevInstr, UnsignedVecForMBB,
362 case InstrType::Legal:
363 mapToLegalUnsigned(It, CanOutlineWithPrevInstr, HaveLegalRange,
364 NumLegalInBlock, UnsignedVecForMBB,
368 case InstrType::LegalTerminator:
369 mapToLegalUnsigned(It, CanOutlineWithPrevInstr, HaveLegalRange,
370 NumLegalInBlock, UnsignedVecForMBB,
374 mapToIllegalUnsigned(It, CanOutlineWithPrevInstr, UnsignedVecForMBB,
378 case InstrType::Invisible:
382 AddedIllegalLastTime =
false;
388 LLVM_DEBUG(
dbgs() <<
"HaveLegalRange = " << HaveLegalRange <<
"\n");
392 if (HaveLegalRange) {
397 mapToIllegalUnsigned(It, CanOutlineWithPrevInstr, UnsignedVecForMBB,
409 "DenseMapInfo<unsigned>'s empty key isn't -1!");
411 "DenseMapInfo<unsigned>'s tombstone key isn't -2!");
432 bool OutlineFromLinkOnceODRs =
false;
435 unsigned OutlineRepeatedNum = 0;
441 bool RunOnAllFunctions =
true;
449 std::unique_ptr<OutlinedHashTree> LocalHashTree;
476 void emitNotOutliningCheaperRemark(
477 unsigned StringLen, std::vector<Candidate> &CandidatesForRepeatedSeq,
497 findCandidates(InstructionMapper &Mapper,
498 std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList);
506 void findGlobalCandidates(
507 InstructionMapper &Mapper,
508 std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList);
518 std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList,
519 InstructionMapper &Mapper,
unsigned &OutlinedFunctionNum);
523 InstructionMapper &Mapper,
529 void computeAndPublishHashSequence(
MachineFunction &MF,
unsigned CandSize);
532 void initializeOutlinerMode(
const Module &M);
535 void emitOutlinedHashTree(
Module &M);
542 bool doOutline(
Module &M,
unsigned &OutlinedFunctionNum);
556 void populateMapper(InstructionMapper &Mapper,
Module &M);
562 void initSizeRemarkInfo(
const Module &M,
568 emitInstrCountChangedRemark(
const Module &M,
573char MachineOutliner::ID = 0;
577 MachineOutliner *OL =
new MachineOutliner();
578 OL->RunOnAllFunctions = RunOnAllFunctions;
587void MachineOutliner::emitNotOutliningCheaperRemark(
594 Candidate &
C = CandidatesForRepeatedSeq.front();
598 C.front().getDebugLoc(),
C.getMBB());
599 R <<
"Did not outline " <<
NV(
"Length", StringLen) <<
" instructions"
600 <<
" from " <<
NV(
"NumOccurrences", CandidatesForRepeatedSeq.size())
602 <<
" Bytes from outlining all occurrences ("
603 <<
NV(
"OutliningCost", OF.getOutliningCost()) <<
")"
604 <<
" >= Unoutlined instruction bytes ("
605 <<
NV(
"NotOutliningCost", OF.getNotOutlinedCost()) <<
")"
606 <<
" (Also found at: ";
609 for (
unsigned i = 1, e = CandidatesForRepeatedSeq.size(); i < e; i++) {
611 CandidatesForRepeatedSeq[i].front().
getDebugLoc());
626 R <<
"Saved " <<
NV(
"OutliningBenefit", OF.
getBenefit()) <<
" bytes by "
627 <<
"outlining " <<
NV(
"Length", OF.
getNumInstrs()) <<
" instructions "
633 for (
size_t i = 0, e = OF.
Candidates.size(); i < e; i++) {
659 auto &InstrList = Mapper.InstrList;
660 auto &UnsignedVec = Mapper.UnsignedVec;
669 auto getValidInstr = [&](
unsigned Index) ->
const MachineInstr * {
670 if (UnsignedVec[Index] >= Mapper.LegalInstrNumber)
672 return &(*InstrList[Index]);
675 auto getStableHashAndFollow =
680 auto It = CurrNode->Successors.find(StableHash);
681 return (It == CurrNode->Successors.end()) ? nullptr : It->second.get();
684 for (
unsigned I = 0;
I <
Size; ++
I) {
686 if (!
MI ||
MI->isDebugInstr())
688 const HashNode *CurrNode = getStableHashAndFollow(*
MI, RootNode);
692 for (
unsigned J =
I + 1; J <
Size; ++J) {
699 CurrNode = getStableHashAndFollow(*MJ, CurrNode);
709 return MatchedEntries;
712void MachineOutliner::findGlobalCandidates(
713 InstructionMapper &Mapper,
714 std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList) {
715 FunctionList.
clear();
717 auto &MBBFlagsMap = Mapper.MBBFlagsMap;
719 std::vector<Candidate> CandidatesForRepeatedSeq;
721 CandidatesForRepeatedSeq.
clear();
724 auto Length = ME.EndIdx - ME.StartIdx + 1;
726 CandidatesForRepeatedSeq.emplace_back(ME.StartIdx,
Length, StartIt, EndIt,
731 unsigned MinRepeats = 1;
732 std::optional<std::unique_ptr<OutlinedFunction>> OF =
733 TII->getOutliningCandidateInfo(*MMI, CandidatesForRepeatedSeq,
735 if (!OF.has_value() || OF.value()->Candidates.empty())
738 assert(OF.value()->Candidates.size() == MinRepeats);
739 FunctionList.emplace_back(std::make_unique<GlobalOutlinedFunction>(
740 std::move(OF.value()), ME.Count));
744void MachineOutliner::findCandidates(
745 InstructionMapper &Mapper,
746 std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList) {
747 FunctionList.clear();
752 std::vector<Candidate> CandidatesForRepeatedSeq;
753 LLVM_DEBUG(
dbgs() <<
"*** Discarding overlapping candidates *** \n");
755 dbgs() <<
"Searching for overlaps in all repeated sequences...\n");
757 CandidatesForRepeatedSeq.clear();
758 unsigned StringLen = RS.Length;
762 unsigned NumDiscarded = 0;
763 unsigned NumKept = 0;
768 for (
const unsigned &StartIdx : RS.StartIndices) {
790 unsigned EndIdx = StartIdx + StringLen - 1;
791 if (!CandidatesForRepeatedSeq.empty() &&
792 StartIdx <= CandidatesForRepeatedSeq.back().getEndIdx()) {
795 LLVM_DEBUG(
dbgs() <<
" .. DISCARD candidate @ [" << StartIdx <<
", "
796 << EndIdx <<
"]; overlaps with candidate @ ["
797 << CandidatesForRepeatedSeq.back().getStartIdx()
798 <<
", " << CandidatesForRepeatedSeq.back().getEndIdx()
812 CandidatesForRepeatedSeq.emplace_back(StartIdx, StringLen, StartIt, EndIt,
814 Mapper.MBBFlagsMap[
MBB]);
821 unsigned MinRepeats = 2;
826 if (CandidatesForRepeatedSeq.size() < MinRepeats)
832 CandidatesForRepeatedSeq[0].getMF()->getSubtarget().getInstrInfo();
834 std::optional<std::unique_ptr<OutlinedFunction>> OF =
835 TII->getOutliningCandidateInfo(*MMI, CandidatesForRepeatedSeq,
840 if (!OF.has_value() || OF.value()->Candidates.size() < MinRepeats)
845 emitNotOutliningCheaperRemark(StringLen, CandidatesForRepeatedSeq,
850 FunctionList.emplace_back(std::move(OF.value()));
854void MachineOutliner::computeAndPublishHashSequence(
MachineFunction &MF,
858 for (
auto &
MBB : MF) {
859 for (
auto &NewMI :
MBB) {
862 OutlinedHashSequence.
clear();
873 MF.getName().str() +
".content." + std::to_string(CombinedHash);
874 MF.getFunction().setName(NewName);
878 if (OutlinerMode == CGDataMode::Write) {
879 StableHashAttempts++;
880 if (!OutlinedHashSequence.
empty())
881 LocalHashTree->insert({OutlinedHashSequence, CandSize});
893 std::string FunctionName =
"OUTLINED_FUNCTION_";
894 if (OutlineRepeatedNum > 0)
895 FunctionName += std::to_string(OutlineRepeatedNum + 1) +
"_";
896 FunctionName += std::to_string(
Name);
902 Function::ExternalLinkage, FunctionName, M);
907 F->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
911 F->addFnAttr(Attribute::OptimizeForSize);
912 F->addFnAttr(Attribute::MinSize);
924 return std::max(K, C.getMF()->getFunction().getUWTableKind());
926 F->setUWTableKind(UW);
930 Builder.CreateRetVoid();
941 const std::vector<MCCFIInstruction> &Instrs =
943 for (
auto &
MI : FirstCand) {
944 if (
MI.isDebugInstr())
949 if (
MI.isCFIInstruction()) {
950 unsigned CFIIndex =
MI.getOperand(0).getCFIIndex();
961 if (OutlinerMode != CGDataMode::None)
962 computeAndPublishHashSequence(MF, OF.
Candidates.size());
968 MF.
getProperties().
set(MachineFunctionProperties::Property::TracksLiveness);
979 CandLiveIns.addLiveOuts(OutlineBB);
982 CandLiveIns.stepBackward(
MI);
991 TII.buildOutlinedFrame(
MBB, MF, OF);
999 DIFile *Unit = SP->getFile();
1007 Unit ,
F->getName(),
StringRef(Dummy), Unit ,
1009 DB.createSubroutineType(
DB.getOrCreateTypeArray({})),
1011 DINode::DIFlags::FlagArtificial ,
1013 DISubprogram::SPFlagDefinition | DISubprogram::SPFlagOptimized);
1016 DB.finalizeSubprogram(OutlinedSP);
1019 F->setSubprogram(OutlinedSP);
1027bool MachineOutliner::outline(
1028 Module &M, std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList,
1029 InstructionMapper &Mapper,
unsigned &OutlinedFunctionNum) {
1031 LLVM_DEBUG(
dbgs() <<
"NUMBER OF POTENTIAL FUNCTIONS: " << FunctionList.size()
1033 bool OutlinedSomething =
false;
1037 stable_sort(FunctionList, [](
const std::unique_ptr<OutlinedFunction> &LHS,
1038 const std::unique_ptr<OutlinedFunction> &RHS) {
1039 return LHS->getNotOutlinedCost() *
RHS->getOutliningCost() >
1040 RHS->getNotOutlinedCost() *
LHS->getOutliningCost();
1045 auto *UnsignedVecBegin = Mapper.UnsignedVec.begin();
1047 for (
auto &OF : FunctionList) {
1049 auto NumCandidatesBefore = OF->
Candidates.size();
1054 return std::any_of(UnsignedVecBegin + C.getStartIdx(),
1055 UnsignedVecBegin + C.getEndIdx() + 1, [](unsigned I) {
1056 return I == static_cast<unsigned>(-1);
1061 auto NumCandidatesAfter = OF->
Candidates.size();
1062 LLVM_DEBUG(
dbgs() <<
"PRUNED: " << NumCandidatesBefore - NumCandidatesAfter
1063 <<
"/" << NumCandidatesBefore <<
" candidates\n");
1081 emitOutlinedFunctionRemark(*OF);
1083 OutlinedFunctionNum++;
1099 auto MBBBeingOutlinedFromName =
1105 << MFBeingOutlinedFromName <<
":"
1106 << MBBBeingOutlinedFromName <<
"\n");
1115 MachineFunctionProperties::Property::TracksLiveness)) {
1129 Iter !=
Last; Iter++) {
1139 DefRegs.
insert(MOP.getReg());
1140 if (UseRegs.
count(MOP.getReg()) &&
1141 !InstrUseRegs.
count(MOP.getReg()))
1144 UseRegs.
erase(MOP.getReg());
1145 }
else if (!MOP.isUndef()) {
1148 UseRegs.
insert(MOP.getReg());
1149 InstrUseRegs.
insert(MOP.getReg());
1152 if (
MI->isCandidateForCallSiteEntry())
1153 MI->getMF()->eraseCallSiteInfo(
MI);
1172 MBB.
erase(std::next(StartIt), std::next(EndIt));
1175 for (
unsigned &
I :
make_range(UnsignedVecBegin +
C.getStartIdx(),
1176 UnsignedVecBegin +
C.getEndIdx() + 1))
1177 I =
static_cast<unsigned>(-1);
1178 OutlinedSomething =
true;
1185 LLVM_DEBUG(
dbgs() <<
"OutlinedSomething = " << OutlinedSomething <<
"\n");
1186 return OutlinedSomething;
1189void MachineOutliner::populateMapper(InstructionMapper &Mapper,
Module &M) {
1196 if (
F.hasFnAttribute(
"nooutline")) {
1197 LLVM_DEBUG(
dbgs() <<
"SKIP: Function has nooutline attribute\n");
1208 LLVM_DEBUG(
dbgs() <<
"SKIP: Function does not have a MachineFunction\n");
1213 if (!RunOnAllFunctions && !
TII->shouldOutlineFromFunctionByDefault(*MF)) {
1214 LLVM_DEBUG(
dbgs() <<
"SKIP: Target does not want to outline from "
1215 "function by default\n");
1221 if (!
TII->isFunctionSafeToOutlineFrom(*MF, OutlineFromLinkOnceODRs)) {
1223 <<
": unsafe to outline from\n");
1230 const unsigned MinMBBSize = 2;
1240 if (
MBB.
size() < MinMBBSize) {
1241 LLVM_DEBUG(
dbgs() <<
" SKIP: MBB size less than minimum size of "
1242 << MinMBBSize <<
"\n");
1254 Mapper.convertToUnsignedVec(
MBB, *
TII);
1258 UnsignedVecSize = Mapper.UnsignedVec.size();
1261void MachineOutliner::initSizeRemarkInfo(
1276void MachineOutliner::emitInstrCountChangedRemark(
1289 std::string Fname = std::string(
F.getName());
1291 unsigned FnCountBefore = 0;
1294 auto It = FunctionToInstrCount.
find(Fname);
1298 if (It != FunctionToInstrCount.
end())
1299 FnCountBefore = It->second;
1302 int64_t FnDelta =
static_cast<int64_t
>(FnCountAfter) -
1303 static_cast<int64_t
>(FnCountBefore);
1314 <<
": MI instruction count changed from "
1327void MachineOutliner::initializeOutlinerMode(
const Module &M) {
1331 if (
auto *IndexWrapperPass =
1332 getAnalysisIfAvailable<ImmutableModuleSummaryIndexWrapperPass>()) {
1333 auto *TheIndex = IndexWrapperPass->getIndex();
1336 if (TheIndex && !TheIndex->hasExportedFunctions(M))
1345 OutlinerMode = CGDataMode::Write;
1347 LocalHashTree = std::make_unique<OutlinedHashTree>();
1350 OutlinerMode = CGDataMode::Read;
1353void MachineOutliner::emitOutlinedHashTree(
Module &M) {
1355 if (!LocalHashTree->empty()) {
1357 dbgs() <<
"Emit outlined hash tree. Size: " << LocalHashTree->size()
1367 std::unique_ptr<MemoryBuffer> Buffer =
1377bool MachineOutliner::runOnModule(
Module &M) {
1384 initializeOutlinerMode(M);
1386 MMI = &getAnalysis<MachineModuleInfoWrapperPass>().getMMI();
1389 unsigned OutlinedFunctionNum = 0;
1391 OutlineRepeatedNum = 0;
1392 if (!doOutline(M, OutlinedFunctionNum))
1396 OutlinedFunctionNum = 0;
1397 OutlineRepeatedNum++;
1398 if (!doOutline(M, OutlinedFunctionNum)) {
1400 dbgs() <<
"Did not outline on iteration " <<
I + 2 <<
" out of "
1407 if (OutlinerMode == CGDataMode::Write)
1408 emitOutlinedHashTree(M);
1413bool MachineOutliner::doOutline(
Module &M,
unsigned &OutlinedFunctionNum) {
1420 dbgs() <<
"Machine Outliner: Running on ";
1421 if (RunOnAllFunctions)
1422 dbgs() <<
"all functions";
1424 dbgs() <<
"target-default functions";
1431 InstructionMapper Mapper(*MMI);
1434 populateMapper(Mapper, M);
1435 std::vector<std::unique_ptr<OutlinedFunction>> FunctionList;
1438 if (OutlinerMode == CGDataMode::Read)
1439 findGlobalCandidates(Mapper, FunctionList);
1441 findCandidates(Mapper, FunctionList);
1452 bool ShouldEmitSizeRemarks =
M.shouldEmitInstrCountChangedRemark();
1454 if (ShouldEmitSizeRemarks)
1455 initSizeRemarkInfo(M, FunctionToInstrCount);
1458 bool OutlinedSomething =
1459 outline(M, FunctionList, Mapper, OutlinedFunctionNum);
1464 if (ShouldEmitSizeRemarks && OutlinedSomething)
1465 emitInstrCountChangedRemark(M, FunctionToInstrCount);
1468 if (!OutlinedSomething)
1469 dbgs() <<
"Stopped outlining at iteration " << OutlineRepeatedNum
1470 <<
" because no changes were found.\n";
1473 return OutlinedSomething;
unsigned const MachineRegisterInfo * MRI
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....
unsigned const TargetRegisterInfo * TRI
This is the interface to build a ModuleSummaryIndex for a module.
static Expected< Function * > createOutlinedFunction(OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder, StringRef FuncName, SmallVectorImpl< Value * > &Inputs, OpenMPIRBuilder::TargetBodyGenCallbackTy &CBFunc, OpenMPIRBuilder::TargetGenArgAccessorsCallbackTy &ArgAccessorFuncCB)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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)
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.
DISubprogram * getSubprogram() const
Get the subprogram for this scope.
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,...
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.
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
StringRef getName() const
Return the name of the corresponding LLVM basic block, or an empty string.
MachineFunctionProperties & set(Property P)
bool hasProperty(Property P) const
MachineFunctionProperties & reset(Property P)
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
void dropMemRefs(MachineFunction &MF)
Clear this MachineInstr's memory reference descriptor list.
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.
MachineFunction & getOrCreateMachineFunction(Function &F)
Returns the MachineFunction constructed for the IR function F.
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,...
void freezeReservedRegs()
freezeReservedRegs - Called by the register allocator to freeze the set of reserved registers before ...
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 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.
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.
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 Type * getVoidTy(LLVMContext &C)
A raw_ostream that writes to an std::string.
A raw_ostream that writes to an SmallVector or SmallString.
@ C
The default llvm calling convention, compatible with C.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
SmallVector< 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.
auto reverse(ContainerTy &&C)
void sort(IteratorTy Start, IteratorTy End)
stable_hash stableHashValue(const MachineOperand &MO)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
void initializeMachineOutlinerPass(PassRegistry &)
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)
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.
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.
virtual unsigned getOccurrenceCount() const
Return the number of candidates for this OutlinedFunction.
unsigned getBenefit() const
Return the number of instructions that would be saved by outlining this function.
MachineFunction * MF
The actual outlined function created.
unsigned getNumInstrs() const
Return the number of instructions in this sequence.
std::vector< Candidate > Candidates