2002-04-27 06:56:12 +00:00
|
|
|
//===-- FunctionLiveVarInfo.cpp - Live Variable Analysis for a Function ---===//
|
2003-10-20 19:43:21 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2002-02-05 02:51:01 +00:00
|
|
|
//
|
2002-04-27 06:56:12 +00:00
|
|
|
// This is the interface to function level live variable information that is
|
2002-02-05 02:51:01 +00:00
|
|
|
// provided by live variable analysis.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2003-01-14 23:05:08 +00:00
|
|
|
#include "llvm/CodeGen/FunctionLiveVarInfo.h"
|
2001-08-20 21:12:49 +00:00
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2002-10-28 18:01:21 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2003-08-12 22:19:59 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2002-02-12 21:07:25 +00:00
|
|
|
#include "llvm/Support/CFG.h"
|
2001-11-27 00:03:19 +00:00
|
|
|
#include "Support/PostOrderIterator.h"
|
2002-02-05 03:35:53 +00:00
|
|
|
#include "Support/SetOperations.h"
|
2002-05-22 17:08:27 +00:00
|
|
|
#include "Support/CommandLine.h"
|
2003-01-14 23:05:08 +00:00
|
|
|
#include "BBLiveVar.h"
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2002-07-26 21:12:44 +00:00
|
|
|
static RegisterAnalysis<FunctionLiveVarInfo>
|
|
|
|
X("livevar", "Live Variable Analysis");
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2002-05-22 17:08:27 +00:00
|
|
|
LiveVarDebugLevel_t DEBUG_LV;
|
|
|
|
|
2002-07-22 02:10:13 +00:00
|
|
|
static cl::opt<LiveVarDebugLevel_t, true>
|
|
|
|
DEBUG_LV_opt("dlivevar", cl::Hidden, cl::location(DEBUG_LV),
|
|
|
|
cl::desc("enable live-variable debugging information"),
|
|
|
|
cl::values(
|
|
|
|
clEnumValN(LV_DEBUG_None , "n", "disable debug output"),
|
|
|
|
clEnumValN(LV_DEBUG_Normal , "y", "enable debug output"),
|
|
|
|
clEnumValN(LV_DEBUG_Instr, "i", "print live-var sets before/after "
|
|
|
|
"every machine instrn"),
|
|
|
|
clEnumValN(LV_DEBUG_Verbose, "v", "print def, use sets for every instrn also"),
|
|
|
|
0));
|
2002-03-18 03:45:41 +00:00
|
|
|
|
2002-05-22 17:08:27 +00:00
|
|
|
|
|
|
|
|
2002-02-05 00:34:50 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Accessor Functions
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// gets OutSet of a BB
|
2002-04-27 07:27:19 +00:00
|
|
|
const ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) const {
|
2003-10-20 20:52:23 +00:00
|
|
|
return BBLiveVarInfo.find(BB)->second->getOutSet();
|
2002-02-05 00:34:50 +00:00
|
|
|
}
|
2003-08-12 22:19:59 +00:00
|
|
|
ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) {
|
2003-10-20 20:52:23 +00:00
|
|
|
return BBLiveVarInfo[BB]->getOutSet();
|
2003-08-12 22:19:59 +00:00
|
|
|
}
|
2002-02-05 00:34:50 +00:00
|
|
|
|
|
|
|
// gets InSet of a BB
|
2002-04-27 07:27:19 +00:00
|
|
|
const ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const {
|
2003-10-20 20:52:23 +00:00
|
|
|
return BBLiveVarInfo.find(BB)->second->getInSet();
|
2002-02-05 00:34:50 +00:00
|
|
|
}
|
2003-10-20 20:52:23 +00:00
|
|
|
ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) {
|
|
|
|
return BBLiveVarInfo[BB]->getInSet();
|
2003-08-12 22:19:59 +00:00
|
|
|
}
|
2002-02-05 00:34:50 +00:00
|
|
|
|
2001-12-08 21:05:27 +00:00
|
|
|
|
2002-02-04 20:49:04 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2002-04-27 06:56:12 +00:00
|
|
|
// Performs live var analysis for a function
|
2002-02-04 20:49:04 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2001-12-08 21:05:27 +00:00
|
|
|
|
2002-06-25 16:12:52 +00:00
|
|
|
bool FunctionLiveVarInfo::runOnFunction(Function &F) {
|
|
|
|
M = &F;
|
2002-02-04 23:31:16 +00:00
|
|
|
if (DEBUG_LV) std::cerr << "Analysing live variables ...\n";
|
2001-12-08 21:05:27 +00:00
|
|
|
|
2002-02-04 20:49:04 +00:00
|
|
|
// create and initialize all the BBLiveVars of the CFG
|
2002-06-25 16:12:52 +00:00
|
|
|
constructBBs(M);
|
2001-12-08 21:05:27 +00:00
|
|
|
|
2002-03-18 03:45:41 +00:00
|
|
|
unsigned int iter=0;
|
2002-06-25 16:12:52 +00:00
|
|
|
while (doSingleBackwardPass(M, iter++))
|
2002-02-04 20:49:04 +00:00
|
|
|
; // Iterate until we are done.
|
|
|
|
|
2002-02-04 23:31:16 +00:00
|
|
|
if (DEBUG_LV) std::cerr << "Live Variable Analysis complete!\n";
|
2002-02-04 20:49:04 +00:00
|
|
|
return false;
|
2002-02-04 20:00:08 +00:00
|
|
|
}
|
2001-07-24 17:14:13 +00:00
|
|
|
|
|
|
|
|
2001-12-08 21:05:27 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2001-08-20 21:12:49 +00:00
|
|
|
// constructs BBLiveVars and init Def and In sets
|
2001-12-08 21:05:27 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2002-10-28 18:01:21 +00:00
|
|
|
void FunctionLiveVarInfo::constructBBs(const Function *F) {
|
|
|
|
unsigned POId = 0; // Reverse Depth-first Order ID
|
|
|
|
std::map<const BasicBlock*, unsigned> PONumbering;
|
|
|
|
|
|
|
|
for (po_iterator<const Function*> BBI = po_begin(M), BBE = po_end(M);
|
|
|
|
BBI != BBE; ++BBI)
|
|
|
|
PONumbering[*BBI] = POId++;
|
2001-09-30 23:28:04 +00:00
|
|
|
|
2002-10-28 18:01:21 +00:00
|
|
|
MachineFunction &MF = MachineFunction::get(F);
|
|
|
|
for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
|
|
|
|
const BasicBlock &BB = *I->getBasicBlock(); // get the current BB
|
2002-02-05 01:43:49 +00:00
|
|
|
if (DEBUG_LV) std::cerr << " For BB " << RAV(BB) << ":\n";
|
2001-09-30 23:28:04 +00:00
|
|
|
|
2002-10-28 18:01:21 +00:00
|
|
|
BBLiveVar *LVBB;
|
|
|
|
std::map<const BasicBlock*, unsigned>::iterator POI = PONumbering.find(&BB);
|
|
|
|
if (POI != PONumbering.end()) {
|
|
|
|
// create a new BBLiveVar
|
2003-10-20 20:52:23 +00:00
|
|
|
LVBB = new BBLiveVar(BB, *I, POId);
|
2002-10-28 18:01:21 +00:00
|
|
|
} else {
|
|
|
|
// The PO iterator does not discover unreachable blocks, but the random
|
|
|
|
// iterator later may access these blocks. We must make sure to
|
|
|
|
// initialize unreachable blocks as well. However, LV info is not correct
|
|
|
|
// for those blocks (they are not analyzed)
|
|
|
|
//
|
2003-10-20 20:52:23 +00:00
|
|
|
LVBB = new BBLiveVar(BB, *I, ++POId);
|
2002-10-28 18:01:21 +00:00
|
|
|
}
|
2003-10-20 20:52:23 +00:00
|
|
|
BBLiveVarInfo[&BB] = LVBB;
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2002-02-04 23:31:16 +00:00
|
|
|
if (DEBUG_LV)
|
2001-08-20 21:12:49 +00:00
|
|
|
LVBB->printAllSets();
|
2001-07-24 17:14:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-20 21:12:49 +00:00
|
|
|
|
2001-12-08 21:05:27 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// do one backward pass over the CFG (for iterative analysis)
|
|
|
|
//-----------------------------------------------------------------------------
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2002-04-27 07:27:19 +00:00
|
|
|
bool FunctionLiveVarInfo::doSingleBackwardPass(const Function *M,
|
|
|
|
unsigned iter) {
|
2002-03-18 03:45:41 +00:00
|
|
|
if (DEBUG_LV) std::cerr << "\n After Backward Pass " << iter << "...\n";
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2002-02-04 23:31:16 +00:00
|
|
|
bool NeedAnotherIteration = false;
|
2002-04-09 05:14:14 +00:00
|
|
|
for (po_iterator<const Function*> BBI = po_begin(M), BBE = po_end(M);
|
|
|
|
BBI != BBE; ++BBI) {
|
2003-10-20 20:52:23 +00:00
|
|
|
BBLiveVar *LVBB = BBLiveVarInfo[*BBI];
|
2002-02-04 23:31:16 +00:00
|
|
|
assert(LVBB && "BasicBlock information not set for block!");
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2002-02-04 23:31:16 +00:00
|
|
|
if (DEBUG_LV) std::cerr << " For BB " << (*BBI)->getName() << ":\n";
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2002-03-18 03:45:41 +00:00
|
|
|
// InSets are initialized to "GenSet". Recompute only if OutSet changed.
|
2002-02-04 20:49:04 +00:00
|
|
|
if(LVBB->isOutSetChanged())
|
2001-08-20 21:12:49 +00:00
|
|
|
LVBB->applyTransferFunc(); // apply the Tran Func to calc InSet
|
2002-03-18 03:45:41 +00:00
|
|
|
|
2002-04-09 05:14:14 +00:00
|
|
|
// OutSets are initialized to EMPTY. Recompute on first iter or if InSet
|
|
|
|
// changed.
|
2002-03-18 03:45:41 +00:00
|
|
|
if (iter == 0 || LVBB->isInSetChanged()) // to calc Outsets of preds
|
2003-10-20 20:52:23 +00:00
|
|
|
NeedAnotherIteration |= LVBB->applyFlowFunc(BBLiveVarInfo);
|
2002-03-18 03:45:41 +00:00
|
|
|
|
2002-02-04 23:31:16 +00:00
|
|
|
if (DEBUG_LV) LVBB->printInOutSets();
|
2001-07-24 17:14:13 +00:00
|
|
|
}
|
|
|
|
|
2001-08-20 21:12:49 +00:00
|
|
|
// true if we need to reiterate over the CFG
|
|
|
|
return NeedAnotherIteration;
|
2001-07-24 17:14:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-04-27 07:27:19 +00:00
|
|
|
void FunctionLiveVarInfo::releaseMemory() {
|
2003-10-20 20:52:23 +00:00
|
|
|
// First remove all BBLiveVars created in constructBBs().
|
|
|
|
if (M) {
|
2002-04-08 22:03:57 +00:00
|
|
|
for (Function::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
|
2003-10-20 20:52:23 +00:00
|
|
|
delete BBLiveVarInfo[I];
|
|
|
|
BBLiveVarInfo.clear();
|
|
|
|
}
|
2002-02-05 06:52:25 +00:00
|
|
|
M = 0;
|
2001-10-16 01:25:05 +00:00
|
|
|
|
2002-02-05 02:51:01 +00:00
|
|
|
// Then delete all objects of type ValueSet created in calcLiveVarSetsForBB
|
2003-08-12 22:19:59 +00:00
|
|
|
// and entered into MInst2LVSetBI and MInst2LVSetAI (these are caches
|
|
|
|
// to return ValueSet's before/after a machine instruction quickly).
|
|
|
|
// We do not need to free up ValueSets in MInst2LVSetAI because it holds
|
|
|
|
// pointers to the same sets as in MInst2LVSetBI (for all instructions
|
|
|
|
// except the last one in a BB) or in BBLiveVar (for the last instruction).
|
2002-02-04 20:49:04 +00:00
|
|
|
//
|
2003-08-12 22:19:59 +00:00
|
|
|
for (hash_map<const MachineInstr*, ValueSet*>::iterator
|
2002-02-05 00:34:50 +00:00
|
|
|
MI = MInst2LVSetBI.begin(),
|
2002-02-04 23:31:16 +00:00
|
|
|
ME = MInst2LVSetBI.end(); MI != ME; ++MI)
|
2002-02-05 02:51:01 +00:00
|
|
|
delete MI->second; // delete all ValueSets in MInst2LVSetBI
|
2001-08-20 21:12:49 +00:00
|
|
|
|
2002-02-04 20:49:04 +00:00
|
|
|
MInst2LVSetBI.clear();
|
|
|
|
MInst2LVSetAI.clear();
|
2001-07-24 17:14:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-02-04 20:49:04 +00:00
|
|
|
|
2001-12-08 21:05:27 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2002-02-04 23:31:16 +00:00
|
|
|
// Following functions will give the LiveVar info for any machine instr in
|
2002-04-27 06:56:12 +00:00
|
|
|
// a function. It should be called after a call to analyze().
|
2002-02-04 23:31:16 +00:00
|
|
|
//
|
2003-09-11 18:14:24 +00:00
|
|
|
// These functions calculate live var info for all the machine instrs in a
|
2002-02-04 23:31:16 +00:00
|
|
|
// BB when LVInfo for one inst is requested. Hence, this function is useful
|
|
|
|
// when live var info is required for many (or all) instructions in a basic
|
2002-04-27 06:56:12 +00:00
|
|
|
// block. Also, the arguments to this function does not require specific
|
2002-02-04 23:31:16 +00:00
|
|
|
// iterators.
|
2001-12-08 21:05:27 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2001-12-08 21:05:27 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Gives live variable information before a machine instruction
|
|
|
|
//-----------------------------------------------------------------------------
|
2002-02-04 23:31:16 +00:00
|
|
|
|
2002-02-05 04:20:12 +00:00
|
|
|
const ValueSet &
|
2003-08-12 22:19:59 +00:00
|
|
|
FunctionLiveVarInfo::getLiveVarSetBeforeMInst(const MachineInstr *MI,
|
2002-04-27 07:27:19 +00:00
|
|
|
const BasicBlock *BB) {
|
2003-08-12 22:19:59 +00:00
|
|
|
ValueSet* &LVSet = MInst2LVSetBI[MI]; // ref. to map entry
|
2003-07-29 19:42:32 +00:00
|
|
|
if (LVSet == NULL && BB != NULL) { // if not found and BB provided
|
|
|
|
calcLiveVarSetsForBB(BB); // calc LVSet for all instrs in BB
|
2003-08-12 22:19:59 +00:00
|
|
|
assert(LVSet != NULL);
|
2001-08-20 21:12:49 +00:00
|
|
|
}
|
2003-07-29 19:42:32 +00:00
|
|
|
return *LVSet;
|
2001-08-20 21:12:49 +00:00
|
|
|
}
|
2001-07-24 17:14:13 +00:00
|
|
|
|
|
|
|
|
2001-12-08 21:05:27 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Gives live variable information after a machine instruction
|
|
|
|
//-----------------------------------------------------------------------------
|
2003-07-29 19:42:32 +00:00
|
|
|
|
2002-02-05 04:20:12 +00:00
|
|
|
const ValueSet &
|
2002-04-27 07:27:19 +00:00
|
|
|
FunctionLiveVarInfo::getLiveVarSetAfterMInst(const MachineInstr *MI,
|
|
|
|
const BasicBlock *BB) {
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2003-08-12 22:19:59 +00:00
|
|
|
ValueSet* &LVSet = MInst2LVSetAI[MI]; // ref. to map entry
|
2003-07-29 19:42:32 +00:00
|
|
|
if (LVSet == NULL && BB != NULL) { // if not found and BB provided
|
|
|
|
calcLiveVarSetsForBB(BB); // calc LVSet for all instrs in BB
|
2003-08-12 22:19:59 +00:00
|
|
|
assert(LVSet != NULL);
|
2001-08-20 21:12:49 +00:00
|
|
|
}
|
2003-07-29 19:42:32 +00:00
|
|
|
return *LVSet;
|
2001-08-20 21:12:49 +00:00
|
|
|
}
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2002-02-05 02:51:01 +00:00
|
|
|
// This function applies a machine instr to a live var set (accepts OutSet) and
|
|
|
|
// makes necessary changes to it (produces InSet). Note that two for loops are
|
|
|
|
// used to first kill all defs and then to add all uses. This is because there
|
2003-09-11 18:14:24 +00:00
|
|
|
// can be instructions like Val = Val + 1 since we allow multiple defs to a
|
2002-02-05 02:51:01 +00:00
|
|
|
// machine instruction operand.
|
|
|
|
//
|
|
|
|
static void applyTranferFuncForMInst(ValueSet &LVS, const MachineInstr *MInst) {
|
2002-02-05 06:02:59 +00:00
|
|
|
for (MachineInstr::const_val_op_iterator OpI = MInst->begin(),
|
|
|
|
OpE = MInst->end(); OpI != OpE; ++OpI) {
|
2003-12-14 13:24:17 +00:00
|
|
|
if (OpI.isDef()) // kill if this operand is a def
|
2003-05-27 00:06:48 +00:00
|
|
|
LVS.erase(*OpI); // this definition kills any uses
|
2002-02-05 02:51:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// do for implicit operands as well
|
|
|
|
for (unsigned i=0; i < MInst->getNumImplicitRefs(); ++i) {
|
2003-12-14 13:24:17 +00:00
|
|
|
if (MInst->getImplicitOp(i).isDef())
|
2002-02-05 02:51:01 +00:00
|
|
|
LVS.erase(MInst->getImplicitRef(i));
|
|
|
|
}
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2002-02-05 06:02:59 +00:00
|
|
|
for (MachineInstr::const_val_op_iterator OpI = MInst->begin(),
|
|
|
|
OpE = MInst->end(); OpI != OpE; ++OpI) {
|
2002-04-09 05:14:14 +00:00
|
|
|
if (!isa<BasicBlock>(*OpI)) // don't process labels
|
2002-07-08 22:56:34 +00:00
|
|
|
// add only if this operand is a use
|
2003-12-14 13:24:17 +00:00
|
|
|
if (OpI.isUse())
|
2002-04-09 05:14:14 +00:00
|
|
|
LVS.insert(*OpI); // An operand is a use - so add to use set
|
2002-02-05 02:51:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// do for implicit operands as well
|
2002-04-09 05:14:14 +00:00
|
|
|
for (unsigned i = 0, e = MInst->getNumImplicitRefs(); i != e; ++i)
|
2003-12-14 13:24:17 +00:00
|
|
|
if (MInst->getImplicitOp(i).isUse())
|
2002-02-05 02:51:01 +00:00
|
|
|
LVS.insert(MInst->getImplicitRef(i));
|
|
|
|
}
|
2001-12-08 21:05:27 +00:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// This method calculates the live variable information for all the
|
|
|
|
// instructions in a basic block and enter the newly constructed live
|
2002-02-04 23:31:16 +00:00
|
|
|
// variable sets into a the caches (MInst2LVSetAI, MInst2LVSetBI)
|
2001-12-08 21:05:27 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2002-02-04 23:31:16 +00:00
|
|
|
|
2002-04-27 07:27:19 +00:00
|
|
|
void FunctionLiveVarInfo::calcLiveVarSetsForBB(const BasicBlock *BB) {
|
2003-10-20 20:52:23 +00:00
|
|
|
BBLiveVar *BBLV = BBLiveVarInfo[BB];
|
2002-10-28 18:01:21 +00:00
|
|
|
assert(BBLV && "BBLiveVar annotation doesn't exist?");
|
|
|
|
const MachineBasicBlock &MIVec = BBLV->getMachineBasicBlock();
|
2003-08-12 22:19:59 +00:00
|
|
|
const MachineFunction &MF = MachineFunction::get(M);
|
|
|
|
const TargetMachine &TM = MF.getTarget();
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2002-04-09 05:14:14 +00:00
|
|
|
if (DEBUG_LV >= LV_DEBUG_Instr)
|
|
|
|
std::cerr << "\n======For BB " << BB->getName()
|
|
|
|
<< ": Live var sets for instructions======\n";
|
2002-03-18 03:45:41 +00:00
|
|
|
|
2003-08-12 22:19:59 +00:00
|
|
|
ValueSet *SetAI = &getOutSetOfBB(BB); // init SetAI with OutSet
|
|
|
|
ValueSet CurSet(*SetAI); // CurSet now contains OutSet
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2001-08-20 21:12:49 +00:00
|
|
|
// iterate over all the machine instructions in BB
|
2002-10-28 01:41:47 +00:00
|
|
|
for (MachineBasicBlock::const_reverse_iterator MII = MIVec.rbegin(),
|
2002-02-04 23:31:16 +00:00
|
|
|
MIE = MIVec.rend(); MII != MIE; ++MII) {
|
|
|
|
// MI is cur machine inst
|
|
|
|
const MachineInstr *MI = *MII;
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2002-02-04 23:31:16 +00:00
|
|
|
MInst2LVSetAI[MI] = SetAI; // record in After Inst map
|
2001-08-20 21:12:49 +00:00
|
|
|
|
2002-04-09 05:14:14 +00:00
|
|
|
applyTranferFuncForMInst(CurSet, MI); // apply the transfer Func
|
2003-08-12 22:19:59 +00:00
|
|
|
ValueSet *NewSet = new ValueSet(CurSet); // create a new set with a copy
|
|
|
|
// of the set after T/F
|
2002-02-04 23:31:16 +00:00
|
|
|
MInst2LVSetBI[MI] = NewSet; // record in Before Inst map
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2003-08-12 22:19:59 +00:00
|
|
|
// If the current machine instruction has delay slots, mark values
|
|
|
|
// used by this instruction as live before and after each delay slot
|
|
|
|
// instruction (After(MI) is the same as Before(MI+1) except for last MI).
|
2004-02-11 20:47:34 +00:00
|
|
|
if (unsigned DS = TM.getInstrInfo().getNumDelaySlots(MI->getOpcode())) {
|
2003-08-12 22:19:59 +00:00
|
|
|
MachineBasicBlock::const_iterator fwdMII = MII.base(); // ptr to *next* MI
|
|
|
|
for (unsigned i = 0; i < DS; ++i, ++fwdMII) {
|
|
|
|
assert(fwdMII != MIVec.end() && "Missing instruction in delay slot?");
|
|
|
|
MachineInstr* DelaySlotMI = *fwdMII;
|
2004-02-11 20:47:34 +00:00
|
|
|
if (! TM.getInstrInfo().isNop(DelaySlotMI->getOpcode())) {
|
2003-08-14 20:45:56 +00:00
|
|
|
set_union(*MInst2LVSetBI[DelaySlotMI], *NewSet);
|
|
|
|
if (i+1 == DS)
|
|
|
|
set_union(*MInst2LVSetAI[DelaySlotMI], *NewSet);
|
|
|
|
}
|
2003-08-12 22:19:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-18 03:45:41 +00:00
|
|
|
if (DEBUG_LV >= LV_DEBUG_Instr) {
|
2002-04-09 05:14:14 +00:00
|
|
|
std::cerr << "\nLive var sets before/after instruction " << *MI;
|
2002-06-25 20:35:19 +00:00
|
|
|
std::cerr << " Before: "; printSet(*NewSet); std::cerr << "\n";
|
|
|
|
std::cerr << " After : "; printSet(*SetAI); std::cerr << "\n";
|
2002-03-18 03:45:41 +00:00
|
|
|
}
|
|
|
|
|
2001-08-20 21:12:49 +00:00
|
|
|
// SetAI will be used in the next iteration
|
|
|
|
SetAI = NewSet;
|
|
|
|
}
|
2001-07-24 17:14:13 +00:00
|
|
|
}
|
2003-11-11 22:41:34 +00:00
|
|
|
|
|
|
|
} // End llvm namespace
|