Add a BlockInfo::FirstDef field.
authorJakob Stoklund Olesen <stoklund@2pi.dk>
Tue, 2 Aug 2011 22:37:22 +0000 (22:37 +0000)
committerJakob Stoklund Olesen <stoklund@2pi.dk>
Tue, 2 Aug 2011 22:37:22 +0000 (22:37 +0000)
This is either an invalid SlotIndex, or valno->def for the first value
defined inside the block. PHI values are not counted as defined inside
the block.

The FirstDef field will be used when estimating the cost of spilling
around a block.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@136736 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SplitKit.cpp
lib/CodeGen/SplitKit.h

index 0679a619f5c81dd97edb80663cd11472f0da09e8..45b976ca25be55afca898a2df16970bcce7b2084 100644 (file)
@@ -188,6 +188,13 @@ bool SplitAnalysis::calcLiveBlockInfo() {
       // LVI is the first live segment overlapping MBB.
       BI.LiveIn = LVI->start <= Start;
 
+      // When not live in, the first use should be a def.
+      if (!BI.LiveIn) {
+        assert(LVI->start == LVI->valno->def && "Dangling LiveRange start");
+        assert(LVI->start == BI.FirstUse && "First instr should be a def");
+        BI.FirstDef = BI.FirstUse;
+      }
+
       // Look for gaps in the live range.
       BI.LiveOut = true;
       while (LVI->end < Stop) {
@@ -197,6 +204,7 @@ bool SplitAnalysis::calcLiveBlockInfo() {
           BI.LastUse = LastStop;
           break;
         }
+
         if (LastStop < LVI->start) {
           // There is a gap in the live range. Create duplicate entries for the
           // live-in snippet and the live-out snippet.
@@ -210,8 +218,13 @@ bool SplitAnalysis::calcLiveBlockInfo() {
           // Set up BI for the live-out part.
           BI.LiveIn = false;
           BI.LiveOut = true;
-          BI.FirstUse = LVI->start;
+          BI.FirstUse = BI.FirstDef = LVI->start;
         }
+
+        // A LiveRange that starts in the middle of the block must be a def.
+        assert(LVI->start == LVI->valno->def && "Dangling LiveRange start");
+        if (!BI.FirstDef)
+          BI.FirstDef = LVI->start;
       }
 
       UseBlocks.push_back(BI);
index 4566b84ca7e5acd8c8375e05adc2b02420006c63..92d6bc88f508ab34c7e129019516630f0013d014 100644 (file)
@@ -78,6 +78,7 @@ public:
     MachineBasicBlock *MBB;
     SlotIndex FirstUse;   ///< First instr using current reg.
     SlotIndex LastUse;    ///< Last instr using current reg.
+    SlotIndex FirstDef;   ///< First non-phi valno->def, or SlotIndex().
     bool LiveIn;          ///< Current reg is live in.
     bool LiveOut;         ///< Current reg is live out.