58 auto TII = MF.getSubtarget().getInstrInfo();
65 for (
auto &
I : OrigBB.
instrs()) {
67 if (
I.isBundledWithPred())
69 TII->duplicate(*CloneBB, CloneBB->
end(),
I);
94 for (
size_t I = 0;
I < ClonePath.
size(); ++
I) {
95 unsigned BBID = ClonePath[
I];
106 <<
"block #" << BBID <<
" is not a successor of block #"
112 for (
auto &
MI : *PathBB) {
116 if (
MI.isNotDuplicable() && !
MI.isCFIInstruction()) {
119 <<
" has non-duplicable instructions in function " << MF.
getName()
124 if (PathBB->isMachineBlockAddressTaken()) {
129 <<
" has its machine block address taken in function "
133 if (PathBB->isInlineAsmBrIndirectTarget()) {
137 <<
" is a branch target of an 'asm goto' in function "
143 if (
I != ClonePath.
size() - 1 && !PathBB->empty() &&
144 PathBB->back().isIndirectBranch()) {
147 <<
" has indirect branch and appears as the non-tail block of a "
161 if (ClonePaths.empty())
163 bool AnyPathsCloned =
false;
167 BBIDToBlock.
try_emplace(BB.getBBID()->BaseID, &BB);
170 auto TII = MF.getSubtarget().getInstrInfo();
171 for (
const auto &ClonePath : ClonePaths) {
172 if (!IsValidCloning(MF, BBIDToBlock, ClonePath)) {
175 for (
unsigned BBID : ClonePath)
176 ++NClonesForBBID[BBID];
180 for (
unsigned BBID : ClonePath) {
182 if (PrevBB ==
nullptr) {
187 TII->insertUnconditionalBranch(*OrigBB, FT,
194 CloneMachineBasicBlock(*OrigBB, ++NClonesForBBID[BBID]);
202 for (
auto &LiveIn : OrigBB->
liveins())
207 AnyPathsCloned =
true;
209 return AnyPathsCloned;
216 BasicBlockSectionsProfileReaderWrapperPass *BBSectionsProfileReader =
nullptr;
218 BasicBlockPathCloning() : MachineFunctionPass(ID) {}
220 StringRef getPassName()
const override {
return "Basic Block Path Cloning"; }
222 void getAnalysisUsage(AnalysisUsage &AU)
const override;
231char BasicBlockPathCloning::ID = 0;
233 BasicBlockPathCloning,
"bb-path-cloning",
234 "Applies path clonings for the -basic-block-sections=list option",
false,
238 BasicBlockPathCloning,
"bb-path-cloning",
239 "Applies path clonings for the -basic-block-sections=list option",
false,
244 "BB Sections list not enabled!");
248 return ApplyCloning(MF,
249 getAnalysis<BasicBlockSectionsProfileReaderWrapperPass>()
250 .getClonePathsForFunction(MF.getName()));
253void BasicBlockPathCloning::getAnalysisUsage(
AnalysisUsage &AU)
const {
254 AU.
addRequired<BasicBlockSectionsProfileReaderWrapperPass>();
260 return new BasicBlockPathCloning();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const HexagonInstrInfo * TII
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This file defines the SmallVector class.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
ValueT & at(const_arg_type_t< KeyT > Val)
Return the entry for the specified key, or abort if no such entry exists.
ValueT lookup(const_arg_type_t< KeyT > Val) const
Return the entry for the specified key, or a default constructed value if no such entry exists.
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
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...
iterator_range< livein_iterator > liveins() const
void push_back(MachineInstr *MI)
std::optional< UniqueBBID > getBBID() const
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
succ_iterator succ_begin()
LLVM_ABI void copySuccessor(const MachineBasicBlock *Orig, succ_iterator I)
Copy a successor (and any probability info) from original block to this block's.
LLVM_ABI void ReplaceUsesOfBlockWith(MachineBasicBlock *Old, MachineBasicBlock *New)
Given a machine basic block that branched to 'Old', change the code and CFG so that it branches to 'N...
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
LLVM_ABI DebugLoc findBranchDebugLoc()
Find and return the merged DebugLoc of the branch instructions of the block.
LLVM_ABI bool isSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a successor of this block.
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.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
static LLVM_ABI raw_ostream & warning()
Convenience method for printing "warning: " to stderr.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI bool hasInstrProfHashMismatch(MachineFunction &MF)
This checks if the source of this function has drifted since this binary was profiled previously.
LLVM_ABI MachineFunctionPass * createBasicBlockPathCloningPass()