This is an archive of the discontinued LLVM Phabricator instance.

CodeGen: Remove MachineFunctionAnalysis => Enable (Machine)ModulePasses
ClosedPublic

Authored by MatzeB on Aug 19 2016, 7:03 PM.

Details

Summary

This patch removes the MachineFunctionAnalysis. Instead we keep a
map from IR Function to MachineFunction in the MachineModuleInfo.

This allows the insertion of ModulePasses into the codegen pipeline
without breaking it because the MachineFunctionAnalysis gets dropped
before a module pass.

Peak memory should stay unchanged without a ModulePass in the codegen
pipeline: Previously the MachineFunction was freed at the end of a codegen
function pipeline because the MachineFunctionAnalysis was dropped; With
this patch the MachineFunction is freed after the AsmPrinter has
finished.

Note that this is not complete yet. It works nice without a ModulePass in the codegen pipeline. It works in many cases with a ModulePass, but still fails in some instances because have some metadata about the current function in MachineModuleInfo which needs to be moved into the MachineFunction class.

Diff Detail

Repository
rL LLVM

Event Timeline

MatzeB updated this revision to Diff 68760.Aug 19 2016, 7:03 PM
MatzeB retitled this revision from to CodeGen: Remove MachineFunctionAnalysis => Enable (Machine)ModulePasses.
MatzeB updated this object.
MatzeB set the repository for this revision to rL LLVM.
MatzeB added subscribers: llvm-commits, jpaquette.

This illustrates how a ModulePass in the codegen pipeline could look like: https://reviews.llvm.org/D23737

chandlerc accepted this revision.Aug 19 2016, 9:46 PM
chandlerc edited edge metadata.

This seems generally fine to me. LGTM, optional comments below that are also fine in follow-up if at all.

include/llvm/CodeGen/MachineModuleInfo.h
191 ↗(On Diff #68760)

And it owns the machine functions.

Doesn't this make it hard to iterate the machine functions in a deterministic order?

Would it be better to have a vector of unique pointers for ownership and iteration, and a map from raw pointer to raw pointer for lookup? (genuine question, you know this area much better.

193–194 ↗(On Diff #68760)

Is this really that hot? It seems a risky technique...

This revision is now accepted and ready to land.Aug 19 2016, 9:46 PM
MatzeB added inline comments.Aug 22 2016, 11:05 AM
include/llvm/CodeGen/MachineModuleInfo.h
191 ↗(On Diff #68760)

Indeed this should not be used for iteration to avoid indeterministic order.
Right now nobody is using the iteration functionality so this is just a minimal set of functionality to get things going. It is likely that we will need/add iteration functionality in upcoming patches.

193–194 ↗(On Diff #68760)

To be honest I don't know, quite possibly not. I did not want to slow things down compared what we get today with the MachineFunctionAnalysis, anyway I'll run some tests and remove this if I can't measure a difference even in examples with lots of small functions.

I'll go ahead and push a first version after the LGTM, I'll be happy to address further issues in follow-up patches.

include/llvm/CodeGen/MachineModuleInfo.h
193–194 ↗(On Diff #68760)

With a testcase of 1000 functions that just return, valgrind/callgrind measures a difference of slightly more than 1% in the executed instructions.
This isn't that much considering it is an artificial testcase, on the other hand I believe this caching scheme to be extremely simple so I'd like to keep it.

This revision was automatically updated to reflect the committed changes.
llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp