1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 19:52:54 +01:00

[MachineOutliner][NFC] Move debug info emission to createOutlinedFunction

When you create an outlined function, you know everything you need to know
to decide if debug info should be created. If we emit debug info in
createOutlinedFunction, then we don't need to keep track of every IR function
we create.

llvm-svn: 342677
This commit is contained in:
Jessica Paquette 2018-09-20 18:53:53 +00:00
parent 6c1297ecd0
commit 8852ffb12f

View File

@ -703,9 +703,6 @@ struct MachineOutliner : public ModulePass {
/// Set when the pass is constructed in TargetPassConfig.
bool RunOnAllFunctions = true;
// Collection of IR functions created by the outliner.
std::vector<Function *> CreatedIRFunctions;
StringRef getPassName() const override { return "Machine Outliner"; }
void getAnalysisUsage(AnalysisUsage &AU) const override {
@ -1205,9 +1202,6 @@ MachineOutliner::createOutlinedFunction(Module &M, const OutlinedFunction &OF,
F->addFnAttr(Attribute::OptimizeForSize);
F->addFnAttr(Attribute::MinSize);
// Save F so that we can add debug info later if we need to.
CreatedIRFunctions.push_back(F);
BasicBlock *EntryBB = BasicBlock::Create(C, "entry", F);
IRBuilder<> Builder(EntryBB);
Builder.CreateRetVoid();
@ -1235,6 +1229,10 @@ MachineOutliner::createOutlinedFunction(Module &M, const OutlinedFunction &OF,
TII.buildOutlinedFrame(MBB, MF, OF);
// Outlined functions shouldn't preserve liveness.
MF.getProperties().reset(MachineFunctionProperties::Property::TracksLiveness);
MF.getRegInfo().freezeReservedRegs(MF);
// If there's a DISubprogram associated with this outlined function, then
// emit debug info for the outlined function.
if (DISubprogram *SP = getSubprogramOrNull(OF)) {
@ -1243,39 +1241,29 @@ MachineOutliner::createOutlinedFunction(Module &M, const OutlinedFunction &OF,
DIBuilder DB(M, true, CU);
DIFile *Unit = SP->getFile();
Mangler Mg;
// Get the mangled name of the function for the linkage name.
std::string Dummy;
llvm::raw_string_ostream MangledNameStream(Dummy);
Mg.getNameWithPrefix(MangledNameStream, F, false);
// Walk over each IR function we created in the outliner and create
// DISubprograms for each function.
for (Function *F : CreatedIRFunctions) {
// Get the mangled name of the function for the linkage name.
std::string Dummy;
llvm::raw_string_ostream MangledNameStream(Dummy);
Mg.getNameWithPrefix(MangledNameStream, F, false);
DISubprogram *OutlinedSP = DB.createFunction(
Unit /* Context */, F->getName(), StringRef(MangledNameStream.str()),
Unit /* File */,
0 /* Line 0 is reserved for compiler-generated code. */,
DB.createSubroutineType(DB.getOrCreateTypeArray(None)), /* void type */
false, true, 0, /* Line 0 is reserved for compiler-generated code. */
DINode::DIFlags::FlagArtificial /* Compiler-generated code. */,
true /* Outlined code is optimized code by definition. */);
DISubprogram *SP = DB.createFunction(
Unit /* Context */, F->getName(), StringRef(MangledNameStream.str()),
Unit /* File */,
0 /* Line 0 is reserved for compiler-generated code. */,
DB.createSubroutineType(
DB.getOrCreateTypeArray(None)), /* void type */
false, true, 0, /* Line 0 is reserved for compiler-generated code. */
DINode::DIFlags::FlagArtificial /* Compiler-generated code. */,
true /* Outlined code is optimized code by definition. */);
// Don't add any new variables to the subprogram.
DB.finalizeSubprogram(SP);
// Attach subprogram to the function.
F->setSubprogram(SP);
}
// Don't add any new variables to the subprogram.
DB.finalizeSubprogram(OutlinedSP);
// Attach subprogram to the function.
F->setSubprogram(OutlinedSP);
// We're done with the DIBuilder.
DB.finalize();
}
// Outlined functions shouldn't preserve liveness.
MF.getProperties().reset(MachineFunctionProperties::Property::TracksLiveness);
MF.getRegInfo().freezeReservedRegs(MF);
return &MF;
}