blob: 2883bf1c0925aa8415b0056317ab18f88d30cc20 [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
Brian Gaeke748fba12004-02-24 19:46:00 +000015#include "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"
Reid Spencer551ccae2004-09-01 22:55:40 +000021#include "llvm/ADT/PostOrderIterator.h"
22#include "llvm/ADT/SetOperations.h"
23#include "llvm/Support/CommandLine.h"
Chris Lattner92ba2aa2003-01-14 23:05:08 +000024#include "BBLiveVar.h"
Reid Spencer954da372004-07-04 12:19:56 +000025#include <iostream>
Ruchira Sasanka683847f2001-07-24 17:14:13 +000026
Brian Gaeked0fde302003-11-11 22:41:34 +000027namespace llvm {
28
Chris Lattner1e435162002-07-26 21:12:44 +000029static RegisterAnalysis<FunctionLiveVarInfo>
30X("livevar", "Live Variable Analysis");
Ruchira Sasanka683847f2001-07-24 17:14:13 +000031
Chris Lattner70e60cb2002-05-22 17:08:27 +000032LiveVarDebugLevel_t DEBUG_LV;
33
Chris Lattner5ff62e92002-07-22 02:10:13 +000034static cl::opt<LiveVarDebugLevel_t, true>
35DEBUG_LV_opt("dlivevar", cl::Hidden, cl::location(DEBUG_LV),
36 cl::desc("enable live-variable debugging information"),
37 cl::values(
38clEnumValN(LV_DEBUG_None , "n", "disable debug output"),
39clEnumValN(LV_DEBUG_Normal , "y", "enable debug output"),
40clEnumValN(LV_DEBUG_Instr, "i", "print live-var sets before/after "
41 "every machine instrn"),
42clEnumValN(LV_DEBUG_Verbose, "v", "print def, use sets for every instrn also"),
Chris Lattner4d143ee2004-07-16 00:08:28 +000043 clEnumValEnd));
Vikram S. Adve9cf85a72002-03-18 03:45:41 +000044
Chris Lattner70e60cb2002-05-22 17:08:27 +000045
46
Chris Lattnerab584112002-02-05 00:34:50 +000047//-----------------------------------------------------------------------------
48// Accessor Functions
49//-----------------------------------------------------------------------------
50
51// gets OutSet of a BB
Chris Lattner483e14e2002-04-27 07:27:19 +000052const ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) const {
Chris Lattnere9d3c6b2003-10-20 20:52:23 +000053 return BBLiveVarInfo.find(BB)->second->getOutSet();
Chris Lattnerab584112002-02-05 00:34:50 +000054}
Vikram S. Adve88d962a2003-08-12 22:19:59 +000055 ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) {
Chris Lattnere9d3c6b2003-10-20 20:52:23 +000056 return BBLiveVarInfo[BB]->getOutSet();
Vikram S. Adve88d962a2003-08-12 22:19:59 +000057}
Chris Lattnerab584112002-02-05 00:34:50 +000058
59// gets InSet of a BB
Chris Lattner483e14e2002-04-27 07:27:19 +000060const ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const {
Chris Lattnere9d3c6b2003-10-20 20:52:23 +000061 return BBLiveVarInfo.find(BB)->second->getInSet();
Chris Lattnerab584112002-02-05 00:34:50 +000062}
Chris Lattnere9d3c6b2003-10-20 20:52:23 +000063ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) {
64 return BBLiveVarInfo[BB]->getInSet();
Vikram S. Adve88d962a2003-08-12 22:19:59 +000065}
Chris Lattnerab584112002-02-05 00:34:50 +000066
Chris Lattnerbdfd3282002-02-04 20:49:04 +000067
68//-----------------------------------------------------------------------------
Chris Lattnerf57b8452002-04-27 06:56:12 +000069// Performs live var analysis for a function
Chris Lattnerbdfd3282002-02-04 20:49:04 +000070//-----------------------------------------------------------------------------
71
Chris Lattner18961502002-06-25 16:12:52 +000072bool FunctionLiveVarInfo::runOnFunction(Function &F) {
73 M = &F;
Chris Lattnera51c7a82002-02-04 23:31:16 +000074 if (DEBUG_LV) std::cerr << "Analysing live variables ...\n";
Chris Lattnerbdfd3282002-02-04 20:49:04 +000075
76 // create and initialize all the BBLiveVars of the CFG
Chris Lattner18961502002-06-25 16:12:52 +000077 constructBBs(M);
Chris Lattnerbdfd3282002-02-04 20:49:04 +000078
Vikram S. Adve9cf85a72002-03-18 03:45:41 +000079 unsigned int iter=0;
Chris Lattner18961502002-06-25 16:12:52 +000080 while (doSingleBackwardPass(M, iter++))
Chris Lattnerbdfd3282002-02-04 20:49:04 +000081 ; // Iterate until we are done.
82
Chris Lattnera51c7a82002-02-04 23:31:16 +000083 if (DEBUG_LV) std::cerr << "Live Variable Analysis complete!\n";
Chris Lattnerbdfd3282002-02-04 20:49:04 +000084 return false;
85}
86
87
88//-----------------------------------------------------------------------------
89// constructs BBLiveVars and init Def and In sets
90//-----------------------------------------------------------------------------
91
Chris Lattner601fc7c2002-10-28 18:01:21 +000092void FunctionLiveVarInfo::constructBBs(const Function *F) {
93 unsigned POId = 0; // Reverse Depth-first Order ID
94 std::map<const BasicBlock*, unsigned> PONumbering;
Chris Lattnerbdfd3282002-02-04 20:49:04 +000095
Chris Lattner601fc7c2002-10-28 18:01:21 +000096 for (po_iterator<const Function*> BBI = po_begin(M), BBE = po_end(M);
97 BBI != BBE; ++BBI)
98 PONumbering[*BBI] = POId++;
99
100 MachineFunction &MF = MachineFunction::get(F);
101 for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
102 const BasicBlock &BB = *I->getBasicBlock(); // get the current BB
Chris Lattner0665a5f2002-02-05 01:43:49 +0000103 if (DEBUG_LV) std::cerr << " For BB " << RAV(BB) << ":\n";
Chris Lattnerbdfd3282002-02-04 20:49:04 +0000104
Chris Lattner601fc7c2002-10-28 18:01:21 +0000105 BBLiveVar *LVBB;
106 std::map<const BasicBlock*, unsigned>::iterator POI = PONumbering.find(&BB);
107 if (POI != PONumbering.end()) {
108 // create a new BBLiveVar
Chris Lattnere9d3c6b2003-10-20 20:52:23 +0000109 LVBB = new BBLiveVar(BB, *I, POId);
Chris Lattner601fc7c2002-10-28 18:01:21 +0000110 } else {
111 // The PO iterator does not discover unreachable blocks, but the random
112 // iterator later may access these blocks. We must make sure to
113 // initialize unreachable blocks as well. However, LV info is not correct
114 // for those blocks (they are not analyzed)
115 //
Chris Lattnere9d3c6b2003-10-20 20:52:23 +0000116 LVBB = new BBLiveVar(BB, *I, ++POId);
Chris Lattner601fc7c2002-10-28 18:01:21 +0000117 }
Chris Lattnere9d3c6b2003-10-20 20:52:23 +0000118 BBLiveVarInfo[&BB] = LVBB;
Chris Lattnerbdfd3282002-02-04 20:49:04 +0000119
Chris Lattnera51c7a82002-02-04 23:31:16 +0000120 if (DEBUG_LV)
Chris Lattnerbdfd3282002-02-04 20:49:04 +0000121 LVBB->printAllSets();
122 }
Chris Lattnerbdfd3282002-02-04 20:49:04 +0000123}
124
125
126//-----------------------------------------------------------------------------
127// do one backward pass over the CFG (for iterative analysis)
128//-----------------------------------------------------------------------------
Chris Lattnera51c7a82002-02-04 23:31:16 +0000129
Chris Lattner483e14e2002-04-27 07:27:19 +0000130bool FunctionLiveVarInfo::doSingleBackwardPass(const Function *M,
131 unsigned iter) {
Vikram S. Adve9cf85a72002-03-18 03:45:41 +0000132 if (DEBUG_LV) std::cerr << "\n After Backward Pass " << iter << "...\n";
Chris Lattnerbdfd3282002-02-04 20:49:04 +0000133
Chris Lattnera51c7a82002-02-04 23:31:16 +0000134 bool NeedAnotherIteration = false;
Chris Lattnerfb005fe2002-04-09 05:14:14 +0000135 for (po_iterator<const Function*> BBI = po_begin(M), BBE = po_end(M);
136 BBI != BBE; ++BBI) {
Chris Lattnere9d3c6b2003-10-20 20:52:23 +0000137 BBLiveVar *LVBB = BBLiveVarInfo[*BBI];
Chris Lattnera51c7a82002-02-04 23:31:16 +0000138 assert(LVBB && "BasicBlock information not set for block!");
Chris Lattnerbdfd3282002-02-04 20:49:04 +0000139
Chris Lattnera51c7a82002-02-04 23:31:16 +0000140 if (DEBUG_LV) std::cerr << " For BB " << (*BBI)->getName() << ":\n";
Chris Lattnerbdfd3282002-02-04 20:49:04 +0000141
Vikram S. Adve9cf85a72002-03-18 03:45:41 +0000142 // InSets are initialized to "GenSet". Recompute only if OutSet changed.
Chris Lattnerbdfd3282002-02-04 20:49:04 +0000143 if(LVBB->isOutSetChanged())
144 LVBB->applyTransferFunc(); // apply the Tran Func to calc InSet
Vikram S. Adve9cf85a72002-03-18 03:45:41 +0000145
Chris Lattnerfb005fe2002-04-09 05:14:14 +0000146 // OutSets are initialized to EMPTY. Recompute on first iter or if InSet
147 // changed.
Vikram S. Adve9cf85a72002-03-18 03:45:41 +0000148 if (iter == 0 || LVBB->isInSetChanged()) // to calc Outsets of preds
Chris Lattnere9d3c6b2003-10-20 20:52:23 +0000149 NeedAnotherIteration |= LVBB->applyFlowFunc(BBLiveVarInfo);
Vikram S. Adve9cf85a72002-03-18 03:45:41 +0000150
Chris Lattnera51c7a82002-02-04 23:31:16 +0000151 if (DEBUG_LV) LVBB->printInOutSets();
Chris Lattnerbdfd3282002-02-04 20:49:04 +0000152 }
153
154 // true if we need to reiterate over the CFG
155 return NeedAnotherIteration;
156}
157
158
Chris Lattner483e14e2002-04-27 07:27:19 +0000159void FunctionLiveVarInfo::releaseMemory() {
Chris Lattnere9d3c6b2003-10-20 20:52:23 +0000160 // First remove all BBLiveVars created in constructBBs().
161 if (M) {
Chris Lattnerb7653df2002-04-08 22:03:57 +0000162 for (Function::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
Chris Lattnere9d3c6b2003-10-20 20:52:23 +0000163 delete BBLiveVarInfo[I];
164 BBLiveVarInfo.clear();
165 }
Chris Lattner6357a3f2002-02-05 06:52:25 +0000166 M = 0;
Ruchira Sasanka789cebb2001-12-08 21:05:27 +0000167
Chris Lattner5e5dfa32002-02-05 02:51:01 +0000168 // Then delete all objects of type ValueSet created in calcLiveVarSetsForBB
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000169 // and entered into MInst2LVSetBI and MInst2LVSetAI (these are caches
170 // to return ValueSet's before/after a machine instruction quickly).
171 // We do not need to free up ValueSets in MInst2LVSetAI because it holds
172 // pointers to the same sets as in MInst2LVSetBI (for all instructions
173 // except the last one in a BB) or in BBLiveVar (for the last instruction).
Ruchira Sasanka789cebb2001-12-08 21:05:27 +0000174 //
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000175 for (hash_map<const MachineInstr*, ValueSet*>::iterator
Chris Lattnerab584112002-02-05 00:34:50 +0000176 MI = MInst2LVSetBI.begin(),
Chris Lattnera51c7a82002-02-04 23:31:16 +0000177 ME = MInst2LVSetBI.end(); MI != ME; ++MI)
Chris Lattner5e5dfa32002-02-05 02:51:01 +0000178 delete MI->second; // delete all ValueSets in MInst2LVSetBI
Chris Lattner4fd2dbb2002-02-04 20:00:08 +0000179
180 MInst2LVSetBI.clear();
181 MInst2LVSetAI.clear();
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000182}
183
184
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000185
186
Ruchira Sasanka789cebb2001-12-08 21:05:27 +0000187//-----------------------------------------------------------------------------
Chris Lattnera51c7a82002-02-04 23:31:16 +0000188// Following functions will give the LiveVar info for any machine instr in
Chris Lattnerf57b8452002-04-27 06:56:12 +0000189// a function. It should be called after a call to analyze().
Chris Lattnera51c7a82002-02-04 23:31:16 +0000190//
Misha Brukman2f2d0652003-09-11 18:14:24 +0000191// These functions calculate live var info for all the machine instrs in a
Chris Lattnera51c7a82002-02-04 23:31:16 +0000192// BB when LVInfo for one inst is requested. Hence, this function is useful
193// when live var info is required for many (or all) instructions in a basic
Chris Lattnerf57b8452002-04-27 06:56:12 +0000194// block. Also, the arguments to this function does not require specific
Chris Lattnera51c7a82002-02-04 23:31:16 +0000195// iterators.
Ruchira Sasanka789cebb2001-12-08 21:05:27 +0000196//-----------------------------------------------------------------------------
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000197
Ruchira Sasanka789cebb2001-12-08 21:05:27 +0000198//-----------------------------------------------------------------------------
199// Gives live variable information before a machine instruction
200//-----------------------------------------------------------------------------
Chris Lattnera51c7a82002-02-04 23:31:16 +0000201
Chris Lattner748697d2002-02-05 04:20:12 +0000202const ValueSet &
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000203FunctionLiveVarInfo::getLiveVarSetBeforeMInst(const MachineInstr *MI,
Chris Lattner483e14e2002-04-27 07:27:19 +0000204 const BasicBlock *BB) {
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000205 ValueSet* &LVSet = MInst2LVSetBI[MI]; // ref. to map entry
Vikram S. Adve7a81a0f2003-07-29 19:42:32 +0000206 if (LVSet == NULL && BB != NULL) { // if not found and BB provided
207 calcLiveVarSetsForBB(BB); // calc LVSet for all instrs in BB
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000208 assert(LVSet != NULL);
Ruchira Sasankae27c3442001-08-20 21:12:49 +0000209 }
Vikram S. Adve7a81a0f2003-07-29 19:42:32 +0000210 return *LVSet;
Ruchira Sasankae27c3442001-08-20 21:12:49 +0000211}
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000212
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000213
Ruchira Sasanka789cebb2001-12-08 21:05:27 +0000214//-----------------------------------------------------------------------------
215// Gives live variable information after a machine instruction
216//-----------------------------------------------------------------------------
Vikram S. Adve7a81a0f2003-07-29 19:42:32 +0000217
Chris Lattner748697d2002-02-05 04:20:12 +0000218const ValueSet &
Chris Lattner483e14e2002-04-27 07:27:19 +0000219FunctionLiveVarInfo::getLiveVarSetAfterMInst(const MachineInstr *MI,
220 const BasicBlock *BB) {
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000221
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000222 ValueSet* &LVSet = MInst2LVSetAI[MI]; // ref. to map entry
Vikram S. Adve7a81a0f2003-07-29 19:42:32 +0000223 if (LVSet == NULL && BB != NULL) { // if not found and BB provided
224 calcLiveVarSetsForBB(BB); // calc LVSet for all instrs in BB
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000225 assert(LVSet != NULL);
Ruchira Sasankae27c3442001-08-20 21:12:49 +0000226 }
Vikram S. Adve7a81a0f2003-07-29 19:42:32 +0000227 return *LVSet;
Ruchira Sasankae27c3442001-08-20 21:12:49 +0000228}
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000229
Chris Lattner5e5dfa32002-02-05 02:51:01 +0000230// This function applies a machine instr to a live var set (accepts OutSet) and
231// makes necessary changes to it (produces InSet). Note that two for loops are
232// used to first kill all defs and then to add all uses. This is because there
Misha Brukman2f2d0652003-09-11 18:14:24 +0000233// can be instructions like Val = Val + 1 since we allow multiple defs to a
Chris Lattner5e5dfa32002-02-05 02:51:01 +0000234// machine instruction operand.
235//
236static void applyTranferFuncForMInst(ValueSet &LVS, const MachineInstr *MInst) {
Chris Lattner2f898d22002-02-05 06:02:59 +0000237 for (MachineInstr::const_val_op_iterator OpI = MInst->begin(),
238 OpE = MInst->end(); OpI != OpE; ++OpI) {
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000239 if (OpI.isDef()) // kill if this operand is a def
Vikram S. Advea22eace2003-05-27 00:06:48 +0000240 LVS.erase(*OpI); // this definition kills any uses
Chris Lattner5e5dfa32002-02-05 02:51:01 +0000241 }
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000242
Chris Lattner5e5dfa32002-02-05 02:51:01 +0000243 // do for implicit operands as well
244 for (unsigned i=0; i < MInst->getNumImplicitRefs(); ++i) {
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000245 if (MInst->getImplicitOp(i).isDef())
Chris Lattner5e5dfa32002-02-05 02:51:01 +0000246 LVS.erase(MInst->getImplicitRef(i));
247 }
248
Chris Lattner2f898d22002-02-05 06:02:59 +0000249 for (MachineInstr::const_val_op_iterator OpI = MInst->begin(),
250 OpE = MInst->end(); OpI != OpE; ++OpI) {
Chris Lattnerfb005fe2002-04-09 05:14:14 +0000251 if (!isa<BasicBlock>(*OpI)) // don't process labels
Vikram S. Adve9afa88c2002-07-08 22:56:34 +0000252 // add only if this operand is a use
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000253 if (OpI.isUse())
Chris Lattnerfb005fe2002-04-09 05:14:14 +0000254 LVS.insert(*OpI); // An operand is a use - so add to use set
Chris Lattner5e5dfa32002-02-05 02:51:01 +0000255 }
256
257 // do for implicit operands as well
Chris Lattnerfb005fe2002-04-09 05:14:14 +0000258 for (unsigned i = 0, e = MInst->getNumImplicitRefs(); i != e; ++i)
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000259 if (MInst->getImplicitOp(i).isUse())
Chris Lattner5e5dfa32002-02-05 02:51:01 +0000260 LVS.insert(MInst->getImplicitRef(i));
Chris Lattner5e5dfa32002-02-05 02:51:01 +0000261}
Ruchira Sasanka789cebb2001-12-08 21:05:27 +0000262
263//-----------------------------------------------------------------------------
264// This method calculates the live variable information for all the
265// instructions in a basic block and enter the newly constructed live
Chris Lattnera51c7a82002-02-04 23:31:16 +0000266// variable sets into a the caches (MInst2LVSetAI, MInst2LVSetBI)
Ruchira Sasanka789cebb2001-12-08 21:05:27 +0000267//-----------------------------------------------------------------------------
Chris Lattnera51c7a82002-02-04 23:31:16 +0000268
Chris Lattner483e14e2002-04-27 07:27:19 +0000269void FunctionLiveVarInfo::calcLiveVarSetsForBB(const BasicBlock *BB) {
Chris Lattnere9d3c6b2003-10-20 20:52:23 +0000270 BBLiveVar *BBLV = BBLiveVarInfo[BB];
Chris Lattner601fc7c2002-10-28 18:01:21 +0000271 assert(BBLV && "BBLiveVar annotation doesn't exist?");
272 const MachineBasicBlock &MIVec = BBLV->getMachineBasicBlock();
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000273 const MachineFunction &MF = MachineFunction::get(M);
274 const TargetMachine &TM = MF.getTarget();
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000275
Chris Lattnerfb005fe2002-04-09 05:14:14 +0000276 if (DEBUG_LV >= LV_DEBUG_Instr)
277 std::cerr << "\n======For BB " << BB->getName()
278 << ": Live var sets for instructions======\n";
Vikram S. Adve9cf85a72002-03-18 03:45:41 +0000279
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000280 ValueSet *SetAI = &getOutSetOfBB(BB); // init SetAI with OutSet
281 ValueSet CurSet(*SetAI); // CurSet now contains OutSet
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000282
Ruchira Sasankae27c3442001-08-20 21:12:49 +0000283 // iterate over all the machine instructions in BB
Chris Lattner55291ea2002-10-28 01:41:47 +0000284 for (MachineBasicBlock::const_reverse_iterator MII = MIVec.rbegin(),
Chris Lattnera51c7a82002-02-04 23:31:16 +0000285 MIE = MIVec.rend(); MII != MIE; ++MII) {
286 // MI is cur machine inst
Alkis Evlogimenosc0b9dc52004-02-12 02:27:10 +0000287 const MachineInstr *MI = &*MII;
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000288
Chris Lattnera51c7a82002-02-04 23:31:16 +0000289 MInst2LVSetAI[MI] = SetAI; // record in After Inst map
Ruchira Sasankae27c3442001-08-20 21:12:49 +0000290
Chris Lattnerfb005fe2002-04-09 05:14:14 +0000291 applyTranferFuncForMInst(CurSet, MI); // apply the transfer Func
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000292 ValueSet *NewSet = new ValueSet(CurSet); // create a new set with a copy
293 // of the set after T/F
Chris Lattnera51c7a82002-02-04 23:31:16 +0000294 MInst2LVSetBI[MI] = NewSet; // record in Before Inst map
Ruchira Sasankae27c3442001-08-20 21:12:49 +0000295
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000296 // If the current machine instruction has delay slots, mark values
297 // used by this instruction as live before and after each delay slot
298 // instruction (After(MI) is the same as Before(MI+1) except for last MI).
Chris Lattnerd029cd22004-06-02 05:55:25 +0000299 if (unsigned DS = TM.getInstrInfo()->getNumDelaySlots(MI->getOpcode())) {
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000300 MachineBasicBlock::const_iterator fwdMII = MII.base(); // ptr to *next* MI
301 for (unsigned i = 0; i < DS; ++i, ++fwdMII) {
302 assert(fwdMII != MIVec.end() && "Missing instruction in delay slot?");
Alkis Evlogimenosc0b9dc52004-02-12 02:27:10 +0000303 const MachineInstr* DelaySlotMI = fwdMII;
Chris Lattnerd029cd22004-06-02 05:55:25 +0000304 if (! TM.getInstrInfo()->isNop(DelaySlotMI->getOpcode())) {
Vikram S. Adve891bd822003-08-14 20:45:56 +0000305 set_union(*MInst2LVSetBI[DelaySlotMI], *NewSet);
306 if (i+1 == DS)
307 set_union(*MInst2LVSetAI[DelaySlotMI], *NewSet);
308 }
Vikram S. Adve88d962a2003-08-12 22:19:59 +0000309 }
310 }
311
Vikram S. Adve9cf85a72002-03-18 03:45:41 +0000312 if (DEBUG_LV >= LV_DEBUG_Instr) {
Chris Lattnerfb005fe2002-04-09 05:14:14 +0000313 std::cerr << "\nLive var sets before/after instruction " << *MI;
Anand Shuklaa9284032002-06-25 20:35:19 +0000314 std::cerr << " Before: "; printSet(*NewSet); std::cerr << "\n";
315 std::cerr << " After : "; printSet(*SetAI); std::cerr << "\n";
Vikram S. Adve9cf85a72002-03-18 03:45:41 +0000316 }
317
Ruchira Sasankae27c3442001-08-20 21:12:49 +0000318 // SetAI will be used in the next iteration
319 SetAI = NewSet;
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000320 }
Ruchira Sasanka683847f2001-07-24 17:14:13 +0000321}
Brian Gaeked0fde302003-11-11 22:41:34 +0000322
323} // End llvm namespace