From 52042aa21e6ef8b694e254491d2c3a6bb4779124 Mon Sep 17 00:00:00 2001 From: Francis Visoiu Mistrih Date: Wed, 19 Jul 2017 23:47:32 +0000 Subject: [PEI] Add basic opt-remarks support Add optimization remarks support to the PrologueEpilogueInserter. For now, emit the stack size as an analysis remark, but more additions wrt shrink-wrapping may be added. https://reviews.llvm.org/D35645 llvm-svn: 308556 --- llvm/lib/CodeGen/PrologEpilogInserter.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'llvm/lib/CodeGen/PrologEpilogInserter.cpp') diff --git a/llvm/lib/CodeGen/PrologEpilogInserter.cpp b/llvm/lib/CodeGen/PrologEpilogInserter.cpp index b437b5c0b00..9361a2a8b0e 100644 --- a/llvm/lib/CodeGen/PrologEpilogInserter.cpp +++ b/llvm/lib/CodeGen/PrologEpilogInserter.cpp @@ -25,6 +25,7 @@ #include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/MachineLoopInfo.h" #include "llvm/CodeGen/MachineModuleInfo.h" +#include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h" #include "llvm/CodeGen/MachineRegisterInfo.h" #include "llvm/CodeGen/Passes.h" #include "llvm/CodeGen/RegisterScavenging.h" @@ -98,6 +99,9 @@ private: // FrameIndexVirtualScavenging is used. bool FrameIndexEliminationScavenging; + // Emit remarks. + MachineOptimizationRemarkEmitter *ORE = nullptr; + void calculateCallFrameInfo(MachineFunction &Fn); void calculateSaveRestoreBlocks(MachineFunction &Fn); void doSpillCalleeSavedRegs(MachineFunction &MF); @@ -122,6 +126,7 @@ INITIALIZE_PASS_BEGIN(PEI, DEBUG_TYPE, "Prologue/Epilogue Insertion", false, INITIALIZE_PASS_DEPENDENCY(MachineLoopInfo) INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree) INITIALIZE_PASS_DEPENDENCY(StackProtector) +INITIALIZE_PASS_DEPENDENCY(MachineOptimizationRemarkEmitterPass) INITIALIZE_PASS_END(PEI, DEBUG_TYPE, "Prologue/Epilogue Insertion & Frame Finalization", false, false) @@ -138,6 +143,7 @@ void PEI::getAnalysisUsage(AnalysisUsage &AU) const { AU.addPreserved(); AU.addPreserved(); AU.addRequired(); + AU.addRequired(); MachineFunctionPass::getAnalysisUsage(AU); } @@ -171,6 +177,7 @@ bool PEI::runOnMachineFunction(MachineFunction &Fn) { FrameIndexVirtualScavenging = TRI->requiresFrameIndexScavenging(Fn); FrameIndexEliminationScavenging = (RS && !FrameIndexVirtualScavenging) || TRI->requiresFrameIndexReplacementScavenging(Fn); + ORE = &getAnalysis().getORE(); // Calculate the MaxCallFrameSize and AdjustsStack variables for the // function's frame information. Also eliminates call frame pseudo @@ -938,6 +945,12 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) { int64_t StackSize = Offset - LocalAreaOffset; MFI.setStackSize(StackSize); NumBytesStackSpace += StackSize; + + MachineOptimizationRemarkAnalysis R( + DEBUG_TYPE, "StackSize", Fn.getFunction()->getSubprogram(), &Fn.front()); + R << ore::NV("NumStackBytes", static_cast(StackSize)) + << " stack bytes in function"; + ORE->emit(R); } /// insertPrologEpilogCode - Scan the function for modified callee saved -- cgit v1.2.3