aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineFunctionPass.cpp
diff options
context:
space:
mode:
authorJessica Paquette <jpaquette@apple.com>2018-09-10 22:24:10 +0000
committerJessica Paquette <jpaquette@apple.com>2018-09-10 22:24:10 +0000
commit54fbfaeaceb766d8057ff0a92637504ba2fde584 (patch)
treece1b223ff75ea77f27521ef713a0e3b6499bc64a /llvm/lib/CodeGen/MachineFunctionPass.cpp
parent7e6c32aa4519b21098807ae4f0255ec0ac4ee0ef (diff)
downloadllvm-54fbfaeaceb766d8057ff0a92637504ba2fde584.zip
llvm-54fbfaeaceb766d8057ff0a92637504ba2fde584.tar.gz
llvm-54fbfaeaceb766d8057ff0a92637504ba2fde584.tar.bz2
Add size remarks to MachineFunctionPass
This adds per-function size remarks to codegen, similar to what we have in the IR layer as of r341588. This only impacts MachineFunctionPasses. This does the same thing, but for `MachineInstr`s instead of just `Instructions`. After this, when a `MachineFunctionPass` modifies the number of `MachineInstr`s in the function it ran on, you'll get a remark. To enable this, use the size-info analysis remark as before. llvm-svn: 341876
Diffstat (limited to 'llvm/lib/CodeGen/MachineFunctionPass.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineFunctionPass.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/MachineFunctionPass.cpp b/llvm/lib/CodeGen/MachineFunctionPass.cpp
index 67ac957..5db4e29 100644
--- a/llvm/lib/CodeGen/MachineFunctionPass.cpp
+++ b/llvm/lib/CodeGen/MachineFunctionPass.cpp
@@ -23,11 +23,13 @@
#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
+#include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
using namespace llvm;
+using namespace ore;
Pass *MachineFunctionPass::createPrinterPass(raw_ostream &O,
const std::string &Banner) const {
@@ -57,9 +59,43 @@ bool MachineFunctionPass::runOnFunction(Function &F) {
llvm_unreachable("MachineFunctionProperties check failed");
}
#endif
+ // Collect the MI count of the function before the pass.
+ unsigned CountBefore, CountAfter;
+
+ // Check if the user asked for size remarks.
+ bool ShouldEmitSizeRemarks =
+ F.getParent()->shouldEmitInstrCountChangedRemark();
+
+ // If we want size remarks, collect the number of MachineInstrs in our
+ // MachineFunction before the pass runs.
+ if (ShouldEmitSizeRemarks)
+ CountBefore = MF.getInstructionCount();
bool RV = runOnMachineFunction(MF);
+ if (ShouldEmitSizeRemarks) {
+ // We wanted size remarks. Check if there was a change to the number of
+ // MachineInstrs in the module. Emit a remark if there was a change.
+ CountAfter = MF.getInstructionCount();
+ if (CountBefore != CountAfter) {
+ MachineOptimizationRemarkEmitter MORE(MF, nullptr);
+ MORE.emit([&]() {
+ int64_t Delta = static_cast<int64_t>(CountAfter) -
+ static_cast<int64_t>(CountBefore);
+ MachineOptimizationRemarkAnalysis R("size-info", "FunctionMISizeChange",
+ MF.getFunction().getSubprogram(),
+ &MF.front());
+ R << NV("Pass", getPassName())
+ << ": Function: " << NV("Function", F.getName()) << ": "
+ << "MI Instruction count changed from "
+ << NV("MIInstrsBefore", CountBefore) << " to "
+ << NV("MIInstrsAfter", CountAfter)
+ << "; Delta: " << NV("Delta", Delta);
+ return R;
+ });
+ }
+ }
+
MFProps.set(SetProperties);
MFProps.reset(ClearedProperties);
return RV;