blob: 588ec646da766e6d36d97486328e1cd0aae0600b [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
Chris Lattner1e435162002-07-26 21:12:44 +000026static RegisterAnalysis<FunctionLiveVarInfo>
27X("livevar", "Live Variable Analysis");
Ruchira Sasanka683847f2001-07-24 17:14:13 +000028
Chris Lattner70e60cb2002-05-22 17:08:27 +000029LiveVarDebugLevel_t DEBUG_LV;
30
Chris Lattner5ff62e92002-07-22 02:10:13 +000031static cl::opt<LiveVarDebugLevel_t, true>
32DEBUG_LV_opt("dlivevar", cl::Hidden, cl::location(DEBUG_LV),
33 cl::desc("enable live-variable debugging information"),
34 cl::values(
35clEnumValN(LV_DEBUG_None , "n", "disable debug output"),
36clEnumValN(LV_DEBUG_Normal , "y", "enable debug output"),
37clEnumValN(LV_DEBUG_Instr, "i", "print live-var sets before/after "
38 "every machine instrn"),
39clEnumValN(LV_DEBUG_Verbose, "v", "print def, use sets for every instrn also"),
40 0));
Vikram S. Adve9cf85a72002-03-18 03:45:41 +000041
Chris Lattner70e60cb2002-05-22 17:08:27 +000042
43
Chris Lattnerab584112002-02-05 00:34:50 +000044//-----------------------------------------------------------------------------
45// Accessor Functions
46//-----------------------------------------------------------------------------
47
48// gets OutSet of a BB
Chris Lattner483e14e2002-04-27 07:27:19 +000049const ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) const {
Chris Lattnere9d3c6b2003-10-20 20:52:23 +000050 return BBLiveVarInfo.find(BB)->second->getOutSet();
Chris Lattnerab584112002-02-05 00:34:50 +000051}
Vikram S. Adve88d962a2003-08-12 22:19:59 +000052 ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) {
Chris Lattnere9d3c6b2003-10-20 20:52:23 +000053 return BBLiveVarInfo[BB]->getOutSet();
Vikram S. Adve88d962a2003-08-12 22:19:59 +000054}
Chris Lattnerab584112002-02-05 00:34:50 +000055
56// gets InSet of a BB
Chris Lattner483e14e2002-04-27 07:27:19 +000057const ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const {
Chris Lattnere9d3c6b2003-10-20 20:52:23 +000058 return BBLiveVarInfo.find(BB)->second->getInSet();
Chris Lattnerab584112002-02-05 00:34:50 +000059}
Chris Lattnere9d3c6b2003-10-20 20:52:23 +000060ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) {
61 return BBLiveVarInfo[BB]->getInSet();
Vikram S. Adve88d962a2003-08-12 22:19:59 +000062}
Chris Lattnerab584112002-02-05 00:34:50 +000063
Chris Lattnerbdfd3282002-02-04 20:49:04 +000064
65//-----------------------------------------------------------------------------
Chris Lattnerf57b8452002-04-27 06:56:12 +000066// Performs live var analysis for a function
Chris Lattnerbdfd3282002-02-04 20:49:04 +000067//-----------------------------------------------------------------------------
68
Chris Lattner18961502002-06-25 16:12:52 +000069bool FunctionLiveVarInfo::runOnFunction(Function &F) {
70 M = &F;
Chris Lattnera51c7a82002-02-04 23:31:16 +000071 if (DEBUG_LV) std::cerr << "Analysing live variables ...\n";
Chris Lattnerbdfd3282002-02-04 20:49:04 +000072
73 // create and initialize all the BBLiveVars of the CFG
Chris Lattner18961502002-06-25 16:12:52 +000074 constructBBs(M);
Chris Lattnerbdfd3282002-02-04 20:49:04 +000075
Vikram S. Adve9cf85a72002-03-18 03:45:41 +000076 unsigned int iter=0;
Chris Lattner18961502002-06-25 16:12:52 +000077 while (doSingleBackwardPass(M, iter++))
Chris Lattnerbdfd3282002-02-04 20:49:04 +000078 ; // Iterate until we are done.
79
Chris Lattnera51c7a82002-02-04 23:31:16 +000080 if (DEBUG_LV) std::cerr << "Live Variable Analysis complete!\n";
Chris Lattnerbdfd3282002-02-04 20:49:04 +000081 return false;
82}
83
84
85//-----------------------------------------------------------------------------
86// constructs BBLiveVars and init Def and In sets
87//-----------------------------------------------------------------------------
88
Chris Lattner601fc7c2002-10-28 18:01:21 +000089void FunctionLiveVarInfo::constructBBs(const Function *F) {
90 unsigned POId = 0; // Reverse Depth-first Order ID
91 std::map<const BasicBlock*, unsigned> PONumbering;
Chris Lattnerbdfd3282002-02-04 20:49:04 +000092
Chris Lattner601fc7c2002-10-28 18:01:21 +000093 for (po_iterator<const Function*> BBI = po_begin(M), BBE = po_end(M);
94 BBI != BBE; ++BBI)
95 PONumbering[*BBI] = POId++;
96
97 MachineFunction &MF = MachineFunction::get(F);
98 for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
99 const BasicBlock &BB = *I->getBasicBlock(); // get the current BB
Chris Lattner0665a5f2002-02-05 01:43:49 +0000100 if (DEBUG_LV) std::cerr << " For BB " << RAV(BB) << ":\n";
Chris Lattnerbdfd3282002-02-04 20:49:04 +0000101
Chris Lattner601fc7c2002-10-28 18:01:21 +0000102 BBLiveVar *LVBB;
103 std::map<const BasicBlock*, unsigned>::iterator POI = PONumbering.find(&BB);
104 if (POI != PONumbering.end()) {
105 // create a new BBLiveVar
Chris Lattnere9d3c6b2003-10-20 20:52:23 +0000106 LVBB = new BBLiveVar(BB, *I, POId);
Chris Lattner601fc7c2002-10-28 18:01:21 +0000107 } else {
108 // The PO iterator does not discover unreachable blocks, but the random
109 // iterator later may access these blocks. We must make sure to
110 // initialize unreachable blocks as well. However, LV info is not correct
111 // for those blocks (they are not analyzed)
112 //
Chris Lattnere9d3c6b2003-10-20 20:52:23 +0000113 LVBB = new BBLiveVar(BB, *I, ++POId);
Chris Lattner601fc7c2002-10-28 18:01:21 +0000114 }
Chris Lattnere9d3c6b2003-10-20 20:52:23 +0000115 BBLiveVarInfo[&BB] = LVBB;
Chris Lattnerbdfd3282002-02-04 20:49:04 +0000116
Chris Lattnera51c7a82002-02-04 23:31:16 +0000117 if (DEBUG_LV)
Chris Lattnerbdfd3282002-02-04 20:49:04 +0000118 LVBB->printAllSets();
119 }
Chris Lattnerbdfd3282002-02-04 20:49:04 +0000120}
121
122
123//-----------------------------------------------------------------------------
124// do one backward pass over the CFG (for iterative analysis)
125//-----------------------------------------------------------------------------
Chris Lattnera51c7a82002-02-04 23:31:16 +0000126
Chris Lattner483e14e2002-04-27 07:27:19 +0000127bool FunctionLiveVarInfo::doSingleBackwardPass(const Function *M,
128 unsigned iter) {
Vikram S. Adve9cf85a72002-03-18 03:45:41 +0000129 if (DEBUG_LV) std::cerr << "\n After Backward Pass " << iter << "...\n";
Chris Lattnerbdfd3282002-02-04 20:49:04 +0000130
Chris Lattnera51c7a82002-02-04 23:31:16 +0000131 bool NeedAnotherIteration = false;
Chris Lattnerfb005fe2002-04-09 05:14:14 +0000132 for (po_iterator<const Function*> BBI = po_begin(M), BBE = po_end(M);
133 BBI != BBE; ++BBI) {
Chris Lattnere9d3c6b2003-10-20 20:52:23 +0000134 BBLiveVar *LVBB = BBLiveVarInfo[*BBI];
Chris Lattnera51c7a82002-02-04 23:31:16 +0000135 assert(LVBB && "BasicBlock information not set for block!");
Chris Lattnerbdfd3282002-02-04 20:49:04 +0000136
Chris Lattnera51c7a82002-02-04 23:31:16 +0000137 if (DEBUG_LV) std::cerr << " For BB " << (*BBI)->getName() << ":\n";
Chris Lattnerbdfd3282002-02-04 20:49:04 +0000138
Vikram S. Adve9cf85a72002-03-18 03:45:41 +0000139 // InSets are initialized to "GenSet". Recompute only if OutSet changed.
Chris Lattnerbdfd3282002-02-04 20:49:04 +0000140 if(LVBB->isOutSetChanged())
141 LVBB->applyTransferFunc(); // apply the Tran Func to calc InSet
Vikram S. Adve9cf85a72002-03-18 03:45:41 +0000142
Chris Lattnerfb005fe2002-04-09 05:14:14 +0000143 // OutSets are initialized to EMPTY. Recompute on first iter or if InSet
144 // changed.
Vikram S. Adve9cf85a72002-03-18 03:45:41 +0000145 if (iter == 0 || LVBB->isInSetChanged()) // to calc Outsets of preds
Chris Lattnere9d3c6b2003-10-20 20:52:23 +0000146 NeedAnotherIteration |= LVBB->applyFlowFunc(BBLiveVarInfo);
Vikram S. Adve9cf85a72002-03-18 03:45:41 +0000147
Chris Lattnera51c7a82002-02-04 23:31:16 +0000148 if (DEBUG_LV) LVBB->printInOutSets();
Chris Lattnerbdfd3282002-02-04 20:49:04 +0000149 }
150
151 // true if we need to reiterate over the CFG
152 return NeedAnotherIteration;
153}
154
155
Chris Lattner483e14e2002-04-27 07:27:19 +0000156void FunctionLiveVarInfo::releaseMemory() {
Chris Lattnere9d3c6b2003-10-20 20:52:23 +0000157 // First remove all BBLiveVars created in constructBBs().
158 if (M) {
Chris Lattnerb7653df2002-04-08 22:03:57 +0000159 for (Function::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
Chris Lattnere9d3c6b2003-10-20 20:52:23 +0000160 delete BBLiveVarInfo[I];
161 BBLiveVarInfo.clear();
162 }
Chris Lattner6357a3f2002-02-05 06:52:25 +0000163 M = 0;
Ruchira Sasanka789cebb2001-12-08 21:05:27 +0000164
Chris Lattner5e5dfa32002-02-05 02:51:01 +0000165 // Then delete all objects of type ValueSet created in calcLiveVarSetsForBB
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000166 // and entered into MInst2LVSetBI and MInst2LVSetAI (these are caches
167 // to return ValueSet's before/after a machine instruction quickly).
168 // We do not need to free up ValueSets in MInst2LVSetAI because it holds
169 // pointers to the same sets as in MInst2LVSetBI (for all instructions
170 // except the last one in a BB) or in BBLiveVar (for the last instruction).
Ruchira Sasanka789cebb2001-12-08 21:05:27 +0000171 //
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000172 for (hash_map<const MachineInstr*, ValueSet*>::iterator
Chris Lattnerab584112002-02-05 00:34:50 +0000173 MI = MInst2LVSetBI.begin(),
Chris Lattnera51c7a82002-02-04 23:31:16 +0000174 ME = MInst2LVSetBI.end(); MI != ME; ++MI)
Chris Lattner5e5dfa32002-02-05 02:51:01 +0000175 delete MI->second; // delete all ValueSets in MInst2LVSetBI
Chris Lattner4fd2dbb2002-02-04 20:00:08 +0000176
177 MInst2LVSetBI.clear();
178 MInst2LVSetAI.clear();
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000179}
180
181
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000182
183
Ruchira Sasanka789cebb2001-12-08 21:05:27 +0000184//-----------------------------------------------------------------------------
Chris Lattnera51c7a82002-02-04 23:31:16 +0000185// Following functions will give the LiveVar info for any machine instr in
Chris Lattnerf57b8452002-04-27 06:56:12 +0000186// a function. It should be called after a call to analyze().
Chris Lattnera51c7a82002-02-04 23:31:16 +0000187//
Misha Brukman2f2d0652003-09-11 18:14:24 +0000188// These functions calculate live var info for all the machine instrs in a
Chris Lattnera51c7a82002-02-04 23:31:16 +0000189// BB when LVInfo for one inst is requested. Hence, this function is useful
190// when live var info is required for many (or all) instructions in a basic
Chris Lattnerf57b8452002-04-27 06:56:12 +0000191// block. Also, the arguments to this function does not require specific
Chris Lattnera51c7a82002-02-04 23:31:16 +0000192// iterators.
Ruchira Sasanka789cebb2001-12-08 21:05:27 +0000193//-----------------------------------------------------------------------------
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000194
Ruchira Sasanka789cebb2001-12-08 21:05:27 +0000195//-----------------------------------------------------------------------------
196// Gives live variable information before a machine instruction
197//-----------------------------------------------------------------------------
Chris Lattnera51c7a82002-02-04 23:31:16 +0000198
Chris Lattner748697d2002-02-05 04:20:12 +0000199const ValueSet &
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000200FunctionLiveVarInfo::getLiveVarSetBeforeMInst(const MachineInstr *MI,
Chris Lattner483e14e2002-04-27 07:27:19 +0000201 const BasicBlock *BB) {
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000202 ValueSet* &LVSet = MInst2LVSetBI[MI]; // ref. to map entry
Vikram S. Adve7a81a0f2003-07-29 19:42:32 +0000203 if (LVSet == NULL && BB != NULL) { // if not found and BB provided
204 calcLiveVarSetsForBB(BB); // calc LVSet for all instrs in BB
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000205 assert(LVSet != NULL);
Ruchira Sasankae27c3442001-08-20 21:12:49 +0000206 }
Vikram S. Adve7a81a0f2003-07-29 19:42:32 +0000207 return *LVSet;
Ruchira Sasankae27c3442001-08-20 21:12:49 +0000208}
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000209
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000210
Ruchira Sasanka789cebb2001-12-08 21:05:27 +0000211//-----------------------------------------------------------------------------
212// Gives live variable information after a machine instruction
213//-----------------------------------------------------------------------------
Vikram S. Adve7a81a0f2003-07-29 19:42:32 +0000214
Chris Lattner748697d2002-02-05 04:20:12 +0000215const ValueSet &
Chris Lattner483e14e2002-04-27 07:27:19 +0000216FunctionLiveVarInfo::getLiveVarSetAfterMInst(const MachineInstr *MI,
217 const BasicBlock *BB) {
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000218
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000219 ValueSet* &LVSet = MInst2LVSetAI[MI]; // ref. to map entry
Vikram S. Adve7a81a0f2003-07-29 19:42:32 +0000220 if (LVSet == NULL && BB != NULL) { // if not found and BB provided
221 calcLiveVarSetsForBB(BB); // calc LVSet for all instrs in BB
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000222 assert(LVSet != NULL);
Ruchira Sasankae27c3442001-08-20 21:12:49 +0000223 }
Vikram S. Adve7a81a0f2003-07-29 19:42:32 +0000224 return *LVSet;
Ruchira Sasankae27c3442001-08-20 21:12:49 +0000225}
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000226
Chris Lattner5e5dfa32002-02-05 02:51:01 +0000227// This function applies a machine instr to a live var set (accepts OutSet) and
228// makes necessary changes to it (produces InSet). Note that two for loops are
229// used to first kill all defs and then to add all uses. This is because there
Misha Brukman2f2d0652003-09-11 18:14:24 +0000230// can be instructions like Val = Val + 1 since we allow multiple defs to a
Chris Lattner5e5dfa32002-02-05 02:51:01 +0000231// machine instruction operand.
232//
233static void applyTranferFuncForMInst(ValueSet &LVS, const MachineInstr *MInst) {
Chris Lattner2f898d22002-02-05 06:02:59 +0000234 for (MachineInstr::const_val_op_iterator OpI = MInst->begin(),
235 OpE = MInst->end(); OpI != OpE; ++OpI) {
Vikram S. Advea22eace2003-05-27 00:06:48 +0000236 if (OpI.isDefOnly() || OpI.isDefAndUse()) // kill if this operand is a def
237 LVS.erase(*OpI); // this definition kills any uses
Chris Lattner5e5dfa32002-02-05 02:51:01 +0000238 }
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000239
Chris Lattner5e5dfa32002-02-05 02:51:01 +0000240 // do for implicit operands as well
241 for (unsigned i=0; i < MInst->getNumImplicitRefs(); ++i) {
Vikram S. Advea22eace2003-05-27 00:06:48 +0000242 if (MInst->getImplicitOp(i).opIsDefOnly() ||
243 MInst->getImplicitOp(i).opIsDefAndUse())
Chris Lattner5e5dfa32002-02-05 02:51:01 +0000244 LVS.erase(MInst->getImplicitRef(i));
245 }
246
Chris Lattner2f898d22002-02-05 06:02:59 +0000247 for (MachineInstr::const_val_op_iterator OpI = MInst->begin(),
248 OpE = MInst->end(); OpI != OpE; ++OpI) {
Chris Lattnerfb005fe2002-04-09 05:14:14 +0000249 if (!isa<BasicBlock>(*OpI)) // don't process labels
Vikram S. Adve9afa88c2002-07-08 22:56:34 +0000250 // add only if this operand is a use
Vikram S. Advea22eace2003-05-27 00:06:48 +0000251 if (!OpI.isDefOnly() || OpI.isDefAndUse() )
Chris Lattnerfb005fe2002-04-09 05:14:14 +0000252 LVS.insert(*OpI); // An operand is a use - so add to use set
Chris Lattner5e5dfa32002-02-05 02:51:01 +0000253 }
254
255 // do for implicit operands as well
Chris Lattnerfb005fe2002-04-09 05:14:14 +0000256 for (unsigned i = 0, e = MInst->getNumImplicitRefs(); i != e; ++i)
Vikram S. Advea22eace2003-05-27 00:06:48 +0000257 if (MInst->getImplicitOp(i).opIsUse() ||
258 MInst->getImplicitOp(i).opIsDefAndUse())
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
286 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).
298 if (unsigned DS = TM.getInstrInfo().getNumDelaySlots(MI->getOpCode())) {
299 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?");
302 MachineInstr* DelaySlotMI = *fwdMII;
Vikram S. Adve891bd822003-08-14 20:45:56 +0000303 if (! TM.getInstrInfo().isNop(DelaySlotMI->getOpCode())) {
304 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}