mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-07 12:28:24 +00:00
LV info on machine instructions
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -3,25 +3,37 @@
|
|||||||
Date: Jun 30, 01
|
Date: Jun 30, 01
|
||||||
Purpose:
|
Purpose:
|
||||||
|
|
||||||
This is the interface for live variable info of a method that is required by
|
This is the interface for live variable info of a method that is required
|
||||||
any other part of the compiler
|
by any other part of the compiler
|
||||||
|
|
||||||
It should be called like:
|
It must be called like:
|
||||||
|
|
||||||
MethodLiveVarInfo MLVI( Mehtod *); // initializes data structures
|
MethodLiveVarInfo MLVI( Mehtod *); // initializes data structures
|
||||||
MLVI.analyze(); // do the actural live variable anal
|
MLVI.analyze(); // do the actural live variable anal
|
||||||
|
|
||||||
After the analysis, getInSetOfBB or getOutSetofBB can be called to get
|
After the analysis, getInSetOfBB or getOutSetofBB can be called to get
|
||||||
live var info of a BB
|
live var info of a BB.
|
||||||
|
|
||||||
The live var set before an instruction can be constructed in several ways:
|
The live var set before an instruction can be obtained in 2 ways:
|
||||||
|
|
||||||
1. Use the OutSet and applyTranferFuncForInst(const Instruction *const Inst)
|
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)
|
||||||
declared in LiveVarSet and traverse the instructions of a basic block in
|
declared in LiveVarSet and traverse the instructions of a basic block in
|
||||||
reverse (using const_reverse_iterator in the BB class).
|
reverse (using const_reverse_iterator in the BB class).
|
||||||
|
|
||||||
This is the most efficient method if you need LV info for several (all)
|
This is the most memory efficient method if you need LV info for
|
||||||
instructions in a BasicBlock. An example is given below:
|
only several instructions in a BasicBlock. An example is given below:
|
||||||
|
|
||||||
|
|
||||||
LiveVarSet LVSet; // this will be the set used to traverse through each BB
|
LiveVarSet LVSet; // this will be the set used to traverse through each BB
|
||||||
@@ -30,7 +42,7 @@
|
|||||||
LVSet.setUnion( LVI->getOutSetOfBB( *BBI ) );
|
LVSet.setUnion( LVI->getOutSetOfBB( *BBI ) );
|
||||||
|
|
||||||
BasicBlock::InstListType::const_reverse_iterator
|
BasicBlock::InstListType::const_reverse_iterator
|
||||||
InstIterator = InstListInBB.rbegin(); // get the reverse it for inst in BB
|
InstIterator = InstListInBB.rbegin(); // get the rev iter for inst in BB
|
||||||
|
|
||||||
// iterate over all the instructions in BB in reverse
|
// iterate over all the instructions in BB in reverse
|
||||||
for( ; InstIterator != InstListInBB.rend(); InstIterator++) {
|
for( ; InstIterator != InstListInBB.rend(); InstIterator++) {
|
||||||
@@ -45,28 +57,16 @@
|
|||||||
See buildInterferenceGraph() for the above example.
|
See buildInterferenceGraph() for the above example.
|
||||||
|
|
||||||
|
|
||||||
2. Use the function getLiveVarSetBeforeInst(Instruction *) to get the LV Info
|
|
||||||
just before an instruction.
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
|
|
||||||
**BUGS: Cannot be called on a method prototype because the BB front()
|
|
||||||
iterator causes a seg fault in CFG.h (Chris will fix this)
|
|
||||||
So, currently, DO NOT call this for method prototypes.
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef METH_LIVE_VAR_INFO_H
|
#ifndef METH_LIVE_VAR_INFO_H
|
||||||
#define METH_LIVE_VAR_INFO_H
|
#define METH_LIVE_VAR_INFO_H
|
||||||
|
|
||||||
// for printing out debug messages
|
// set DEBUG_LV for printing out debug messages
|
||||||
|
// if DEBUG_LV is 1 normal output messages
|
||||||
|
// if DEBUG_LV is 2 extensive debug info for each instr
|
||||||
|
|
||||||
#define DEBUG_LV (1)
|
#define DEBUG_LV (1)
|
||||||
|
|
||||||
#include "LiveVarSet.h"
|
#include "LiveVarSet.h"
|
||||||
@@ -82,38 +82,65 @@
|
|||||||
class MethodLiveVarInfo
|
class MethodLiveVarInfo
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
const Method *Meth; // Live var anal is done on this method
|
|
||||||
// set by constructor
|
|
||||||
|
|
||||||
BBToBBLiveVarMapType BB2BBLVMap; // A map betwn the BasicBlock and BBLiveVar
|
// Live var anal is done on this method - set by constructor
|
||||||
|
const Method *const Meth;
|
||||||
|
|
||||||
InstToLiveVarSetMapType Inst2LVSetMap; // Instruction to LiveVarSet Map
|
// A map betwn the BasicBlock and BBLiveVar
|
||||||
//- for providing LV info for each inst
|
BBToBBLiveVarMapType BB2BBLVMap;
|
||||||
|
|
||||||
void constructBBs(); // constructs BBLiveVars and init Def and In sets
|
// Machine Instr to LiveVarSet Map for providing LVset BEFORE each inst
|
||||||
bool doSingleBackwardPass(); // do one backward pass over the CFG
|
MInstToLiveVarSetMapType MInst2LVSetBI;
|
||||||
|
|
||||||
|
// Machine Instr to LiveVarSet Map for providing LVset AFTER each inst
|
||||||
|
MInstToLiveVarSetMapType MInst2LVSetAI;
|
||||||
|
|
||||||
|
// True if the analyze() method has been called. This is checked when
|
||||||
|
// getInSet/OutSet is called to prevent calling those methods before analyze
|
||||||
|
bool HasAnalyzed;
|
||||||
|
|
||||||
|
|
||||||
|
// --------- private methods -----------------------------------------
|
||||||
|
|
||||||
|
// constructs BBLiveVars and init Def and In sets
|
||||||
|
void constructBBs();
|
||||||
|
|
||||||
|
// do one backward pass over the CFG
|
||||||
|
bool doSingleBackwardPass();
|
||||||
|
|
||||||
|
// calculates live var sets for instructions in a BB
|
||||||
|
void calcLiveVarSetsForBB(const BasicBlock *const BB);
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MethodLiveVarInfo(Method *const Meth); // constructor
|
MethodLiveVarInfo(const Method *const Meth); // constructor
|
||||||
|
|
||||||
~MethodLiveVarInfo(); // destructor
|
~MethodLiveVarInfo(); // destructor
|
||||||
|
|
||||||
void analyze(); // performs a liver var analysis of a single method
|
// performs a liver var analysis of a single method
|
||||||
|
void analyze();
|
||||||
|
|
||||||
// gets OutSet of a BB
|
// gets OutSet of a BB
|
||||||
inline const LiveVarSet *getOutSetOfBB( const BasicBlock *const BB) const {
|
inline const LiveVarSet *getOutSetOfBB( const BasicBlock *const BB) const {
|
||||||
|
assert( HasAnalyzed && "call analyze() before calling this" );
|
||||||
return ( (* (BB2BBLVMap.find(BB)) ).second )->getOutSet();
|
return ( (* (BB2BBLVMap.find(BB)) ).second )->getOutSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
// gets InSet of a BB
|
// gets InSet of a BB
|
||||||
inline const LiveVarSet *getInSetOfBB( const BasicBlock *const BB) const {
|
inline const LiveVarSet *getInSetOfBB( const BasicBlock *const BB) const {
|
||||||
|
assert( HasAnalyzed && "call analyze() before calling this" );
|
||||||
return ( (* (BB2BBLVMap.find(BB)) ).second )->getInSet();
|
return ( (* (BB2BBLVMap.find(BB)) ).second )->getInSet();
|
||||||
}
|
}
|
||||||
// gets the Live var set before an instruction
|
|
||||||
const LiveVarSet *
|
// gets the Live var set BEFORE an instruction
|
||||||
MethodLiveVarInfo::getLiveVarSetBeforeInst(const Instruction *const Inst);
|
const LiveVarSet * getLiveVarSetBeforeMInst(const MachineInstr *const Inst,
|
||||||
|
const BasicBlock *const CurBB);
|
||||||
|
|
||||||
|
// gets the Live var set AFTER an instruction
|
||||||
|
const LiveVarSet * getLiveVarSetAfterMInst(const MachineInstr *const MInst,
|
||||||
|
const BasicBlock *const CurBB);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/* Title: ValueSet.h
|
/* Title: LiveVarMap.h
|
||||||
Author: Ruchira Sasanka
|
Author: Ruchira Sasanka
|
||||||
Date: Jun 30, 01
|
Date: Jun 30, 01
|
||||||
Purpose: This file contains the class for a map between the BasicBlock class
|
Purpose: This file contains the class for a map between the BasicBlock class
|
||||||
@@ -18,8 +18,8 @@ class BasicBlock;
|
|||||||
class BBLiveVar;
|
class BBLiveVar;
|
||||||
|
|
||||||
|
|
||||||
struct hashFuncInst { // sturcture containing the hash function for Inst
|
struct hashFuncMInst { // sturcture containing the hash function for MInst
|
||||||
inline size_t operator () (const Instruction *val) const {
|
inline size_t operator () (const MachineInstr *val) const {
|
||||||
return (size_t) val;
|
return (size_t) val;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -37,8 +37,8 @@ struct hashFuncBB { // sturcture containing the hash function for BB
|
|||||||
typedef hash_map<const BasicBlock *,
|
typedef hash_map<const BasicBlock *,
|
||||||
BBLiveVar *, hashFuncBB > BBToBBLiveVarMapType;
|
BBLiveVar *, hashFuncBB > BBToBBLiveVarMapType;
|
||||||
|
|
||||||
typedef hash_map<const Instruction *, const LiveVarSet *,
|
typedef hash_map<const MachineInstr *, const LiveVarSet *,
|
||||||
hashFuncInst> InstToLiveVarSetMapType;
|
hashFuncMInst> MInstToLiveVarSetMapType;
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/* Title: ValueSet.h
|
/* Title: LiveVarSet.h
|
||||||
Author: Ruchira Sasanka
|
Author: Ruchira Sasanka
|
||||||
Date: Jun 30, 01
|
Date: Jun 30, 01
|
||||||
Purpose: Contains the class definition of LiveVarSet which is used for
|
Purpose: Contains the class definition of LiveVarSet which is used for
|
||||||
@@ -16,7 +16,11 @@ class LiveVarSet : public ValueSet
|
|||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void applyTranferFuncForInst(const Instruction *const Inst);
|
|
||||||
|
// This function applies a machine instr to a live var set (accepts OutSet)
|
||||||
|
// and makes necessary changes to it (produces InSet).
|
||||||
|
|
||||||
|
void applyTranferFuncForMInst(const MachineInstr *const MInst);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
Author: Ruchira Sasanka
|
Author: Ruchira Sasanka
|
||||||
Date: Jun 30, 01
|
Date: Jun 30, 01
|
||||||
Purpose: Contains a mathematical set of Values. LiveVarSet is derived from
|
Purpose: Contains a mathematical set of Values. LiveVarSet is derived from
|
||||||
this. Contains both class and method definitions
|
this. Contains both class and method definitions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef VALUE_SET_H
|
#ifndef VALUE_SET_H
|
||||||
@@ -20,14 +20,14 @@
|
|||||||
|
|
||||||
//------------------------ Support functions ---------------------------------
|
//------------------------ Support functions ---------------------------------
|
||||||
|
|
||||||
struct hashFuncValue { // sturcture containing the hash function.
|
struct hashFuncValue { // sturcture containing the hash func
|
||||||
inline size_t operator () (const Value *const val) const
|
inline size_t operator () (const Value *const val) const
|
||||||
{ return (size_t) val; }
|
{ return (size_t) val; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//------------------- Class Definition for ValueSet ----------------------------
|
//------------------- Class Definition for ValueSet --------------------------
|
||||||
|
|
||||||
void printValue( const Value *const v); // func to print a Value
|
void printValue( const Value *const v); // func to print a Value
|
||||||
|
|
||||||
@@ -43,12 +43,12 @@ class ValueSet : public hash_set<const Value *, hashFuncValue >
|
|||||||
{ assert( val ); insert(val);} // for adding a live variable to set
|
{ assert( val ); insert(val);} // for adding a live variable to set
|
||||||
|
|
||||||
inline void remove(const Value *const val)
|
inline void remove(const Value *const val)
|
||||||
{ assert( val ); erase(val); } // for removing a live variable from set
|
{ assert( val ); erase(val); } // for removing a live var from set
|
||||||
|
|
||||||
|
bool setUnion( const ValueSet *const set1); // for performing set union
|
||||||
|
void setSubtract( const ValueSet *const set1); // for performing set diff
|
||||||
|
|
||||||
bool setUnion( const ValueSet *const set1); // for performing two set unions
|
|
||||||
void setSubtract( const ValueSet *const set1); // for performing set difference
|
|
||||||
|
|
||||||
// for performing set difference
|
|
||||||
void setDifference( const ValueSet *const set1, const ValueSet *const set2);
|
void setDifference( const ValueSet *const set1, const ValueSet *const set2);
|
||||||
|
|
||||||
void printSet() const; // for printing a live variable set
|
void printSet() const; // for printing a live variable set
|
||||||
|
@@ -3,25 +3,37 @@
|
|||||||
Date: Jun 30, 01
|
Date: Jun 30, 01
|
||||||
Purpose:
|
Purpose:
|
||||||
|
|
||||||
This is the interface for live variable info of a method that is required by
|
This is the interface for live variable info of a method that is required
|
||||||
any other part of the compiler
|
by any other part of the compiler
|
||||||
|
|
||||||
It should be called like:
|
It must be called like:
|
||||||
|
|
||||||
MethodLiveVarInfo MLVI( Mehtod *); // initializes data structures
|
MethodLiveVarInfo MLVI( Mehtod *); // initializes data structures
|
||||||
MLVI.analyze(); // do the actural live variable anal
|
MLVI.analyze(); // do the actural live variable anal
|
||||||
|
|
||||||
After the analysis, getInSetOfBB or getOutSetofBB can be called to get
|
After the analysis, getInSetOfBB or getOutSetofBB can be called to get
|
||||||
live var info of a BB
|
live var info of a BB.
|
||||||
|
|
||||||
The live var set before an instruction can be constructed in several ways:
|
The live var set before an instruction can be obtained in 2 ways:
|
||||||
|
|
||||||
1. Use the OutSet and applyTranferFuncForInst(const Instruction *const Inst)
|
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)
|
||||||
declared in LiveVarSet and traverse the instructions of a basic block in
|
declared in LiveVarSet and traverse the instructions of a basic block in
|
||||||
reverse (using const_reverse_iterator in the BB class).
|
reverse (using const_reverse_iterator in the BB class).
|
||||||
|
|
||||||
This is the most efficient method if you need LV info for several (all)
|
This is the most memory efficient method if you need LV info for
|
||||||
instructions in a BasicBlock. An example is given below:
|
only several instructions in a BasicBlock. An example is given below:
|
||||||
|
|
||||||
|
|
||||||
LiveVarSet LVSet; // this will be the set used to traverse through each BB
|
LiveVarSet LVSet; // this will be the set used to traverse through each BB
|
||||||
@@ -30,7 +42,7 @@
|
|||||||
LVSet.setUnion( LVI->getOutSetOfBB( *BBI ) );
|
LVSet.setUnion( LVI->getOutSetOfBB( *BBI ) );
|
||||||
|
|
||||||
BasicBlock::InstListType::const_reverse_iterator
|
BasicBlock::InstListType::const_reverse_iterator
|
||||||
InstIterator = InstListInBB.rbegin(); // get the reverse it for inst in BB
|
InstIterator = InstListInBB.rbegin(); // get the rev iter for inst in BB
|
||||||
|
|
||||||
// iterate over all the instructions in BB in reverse
|
// iterate over all the instructions in BB in reverse
|
||||||
for( ; InstIterator != InstListInBB.rend(); InstIterator++) {
|
for( ; InstIterator != InstListInBB.rend(); InstIterator++) {
|
||||||
@@ -45,28 +57,16 @@
|
|||||||
See buildInterferenceGraph() for the above example.
|
See buildInterferenceGraph() for the above example.
|
||||||
|
|
||||||
|
|
||||||
2. Use the function getLiveVarSetBeforeInst(Instruction *) to get the LV Info
|
|
||||||
just before an instruction.
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
|
|
||||||
**BUGS: Cannot be called on a method prototype because the BB front()
|
|
||||||
iterator causes a seg fault in CFG.h (Chris will fix this)
|
|
||||||
So, currently, DO NOT call this for method prototypes.
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef METH_LIVE_VAR_INFO_H
|
#ifndef METH_LIVE_VAR_INFO_H
|
||||||
#define METH_LIVE_VAR_INFO_H
|
#define METH_LIVE_VAR_INFO_H
|
||||||
|
|
||||||
// for printing out debug messages
|
// set DEBUG_LV for printing out debug messages
|
||||||
|
// if DEBUG_LV is 1 normal output messages
|
||||||
|
// if DEBUG_LV is 2 extensive debug info for each instr
|
||||||
|
|
||||||
#define DEBUG_LV (1)
|
#define DEBUG_LV (1)
|
||||||
|
|
||||||
#include "LiveVarSet.h"
|
#include "LiveVarSet.h"
|
||||||
@@ -82,38 +82,65 @@
|
|||||||
class MethodLiveVarInfo
|
class MethodLiveVarInfo
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
const Method *Meth; // Live var anal is done on this method
|
|
||||||
// set by constructor
|
|
||||||
|
|
||||||
BBToBBLiveVarMapType BB2BBLVMap; // A map betwn the BasicBlock and BBLiveVar
|
// Live var anal is done on this method - set by constructor
|
||||||
|
const Method *const Meth;
|
||||||
|
|
||||||
InstToLiveVarSetMapType Inst2LVSetMap; // Instruction to LiveVarSet Map
|
// A map betwn the BasicBlock and BBLiveVar
|
||||||
//- for providing LV info for each inst
|
BBToBBLiveVarMapType BB2BBLVMap;
|
||||||
|
|
||||||
void constructBBs(); // constructs BBLiveVars and init Def and In sets
|
// Machine Instr to LiveVarSet Map for providing LVset BEFORE each inst
|
||||||
bool doSingleBackwardPass(); // do one backward pass over the CFG
|
MInstToLiveVarSetMapType MInst2LVSetBI;
|
||||||
|
|
||||||
|
// Machine Instr to LiveVarSet Map for providing LVset AFTER each inst
|
||||||
|
MInstToLiveVarSetMapType MInst2LVSetAI;
|
||||||
|
|
||||||
|
// True if the analyze() method has been called. This is checked when
|
||||||
|
// getInSet/OutSet is called to prevent calling those methods before analyze
|
||||||
|
bool HasAnalyzed;
|
||||||
|
|
||||||
|
|
||||||
|
// --------- private methods -----------------------------------------
|
||||||
|
|
||||||
|
// constructs BBLiveVars and init Def and In sets
|
||||||
|
void constructBBs();
|
||||||
|
|
||||||
|
// do one backward pass over the CFG
|
||||||
|
bool doSingleBackwardPass();
|
||||||
|
|
||||||
|
// calculates live var sets for instructions in a BB
|
||||||
|
void calcLiveVarSetsForBB(const BasicBlock *const BB);
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MethodLiveVarInfo(Method *const Meth); // constructor
|
MethodLiveVarInfo(const Method *const Meth); // constructor
|
||||||
|
|
||||||
~MethodLiveVarInfo(); // destructor
|
~MethodLiveVarInfo(); // destructor
|
||||||
|
|
||||||
void analyze(); // performs a liver var analysis of a single method
|
// performs a liver var analysis of a single method
|
||||||
|
void analyze();
|
||||||
|
|
||||||
// gets OutSet of a BB
|
// gets OutSet of a BB
|
||||||
inline const LiveVarSet *getOutSetOfBB( const BasicBlock *const BB) const {
|
inline const LiveVarSet *getOutSetOfBB( const BasicBlock *const BB) const {
|
||||||
|
assert( HasAnalyzed && "call analyze() before calling this" );
|
||||||
return ( (* (BB2BBLVMap.find(BB)) ).second )->getOutSet();
|
return ( (* (BB2BBLVMap.find(BB)) ).second )->getOutSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
// gets InSet of a BB
|
// gets InSet of a BB
|
||||||
inline const LiveVarSet *getInSetOfBB( const BasicBlock *const BB) const {
|
inline const LiveVarSet *getInSetOfBB( const BasicBlock *const BB) const {
|
||||||
|
assert( HasAnalyzed && "call analyze() before calling this" );
|
||||||
return ( (* (BB2BBLVMap.find(BB)) ).second )->getInSet();
|
return ( (* (BB2BBLVMap.find(BB)) ).second )->getInSet();
|
||||||
}
|
}
|
||||||
// gets the Live var set before an instruction
|
|
||||||
const LiveVarSet *
|
// gets the Live var set BEFORE an instruction
|
||||||
MethodLiveVarInfo::getLiveVarSetBeforeInst(const Instruction *const Inst);
|
const LiveVarSet * getLiveVarSetBeforeMInst(const MachineInstr *const Inst,
|
||||||
|
const BasicBlock *const CurBB);
|
||||||
|
|
||||||
|
// gets the Live var set AFTER an instruction
|
||||||
|
const LiveVarSet * getLiveVarSetAfterMInst(const MachineInstr *const MInst,
|
||||||
|
const BasicBlock *const CurBB);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
Author: Ruchira Sasanka
|
Author: Ruchira Sasanka
|
||||||
Date: Jun 30, 01
|
Date: Jun 30, 01
|
||||||
Purpose: Contains a mathematical set of Values. LiveVarSet is derived from
|
Purpose: Contains a mathematical set of Values. LiveVarSet is derived from
|
||||||
this. Contains both class and method definitions
|
this. Contains both class and method definitions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef VALUE_SET_H
|
#ifndef VALUE_SET_H
|
||||||
@@ -20,14 +20,14 @@
|
|||||||
|
|
||||||
//------------------------ Support functions ---------------------------------
|
//------------------------ Support functions ---------------------------------
|
||||||
|
|
||||||
struct hashFuncValue { // sturcture containing the hash function.
|
struct hashFuncValue { // sturcture containing the hash func
|
||||||
inline size_t operator () (const Value *const val) const
|
inline size_t operator () (const Value *const val) const
|
||||||
{ return (size_t) val; }
|
{ return (size_t) val; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//------------------- Class Definition for ValueSet ----------------------------
|
//------------------- Class Definition for ValueSet --------------------------
|
||||||
|
|
||||||
void printValue( const Value *const v); // func to print a Value
|
void printValue( const Value *const v); // func to print a Value
|
||||||
|
|
||||||
@@ -43,12 +43,12 @@ class ValueSet : public hash_set<const Value *, hashFuncValue >
|
|||||||
{ assert( val ); insert(val);} // for adding a live variable to set
|
{ assert( val ); insert(val);} // for adding a live variable to set
|
||||||
|
|
||||||
inline void remove(const Value *const val)
|
inline void remove(const Value *const val)
|
||||||
{ assert( val ); erase(val); } // for removing a live variable from set
|
{ assert( val ); erase(val); } // for removing a live var from set
|
||||||
|
|
||||||
|
bool setUnion( const ValueSet *const set1); // for performing set union
|
||||||
|
void setSubtract( const ValueSet *const set1); // for performing set diff
|
||||||
|
|
||||||
bool setUnion( const ValueSet *const set1); // for performing two set unions
|
|
||||||
void setSubtract( const ValueSet *const set1); // for performing set difference
|
|
||||||
|
|
||||||
// for performing set difference
|
|
||||||
void setDifference( const ValueSet *const set1, const ValueSet *const set2);
|
void setDifference( const ValueSet *const set1, const ValueSet *const set2);
|
||||||
|
|
||||||
void printSet() const; // for printing a live variable set
|
void printSet() const; // for printing a live variable set
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
/* Title: ValueSet.h
|
/* Title: BBLiveVar.h
|
||||||
Author: Ruchira Sasanka
|
Author: Ruchira Sasanka
|
||||||
Date: Jun 30, 01
|
Date: Jun 30, 01
|
||||||
Purpose: This is a wrapper class for BasicBlock which is used by live
|
Purpose: This is a wrapper class for BasicBlock which is used by live
|
||||||
variable anaysis
|
variable anaysis.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LIVE_VAR_BB_H
|
#ifndef LIVE_VAR_BB_H
|
||||||
@@ -28,6 +28,7 @@ class BBLiveVar
|
|||||||
bool InSetChanged, OutSetChanged; // set if the InSet/OutSet is modified
|
bool InSetChanged, OutSetChanged; // set if the InSet/OutSet is modified
|
||||||
|
|
||||||
// map that contains phi args->BB they came
|
// map that contains phi args->BB they came
|
||||||
|
// set by calcDefUseSets & used by setPropagate
|
||||||
hash_map<const Value *, const BasicBlock *, hashFuncValue> PhiArgMap;
|
hash_map<const Value *, const BasicBlock *, hashFuncValue> PhiArgMap;
|
||||||
|
|
||||||
// method to propogate an InSet to OutSet of a predecessor
|
// method to propogate an InSet to OutSet of a predecessor
|
||||||
@@ -56,7 +57,9 @@ class BBLiveVar
|
|||||||
void printAllSets() const; // for printing Def/In/Out sets
|
void printAllSets() const; // for printing Def/In/Out sets
|
||||||
void printInOutSets() const; // for printing In/Out sets
|
void printInOutSets() const; // for printing In/Out sets
|
||||||
|
|
||||||
//TODO write a destructor to deallocate Def/In.Out sets and PhiArgMap
|
~BBLiveVar() { } // nothing to do since only composite objects
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -65,5 +68,6 @@ class BBLiveVar
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
/* Title: ValueSet.h
|
/* Title: BBLiveVar.h
|
||||||
Author: Ruchira Sasanka
|
Author: Ruchira Sasanka
|
||||||
Date: Jun 30, 01
|
Date: Jun 30, 01
|
||||||
Purpose: This is a wrapper class for BasicBlock which is used by live
|
Purpose: This is a wrapper class for BasicBlock which is used by live
|
||||||
variable anaysis
|
variable anaysis.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LIVE_VAR_BB_H
|
#ifndef LIVE_VAR_BB_H
|
||||||
@@ -28,6 +28,7 @@ class BBLiveVar
|
|||||||
bool InSetChanged, OutSetChanged; // set if the InSet/OutSet is modified
|
bool InSetChanged, OutSetChanged; // set if the InSet/OutSet is modified
|
||||||
|
|
||||||
// map that contains phi args->BB they came
|
// map that contains phi args->BB they came
|
||||||
|
// set by calcDefUseSets & used by setPropagate
|
||||||
hash_map<const Value *, const BasicBlock *, hashFuncValue> PhiArgMap;
|
hash_map<const Value *, const BasicBlock *, hashFuncValue> PhiArgMap;
|
||||||
|
|
||||||
// method to propogate an InSet to OutSet of a predecessor
|
// method to propogate an InSet to OutSet of a predecessor
|
||||||
@@ -56,7 +57,9 @@ class BBLiveVar
|
|||||||
void printAllSets() const; // for printing Def/In/Out sets
|
void printAllSets() const; // for printing Def/In/Out sets
|
||||||
void printInOutSets() const; // for printing In/Out sets
|
void printInOutSets() const; // for printing In/Out sets
|
||||||
|
|
||||||
//TODO write a destructor to deallocate Def/In.Out sets and PhiArgMap
|
~BBLiveVar() { } // nothing to do since only composite objects
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -65,5 +68,6 @@ class BBLiveVar
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user