93 "bbsections-cold-text-prefix",
94 cl::desc(
"The text prefix to use for cold basic block clusters"),
98 "bbsections-detect-source-drift",
99 cl::desc(
"This checks if there is a fdo instr. profile hash "
100 "mismatch for this function"),
116 return "Basic Block Sections Analysis";
132char BasicBlockSections::ID = 0;
134 BasicBlockSections,
"bbsections-prepare",
135 "Prepares for basic block sections, by splitting functions "
136 "into clusters of basic blocks.",
151 for (
auto &
MBB : MF) {
195 std::optional<MBBSectionID> EHPadsSectionID;
197 for (
auto &
MBB : MF) {
203 FuncClusterInfo.
empty()) {
211 if (
I != FuncClusterInfo.
end()) {
217 if (
TII.isMBBSafeToSplitToCold(
MBB)) {
253 "Entry block should not be displaced by basic block sections");
269 for (
auto &
MBB : MF) {
272 while (!
MI->isEHLabel())
283 const char MetadataName[] =
"instr_prof_hash_mismatch";
286 MDTuple *Tuple = cast<MDTuple>(Existing);
288 if (
N.equalsStr(MetadataName))
299 if (BBSectionsType == BasicBlockSection::None)
308 if (BBSectionsType == BasicBlockSection::List &&
316 if (BBSectionsType == BasicBlockSection::List) {
318 getAnalysis<BasicBlockSectionsProfileReaderWrapperPass>()
319 .getClusterInfoForFunction(MF.
getName());
343 if (LHS == EntryBBSectionID || RHS == EntryBBSectionID)
344 return LHS == EntryBBSectionID;
356 auto XSectionID =
X.getSectionID();
357 auto YSectionID =
Y.getSectionID();
358 if (XSectionID != YSectionID)
359 return MBBSectionOrder(XSectionID, YSectionID);
361 if (&
X == &EntryBB || &
Y == &EntryBB)
362 return &
X == &EntryBB;
365 if (XSectionID.Type == MBBSectionID::SectionType::Default)
366 return FuncClusterInfo.
lookup(*
X.getBBID()).PositionInCluster <
367 FuncClusterInfo.
lookup(*
Y.getBBID()).PositionInCluster;
368 return X.getNumber() <
Y.getNumber();
389 auto R1 = handleBBSections(MF);
391 auto R2 = handleBBAddrMap(MF);
394 if (
auto *WP = getAnalysisIfAvailable<MachineDominatorTreeWrapperPass>())
395 WP->getDomTree().updateBlockNumbers();
396 if (
auto *WP = getAnalysisIfAvailable<MachinePostDominatorTreeWrapperPass>())
397 WP->getPostDomTree().updateBlockNumbers();
402void BasicBlockSections::getAnalysisUsage(
AnalysisUsage &AU)
const {
411 return new BasicBlockSections();
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Lower uses of LDS variables from non kernel functions
static void assignSections(MachineFunction &MF, const DenseMap< UniqueBBID, BBClusterInfo > &FuncClusterInfo)
static cl::opt< bool > BBSectionsDetectSourceDrift("bbsections-detect-source-drift", cl::desc("This checks if there is a fdo instr. profile hash " "mismatch for this function"), cl::init(true), cl::Hidden)
bbsections Prepares for basic block by splitting functions into clusters of basic blocks
bbsections Prepares for basic block by splitting functions into clusters of basic static false void updateBranches(MachineFunction &MF, const SmallVector< MachineBasicBlock * > &PreLayoutFallThroughs)
bbsections Prepares for basic block sections
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
const HexagonInstrInfo * TII
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
const SmallVectorImpl< MachineOperand > & Cond
This file defines the SmallVector class.
unify loop Fixup each natural loop to have a single exit block
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()
void setPreservesAll()
Set by analyses that do not transform their input at all.
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...
iterator find(const_arg_type_t< KeyT > Val)
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify) const override
Analyze the branching code at the end of MBB, returning true if it cannot be understood (e....
ArrayRef< MDOperand > operands() const
bool isEHPad() const
Returns true if the block is a landing pad.
LLVM_ABI MachineBasicBlock * getFallThrough(bool JumpToFallThrough=true)
Return the fallthrough block if the block can implicitly transfer control to the block after it by fa...
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
std::optional< UniqueBBID > getBBID() const
LLVM_ABI void updateTerminator(MachineBasicBlock *PreviousLayoutSuccessor)
Update the terminator instructions in block to account for changes to block layout which may have bee...
MBBSectionID getSectionID() const
Returns the section ID of this basic block.
void setSectionID(MBBSectionID V)
Sets the section ID for this basic block.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
bool isBeginSection() const
Returns true if this block begins any section.
LLVM_ABI DebugLoc findBranchDebugLoc()
Find and return the merged DebugLoc of the branch instructions of the block.
bool isEndSection() const
Returns true if this block ends any section.
Analysis pass which computes a MachineDominatorTree.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
void setBBSectionsType(BasicBlockSection V)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
bool hasBBSections() const
Returns true if this function has basic block sections enabled.
Function & getFunction()
Return the LLVM function that this machine code represents.
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
void RenumberBlocks(MachineBasicBlock *MBBFrom=nullptr)
RenumberBlocks - This discards all of the MachineBasicBlock numbers and recomputes them.
const MachineBasicBlock & front() const
void assignBeginEndSections()
Assign IsBeginSection IsEndSection fields for basic blocks in this function.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
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.
TargetInstrInfo - Interface to description of machine instruction set.
virtual void insertNoop(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const
Insert a noop into the instruction stream at the specified point.
llvm::BasicBlockSection getBBSectionsType() const
If basic blocks should be emitted into their own section, corresponding to -fbasic-block-sections.
virtual const TargetInstrInfo * getInstrInfo() const
An efficient, type-erasing, non-owning reference to a callable.
self_iterator getIterator()
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI MachineFunctionPass * createBasicBlockSectionsPass()
createBasicBlockSections Pass - This pass assigns sections to machine basic blocks and is enabled wit...
LLVM_ABI void initializeBasicBlockSectionsPass(PassRegistry &)
bool hasInstrProfHashMismatch(MachineFunction &MF)
This checks if the source of this function has drifted since this binary was profiled previously.
SmallPtrSet< SUnit *, 8 > ClusterInfo
Keep record of which SUnit are in the same cluster group.
void avoidZeroOffsetLandingPad(MachineFunction &MF)
cl::opt< std::string > BBSectionsColdTextPrefix
void sortBasicBlocksAndUpdateBranches(MachineFunction &MF, MachineBasicBlockComparator MBBCmp)
LLVM_ABI static const MBBSectionID ExceptionSectionID
LLVM_ABI static const MBBSectionID ColdSectionID