<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 14, 2014 at 12:17 AM, Eric Christopher <span dir="ltr"><<a href="mailto:echristo@gmail.com" target="_blank">echristo@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: echristo<br>
Date: Tue Oct 14 02:17:20 2014<br>
New Revision: 219669<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=219669&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=219669&view=rev</a><br>
Log:<br>
Instead of the TargetMachine cache the MachineFunction<br></blockquote><div><br></div><div>Why not just cache the Subtarget itself?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
and TargetRegisterInfo in the peephole optimizer. This<br>
makes it easier to grab subtarget dependent variables off<br>
of the MachineFunction rather than the TargetMachine.<br>
<br>
Modified:<br>
llvm/trunk/lib/CodeGen/PeepholeOptimizer.cpp<br>
<br>
Modified: llvm/trunk/lib/CodeGen/PeepholeOptimizer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/PeepholeOptimizer.cpp?rev=219669&r1=219668&r2=219669&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/PeepholeOptimizer.cpp?rev=219669&r1=219668&r2=219669&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/PeepholeOptimizer.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/PeepholeOptimizer.cpp Tue Oct 14 02:17:20 2014<br>
@@ -107,8 +107,9 @@ STATISTIC(NumRewrittenCopies, "Number of<br>
<br>
namespace {<br>
class PeepholeOptimizer : public MachineFunctionPass {<br>
- const TargetMachine *TM;<br>
+ MachineFunction *MF;<br>
const TargetInstrInfo *TII;<br>
+ const TargetRegisterInfo *TRI;<br>
MachineRegisterInfo *MRI;<br>
MachineDominatorTree *DT; // Machine dominator tree<br>
<br>
@@ -327,8 +328,7 @@ optimizeExtInstr(MachineInstr *MI, Machi<br>
// Ensure DstReg can get a register class that actually supports<br>
// sub-registers. Don't change the class until we commit.<br>
const TargetRegisterClass *DstRC = MRI->getRegClass(DstReg);<br>
- DstRC = TM->getSubtargetImpl()->getRegisterInfo()->getSubClassWithSubReg(<br>
- DstRC, SubIdx);<br>
+ DstRC = TRI->getSubClassWithSubReg(DstRC, SubIdx);<br>
if (!DstRC)<br>
return false;<br>
<br>
@@ -338,8 +338,7 @@ optimizeExtInstr(MachineInstr *MI, Machi<br>
// If UseSrcSubIdx is Set, SubIdx also applies to SrcReg, and only uses of<br>
// SrcReg:SubIdx should be replaced.<br>
bool UseSrcSubIdx =<br>
- TM->getSubtargetImpl()->getRegisterInfo()->getSubClassWithSubReg(<br>
- MRI->getRegClass(SrcReg), SubIdx) != nullptr;<br>
+ TRI->getSubClassWithSubReg(MRI->getRegClass(SrcReg), SubIdx) != nullptr;<br>
<br>
// The source has other uses. See if we can replace the other uses with use of<br>
// the result of the extension.<br>
@@ -548,7 +547,6 @@ bool PeepholeOptimizer::findNextSource(u<br>
unsigned Src;<br>
unsigned SrcSubReg;<br>
bool ShouldRewrite = false;<br>
- const TargetRegisterInfo &TRI = *TM->getSubtargetImpl()->getRegisterInfo();<br>
<br>
// Follow the chain of copies until we reach the top of the use-def chain<br>
// or find a more suitable source.<br>
@@ -571,7 +569,7 @@ bool PeepholeOptimizer::findNextSource(u<br>
const TargetRegisterClass *SrcRC = MRI->getRegClass(Src);<br>
<br>
// If this source does not incur a cross register bank copy, use it.<br>
- ShouldRewrite = shareSameRegisterFile(TRI, DefRC, DefSubReg, SrcRC,<br>
+ ShouldRewrite = shareSameRegisterFile(*TRI, DefRC, DefSubReg, SrcRC,<br>
SrcSubReg);<br>
} while (!ShouldRewrite);<br>
<br>
@@ -1047,24 +1045,25 @@ bool PeepholeOptimizer::foldImmediate(Ma<br>
return false;<br>
}<br>
<br>
-bool PeepholeOptimizer::runOnMachineFunction(MachineFunction &MF) {<br>
- if (skipOptnoneFunction(*MF.getFunction()))<br>
+bool PeepholeOptimizer::runOnMachineFunction(MachineFunction &mf) {<br>
+ if (skipOptnoneFunction(*mf.getFunction()))<br>
return false;<br>
<br>
DEBUG(dbgs() << "********** PEEPHOLE OPTIMIZER **********\n");<br>
- DEBUG(dbgs() << "********** Function: " << MF.getName() << '\n');<br>
+ DEBUG(dbgs() << "********** Function: " << mf.getName() << '\n');<br>
<br>
if (DisablePeephole)<br>
return false;<br>
<br>
- TM = &MF.getTarget();<br>
- TII = TM->getSubtargetImpl()->getInstrInfo();<br>
- MRI = &MF.getRegInfo();<br>
+ MF = &mf;<br>
+ TII = MF->getSubtarget().getInstrInfo();<br>
+ TRI = MF->getSubtarget().getRegisterInfo();<br>
+ MRI = &MF->getRegInfo();<br>
DT = Aggressive ? &getAnalysis<MachineDominatorTree>() : nullptr;<br>
<br>
bool Changed = false;<br>
<br>
- for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {<br>
+ for (MachineFunction::iterator I = MF->begin(), E = MF->end(); I != E; ++I) {<br>
MachineBasicBlock *MBB = &*I;<br>
<br>
bool SeenMoveImm = false;<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>