Go to the documentation of this file.
98 "bbsections-cold-text-prefix",
99 cl::desc(
"The text prefix to use for cold basic block clusters"),
103 "bbsections-detect-source-drift",
104 cl::desc(
"This checks if there is a fdo instr. profile hash "
105 "mismatch for this function"),
111 struct BBClusterInfo {
117 unsigned PositionInCluster;
135 ProgramBBClusterInfoMapTy ProgramBBClusterInfo;
151 return "Basic Block Sections Analysis";
157 bool doInitialization(
Module &M)
override;
168 "Prepares for basic block sections, by splitting functions "
169 "into clusters of basic blocks.",
174 static
void updateBranches(
210 const ProgramBBClusterInfoMapTy &ProgramBBClusterInfo,
214 auto R = FuncAliasMap.
find(FuncName);
215 StringRef AliasName = R == FuncAliasMap.
end() ? FuncName : R->second;
218 auto P = ProgramBBClusterInfo.find(AliasName);
219 if (
P == ProgramBBClusterInfo.end())
222 if (
P->second.empty()) {
230 for (
auto bbClusterInfo :
P->second) {
234 V[bbClusterInfo.MBBNumber] = bbClusterInfo;
257 for (
auto &
MBB : MF) {
263 FuncBBClusterInfo.empty()) {
268 }
else if (FuncBBClusterInfo[
MBB.
getNumber()].hasValue())
281 EHPadsSectionID = EHPadsSectionID.
hasValue()
305 MF.assignBeginEndSections();
318 for (
auto &
MBB : MF) {
321 while (!
MI->isEHLabel())
323 MCInst Nop = MF.getSubtarget().getInstrInfo()->getNop();
325 MF.getSubtarget().getInstrInfo()->
get(
Nop.getOpcode()));
341 const char MetadataName[] =
"instr_prof_hash_mismatch";
344 MDTuple *Tuple = cast<MDTuple>(Existing);
346 if (cast<MDString>(
N.get())->getString() == MetadataName)
356 "BB Sections not enabled!");
379 std::vector<Optional<BBClusterInfo>> FuncBBClusterInfo;
401 if (
LHS == EntryBBSectionID ||
RHS == EntryBBSectionID)
402 return LHS == EntryBBSectionID;
412 auto XSectionID =
X.getSectionID();
413 auto YSectionID =
Y.getSectionID();
414 if (XSectionID != YSectionID)
415 return MBBSectionOrder(XSectionID, YSectionID);
419 return FuncBBClusterInfo[
X.getNumber()]->PositionInCluster <
420 FuncBBClusterInfo[
Y.getNumber()]->PositionInCluster;
421 return X.getNumber() <
Y.getNumber();
443 ProgramBBClusterInfoMapTy &ProgramBBClusterInfo,
448 auto invalidProfileError = [&](
auto Message) {
449 return make_error<StringError>(
455 auto FI = ProgramBBClusterInfo.end();
458 unsigned CurrentCluster = 0;
460 unsigned CurrentPosition = 0;
471 if (!
S.consume_front(
"!") ||
S.empty())
474 if (
S.consume_front(
"!")) {
475 if (FI == ProgramBBClusterInfo.end())
476 return invalidProfileError(
477 "Cluster list does not follow a function name specifier.");
479 S.split(BBIndexes,
' ');
482 for (
auto BBIndexStr : BBIndexes) {
483 unsigned long long BBIndex;
485 return invalidProfileError(
Twine(
"Unsigned integer expected: '") +
487 if (!FuncBBIDs.
insert(BBIndex).second)
488 return invalidProfileError(
Twine(
"Duplicate basic block id found '") +
490 if (!BBIndex && CurrentPosition)
491 return invalidProfileError(
"Entry BB (0) does not begin a cluster.");
493 FI->second.emplace_back(BBClusterInfo{
494 ((unsigned)BBIndex), CurrentCluster, CurrentPosition++});
502 S.split(Aliases,
'/');
503 for (
size_t i = 1;
i < Aliases.size(); ++
i)
508 FI = ProgramBBClusterInfo.try_emplace(Aliases.front()).first;
516 bool BasicBlockSections::doInitialization(
Module &M) {
524 void BasicBlockSections::getAnalysisUsage(
AnalysisUsage &AU)
const {
531 return new BasicBlockSections(Buf);
This is an optimization pass for GlobalISel generic memory operations.
void sortBasicBlocksAndUpdateBranches(MachineFunction &MF, MachineBasicBlockComparator MBBCmp)
static const unsigned Nop
Instruction opcodes emitted via means other than CodeGen.
A forward iterator which reads text lines from a buffer.
cl::opt< std::string > BBSectionsColdTextPrefix
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
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....
static bool getBBClusterInfoForFunction(const MachineFunction &MF, const StringMap< StringRef > FuncAliasMap, const ProgramBBClusterInfoMapTy &ProgramBBClusterInfo, std::vector< Optional< BBClusterInfo >> &V)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
static ErrorSuccess success()
Create a success value.
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
static bool avoidZeroOffsetLandingPad(MachineFunction &MF)
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
static Error getBBClusterInfo(const MemoryBuffer *MBuf, ProgramBBClusterInfoMapTy &ProgramBBClusterInfo, StringMap< StringRef > &FuncAliasMap)
Instances of this class represent a single low-level machine instruction.
iterator find(StringRef Key)
This interface provides simple read-only access to a block of memory, and provides simple methods for...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
op_range operands() const
bool isBeginSection() const
Returns true if this block begins any section.
constexpr bool hasValue() const
void setSectionID(MBBSectionID V)
Sets the section ID for this basic block.
const MachineBasicBlock & front() const
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
TargetInstrInfo - Interface to description of machine instruction set.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
bool getAsUnsignedInteger(StringRef Str, unsigned Radix, unsigned long long &Result)
Helper functions for StringRef::getAsInteger.
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
Represent the analysis usage information of a pass.
const HexagonInstrInfo * TII
INITIALIZE_PASS(BasicBlockSections, "bbsections-prepare", "Prepares for basic block sections, by splitting functions " "into clusters of basic blocks.", false, false) static void updateBranches(MachineFunction &MF
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
virtual StringRef getBufferIdentifier() const
Return an identifier for this buffer, typically the filename it was read from.
An efficient, type-erasing, non-owning reference to a callable.
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
initializer< Ty > init(const Ty &Val)
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
const static MBBSectionID ExceptionSectionID
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
constexpr const T & getValue() const &
A Module instance is used to store all the information related to an LLVM module.
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
SmallVector< MachineOperand, 4 > Cond
bool isEHPad() const
Returns true if the block is a landing pad.
StringRef - Represent a constant reference to a string, i.e.
DebugLoc findBranchDebugLoc()
Find and return the merged DebugLoc of the branch instructions of the block.
self_iterator getIterator()
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
bool hasBBSections() const
Returns true if this function has basic block sections enabled.
void initializeBasicBlockSectionsPass(PassRegistry &)
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
MBBSectionID getSectionID() const
Returns the section ID of this basic block.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static bool hasInstrProfHashMismatch(MachineFunction &MF)
Function & getFunction()
Return the LLVM function that this machine code represents.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
void setPreservesAll()
Set by analyses that do not transform their input at all.
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
bool isEndSection() const
Returns true if this block ends any section.
const static MBBSectionID ColdSectionID
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)
MachineFunctionPass * createBasicBlockSectionsPass(const MemoryBuffer *Buf)
createBasicBlockSections Pass - This pass assigns sections to machine basic blocks and is enabled wit...
Lightweight error class with error context and mandatory checking.
bool is_at_eof() const
Return true if we've reached EOF or are an "end" iterator.
MachineBasicBlock * getFallThrough()
Return the fallthrough block if the block can implicitly transfer control to the block after it by fa...
int64_t line_number() const
Return the current line number. May return any number at EOF.
const SmallVector< MachineBasicBlock *, 4 > & PreLayoutFallThroughs
static void assignSections(MachineFunction &MF, const std::vector< Optional< BBClusterInfo >> &FuncBBClusterInfo)
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
void updateTerminator(MachineBasicBlock *PreviousLayoutSuccessor)
Update the terminator instructions in block to account for changes to block layout which may have bee...
void setBBSectionsType(BasicBlockSection V)
void RenumberBlocks(MachineBasicBlock *MBBFrom=nullptr)
RenumberBlocks - This discards all of the MachineBasicBlock numbers and recomputes them.
std::pair< iterator, bool > try_emplace(StringRef Key, ArgsTy &&... Args)
Emplace a new element for the specified key into the map if the key isn't already in the map.
llvm::BasicBlockSection getBBSectionsType() const
If basic blocks should be emitted into their own section, corresponding to -fbasic-block-sections.