Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/CodeGen/MachineOutliner.cpp
Show First 20 Lines • Show All 840 Lines • ▼ Show 20 Lines | struct MachineOutliner : public ModulePass { | ||||
/// considered safe for outlining. | /// considered safe for outlining. | ||||
/// Set to true by default for compatibility with llc's -run-pass option. | /// Set to true by default for compatibility with llc's -run-pass option. | ||||
/// Set when the pass is constructed in TargetPassConfig. | /// Set when the pass is constructed in TargetPassConfig. | ||||
bool RunOnAllFunctions = true; | bool RunOnAllFunctions = true; | ||||
StringRef getPassName() const override { return "Machine Outliner"; } | StringRef getPassName() const override { return "Machine Outliner"; } | ||||
void getAnalysisUsage(AnalysisUsage &AU) const override { | void getAnalysisUsage(AnalysisUsage &AU) const override { | ||||
AU.addRequired<MachineModuleInfo>(); | AU.addRequired<MachineModuleInfoWrapperPass>(); | ||||
AU.addPreserved<MachineModuleInfo>(); | AU.addPreserved<MachineModuleInfoWrapperPass>(); | ||||
AU.setPreservesAll(); | AU.setPreservesAll(); | ||||
ModulePass::getAnalysisUsage(AU); | ModulePass::getAnalysisUsage(AU); | ||||
} | } | ||||
MachineOutliner() : ModulePass(ID) { | MachineOutliner() : ModulePass(ID) { | ||||
initializeMachineOutlinerPass(*PassRegistry::getPassRegistry()); | initializeMachineOutlinerPass(*PassRegistry::getPassRegistry()); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 264 Lines • ▼ Show 20 Lines | MachineOutliner::createOutlinedFunction(Module &M, OutlinedFunction &OF, | ||||
const Function &ParentFn = FirstCand.getMF()->getFunction(); | const Function &ParentFn = FirstCand.getMF()->getFunction(); | ||||
if (ParentFn.hasFnAttribute("target-features")) | if (ParentFn.hasFnAttribute("target-features")) | ||||
F->addFnAttr(ParentFn.getFnAttribute("target-features")); | F->addFnAttr(ParentFn.getFnAttribute("target-features")); | ||||
BasicBlock *EntryBB = BasicBlock::Create(C, "entry", F); | BasicBlock *EntryBB = BasicBlock::Create(C, "entry", F); | ||||
IRBuilder<> Builder(EntryBB); | IRBuilder<> Builder(EntryBB); | ||||
Builder.CreateRetVoid(); | Builder.CreateRetVoid(); | ||||
MachineModuleInfo &MMI = getAnalysis<MachineModuleInfo>(); | MachineModuleInfo &MMI = getAnalysis<MachineModuleInfoWrapperPass>().getMMI(); | ||||
MachineFunction &MF = MMI.getOrCreateMachineFunction(*F); | MachineFunction &MF = MMI.getOrCreateMachineFunction(*F); | ||||
MachineBasicBlock &MBB = *MF.CreateMachineBasicBlock(); | MachineBasicBlock &MBB = *MF.CreateMachineBasicBlock(); | ||||
const TargetSubtargetInfo &STI = MF.getSubtarget(); | const TargetSubtargetInfo &STI = MF.getSubtarget(); | ||||
const TargetInstrInfo &TII = *STI.getInstrInfo(); | const TargetInstrInfo &TII = *STI.getInstrInfo(); | ||||
// Insert the new function into the module. | // Insert the new function into the module. | ||||
MF.insert(MF.begin(), &MBB); | MF.insert(MF.begin(), &MBB); | ||||
▲ Show 20 Lines • Show All 276 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
bool MachineOutliner::runOnModule(Module &M) { | bool MachineOutliner::runOnModule(Module &M) { | ||||
// Check if there's anything in the module. If it's empty, then there's | // Check if there's anything in the module. If it's empty, then there's | ||||
// nothing to outline. | // nothing to outline. | ||||
if (M.empty()) | if (M.empty()) | ||||
return false; | return false; | ||||
MachineModuleInfo &MMI = getAnalysis<MachineModuleInfo>(); | MachineModuleInfo &MMI = getAnalysis<MachineModuleInfoWrapperPass>().getMMI(); | ||||
// If the user passed -enable-machine-outliner=always or | // If the user passed -enable-machine-outliner=always or | ||||
// -enable-machine-outliner, the pass will run on all functions in the module. | // -enable-machine-outliner, the pass will run on all functions in the module. | ||||
// Otherwise, if the target supports default outlining, it will run on all | // Otherwise, if the target supports default outlining, it will run on all | ||||
// functions deemed by the target to be worth outlining from by default. Tell | // functions deemed by the target to be worth outlining from by default. Tell | ||||
// the user how the outliner is running. | // the user how the outliner is running. | ||||
LLVM_DEBUG( | LLVM_DEBUG( | ||||
dbgs() << "Machine Outliner: Running on "; | dbgs() << "Machine Outliner: Running on "; | ||||
▲ Show 20 Lines • Show All 44 Lines • Show Last 20 Lines |