[llvm-commits] [llvm] r61802 - /llvm/trunk/lib/CodeGen/PreAllocSplitting.cpp
Evan Cheng
echeng at apple.com
Thu Jan 8 13:31:07 PST 2009
Can you add some test cases to the various pre-splitting features you
are adding?
Thanks,
Evan
On Jan 5, 2009, at 11:53 PM, Owen Anderson wrote:
> Author: resistor
> Date: Tue Jan 6 01:53:32 2009
> New Revision: 61802
>
> URL: http://llvm.org/viewvc/llvm-project?rev=61802&view=rev
> Log:
> The phi construction algorithm used for interval reconstruction is
> complicated by
> two address instructions. We need to keep track of things we've
> processed AS USES
> independetly of whether we've processed them as defs.
>
> This fixes all known miscompilations when reconstruction is turned on.
>
> Modified:
> llvm/trunk/lib/CodeGen/PreAllocSplitting.cpp
>
> Modified: llvm/trunk/lib/CodeGen/PreAllocSplitting.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/PreAllocSplitting.cpp?rev=61802&r1=61801&r2=61802&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- llvm/trunk/lib/CodeGen/PreAllocSplitting.cpp (original)
> +++ llvm/trunk/lib/CodeGen/PreAllocSplitting.cpp Tue Jan 6 01:53:32
> 2009
> @@ -175,6 +175,7 @@
> VNInfo* PerformPHIConstruction(MachineBasicBlock::iterator use,
> MachineBasicBlock* MBB,
> LiveInterval* LI,
> + SmallPtrSet<MachineInstr*, 4>&
> Visited,
> DenseMap<MachineBasicBlock*, SmallPtrSet<MachineInstr*,
> 2> >& Defs,
> DenseMap<MachineBasicBlock*, SmallPtrSet<MachineInstr*,
> 2> >& Uses,
> DenseMap<MachineInstr*,
> VNInfo*>& NewVNs,
> @@ -593,6 +594,7 @@
>
> MachineBasicBlock::iterator use,
>
> MachineBasicBlock* MBB,
>
> LiveInterval* LI,
> + SmallPtrSet<MachineInstr*,
> 4>& Visited,
> DenseMap<MachineBasicBlock*, SmallPtrSet<MachineInstr*,
> 2> >& Defs,
> DenseMap<MachineBasicBlock*, SmallPtrSet<MachineInstr*,
> 2> >& Uses,
> DenseMap<MachineInstr*,
> VNInfo*>& NewVNs,
> @@ -600,7 +602,9 @@
> DenseMap<MachineBasicBlock*,
> VNInfo*>& Phis,
> bool toplevel, bool
> intrablock) {
> // Return memoized result if it's available.
> - if (intrablock && NewVNs.count(use))
> + if (toplevel && Visited.count(use) && NewVNs.count(use))
> + return NewVNs[use];
> + else if (!toplevel && intrablock && NewVNs.count(use))
> return NewVNs[use];
> else if (!intrablock && LiveOut.count(MBB))
> return LiveOut[MBB];
> @@ -624,8 +628,8 @@
>
> if (MBB->pred_size() == 1) {
> Phis[MBB] = ret = PerformPHIConstruction((*MBB->pred_begin())-
> >end(),
> - *(MBB->pred_begin()), LI,
> Defs,
> - Uses, NewVNs, LiveOut,
> Phis,
> + *(MBB->pred_begin()), LI,
> Visited,
> + Defs, Uses, NewVNs,
> LiveOut, Phis,
> false, false);
> unsigned EndIndex = 0;
> if (intrablock) {
> @@ -646,9 +650,9 @@
> DenseMap<MachineBasicBlock*, VNInfo*> IncomingVNs;
> for (MachineBasicBlock::pred_iterator PI = MBB->pred_begin(),
> PE = MBB->pred_end(); PI != PE; ++PI) {
> - VNInfo* Incoming = PerformPHIConstruction((*PI)->end(),
> *PI, LI, Defs,
> - Uses, NewVNs, LiveOut,
> Phis,
> - false, false);
> + VNInfo* Incoming = PerformPHIConstruction((*PI)->end(),
> *PI, LI,
> + Visited, Defs, Uses,
> NewVNs,
> + LiveOut, Phis, false,
> false);
> if (Incoming != 0)
> IncomingVNs[*PI] = Incoming;
> }
> @@ -732,7 +736,7 @@
>
> // Now, recursively phi construct the VNInfo for the use we found,
> // and then extend it to include the instruction we care about
> - ret = PerformPHIConstruction(walker, MBB, LI, Defs, Uses,
> + ret = PerformPHIConstruction(walker, MBB, LI, Visited, Defs,
> Uses,
> NewVNs, LiveOut, Phis, false, true);
>
> // FIXME: Need to set kills properly for inter-block stuff.
> @@ -789,7 +793,7 @@
> if (foundDef)
> ret = NewVNs[walker];
> else
> - ret = PerformPHIConstruction(walker, MBB, LI, Defs, Uses,
> + ret = PerformPHIConstruction(walker, MBB, LI, Visited, Defs,
> Uses,
> NewVNs, LiveOut, Phis, false,
> true);
>
> if (foundUse && LI->isKill(ret, StartIndex))
> @@ -803,8 +807,11 @@
>
> // Memoize results so we don't have to recompute them.
> if (!intrablock) LiveOut[MBB] = ret;
> - else NewVNs[use] = ret;
> -
> + else {
> + NewVNs[use] = ret;
> + Visited.insert(use);
> + }
> +
> return ret;
> }
>
> @@ -831,7 +838,14 @@
> unsigned DefIdx = LIs->getInstructionIndex(&*DI);
> DefIdx = LiveIntervals::getDefIndex(DefIdx);
>
> - VNInfo* NewVN = LI->getNextValue(DefIdx, /*FIXME*/ 0, Alloc);
> + VNInfo* NewVN = LI->getNextValue(DefIdx, 0, Alloc);
> +
> + // If the def is a move, set the copy field.
> + unsigned source, dest;
> + if (TII->isMoveInstr(*DI, source, dest))
> + if (dest == LI->reg)
> + NewVN->copy = &*DI;
> +
> NewVNs[&*DI] = NewVN;
> }
>
> @@ -845,9 +859,10 @@
> // the way.
> DenseMap<MachineBasicBlock*, VNInfo*> LiveOut;
> DenseMap<MachineBasicBlock*, VNInfo*> Phis;
> + SmallPtrSet<MachineInstr*, 4> Visited;
> for (MachineRegisterInfo::use_iterator UI = MRI->use_begin(LI->reg),
> UE = MRI->use_end(); UI != UE; ++UI) {
> - PerformPHIConstruction(&*UI, UI->getParent(), LI, Defs,
> + PerformPHIConstruction(&*UI, UI->getParent(), LI, Visited, Defs,
> Uses, NewVNs, LiveOut, Phis, true, true);
> }
>
> @@ -1116,7 +1131,6 @@
> }
>
> RepairLiveInterval(CurrLI, ValNo, DefMI, RestoreIdx);
> -
> ++NumSplits;
> ++NumRemats;
> return true;
>
>
> _______________________________________________
> 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