2002-04-27 06:56:12 +00:00
|
|
|
/* Title: FunctionLiveVarInfo.h -*- C++ -*-
|
2001-07-24 17:14:13 +00:00
|
|
|
Author: Ruchira Sasanka
|
|
|
|
Date: Jun 30, 01
|
|
|
|
Purpose:
|
|
|
|
|
2002-04-27 06:56:12 +00:00
|
|
|
This is the interface for live variable info of a function that is required
|
2001-08-20 21:11:01 +00:00
|
|
|
by any other part of the compiler
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2001-08-20 21:11:01 +00:00
|
|
|
It must be called like:
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2002-04-27 06:56:12 +00:00
|
|
|
FunctionLiveVarInfo FLVI(Function *); // initializes data structures
|
|
|
|
FLVI.analyze(); // do the actural live variable anal
|
2001-07-24 17:14:13 +00:00
|
|
|
|
|
|
|
After the analysis, getInSetOfBB or getOutSetofBB can be called to get
|
2001-08-20 21:11:01 +00:00
|
|
|
live var info of a BB.
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2001-08-20 21:11:01 +00:00
|
|
|
The live var set before an instruction can be obtained in 2 ways:
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2001-08-20 21:11:01 +00:00
|
|
|
1. Use the method getLiveVarSetAfterInst(Instruction *) to get the LV Info
|
|
|
|
just after an instruction. (also exists getLiveVarSetBeforeInst(..))
|
|
|
|
|
|
|
|
This function caluclates the LV info for a BB only once and caches that
|
|
|
|
info. If the cache does not contain the LV info of the instruction, it
|
|
|
|
calculates the LV info for the whole BB and caches them.
|
|
|
|
|
|
|
|
Getting liveVar info this way uses more memory since, LV info should be
|
|
|
|
cached. However, if you need LV info of nearly all the instructions of a
|
|
|
|
BB, this is the best and simplest interfrace.
|
|
|
|
|
|
|
|
|
|
|
|
2. Use the OutSet and applyTranferFuncForInst(const Instruction *const Inst)
|
2001-07-24 17:14:13 +00:00
|
|
|
declared in LiveVarSet and traverse the instructions of a basic block in
|
|
|
|
reverse (using const_reverse_iterator in the BB class).
|
|
|
|
|
2001-08-20 21:11:01 +00:00
|
|
|
This is the most memory efficient method if you need LV info for
|
|
|
|
only several instructions in a BasicBlock. An example is given below:
|
2001-07-24 17:14:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
LiveVarSet LVSet; // this will be the set used to traverse through each BB
|
|
|
|
|
2001-08-20 21:11:01 +00:00
|
|
|
// Initialize LVSet so that it is the same as OutSet of the BB
|
2001-07-24 17:14:13 +00:00
|
|
|
LVSet.setUnion( LVI->getOutSetOfBB( *BBI ) );
|
|
|
|
|
|
|
|
BasicBlock::InstListType::const_reverse_iterator
|
2001-08-20 21:11:01 +00:00
|
|
|
InstIterator = InstListInBB.rbegin(); // get the rev iter for inst in BB
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2001-08-20 21:11:01 +00:00
|
|
|
// iterate over all the instructions in BB in reverse
|
2001-07-24 17:14:13 +00:00
|
|
|
for( ; InstIterator != InstListInBB.rend(); InstIterator++) {
|
|
|
|
|
|
|
|
//...... all code here which uses LVSet ........
|
|
|
|
|
|
|
|
LVSet.applyTranferFuncForInst(*InstIterator);
|
|
|
|
|
|
|
|
// Now LVSet contains live vars ABOVE the current instrution
|
|
|
|
}
|
|
|
|
|
|
|
|
See buildInterferenceGraph() for the above example.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef METH_LIVE_VAR_INFO_H
|
|
|
|
#define METH_LIVE_VAR_INFO_H
|
|
|
|
|
2002-02-04 20:00:08 +00:00
|
|
|
#include "llvm/Pass.h"
|
2002-02-05 02:51:01 +00:00
|
|
|
#include "llvm/Analysis/LiveVar/ValueSet.h"
|
2002-03-19 00:59:08 +00:00
|
|
|
|
2002-02-05 00:33:19 +00:00
|
|
|
class BBLiveVar;
|
|
|
|
class MachineInstr;
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2002-04-27 07:27:19 +00:00
|
|
|
class FunctionLiveVarInfo : public FunctionPass {
|
2001-08-20 21:11:01 +00:00
|
|
|
// Machine Instr to LiveVarSet Map for providing LVset BEFORE each inst
|
2002-02-05 02:51:01 +00:00
|
|
|
std::map<const MachineInstr *, const ValueSet *> MInst2LVSetBI;
|
2001-08-20 21:11:01 +00:00
|
|
|
|
|
|
|
// Machine Instr to LiveVarSet Map for providing LVset AFTER each inst
|
2002-02-05 02:51:01 +00:00
|
|
|
std::map<const MachineInstr *, const ValueSet *> MInst2LVSetAI;
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2002-03-23 22:51:58 +00:00
|
|
|
// Stored Function that the data is computed with respect to
|
|
|
|
const Function *M;
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2001-08-20 21:11:01 +00:00
|
|
|
// --------- private methods -----------------------------------------
|
|
|
|
|
|
|
|
// constructs BBLiveVars and init Def and In sets
|
2002-03-23 22:51:58 +00:00
|
|
|
void constructBBs(const Function *F);
|
2001-08-20 21:11:01 +00:00
|
|
|
|
|
|
|
// do one backward pass over the CFG
|
2002-03-23 22:51:58 +00:00
|
|
|
bool doSingleBackwardPass(const Function *F, unsigned int iter);
|
2001-08-20 21:11:01 +00:00
|
|
|
|
|
|
|
// calculates live var sets for instructions in a BB
|
2002-02-04 16:32:40 +00:00
|
|
|
void calcLiveVarSetsForBB(const BasicBlock *BB);
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2002-02-04 20:00:08 +00:00
|
|
|
public:
|
|
|
|
static AnalysisID ID; // We are an analysis, we must have an ID
|
|
|
|
|
2002-04-29 14:57:45 +00:00
|
|
|
virtual const char *getPassName() const { return "Live Variable Analysis"; }
|
|
|
|
|
2002-04-27 06:56:12 +00:00
|
|
|
// --------- Implement the FunctionPass interface ----------------------
|
2002-02-04 20:00:08 +00:00
|
|
|
|
2002-04-27 06:56:12 +00:00
|
|
|
// runOnFunction - Perform analysis, update internal data structures.
|
2002-06-25 16:12:52 +00:00
|
|
|
virtual bool runOnFunction(Function &F);
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2002-02-04 20:00:08 +00:00
|
|
|
// releaseMemory - After LiveVariable analysis has been used, forget!
|
|
|
|
virtual void releaseMemory();
|
|
|
|
|
2002-04-27 06:56:12 +00:00
|
|
|
// getAnalysisUsage - Provide self!
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
AU.addProvided(ID);
|
2002-02-04 20:00:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------- Functions to access analysis results -------------------
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2001-08-20 21:11:01 +00:00
|
|
|
// gets OutSet of a BB
|
2002-02-05 04:20:12 +00:00
|
|
|
const ValueSet &getOutSetOfBB(const BasicBlock *BB) const;
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2001-08-20 21:11:01 +00:00
|
|
|
// gets InSet of a BB
|
2002-02-05 04:20:12 +00:00
|
|
|
const ValueSet &getInSetOfBB(const BasicBlock *BB) const;
|
2001-08-20 21:11:01 +00:00
|
|
|
|
|
|
|
// gets the Live var set BEFORE an instruction
|
2002-02-05 04:20:12 +00:00
|
|
|
const ValueSet &getLiveVarSetBeforeMInst(const MachineInstr *MI,
|
2002-02-05 02:51:01 +00:00
|
|
|
const BasicBlock *BB);
|
2001-08-20 21:11:01 +00:00
|
|
|
|
|
|
|
// gets the Live var set AFTER an instruction
|
2002-02-05 04:20:12 +00:00
|
|
|
const ValueSet &getLiveVarSetAfterMInst(const MachineInstr *MI,
|
2002-02-05 02:51:01 +00:00
|
|
|
const BasicBlock *BB);
|
2001-07-24 17:14:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|