diff options
author | Jessica Paquette <jpaquette@apple.com> | 2018-03-22 21:07:09 +0000 |
---|---|---|
committer | Jessica Paquette <jpaquette@apple.com> | 2018-03-22 21:07:09 +0000 |
commit | df82274f3c6f44b589fc206b67f807c0a0c13ea9 (patch) | |
tree | f687a522a3cbf17c462c89f8decf20212540abff /llvm/lib/CodeGen/MachineOutliner.cpp | |
parent | 022a82cb15cafa4fb80b96865e240373a0fbae65 (diff) | |
download | bcm5719-llvm-df82274f3c6f44b589fc206b67f807c0a0c13ea9.tar.gz bcm5719-llvm-df82274f3c6f44b589fc206b67f807c0a0c13ea9.zip |
[MachineOutliner][NFC] Refactoring + comments in runOnModule
Split up some of the if/else branches in runOnModule. Elaborate on some
comments. Replace a call to getOrCreateMachineFunction with getMachineFunction.
This makes it clearer what's happening in runOnModule, and ensures that the
outliner doesn't create any MachineFunctions which will never be used by the
outliner (or anything else, really).
llvm-svn: 328240
Diffstat (limited to 'llvm/lib/CodeGen/MachineOutliner.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineOutliner.cpp | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/llvm/lib/CodeGen/MachineOutliner.cpp b/llvm/lib/CodeGen/MachineOutliner.cpp index d60cc58e20a..fb8b86512a2 100644 --- a/llvm/lib/CodeGen/MachineOutliner.cpp +++ b/llvm/lib/CodeGen/MachineOutliner.cpp @@ -1406,8 +1406,8 @@ bool MachineOutliner::outline( } bool MachineOutliner::runOnModule(Module &M) { - - // Is there anything in the module at all? + // Check if there's anything in the module. If it's empty, then there's + // nothing to outline. if (M.empty()) return false; @@ -1419,23 +1419,44 @@ bool MachineOutliner::runOnModule(Module &M) { InstructionMapper Mapper; - // Build instruction mappings for each function in the module. + // Build instruction mappings for each function in the module. Start by + // iterating over each Function in M. for (Function &F : M) { - MachineFunction &MF = MMI.getOrCreateMachineFunction(F); - // Is the function empty? Safe to outline from? - if (F.empty() || - !TII->isFunctionSafeToOutlineFrom(MF, OutlineFromLinkOnceODRs)) + // If there's nothing in F, then there's no reason to try and outline from + // it. + if (F.empty()) + continue; + + // There's something in F. Check if it has a MachineFunction associated with + // it. + MachineFunction *MF = MMI.getMachineFunction(F); + + // If it doesn't, then there's nothing to outline from. Move to the next + // Function. + if (!MF) continue; - // If it is, look at each MachineBasicBlock in the function. - for (MachineBasicBlock &MBB : MF) { + // We have a MachineFunction. Ask the target if it's suitable for outlining. + // If it isn't, then move on to the next Function in the module. + if (!TII->isFunctionSafeToOutlineFrom(*MF, OutlineFromLinkOnceODRs)) + continue; + + // We have a function suitable for outlining. Iterate over every + // MachineBasicBlock in MF and try to map its instructions to a list of + // unsigned integers. + for (MachineBasicBlock &MBB : *MF) { + // If there isn't anything in MBB, then there's no point in outlining from + // it. + if (MBB.empty()) + continue; - // Is there anything in MBB? And is it the target of an indirect branch? - if (MBB.empty() || MBB.hasAddressTaken()) + // Check if MBB could be the target of an indirect branch. If it is, then + // we don't want to outline from it. + if (MBB.hasAddressTaken()) continue; - // If yes, map it. + // MBB is suitable for outlining. Map it to a list of unsigneds. Mapper.convertToUnsignedVec(MBB, *TRI, *TII); } } |