//===-- BBLiveVar.cpp - Live Variable Analysis for a BasicBlock -----------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
//
// This is a wrapper class for BasicBlock which is used by live var analysis.
//
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/Support/CFG.h"
#include "Support/SetOperations.h"
+#include "../SparcInternals.h"
-/// BROKEN: Should not include sparc stuff directly into here
-#include "../../Target/Sparc/SparcInternals.h" // Only for PHI defn
-
-using std::cerr;
-
-static AnnotationID AID(AnnotationManager::getID("Analysis::BBLiveVar"));
-
-BBLiveVar *BBLiveVar::CreateOnBB(const BasicBlock &BB, MachineBasicBlock &MBB,
- unsigned POID) {
- BBLiveVar *Result = new BBLiveVar(BB, MBB, POID);
- BB.addAnnotation(Result);
- return Result;
-}
-
-BBLiveVar *BBLiveVar::GetFromBB(const BasicBlock &BB) {
- return (BBLiveVar*)BB.getAnnotation(AID);
-}
-
-void BBLiveVar::RemoveFromBB(const BasicBlock &BB) {
- bool Deleted = BB.deleteAnnotation(AID);
- assert(Deleted && "BBLiveVar annotation did not exist!");
-}
-
+namespace llvm {
-BBLiveVar::BBLiveVar(const BasicBlock &bb, MachineBasicBlock &mbb, unsigned id)
- : Annotation(AID), BB(bb), MBB(mbb), POID(id) {
+BBLiveVar::BBLiveVar(const BasicBlock &bb,
+ const MachineBasicBlock &mbb,
+ unsigned id)
+ : BB(bb), MBB(mbb), POID(id) {
InSetChanged = OutSetChanged = false;
calcDefUseSets();
const MachineInstr *MI = *MII;
if (DEBUG_LV >= LV_DEBUG_Verbose) {
- cerr << " *Iterating over machine instr ";
+ std::cerr << " *Iterating over machine instr ";
MI->dump();
- cerr << "\n";
+ std::cerr << "\n";
}
// iterate over MI operands to find defs
for (MachineInstr::const_val_op_iterator OpI = MI->begin(), OpE = MI->end();
OpI != OpE; ++OpI)
- if (OpI.isDef()) // add to Defs only if this operand is a def
+ if (OpI.isDef()) // add to Defs if this operand is a def
addDef(*OpI);
// do for implicit operands as well
for (unsigned i = 0; i < MI->getNumImplicitRefs(); ++i)
- if (MI->implicitRefIsDefined(i))
+ if (MI->getImplicitOp(i).isDef())
addDef(MI->getImplicitRef(i));
// iterate over MI operands to find uses
if (isa<BasicBlock>(Op))
continue; // don't process labels
- if (!OpI.isDef() || OpI.isDefAndUse()) {
- // add to Uses only if this operand is a use
+ if (OpI.isUse()) { // add to Uses only if this operand is a use
//
// *** WARNING: The following code for handling dummy PHI machine
// instructions is untested. The previous code was broken and I
PredToEdgeInSetMap[PredBB].insert(ArgVal);
if (DEBUG_LV >= LV_DEBUG_Verbose)
- cerr << " - phi operand " << RAV(ArgVal) << " came from BB "
- << RAV(PredBB) << "\n";
+ std::cerr << " - phi operand " << RAV(ArgVal) << " came from BB "
+ << RAV(PredBB) << "\n";
} // if( IsPhi )
else {
// It is not a Phi use: add to regular use set and remove later defs.
if (Op->getType() == Type::LabelTy) // don't process labels
continue;
- if (!MI->implicitRefIsDefined(i) || MI->implicitRefIsDefinedAndUsed(i) )
+ if (MI->getImplicitOp(i).isUse())
addUse(Op);
}
} // for all machine instructions
InSet.erase(Op); // this definition kills any later uses
InSetChanged = true;
- if (DEBUG_LV >= LV_DEBUG_Verbose) cerr << " +Def: " << RAV(Op) << "\n";
+ if (DEBUG_LV >= LV_DEBUG_Verbose) std::cerr << " +Def: " << RAV(Op) << "\n";
}
DefSet.erase(Op); // remove if there is a def below this use
InSetChanged = true;
- if (DEBUG_LV >= LV_DEBUG_Verbose) cerr << " Use: " << RAV(Op) << "\n";
+ if (DEBUG_LV >= LV_DEBUG_Verbose) std::cerr << " Use: " << RAV(Op) << "\n";
}
// propagates in set to OutSets of PREDECESSORs
//-----------------------------------------------------------------------------
-bool BBLiveVar::applyFlowFunc() {
+bool BBLiveVar::applyFlowFunc(hash_map<const BasicBlock*,
+ BBLiveVar*> &BBLiveVarInfo) {
// IMPORTANT: caller should check whether inset changed
// (else no point in calling)
for (pred_const_iterator PI = pred_begin(&BB), PE = pred_end(&BB);
PI != PE ; ++PI) {
- BBLiveVar *PredLVBB = BBLiveVar::GetFromBB(**PI);
+ BBLiveVar *PredLVBB = BBLiveVarInfo[*PI];
// do set union
if (setPropagate(&PredLVBB->OutSet, &InSet, *PI)) {
// ----------------- Methods For Debugging (Printing) -----------------
void BBLiveVar::printAllSets() const {
- cerr << " Defs: "; printSet(DefSet); cerr << "\n";
- cerr << " In: "; printSet(InSet); cerr << "\n";
- cerr << " Out: "; printSet(OutSet); cerr << "\n";
+ std::cerr << " Defs: "; printSet(DefSet); std::cerr << "\n";
+ std::cerr << " In: "; printSet(InSet); std::cerr << "\n";
+ std::cerr << " Out: "; printSet(OutSet); std::cerr << "\n";
}
void BBLiveVar::printInOutSets() const {
- cerr << " In: "; printSet(InSet); cerr << "\n";
- cerr << " Out: "; printSet(OutSet); cerr << "\n";
+ std::cerr << " In: "; printSet(InSet); std::cerr << "\n";
+ std::cerr << " Out: "; printSet(OutSet); std::cerr << "\n";
}
-
-
-
+} // End llvm namespace