For an instruction with delay slots, mark all live values before

the instruction as being live before/after the delay slot
instructions as well.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7795 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Vikram S. Adve 2003-08-12 22:19:59 +00:00
parent aee2fdf069
commit 88d962aa58
4 changed files with 84 additions and 32 deletions

View File

@ -72,7 +72,10 @@ class BBLiveVar : public Annotation {
bool applyFlowFunc(); bool applyFlowFunc();
inline const ValueSet &getOutSet() const { return OutSet; } inline const ValueSet &getOutSet() const { return OutSet; }
inline ValueSet &getOutSet() { return OutSet; }
inline const ValueSet &getInSet() const { return InSet; } inline const ValueSet &getInSet() const { return InSet; }
inline ValueSet &getInSet() { return InSet; }
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

View File

@ -8,6 +8,8 @@
#include "llvm/CodeGen/FunctionLiveVarInfo.h" #include "llvm/CodeGen/FunctionLiveVarInfo.h"
#include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineFunction.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetInstrInfo.h"
#include "llvm/Support/CFG.h" #include "llvm/Support/CFG.h"
#include "Support/PostOrderIterator.h" #include "Support/PostOrderIterator.h"
#include "Support/SetOperations.h" #include "Support/SetOperations.h"
@ -40,11 +42,17 @@ clEnumValN(LV_DEBUG_Verbose, "v", "print def, use sets for every instrn also"),
const ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) const { const ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) const {
return BBLiveVar::GetFromBB(*BB)->getOutSet(); return BBLiveVar::GetFromBB(*BB)->getOutSet();
} }
ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) {
return BBLiveVar::GetFromBB(*BB)->getOutSet();
}
// gets InSet of a BB // gets InSet of a BB
const ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const { const ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const {
return BBLiveVar::GetFromBB(*BB)->getInSet(); return BBLiveVar::GetFromBB(*BB)->getInSet();
} }
ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) {
return BBLiveVar::GetFromBB(*BB)->getInSet();
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -145,12 +153,13 @@ void FunctionLiveVarInfo::releaseMemory() {
M = 0; M = 0;
// Then delete all objects of type ValueSet created in calcLiveVarSetsForBB // Then delete all objects of type ValueSet created in calcLiveVarSetsForBB
// and entered into MInst2LVSetBI and MInst2LVSetAI (these are caches // and entered into MInst2LVSetBI and MInst2LVSetAI (these are caches
// to return ValueSet's before/after a machine instruction quickly). It // to return ValueSet's before/after a machine instruction quickly).
// is sufficient to free up all ValueSet using only one cache since // We do not need to free up ValueSets in MInst2LVSetAI because it holds
// both caches refer to the same sets // 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).
// //
for (std::map<const MachineInstr*, const ValueSet*>::iterator for (hash_map<const MachineInstr*, ValueSet*>::iterator
MI = MInst2LVSetBI.begin(), MI = MInst2LVSetBI.begin(),
ME = MInst2LVSetBI.end(); MI != ME; ++MI) ME = MInst2LVSetBI.end(); MI != ME; ++MI)
delete MI->second; // delete all ValueSets in MInst2LVSetBI delete MI->second; // delete all ValueSets in MInst2LVSetBI
@ -178,12 +187,12 @@ void FunctionLiveVarInfo::releaseMemory() {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
const ValueSet & const ValueSet &
FunctionLiveVarInfo::getLiveVarSetBeforeMInst(const MachineInstr *MInst, FunctionLiveVarInfo::getLiveVarSetBeforeMInst(const MachineInstr *MI,
const BasicBlock *BB) { const BasicBlock *BB) {
const ValueSet *LVSet = MInst2LVSetBI[MInst]; ValueSet* &LVSet = MInst2LVSetBI[MI]; // ref. to map entry
if (LVSet == NULL && BB != NULL) { // if not found and BB provided if (LVSet == NULL && BB != NULL) { // if not found and BB provided
calcLiveVarSetsForBB(BB); // calc LVSet for all instrs in BB calcLiveVarSetsForBB(BB); // calc LVSet for all instrs in BB
LVSet = MInst2LVSetBI[MInst]; assert(LVSet != NULL);
} }
return *LVSet; return *LVSet;
} }
@ -197,10 +206,10 @@ const ValueSet &
FunctionLiveVarInfo::getLiveVarSetAfterMInst(const MachineInstr *MI, FunctionLiveVarInfo::getLiveVarSetAfterMInst(const MachineInstr *MI,
const BasicBlock *BB) { const BasicBlock *BB) {
const ValueSet *LVSet = MInst2LVSetAI[MI]; ValueSet* &LVSet = MInst2LVSetAI[MI]; // ref. to map entry
if (LVSet == NULL && BB != NULL) { // if not found and BB provided if (LVSet == NULL && BB != NULL) { // if not found and BB provided
calcLiveVarSetsForBB(BB); // calc LVSet for all instrs in BB calcLiveVarSetsForBB(BB); // calc LVSet for all instrs in BB
return *MInst2LVSetAI[MI]; assert(LVSet != NULL);
} }
return *LVSet; return *LVSet;
} }
@ -250,14 +259,15 @@ void FunctionLiveVarInfo::calcLiveVarSetsForBB(const BasicBlock *BB) {
BBLiveVar *BBLV = BBLiveVar::GetFromBB(*BB); BBLiveVar *BBLV = BBLiveVar::GetFromBB(*BB);
assert(BBLV && "BBLiveVar annotation doesn't exist?"); assert(BBLV && "BBLiveVar annotation doesn't exist?");
const MachineBasicBlock &MIVec = BBLV->getMachineBasicBlock(); const MachineBasicBlock &MIVec = BBLV->getMachineBasicBlock();
const MachineFunction &MF = MachineFunction::get(M);
const TargetMachine &TM = MF.getTarget();
if (DEBUG_LV >= LV_DEBUG_Instr) if (DEBUG_LV >= LV_DEBUG_Instr)
std::cerr << "\n======For BB " << BB->getName() std::cerr << "\n======For BB " << BB->getName()
<< ": Live var sets for instructions======\n"; << ": Live var sets for instructions======\n";
ValueSet CurSet; ValueSet *SetAI = &getOutSetOfBB(BB); // init SetAI with OutSet
const ValueSet *SetAI = &getOutSetOfBB(BB); // init SetAI with OutSet ValueSet CurSet(*SetAI); // CurSet now contains OutSet
set_union(CurSet, *SetAI); // CurSet now contains OutSet
// iterate over all the machine instructions in BB // iterate over all the machine instructions in BB
for (MachineBasicBlock::const_reverse_iterator MII = MIVec.rbegin(), for (MachineBasicBlock::const_reverse_iterator MII = MIVec.rbegin(),
@ -268,11 +278,24 @@ void FunctionLiveVarInfo::calcLiveVarSetsForBB(const BasicBlock *BB) {
MInst2LVSetAI[MI] = SetAI; // record in After Inst map MInst2LVSetAI[MI] = SetAI; // record in After Inst map
applyTranferFuncForMInst(CurSet, MI); // apply the transfer Func applyTranferFuncForMInst(CurSet, MI); // apply the transfer Func
ValueSet *NewSet = new ValueSet(); // create a new set and ValueSet *NewSet = new ValueSet(CurSet); // create a new set with a copy
set_union(*NewSet, CurSet); // copy the set after T/F to it // of the set after T/F
MInst2LVSetBI[MI] = NewSet; // record in Before Inst map MInst2LVSetBI[MI] = NewSet; // record in Before Inst map
// 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;
set_union(*MInst2LVSetBI[DelaySlotMI], *NewSet);
if (i+1 == DS)
set_union(*MInst2LVSetAI[DelaySlotMI], *NewSet);
}
}
if (DEBUG_LV >= LV_DEBUG_Instr) { if (DEBUG_LV >= LV_DEBUG_Instr) {
std::cerr << "\nLive var sets before/after instruction " << *MI; std::cerr << "\nLive var sets before/after instruction " << *MI;
std::cerr << " Before: "; printSet(*NewSet); std::cerr << "\n"; std::cerr << " Before: "; printSet(*NewSet); std::cerr << "\n";

View File

@ -72,7 +72,10 @@ class BBLiveVar : public Annotation {
bool applyFlowFunc(); bool applyFlowFunc();
inline const ValueSet &getOutSet() const { return OutSet; } inline const ValueSet &getOutSet() const { return OutSet; }
inline ValueSet &getOutSet() { return OutSet; }
inline const ValueSet &getInSet() const { return InSet; } inline const ValueSet &getInSet() const { return InSet; }
inline ValueSet &getInSet() { return InSet; }
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

View File

@ -8,6 +8,8 @@
#include "llvm/CodeGen/FunctionLiveVarInfo.h" #include "llvm/CodeGen/FunctionLiveVarInfo.h"
#include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineFunction.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetInstrInfo.h"
#include "llvm/Support/CFG.h" #include "llvm/Support/CFG.h"
#include "Support/PostOrderIterator.h" #include "Support/PostOrderIterator.h"
#include "Support/SetOperations.h" #include "Support/SetOperations.h"
@ -40,11 +42,17 @@ clEnumValN(LV_DEBUG_Verbose, "v", "print def, use sets for every instrn also"),
const ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) const { const ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) const {
return BBLiveVar::GetFromBB(*BB)->getOutSet(); return BBLiveVar::GetFromBB(*BB)->getOutSet();
} }
ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) {
return BBLiveVar::GetFromBB(*BB)->getOutSet();
}
// gets InSet of a BB // gets InSet of a BB
const ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const { const ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const {
return BBLiveVar::GetFromBB(*BB)->getInSet(); return BBLiveVar::GetFromBB(*BB)->getInSet();
} }
ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) {
return BBLiveVar::GetFromBB(*BB)->getInSet();
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -145,12 +153,13 @@ void FunctionLiveVarInfo::releaseMemory() {
M = 0; M = 0;
// Then delete all objects of type ValueSet created in calcLiveVarSetsForBB // Then delete all objects of type ValueSet created in calcLiveVarSetsForBB
// and entered into MInst2LVSetBI and MInst2LVSetAI (these are caches // and entered into MInst2LVSetBI and MInst2LVSetAI (these are caches
// to return ValueSet's before/after a machine instruction quickly). It // to return ValueSet's before/after a machine instruction quickly).
// is sufficient to free up all ValueSet using only one cache since // We do not need to free up ValueSets in MInst2LVSetAI because it holds
// both caches refer to the same sets // 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).
// //
for (std::map<const MachineInstr*, const ValueSet*>::iterator for (hash_map<const MachineInstr*, ValueSet*>::iterator
MI = MInst2LVSetBI.begin(), MI = MInst2LVSetBI.begin(),
ME = MInst2LVSetBI.end(); MI != ME; ++MI) ME = MInst2LVSetBI.end(); MI != ME; ++MI)
delete MI->second; // delete all ValueSets in MInst2LVSetBI delete MI->second; // delete all ValueSets in MInst2LVSetBI
@ -178,12 +187,12 @@ void FunctionLiveVarInfo::releaseMemory() {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
const ValueSet & const ValueSet &
FunctionLiveVarInfo::getLiveVarSetBeforeMInst(const MachineInstr *MInst, FunctionLiveVarInfo::getLiveVarSetBeforeMInst(const MachineInstr *MI,
const BasicBlock *BB) { const BasicBlock *BB) {
const ValueSet *LVSet = MInst2LVSetBI[MInst]; ValueSet* &LVSet = MInst2LVSetBI[MI]; // ref. to map entry
if (LVSet == NULL && BB != NULL) { // if not found and BB provided if (LVSet == NULL && BB != NULL) { // if not found and BB provided
calcLiveVarSetsForBB(BB); // calc LVSet for all instrs in BB calcLiveVarSetsForBB(BB); // calc LVSet for all instrs in BB
LVSet = MInst2LVSetBI[MInst]; assert(LVSet != NULL);
} }
return *LVSet; return *LVSet;
} }
@ -197,10 +206,10 @@ const ValueSet &
FunctionLiveVarInfo::getLiveVarSetAfterMInst(const MachineInstr *MI, FunctionLiveVarInfo::getLiveVarSetAfterMInst(const MachineInstr *MI,
const BasicBlock *BB) { const BasicBlock *BB) {
const ValueSet *LVSet = MInst2LVSetAI[MI]; ValueSet* &LVSet = MInst2LVSetAI[MI]; // ref. to map entry
if (LVSet == NULL && BB != NULL) { // if not found and BB provided if (LVSet == NULL && BB != NULL) { // if not found and BB provided
calcLiveVarSetsForBB(BB); // calc LVSet for all instrs in BB calcLiveVarSetsForBB(BB); // calc LVSet for all instrs in BB
return *MInst2LVSetAI[MI]; assert(LVSet != NULL);
} }
return *LVSet; return *LVSet;
} }
@ -250,14 +259,15 @@ void FunctionLiveVarInfo::calcLiveVarSetsForBB(const BasicBlock *BB) {
BBLiveVar *BBLV = BBLiveVar::GetFromBB(*BB); BBLiveVar *BBLV = BBLiveVar::GetFromBB(*BB);
assert(BBLV && "BBLiveVar annotation doesn't exist?"); assert(BBLV && "BBLiveVar annotation doesn't exist?");
const MachineBasicBlock &MIVec = BBLV->getMachineBasicBlock(); const MachineBasicBlock &MIVec = BBLV->getMachineBasicBlock();
const MachineFunction &MF = MachineFunction::get(M);
const TargetMachine &TM = MF.getTarget();
if (DEBUG_LV >= LV_DEBUG_Instr) if (DEBUG_LV >= LV_DEBUG_Instr)
std::cerr << "\n======For BB " << BB->getName() std::cerr << "\n======For BB " << BB->getName()
<< ": Live var sets for instructions======\n"; << ": Live var sets for instructions======\n";
ValueSet CurSet; ValueSet *SetAI = &getOutSetOfBB(BB); // init SetAI with OutSet
const ValueSet *SetAI = &getOutSetOfBB(BB); // init SetAI with OutSet ValueSet CurSet(*SetAI); // CurSet now contains OutSet
set_union(CurSet, *SetAI); // CurSet now contains OutSet
// iterate over all the machine instructions in BB // iterate over all the machine instructions in BB
for (MachineBasicBlock::const_reverse_iterator MII = MIVec.rbegin(), for (MachineBasicBlock::const_reverse_iterator MII = MIVec.rbegin(),
@ -268,11 +278,24 @@ void FunctionLiveVarInfo::calcLiveVarSetsForBB(const BasicBlock *BB) {
MInst2LVSetAI[MI] = SetAI; // record in After Inst map MInst2LVSetAI[MI] = SetAI; // record in After Inst map
applyTranferFuncForMInst(CurSet, MI); // apply the transfer Func applyTranferFuncForMInst(CurSet, MI); // apply the transfer Func
ValueSet *NewSet = new ValueSet(); // create a new set and ValueSet *NewSet = new ValueSet(CurSet); // create a new set with a copy
set_union(*NewSet, CurSet); // copy the set after T/F to it // of the set after T/F
MInst2LVSetBI[MI] = NewSet; // record in Before Inst map MInst2LVSetBI[MI] = NewSet; // record in Before Inst map
// 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;
set_union(*MInst2LVSetBI[DelaySlotMI], *NewSet);
if (i+1 == DS)
set_union(*MInst2LVSetAI[DelaySlotMI], *NewSet);
}
}
if (DEBUG_LV >= LV_DEBUG_Instr) { if (DEBUG_LV >= LV_DEBUG_Instr) {
std::cerr << "\nLive var sets before/after instruction " << *MI; std::cerr << "\nLive var sets before/after instruction " << *MI;
std::cerr << " Before: "; printSet(*NewSet); std::cerr << "\n"; std::cerr << " Before: "; printSet(*NewSet); std::cerr << "\n";