2002-04-27 08:56:12 +02:00
|
|
|
//===-- FunctionLiveVarInfo.cpp - Live Variable Analysis for a Function ---===//
|
2003-10-20 21:43:21 +02: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 03:51:01 +01:00
|
|
|
//
|
2002-04-27 08:56:12 +02:00
|
|
|
// This is the interface to function level live variable information that is
|
2002-02-05 03:51:01 +01:00
|
|
|
// provided by live variable analysis.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-07-24 19:14:13 +02:00
|
|
|
|
2003-01-15 00:05:08 +01:00
|
|
|
#include "llvm/CodeGen/FunctionLiveVarInfo.h"
|
2001-08-20 23:12:49 +02:00
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2002-10-28 19:01:21 +01:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2003-08-13 00:19:59 +02:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2002-02-12 22:07:25 +01:00
|
|
|
#include "llvm/Support/CFG.h"
|
2001-11-27 01:03:19 +01:00
|
|
|
#include "Support/PostOrderIterator.h"
|
2002-02-05 04:35:53 +01:00
|
|
|
#include "Support/SetOperations.h"
|
2002-05-22 19:08:27 +02:00
|
|
|
#include "Support/CommandLine.h"
|
2003-01-15 00:05:08 +01:00
|
|
|
#include "BBLiveVar.h"
|
2001-07-24 19:14:13 +02:00
|
|
|
|
2003-11-11 23:41:34 +01:00
|
|
|
namespace llvm {
|
|
|
|
|
2002-07-26 23:12:44 +02:00
|
|
|
static RegisterAnalysis<FunctionLiveVarInfo>
|
|
|
|
X("livevar", "Live Variable Analysis");
|
2001-07-24 19:14:13 +02:00
|
|
|
|
2002-05-22 19:08:27 +02:00
|
|
|
LiveVarDebugLevel_t DEBUG_LV;
|
|
|
|
|
2002-07-22 04:10:13 +02: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 04:45:41 +01:00
|
|
|
|
2002-05-22 19:08:27 +02:00
|
|
|
|
|
|
|
|
2002-02-05 01:34:50 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Accessor Functions
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// gets OutSet of a BB
|
2002-04-27 09:27:19 +02:00
|
|
|
const ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) const {
|
2003-10-20 22:52:23 +02:00
|
|
|
return BBLiveVarInfo.find(BB)->second->getOutSet();
|
2002-02-05 01:34:50 +01:00
|
|
|
}
|
2003-08-13 00:19:59 +02:00
|
|
|
ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) {
|
2003-10-20 22:52:23 +02:00
|
|
|
return BBLiveVarInfo[BB]->getOutSet();
|
2003-08-13 00:19:59 +02:00
|
|
|
}
|
2002-02-05 01:34:50 +01:00
|
|
|
|
|
|
|
// gets InSet of a BB
|
2002-04-27 09:27:19 +02:00
|
|
|
const ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const {
|
2003-10-20 22:52:23 +02:00
|
|
|
return BBLiveVarInfo.find(BB)->second->getInSet();
|
2002-02-05 01:34:50 +01:00
|
|
|
}
|
2003-10-20 22:52:23 +02:00
|
|
|
ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) {
|
|
|
|
return BBLiveVarInfo[BB]->getInSet();
|
2003-08-13 00:19:59 +02:00
|
|
|
}
|
2002-02-05 01:34:50 +01:00
|
|
|
|
2001-12-08 22:05:27 +01:00
|
|
|
|
2002-02-04 21:49:04 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2002-04-27 08:56:12 +02:00
|
|
|
// Performs live var analysis for a function
|
2002-02-04 21:49:04 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2001-12-08 22:05:27 +01:00
|
|
|
|
2002-06-25 18:12:52 +02:00
|
|
|
bool FunctionLiveVarInfo::runOnFunction(Function &F) {
|
|
|
|
M = &F;
|
2002-02-05 00:31:16 +01:00
|
|
|
if (DEBUG_LV) std::cerr << "Analysing live variables ...\n";
|
2001-12-08 22:05:27 +01:00
|
|
|
|
2002-02-04 21:49:04 +01:00
|
|
|
// create and initialize all the BBLiveVars of the CFG
|
2002-06-25 18:12:52 +02:00
|
|
|
constructBBs(M);
|
2001-12-08 22:05:27 +01:00
|
|
|
|
2002-03-18 04:45:41 +01:00
|
|
|
unsigned int iter=0;
|
2002-06-25 18:12:52 +02:00
|
|
|
while (doSingleBackwardPass(M, iter++))
|
2002-02-04 21:49:04 +01:00
|
|
|
; // Iterate until we are done.
|
|
|
|
|
2002-02-05 00:31:16 +01:00
|
|
|
if (DEBUG_LV) std::cerr << "Live Variable Analysis complete!\n";
|
2002-02-04 21:49:04 +01:00
|
|
|
return false;
|
2002-02-04 21:00:08 +01:00
|
|
|
}
|
2001-07-24 19:14:13 +02:00
|
|
|
|
|
|
|
|
2001-12-08 22:05:27 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2001-08-20 23:12:49 +02:00
|
|
|
// constructs BBLiveVars and init Def and In sets
|
2001-12-08 22:05:27 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2002-10-28 19:01:21 +01: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-10-01 01:28:04 +02:00
|
|
|
|
2002-10-28 19:01:21 +01: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 02:43:49 +01:00
|
|
|
if (DEBUG_LV) std::cerr << " For BB " << RAV(BB) << ":\n";
|
2001-10-01 01:28:04 +02:00
|
|
|
|
2002-10-28 19:01:21 +01:00
|
|
|
BBLiveVar *LVBB;
|
|
|
|
std::map<const BasicBlock*, unsigned>::iterator POI = PONumbering.find(&BB);
|
|
|
|
if (POI != PONumbering.end()) {
|
|
|
|
// create a new BBLiveVar
|
2003-10-20 22:52:23 +02:00
|
|
|
LVBB = new BBLiveVar(BB, *I, POId);
|
2002-10-28 19:01:21 +01: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 22:52:23 +02:00
|
|
|
LVBB = new BBLiveVar(BB, *I, ++POId);
|
2002-10-28 19:01:21 +01:00
|
|
|
}
|
2003-10-20 22:52:23 +02:00
|
|
|
BBLiveVarInfo[&BB] = LVBB;
|
2001-07-24 19:14:13 +02:00
|
|
|
|
2002-02-05 00:31:16 +01:00
|
|
|
if (DEBUG_LV)
|
2001-08-20 23:12:49 +02:00
|
|
|
LVBB->printAllSets();
|
2001-07-24 19:14:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-20 23:12:49 +02:00
|
|
|
|
2001-12-08 22:05:27 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// do one backward pass over the CFG (for iterative analysis)
|
|
|
|
//-----------------------------------------------------------------------------
|
2001-07-24 19:14:13 +02:00
|
|
|
|
2002-04-27 09:27:19 +02:00
|
|
|
bool FunctionLiveVarInfo::doSingleBackwardPass(const Function *M,
|
|
|
|
unsigned iter) {
|
2002-03-18 04:45:41 +01:00
|
|
|
if (DEBUG_LV) std::cerr << "\n After Backward Pass " << iter << "...\n";
|
2001-07-24 19:14:13 +02:00
|
|
|
|
2002-02-05 00:31:16 +01:00
|
|
|
bool NeedAnotherIteration = false;
|
2002-04-09 07:14:14 +02:00
|
|
|
for (po_iterator<const Function*> BBI = po_begin(M), BBE = po_end(M);
|
|
|
|
BBI != BBE; ++BBI) {
|
2003-10-20 22:52:23 +02:00
|
|
|
BBLiveVar *LVBB = BBLiveVarInfo[*BBI];
|
2002-02-05 00:31:16 +01:00
|
|
|
assert(LVBB && "BasicBlock information not set for block!");
|
2001-07-24 19:14:13 +02:00
|
|
|
|
2002-02-05 00:31:16 +01:00
|
|
|
if (DEBUG_LV) std::cerr << " For BB " << (*BBI)->getName() << ":\n";
|
2001-07-24 19:14:13 +02:00
|
|
|
|
2002-03-18 04:45:41 +01:00
|
|
|
// InSets are initialized to "GenSet". Recompute only if OutSet changed.
|
2002-02-04 21:49:04 +01:00
|
|
|
if(LVBB->isOutSetChanged())
|
2001-08-20 23:12:49 +02:00
|
|
|
LVBB->applyTransferFunc(); // apply the Tran Func to calc InSet
|
2002-03-18 04:45:41 +01:00
|
|
|
|
2002-04-09 07:14:14 +02:00
|
|
|
// OutSets are initialized to EMPTY. Recompute on first iter or if InSet
|
|
|
|
// changed.
|
2002-03-18 04:45:41 +01:00
|
|
|
if (iter == 0 || LVBB->isInSetChanged()) // to calc Outsets of preds
|
2003-10-20 22:52:23 +02:00
|
|
|
NeedAnotherIteration |= LVBB->applyFlowFunc(BBLiveVarInfo);
|
2002-03-18 04:45:41 +01:00
|
|
|
|
2002-02-05 00:31:16 +01:00
|
|
|
if (DEBUG_LV) LVBB->printInOutSets();
|
2001-07-24 19:14:13 +02:00
|
|
|
}
|
|
|
|
|
2001-08-20 23:12:49 +02:00
|
|
|
// true if we need to reiterate over the CFG
|
|
|
|
return NeedAnotherIteration;
|
2001-07-24 19:14:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-04-27 09:27:19 +02:00
|
|
|
void FunctionLiveVarInfo::releaseMemory() {
|
2003-10-20 22:52:23 +02:00
|
|
|
// First remove all BBLiveVars created in constructBBs().
|
|
|
|
if (M) {
|
2002-04-09 00:03:57 +02:00
|
|
|
for (Function::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
|
2003-10-20 22:52:23 +02:00
|
|
|
delete BBLiveVarInfo[I];
|
|
|
|
BBLiveVarInfo.clear();
|
|
|
|
}
|
2002-02-05 07:52:25 +01:00
|
|
|
M = 0;
|
2001-10-16 03:25:05 +02:00
|
|
|
|
2002-02-05 03:51:01 +01:00
|
|
|
// Then delete all objects of type ValueSet created in calcLiveVarSetsForBB
|
2003-08-13 00:19:59 +02: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 21:49:04 +01:00
|
|
|
//
|
2003-08-13 00:19:59 +02:00
|
|
|
for (hash_map<const MachineInstr*, ValueSet*>::iterator
|
2002-02-05 01:34:50 +01:00
|
|
|
MI = MInst2LVSetBI.begin(),
|
2002-02-05 00:31:16 +01:00
|
|
|
ME = MInst2LVSetBI.end(); MI != ME; ++MI)
|
2002-02-05 03:51:01 +01:00
|
|
|
delete MI->second; // delete all ValueSets in MInst2LVSetBI
|
2001-08-20 23:12:49 +02:00
|
|
|
|
2002-02-04 21:49:04 +01:00
|
|
|
MInst2LVSetBI.clear();
|
|
|
|
MInst2LVSetAI.clear();
|
2001-07-24 19:14:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-02-04 21:49:04 +01:00
|
|
|
|
2001-12-08 22:05:27 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2002-02-05 00:31:16 +01:00
|
|
|
// Following functions will give the LiveVar info for any machine instr in
|
2002-04-27 08:56:12 +02:00
|
|
|
// a function. It should be called after a call to analyze().
|
2002-02-05 00:31:16 +01:00
|
|
|
//
|
2003-09-11 20:14:24 +02:00
|
|
|
// These functions calculate live var info for all the machine instrs in a
|
2002-02-05 00:31:16 +01: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 08:56:12 +02:00
|
|
|
// block. Also, the arguments to this function does not require specific
|
2002-02-05 00:31:16 +01:00
|
|
|
// iterators.
|
2001-12-08 22:05:27 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2001-07-24 19:14:13 +02:00
|
|
|
|
2001-12-08 22:05:27 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Gives live variable information before a machine instruction
|
|
|
|
//-----------------------------------------------------------------------------
|
2002-02-05 00:31:16 +01:00
|
|
|
|
2002-02-05 05:20:12 +01:00
|
|
|
const ValueSet &
|
2003-08-13 00:19:59 +02:00
|
|
|
FunctionLiveVarInfo::getLiveVarSetBeforeMInst(const MachineInstr *MI,
|
2002-04-27 09:27:19 +02:00
|
|
|
const BasicBlock *BB) {
|
2003-08-13 00:19:59 +02:00
|
|
|
ValueSet* &LVSet = MInst2LVSetBI[MI]; // ref. to map entry
|
2003-07-29 21:42:32 +02:00
|
|
|
if (LVSet == NULL && BB != NULL) { // if not found and BB provided
|
|
|
|
calcLiveVarSetsForBB(BB); // calc LVSet for all instrs in BB
|
2003-08-13 00:19:59 +02:00
|
|
|
assert(LVSet != NULL);
|
2001-08-20 23:12:49 +02:00
|
|
|
}
|
2003-07-29 21:42:32 +02:00
|
|
|
return *LVSet;
|
2001-08-20 23:12:49 +02:00
|
|
|
}
|
2001-07-24 19:14:13 +02:00
|
|
|
|
|
|
|
|
2001-12-08 22:05:27 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Gives live variable information after a machine instruction
|
|
|
|
//-----------------------------------------------------------------------------
|
2003-07-29 21:42:32 +02:00
|
|
|
|
2002-02-05 05:20:12 +01:00
|
|
|
const ValueSet &
|
2002-04-27 09:27:19 +02:00
|
|
|
FunctionLiveVarInfo::getLiveVarSetAfterMInst(const MachineInstr *MI,
|
|
|
|
const BasicBlock *BB) {
|
2001-07-24 19:14:13 +02:00
|
|
|
|
2003-08-13 00:19:59 +02:00
|
|
|
ValueSet* &LVSet = MInst2LVSetAI[MI]; // ref. to map entry
|
2003-07-29 21:42:32 +02:00
|
|
|
if (LVSet == NULL && BB != NULL) { // if not found and BB provided
|
|
|
|
calcLiveVarSetsForBB(BB); // calc LVSet for all instrs in BB
|
2003-08-13 00:19:59 +02:00
|
|
|
assert(LVSet != NULL);
|
2001-08-20 23:12:49 +02:00
|
|
|
}
|
2003-07-29 21:42:32 +02:00
|
|
|
return *LVSet;
|
2001-08-20 23:12:49 +02:00
|
|
|
}
|
2001-07-24 19:14:13 +02:00
|
|
|
|
2002-02-05 03:51:01 +01: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 20:14:24 +02:00
|
|
|
// can be instructions like Val = Val + 1 since we allow multiple defs to a
|
2002-02-05 03:51:01 +01:00
|
|
|
// machine instruction operand.
|
|
|
|
//
|
|
|
|
static void applyTranferFuncForMInst(ValueSet &LVS, const MachineInstr *MInst) {
|
2002-02-05 07:02:59 +01:00
|
|
|
for (MachineInstr::const_val_op_iterator OpI = MInst->begin(),
|
|
|
|
OpE = MInst->end(); OpI != OpE; ++OpI) {
|
2003-05-27 02:06:48 +02:00
|
|
|
if (OpI.isDefOnly() || OpI.isDefAndUse()) // kill if this operand is a def
|
|
|
|
LVS.erase(*OpI); // this definition kills any uses
|
2002-02-05 03:51:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// do for implicit operands as well
|
|
|
|
for (unsigned i=0; i < MInst->getNumImplicitRefs(); ++i) {
|
2003-05-27 02:06:48 +02:00
|
|
|
if (MInst->getImplicitOp(i).opIsDefOnly() ||
|
|
|
|
MInst->getImplicitOp(i).opIsDefAndUse())
|
2002-02-05 03:51:01 +01:00
|
|
|
LVS.erase(MInst->getImplicitRef(i));
|
|
|
|
}
|
2001-07-24 19:14:13 +02:00
|
|
|
|
2002-02-05 07:02:59 +01:00
|
|
|
for (MachineInstr::const_val_op_iterator OpI = MInst->begin(),
|
|
|
|
OpE = MInst->end(); OpI != OpE; ++OpI) {
|
2002-04-09 07:14:14 +02:00
|
|
|
if (!isa<BasicBlock>(*OpI)) // don't process labels
|
2002-07-09 00:56:34 +02:00
|
|
|
// add only if this operand is a use
|
2003-05-27 02:06:48 +02:00
|
|
|
if (!OpI.isDefOnly() || OpI.isDefAndUse() )
|
2002-04-09 07:14:14 +02:00
|
|
|
LVS.insert(*OpI); // An operand is a use - so add to use set
|
2002-02-05 03:51:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// do for implicit operands as well
|
2002-04-09 07:14:14 +02:00
|
|
|
for (unsigned i = 0, e = MInst->getNumImplicitRefs(); i != e; ++i)
|
2003-05-27 02:06:48 +02:00
|
|
|
if (MInst->getImplicitOp(i).opIsUse() ||
|
|
|
|
MInst->getImplicitOp(i).opIsDefAndUse())
|
2002-02-05 03:51:01 +01:00
|
|
|
LVS.insert(MInst->getImplicitRef(i));
|
|
|
|
}
|
2001-12-08 22:05:27 +01:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// This method calculates the live variable information for all the
|
|
|
|
// instructions in a basic block and enter the newly constructed live
|
2002-02-05 00:31:16 +01:00
|
|
|
// variable sets into a the caches (MInst2LVSetAI, MInst2LVSetBI)
|
2001-12-08 22:05:27 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2002-02-05 00:31:16 +01:00
|
|
|
|
2002-04-27 09:27:19 +02:00
|
|
|
void FunctionLiveVarInfo::calcLiveVarSetsForBB(const BasicBlock *BB) {
|
2003-10-20 22:52:23 +02:00
|
|
|
BBLiveVar *BBLV = BBLiveVarInfo[BB];
|
2002-10-28 19:01:21 +01:00
|
|
|
assert(BBLV && "BBLiveVar annotation doesn't exist?");
|
|
|
|
const MachineBasicBlock &MIVec = BBLV->getMachineBasicBlock();
|
2003-08-13 00:19:59 +02:00
|
|
|
const MachineFunction &MF = MachineFunction::get(M);
|
|
|
|
const TargetMachine &TM = MF.getTarget();
|
2001-07-24 19:14:13 +02:00
|
|
|
|
2002-04-09 07:14:14 +02:00
|
|
|
if (DEBUG_LV >= LV_DEBUG_Instr)
|
|
|
|
std::cerr << "\n======For BB " << BB->getName()
|
|
|
|
<< ": Live var sets for instructions======\n";
|
2002-03-18 04:45:41 +01:00
|
|
|
|
2003-08-13 00:19:59 +02:00
|
|
|
ValueSet *SetAI = &getOutSetOfBB(BB); // init SetAI with OutSet
|
|
|
|
ValueSet CurSet(*SetAI); // CurSet now contains OutSet
|
2001-07-24 19:14:13 +02:00
|
|
|
|
2001-08-20 23:12:49 +02:00
|
|
|
// iterate over all the machine instructions in BB
|
2002-10-28 02:41:47 +01:00
|
|
|
for (MachineBasicBlock::const_reverse_iterator MII = MIVec.rbegin(),
|
2002-02-05 00:31:16 +01:00
|
|
|
MIE = MIVec.rend(); MII != MIE; ++MII) {
|
|
|
|
// MI is cur machine inst
|
|
|
|
const MachineInstr *MI = *MII;
|
2001-07-24 19:14:13 +02:00
|
|
|
|
2002-02-05 00:31:16 +01:00
|
|
|
MInst2LVSetAI[MI] = SetAI; // record in After Inst map
|
2001-08-20 23:12:49 +02:00
|
|
|
|
2002-04-09 07:14:14 +02:00
|
|
|
applyTranferFuncForMInst(CurSet, MI); // apply the transfer Func
|
2003-08-13 00:19:59 +02:00
|
|
|
ValueSet *NewSet = new ValueSet(CurSet); // create a new set with a copy
|
|
|
|
// of the set after T/F
|
2002-02-05 00:31:16 +01:00
|
|
|
MInst2LVSetBI[MI] = NewSet; // record in Before Inst map
|
2001-07-24 19:14:13 +02:00
|
|
|
|
2003-08-13 00:19:59 +02: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).
|
|
|
|
if (unsigned DS = TM.getInstrInfo().getNumDelaySlots(MI->getOpCode())) {
|
|
|
|
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;
|
2003-08-14 22:45:56 +02:00
|
|
|
if (! TM.getInstrInfo().isNop(DelaySlotMI->getOpCode())) {
|
|
|
|
set_union(*MInst2LVSetBI[DelaySlotMI], *NewSet);
|
|
|
|
if (i+1 == DS)
|
|
|
|
set_union(*MInst2LVSetAI[DelaySlotMI], *NewSet);
|
|
|
|
}
|
2003-08-13 00:19:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-18 04:45:41 +01:00
|
|
|
if (DEBUG_LV >= LV_DEBUG_Instr) {
|
2002-04-09 07:14:14 +02:00
|
|
|
std::cerr << "\nLive var sets before/after instruction " << *MI;
|
2002-06-25 22:35:19 +02:00
|
|
|
std::cerr << " Before: "; printSet(*NewSet); std::cerr << "\n";
|
|
|
|
std::cerr << " After : "; printSet(*SetAI); std::cerr << "\n";
|
2002-03-18 04:45:41 +01:00
|
|
|
}
|
|
|
|
|
2001-08-20 23:12:49 +02:00
|
|
|
// SetAI will be used in the next iteration
|
|
|
|
SetAI = NewSet;
|
|
|
|
}
|
2001-07-24 19:14:13 +02:00
|
|
|
}
|
2003-11-11 23:41:34 +01:00
|
|
|
|
|
|
|
} // End llvm namespace
|