blob: e2822c300e894570c33e1b10d4a5da9c2ba6afb1 [file] [log] [blame]
Chris Lattnerf57b8452002-04-27 06:56:12 +00001//===-- FunctionLiveVarInfo.cpp - Live Variable Analysis for a Function ---===//
John Criswellb576c942003-10-20 19:43:21 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
Chris Lattner5e5dfa32002-02-05 02:51:01 +00009//
Chris Lattnerf57b8452002-04-27 06:56:12 +000010// This is the interface to function level live variable information that is
Chris Lattner5e5dfa32002-02-05 02:51:01 +000011// provided by live variable analysis.
12//
13//===----------------------------------------------------------------------===//
Ruchira Sasanka683847f2001-07-24 17:14:13 +000014
Chris Lattner92ba2aa2003-01-14 23:05:08 +000015#include "llvm/CodeGen/FunctionLiveVarInfo.h"
Ruchira Sasankae27c3442001-08-20 21:12:49 +000016#include "llvm/CodeGen/MachineInstr.h"
Chris Lattner601fc7c2002-10-28 18:01:21 +000017#include "llvm/CodeGen/MachineFunction.h"
Vikram S. Adve88d962a2003-08-12 22:19:59 +000018#include "llvm/Target/TargetMachine.h"
19#include "llvm/Target/TargetInstrInfo.h"
Chris Lattner221d6882002-02-12 21:07:25 +000020#include "llvm/Support/CFG.h"
Chris Lattnercee8f9a2001-11-27 00:03:19 +000021#include "Support/PostOrderIterator.h"
Chris Lattner7471a7b2002-02-05 03:35:53 +000022#include "Support/SetOperations.h"
Chris Lattner70e60cb2002-05-22 17:08:27 +000023#include "Support/CommandLine.h"
Chris Lattner92ba2aa2003-01-14 23:05:08 +000024#include "BBLiveVar.h"
Ruchira Sasanka683847f2001-07-24 17:14:13 +000025
Brian Gaeked0fde302003-11-11 22:41:34 +000026namespace llvm {
27
Chris Lattner1e435162002-07-26 21:12:44 +000028static RegisterAnalysis<FunctionLiveVarInfo>
29X("livevar", "Live Variable Analysis");
Ruchira Sasanka683847f2001-07-24 17:14:13 +000030
Chris Lattner70e60cb2002-05-22 17:08:27 +000031LiveVarDebugLevel_t DEBUG_LV;
32
Chris Lattner5ff62e92002-07-22 02:10:13 +000033static cl::opt<LiveVarDebugLevel_t, true>
34DEBUG_LV_opt("dlivevar", cl::Hidden, cl::location(DEBUG_LV),
35 cl::desc("enable live-variable debugging information"),
36 cl::values(
37clEnumValN(LV_DEBUG_None , "n", "disable debug output"),
38clEnumValN(LV_DEBUG_Normal , "y", "enable debug output"),
39clEnumValN(LV_DEBUG_Instr, "i", "print live-var sets before/after "
40 "every machine instrn"),
41clEnumValN(LV_DEBUG_Verbose, "v", "print def, use sets for every instrn also"),
42 0));
Vikram S. Adve9cf85a72002-03-18 03:45:41 +000043
Chris Lattner70e60cb2002-05-22 17:08:27 +000044
45
Chris Lattnerab584112002-02-05 00:34:50 +000046//-----------------------------------------------------------------------------
47// Accessor Functions
48//-----------------------------------------------------------------------------
49
50// gets OutSet of a BB
Chris Lattner483e14e2002-04-27 07:27:19 +000051const ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) const {
Chris Lattnere9d3c6b2003-10-20 20:52:23 +000052 return BBLiveVarInfo.find(BB)->second->getOutSet();
Chris Lattnerab584112002-02-05 00:34:50 +000053}
Vikram S. Adve88d962a2003-08-12 22:19:59 +000054 ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) {
Chris Lattnere9d3c6b2003-10-20 20:52:23 +000055 return BBLiveVarInfo[BB]->getOutSet();
Vikram S. Adve88d962a2003-08-12 22:19:59 +000056}
Chris Lattnerab584112002-02-05 00:34:50 +000057
58// gets InSet of a BB
Chris Lattner483e14e2002-04-27 07:27:19 +000059const ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const {
Chris Lattnere9d3c6b2003-10-20 20:52:23 +000060 return BBLiveVarInfo.find(BB)->second->getInSet();
Chris Lattnerab584112002-02-05 00:34:50 +000061}
Chris Lattnere9d3c6b2003-10-20 20:52:23 +000062ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) {
63 return BBLiveVarInfo[BB]->getInSet();
Vikram S. Adve88d962a2003-08-12 22:19:59 +000064}
Chris Lattnerab584112002-02-05 00:34:50 +000065
Chris Lattnerbdfd3282002-02-04 20:49:04 +000066
67//-----------------------------------------------------------------------------
Chris Lattnerf57b8452002-04-27 06:56:12 +000068// Performs live var analysis for a function
Chris Lattnerbdfd3282002-02-04 20:49:04 +000069//-----------------------------------------------------------------------------
70
Chris Lattner18961502002-06-25 16:12:52 +000071bool FunctionLiveVarInfo::runOnFunction(Function &F) {
72 M = &F;
Chris Lattnera51c7a82002-02-04 23:31:16 +000073 if (DEBUG_LV) std::cerr << "Analysing live variables ...\n";
Chris Lattnerbdfd3282002-02-04 20:49:04 +000074
75 // create and initialize all the BBLiveVars of the CFG
Chris Lattner18961502002-06-25 16:12:52 +000076 constructBBs(M);
Chris Lattnerbdfd3282002-02-04 20:49:04 +000077
Vikram S. Adve9cf85a72002-03-18 03:45:41 +000078 unsigned int iter=0;
Chris Lattner18961502002-06-25 16:12:52 +000079 while (doSingleBackwardPass(M, iter++))
Chris Lattnerbdfd3282002-02-04 20:49:04 +000080 ; // Iterate until we are done.
81
Chris Lattnera51c7a82002-02-04 23:31:16 +000082 if (DEBUG_LV) std::cerr << "Live Variable Analysis complete!\n";
Chris Lattnerbdfd3282002-02-04 20:49:04 +000083 return false;
84}
85
86
87//-----------------------------------------------------------------------------
88// constructs BBLiveVars and init Def and In sets
89//-----------------------------------------------------------------------------
90
Chris Lattner601fc7c2002-10-28 18:01:21 +000091void FunctionLiveVarInfo::constructBBs(const Function *F) {
92 unsigned POId = 0; // Reverse Depth-first Order ID
93 std::map<const BasicBlock*, unsigned> PONumbering;
Chris Lattnerbdfd3282002-02-04 20:49:04 +000094
Chris Lattner601fc7c2002-10-28 18:01:21 +000095 for (po_iterator<const Function*> BBI = po_begin(M), BBE = po_end(M);
96 BBI != BBE; ++BBI)
97 PONumbering[*BBI] = POId++;
98
99 MachineFunction &MF = MachineFunction::get(F);
100 for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
101 const BasicBlock &BB = *I->getBasicBlock(); // get the current BB
Chris Lattner0665a5f2002-02-05 01:43:49 +0000102 if (DEBUG_LV) std::cerr << " For BB " << RAV(BB) << ":\n";
Chris Lattnerbdfd3282002-02-04 20:49:04 +0000103
Chris Lattner601fc7c2002-10-28 18:01:21 +0000104 BBLiveVar *LVBB;
105 std::map<const BasicBlock*, unsigned>::iterator POI = PONumbering.find(&BB);
106 if (POI != PONumbering.end()) {
107 // create a new BBLiveVar
Chris Lattnere9d3c6b2003-10-20 20:52:23 +0000108 LVBB = new BBLiveVar(BB, *I, POId);
Chris Lattner601fc7c2002-10-28 18:01:21 +0000109 } else {
110 // The PO iterator does not discover unreachable blocks, but the random
111 // iterator later may access these blocks. We must make sure to
112 // initialize unreachable blocks as well. However, LV info is not correct
113 // for those blocks (they are not analyzed)
114 //
Chris Lattnere9d3c6b2003-10-20 20:52:23 +0000115 LVBB = new BBLiveVar(BB, *I, ++POId);
Chris Lattner601fc7c2002-10-28 18:01:21 +0000116 }
Chris Lattnere9d3c6b2003-10-20 20:52:23 +0000117 BBLiveVarInfo[&BB] = LVBB;
Chris Lattnerbdfd3282002-02-04 20:49:04 +0000118
Chris Lattnera51c7a82002-02-04 23:31:16 +0000119 if (DEBUG_LV)
Chris Lattnerbdfd3282002-02-04 20:49:04 +0000120 LVBB->printAllSets();
121 }
Chris Lattnerbdfd3282002-02-04 20:49:04 +0000122}
123
124
125//-----------------------------------------------------------------------------
126// do one backward pass over the CFG (for iterative analysis)
127//-----------------------------------------------------------------------------
Chris Lattnera51c7a82002-02-04 23:31:16 +0000128
Chris Lattner483e14e2002-04-27 07:27:19 +0000129bool FunctionLiveVarInfo::doSingleBackwardPass(const Function *M,
130 unsigned iter) {
Vikram S. Adve9cf85a72002-03-18 03:45:41 +0000131 if (DEBUG_LV) std::cerr << "\n After Backward Pass " << iter << "...\n";
Chris Lattnerbdfd3282002-02-04 20:49:04 +0000132
Chris Lattnera51c7a82002-02-04 23:31:16 +0000133 bool NeedAnotherIteration = false;
Chris Lattnerfb005fe2002-04-09 05:14:14 +0000134 for (po_iterator<const Function*> BBI = po_begin(M), BBE = po_end(M);
135 BBI != BBE; ++BBI) {
Chris Lattnere9d3c6b2003-10-20 20:52:23 +0000136 BBLiveVar *LVBB = BBLiveVarInfo[*BBI];
Chris Lattnera51c7a82002-02-04 23:31:16 +0000137 assert(LVBB && "BasicBlock information not set for block!");
Chris Lattnerbdfd3282002-02-04 20:49:04 +0000138
Chris Lattnera51c7a82002-02-04 23:31:16 +0000139 if (DEBUG_LV) std::cerr << " For BB " << (*BBI)->getName() << ":\n";
Chris Lattnerbdfd3282002-02-04 20:49:04 +0000140
Vikram S. Adve9cf85a72002-03-18 03:45:41 +0000141 // InSets are initialized to "GenSet". Recompute only if OutSet changed.
Chris Lattnerbdfd3282002-02-04 20:49:04 +0000142 if(LVBB->isOutSetChanged())
143 LVBB->applyTransferFunc(); // apply the Tran Func to calc InSet
Vikram S. Adve9cf85a72002-03-18 03:45:41 +0000144
Chris Lattnerfb005fe2002-04-09 05:14:14 +0000145 // OutSets are initialized to EMPTY. Recompute on first iter or if InSet
146 // changed.
Vikram S. Adve9cf85a72002-03-18 03:45:41 +0000147 if (iter == 0 || LVBB->isInSetChanged()) // to calc Outsets of preds
Chris Lattnere9d3c6b2003-10-20 20:52:23 +0000148 NeedAnotherIteration |= LVBB->applyFlowFunc(BBLiveVarInfo);
Vikram S. Adve9cf85a72002-03-18 03:45:41 +0000149
Chris Lattnera51c7a82002-02-04 23:31:16 +0000150 if (DEBUG_LV) LVBB->printInOutSets();
Chris Lattnerbdfd3282002-02-04 20:49:04 +0000151 }
152
153 // true if we need to reiterate over the CFG
154 return NeedAnotherIteration;
155}
156
157
Chris Lattner483e14e2002-04-27 07:27:19 +0000158void FunctionLiveVarInfo::releaseMemory() {
Chris Lattnere9d3c6b2003-10-20 20:52:23 +0000159 // First remove all BBLiveVars created in constructBBs().
160 if (M) {
Chris Lattnerb7653df2002-04-08 22:03:57 +0000161 for (Function::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
Chris Lattnere9d3c6b2003-10-20 20:52:23 +0000162 delete BBLiveVarInfo[I];
163 BBLiveVarInfo.clear();
164 }
Chris Lattner6357a3f2002-02-05 06:52:25 +0000165 M = 0;
Ruchira Sasanka789cebb2001-12-08 21:05:27 +0000166
Chris Lattner5e5dfa32002-02-05 02:51:01 +0000167 // Then delete all objects of type ValueSet created in calcLiveVarSetsForBB
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000168 // and entered into MInst2LVSetBI and MInst2LVSetAI (these are caches
169 // to return ValueSet's before/after a machine instruction quickly).
170 // We do not need to free up ValueSets in MInst2LVSetAI because it holds
171 // pointers to the same sets as in MInst2LVSetBI (for all instructions
172 // except the last one in a BB) or in BBLiveVar (for the last instruction).
Ruchira Sasanka789cebb2001-12-08 21:05:27 +0000173 //
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000174 for (hash_map<const MachineInstr*, ValueSet*>::iterator
Chris Lattnerab584112002-02-05 00:34:50 +0000175 MI = MInst2LVSetBI.begin(),
Chris Lattnera51c7a82002-02-04 23:31:16 +0000176 ME = MInst2LVSetBI.end(); MI != ME; ++MI)
Chris Lattner5e5dfa32002-02-05 02:51:01 +0000177 delete MI->second; // delete all ValueSets in MInst2LVSetBI
Chris Lattner4fd2dbb2002-02-04 20:00:08 +0000178
179 MInst2LVSetBI.clear();
180 MInst2LVSetAI.clear();
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000181}
182
183
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000184
185
Ruchira Sasanka789cebb2001-12-08 21:05:27 +0000186//-----------------------------------------------------------------------------
Chris Lattnera51c7a82002-02-04 23:31:16 +0000187// Following functions will give the LiveVar info for any machine instr in
Chris Lattnerf57b8452002-04-27 06:56:12 +0000188// a function. It should be called after a call to analyze().
Chris Lattnera51c7a82002-02-04 23:31:16 +0000189//
Misha Brukman2f2d0652003-09-11 18:14:24 +0000190// These functions calculate live var info for all the machine instrs in a
Chris Lattnera51c7a82002-02-04 23:31:16 +0000191// BB when LVInfo for one inst is requested. Hence, this function is useful
192// when live var info is required for many (or all) instructions in a basic
Chris Lattnerf57b8452002-04-27 06:56:12 +0000193// block. Also, the arguments to this function does not require specific
Chris Lattnera51c7a82002-02-04 23:31:16 +0000194// iterators.
Ruchira Sasanka789cebb2001-12-08 21:05:27 +0000195//-----------------------------------------------------------------------------
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000196
Ruchira Sasanka789cebb2001-12-08 21:05:27 +0000197//-----------------------------------------------------------------------------
198// Gives live variable information before a machine instruction
199//-----------------------------------------------------------------------------
Chris Lattnera51c7a82002-02-04 23:31:16 +0000200
Chris Lattner748697d2002-02-05 04:20:12 +0000201const ValueSet &
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000202FunctionLiveVarInfo::getLiveVarSetBeforeMInst(const MachineInstr *MI,
Chris Lattner483e14e2002-04-27 07:27:19 +0000203 const BasicBlock *BB) {
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000204 ValueSet* &LVSet = MInst2LVSetBI[MI]; // ref. to map entry
Vikram S. Adve7a81a0f2003-07-29 19:42:32 +0000205 if (LVSet == NULL && BB != NULL) { // if not found and BB provided
206 calcLiveVarSetsForBB(BB); // calc LVSet for all instrs in BB
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000207 assert(LVSet != NULL);
Ruchira Sasankae27c3442001-08-20 21:12:49 +0000208 }
Vikram S. Adve7a81a0f2003-07-29 19:42:32 +0000209 return *LVSet;
Ruchira Sasankae27c3442001-08-20 21:12:49 +0000210}
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000211
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000212
Ruchira Sasanka789cebb2001-12-08 21:05:27 +0000213//-----------------------------------------------------------------------------
214// Gives live variable information after a machine instruction
215//-----------------------------------------------------------------------------
Vikram S. Adve7a81a0f2003-07-29 19:42:32 +0000216
Chris Lattner748697d2002-02-05 04:20:12 +0000217const ValueSet &
Chris Lattner483e14e2002-04-27 07:27:19 +0000218FunctionLiveVarInfo::getLiveVarSetAfterMInst(const MachineInstr *MI,
219 const BasicBlock *BB) {
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000220
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000221 ValueSet* &LVSet = MInst2LVSetAI[MI]; // ref. to map entry
Vikram S. Adve7a81a0f2003-07-29 19:42:32 +0000222 if (LVSet == NULL && BB != NULL) { // if not found and BB provided
223 calcLiveVarSetsForBB(BB); // calc LVSet for all instrs in BB
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000224 assert(LVSet != NULL);
Ruchira Sasankae27c3442001-08-20 21:12:49 +0000225 }
Vikram S. Adve7a81a0f2003-07-29 19:42:32 +0000226 return *LVSet;
Ruchira Sasankae27c3442001-08-20 21:12:49 +0000227}
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000228
Chris Lattner5e5dfa32002-02-05 02:51:01 +0000229// This function applies a machine instr to a live var set (accepts OutSet) and
230// makes necessary changes to it (produces InSet). Note that two for loops are
231// used to first kill all defs and then to add all uses. This is because there
Misha Brukman2f2d0652003-09-11 18:14:24 +0000232// can be instructions like Val = Val + 1 since we allow multiple defs to a
Chris Lattner5e5dfa32002-02-05 02:51:01 +0000233// machine instruction operand.
234//
235static void applyTranferFuncForMInst(ValueSet &LVS, const MachineInstr *MInst) {
Chris Lattner2f898d22002-02-05 06:02:59 +0000236 for (MachineInstr::const_val_op_iterator OpI = MInst->begin(),
237 OpE = MInst->end(); OpI != OpE; ++OpI) {
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000238 if (OpI.isDef()) // kill if this operand is a def
Vikram S. Advea22eace2003-05-27 00:06:48 +0000239 LVS.erase(*OpI); // this definition kills any uses
Chris Lattner5e5dfa32002-02-05 02:51:01 +0000240 }
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000241
Chris Lattner5e5dfa32002-02-05 02:51:01 +0000242 // do for implicit operands as well
243 for (unsigned i=0; i < MInst->getNumImplicitRefs(); ++i) {
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000244 if (MInst->getImplicitOp(i).isDef())
Chris Lattner5e5dfa32002-02-05 02:51:01 +0000245 LVS.erase(MInst->getImplicitRef(i));
246 }
247
Chris Lattner2f898d22002-02-05 06:02:59 +0000248 for (MachineInstr::const_val_op_iterator OpI = MInst->begin(),
249 OpE = MInst->end(); OpI != OpE; ++OpI) {
Chris Lattnerfb005fe2002-04-09 05:14:14 +0000250 if (!isa<BasicBlock>(*OpI)) // don't process labels
Vikram S. Adve9afa88c2002-07-08 22:56:34 +0000251 // add only if this operand is a use
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000252 if (OpI.isUse())
Chris Lattnerfb005fe2002-04-09 05:14:14 +0000253 LVS.insert(*OpI); // An operand is a use - so add to use set
Chris Lattner5e5dfa32002-02-05 02:51:01 +0000254 }
255
256 // do for implicit operands as well
Chris Lattnerfb005fe2002-04-09 05:14:14 +0000257 for (unsigned i = 0, e = MInst->getNumImplicitRefs(); i != e; ++i)
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000258 if (MInst->getImplicitOp(i).isUse())
Chris Lattner5e5dfa32002-02-05 02:51:01 +0000259 LVS.insert(MInst->getImplicitRef(i));
Chris Lattner5e5dfa32002-02-05 02:51:01 +0000260}
Ruchira Sasanka789cebb2001-12-08 21:05:27 +0000261
262//-----------------------------------------------------------------------------
263// This method calculates the live variable information for all the
264// instructions in a basic block and enter the newly constructed live
Chris Lattnera51c7a82002-02-04 23:31:16 +0000265// variable sets into a the caches (MInst2LVSetAI, MInst2LVSetBI)
Ruchira Sasanka789cebb2001-12-08 21:05:27 +0000266//-----------------------------------------------------------------------------
Chris Lattnera51c7a82002-02-04 23:31:16 +0000267
Chris Lattner483e14e2002-04-27 07:27:19 +0000268void FunctionLiveVarInfo::calcLiveVarSetsForBB(const BasicBlock *BB) {
Chris Lattnere9d3c6b2003-10-20 20:52:23 +0000269 BBLiveVar *BBLV = BBLiveVarInfo[BB];
Chris Lattner601fc7c2002-10-28 18:01:21 +0000270 assert(BBLV && "BBLiveVar annotation doesn't exist?");
271 const MachineBasicBlock &MIVec = BBLV->getMachineBasicBlock();
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000272 const MachineFunction &MF = MachineFunction::get(M);
273 const TargetMachine &TM = MF.getTarget();
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000274
Chris Lattnerfb005fe2002-04-09 05:14:14 +0000275 if (DEBUG_LV >= LV_DEBUG_Instr)
276 std::cerr << "\n======For BB " << BB->getName()
277 << ": Live var sets for instructions======\n";
Vikram S. Adve9cf85a72002-03-18 03:45:41 +0000278
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000279 ValueSet *SetAI = &getOutSetOfBB(BB); // init SetAI with OutSet
280 ValueSet CurSet(*SetAI); // CurSet now contains OutSet
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000281
Ruchira Sasankae27c3442001-08-20 21:12:49 +0000282 // iterate over all the machine instructions in BB
Chris Lattner55291ea2002-10-28 01:41:47 +0000283 for (MachineBasicBlock::const_reverse_iterator MII = MIVec.rbegin(),
Chris Lattnera51c7a82002-02-04 23:31:16 +0000284 MIE = MIVec.rend(); MII != MIE; ++MII) {
285 // MI is cur machine inst
Alkis Evlogimenosc0b9dc52004-02-12 02:27:10 +0000286 const MachineInstr *MI = &*MII;
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000287
Chris Lattnera51c7a82002-02-04 23:31:16 +0000288 MInst2LVSetAI[MI] = SetAI; // record in After Inst map
Ruchira Sasankae27c3442001-08-20 21:12:49 +0000289
Chris Lattnerfb005fe2002-04-09 05:14:14 +0000290 applyTranferFuncForMInst(CurSet, MI); // apply the transfer Func
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000291 ValueSet *NewSet = new ValueSet(CurSet); // create a new set with a copy
292 // of the set after T/F
Chris Lattnera51c7a82002-02-04 23:31:16 +0000293 MInst2LVSetBI[MI] = NewSet; // record in Before Inst map
Ruchira Sasankae27c3442001-08-20 21:12:49 +0000294
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000295 // If the current machine instruction has delay slots, mark values
296 // used by this instruction as live before and after each delay slot
297 // instruction (After(MI) is the same as Before(MI+1) except for last MI).
Brian Gaeke12c1d2c2004-02-11 20:47:34 +0000298 if (unsigned DS = TM.getInstrInfo().getNumDelaySlots(MI->getOpcode())) {
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000299 MachineBasicBlock::const_iterator fwdMII = MII.base(); // ptr to *next* MI
300 for (unsigned i = 0; i < DS; ++i, ++fwdMII) {
301 assert(fwdMII != MIVec.end() && "Missing instruction in delay slot?");
Alkis Evlogimenosc0b9dc52004-02-12 02:27:10 +0000302 const MachineInstr* DelaySlotMI = fwdMII;
Brian Gaeke12c1d2c2004-02-11 20:47:34 +0000303 if (! TM.getInstrInfo().isNop(DelaySlotMI->getOpcode())) {
Vikram S. Adve891bd822003-08-14 20:45:56 +0000304 set_union(*MInst2LVSetBI[DelaySlotMI], *NewSet);
305 if (i+1 == DS)
306 set_union(*MInst2LVSetAI[DelaySlotMI], *NewSet);
307 }
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000308 }
309 }
310
Vikram S. Adve9cf85a72002-03-18 03:45:41 +0000311 if (DEBUG_LV >= LV_DEBUG_Instr) {
Chris Lattnerfb005fe2002-04-09 05:14:14 +0000312 std::cerr << "\nLive var sets before/after instruction " << *MI;
Anand Shuklaa9284032002-06-25 20:35:19 +0000313 std::cerr << " Before: "; printSet(*NewSet); std::cerr << "\n";
314 std::cerr << " After : "; printSet(*SetAI); std::cerr << "\n";
Vikram S. Adve9cf85a72002-03-18 03:45:41 +0000315 }
316
Ruchira Sasankae27c3442001-08-20 21:12:49 +0000317 // SetAI will be used in the next iteration
318 SetAI = NewSet;
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000319 }
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000320}
Brian Gaeked0fde302003-11-11 22:41:34 +0000321
322} // End llvm namespace