[llvm] r219669 - Instead of the TargetMachine cache the MachineFunction

Eric Christopher echristo at gmail.com
Tue Oct 14 13:05:24 PDT 2014


On Tue, Oct 14, 2014 at 8:12 AM, David Blaikie <dblaikie at gmail.com> wrote:
>
>
> On Tue, Oct 14, 2014 at 12:17 AM, Eric Christopher <echristo at gmail.com>
> wrote:
>>
>> Author: echristo
>> Date: Tue Oct 14 02:17:20 2014
>> New Revision: 219669
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=219669&view=rev
>> Log:
>> Instead of the TargetMachine cache the MachineFunction
>
>
> Why not just cache the Subtarget itself?

*shrug* No reason to make the calls. It really looks like no reason to
cache the MachineFunction either so I'll probably just kill that part.

-eric

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



More information about the llvm-commits mailing list