//===-- 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 "BBLiveVar.h"
-#include "llvm/Analysis/LiveVar/FunctionLiveVarInfo.h"
+#include "llvm/CodeGen/FunctionLiveVarInfo.h"
#include "llvm/CodeGen/MachineInstr.h"
-#include "llvm/BasicBlock.h"
+#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/Support/CFG.h"
#include "Support/SetOperations.h"
-#include <iostream>
/// BROKEN: Should not include sparc stuff directly into here
#include "../../Target/Sparc/SparcInternals.h" // Only for PHI defn
static AnnotationID AID(AnnotationManager::getID("Analysis::BBLiveVar"));
-BBLiveVar *BBLiveVar::CreateOnBB(const BasicBlock *BB, unsigned POID) {
- BBLiveVar *Result = new BBLiveVar(BB, POID);
- BB->addAnnotation(Result);
+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);
+BBLiveVar *BBLiveVar::GetFromBB(const BasicBlock &BB) {
+ return (BBLiveVar*)BB.getAnnotation(AID);
}
-void BBLiveVar::RemoveFromBB(const BasicBlock *BB) {
- bool Deleted = BB->deleteAnnotation(AID);
+void BBLiveVar::RemoveFromBB(const BasicBlock &BB) {
+ bool Deleted = BB.deleteAnnotation(AID);
assert(Deleted && "BBLiveVar annotation did not exist!");
}
-BBLiveVar::BBLiveVar(const BasicBlock *bb, unsigned id)
- : Annotation(AID), BB(bb), POID(id) {
+BBLiveVar::BBLiveVar(const BasicBlock &bb, MachineBasicBlock &mbb, unsigned id)
+ : Annotation(AID), BB(bb), MBB(mbb), POID(id) {
InSetChanged = OutSetChanged = false;
calcDefUseSets();
//-----------------------------------------------------------------------------
void BBLiveVar::calcDefUseSets() {
- // get the iterator for machine instructions
- const MachineCodeForBasicBlock &MIVec = BB->getMachineInstrVec();
-
// iterate over all the machine instructions in BB
- for (MachineCodeForBasicBlock::const_reverse_iterator MII = MIVec.rbegin(),
- MIE = MIVec.rend(); MII != MIE; ++MII) {
+ for (MachineBasicBlock::const_reverse_iterator MII = MBB.rbegin(),
+ MIE = MBB.rend(); MII != MIE; ++MII) {
const MachineInstr *MI = *MII;
- if (DEBUG_LV >= LV_DEBUG_Verbose) { // debug msg
+ if (DEBUG_LV >= LV_DEBUG_Verbose) {
cerr << " *Iterating over machine instr ";
MI->dump();
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.isDefOnly() || OpI.isDefAndUse()) // 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).opIsDefOnly() || MI->getImplicitOp(i).opIsDefAndUse())
addDef(MI->getImplicitRef(i));
// iterate over MI operands to find uses
if (isa<BasicBlock>(Op))
continue; // don't process labels
- if (!OpI.isDef()) { // add to Uses only if this operand is a use
-
+ if (OpI.isUseOnly() || OpI.isDefAndUse()) {
+ // 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
- // fixed it, but it turned out to be unused as long as Phi elimination
- // is performed during instruction selection.
+ // fixed it, but it turned out to be unused as long as Phi
+ // elimination is performed during instruction selection.
//
// Put Phi operands in UseSet for the incoming edge, not node.
// They must not "hide" later defs, and must be handled specially
// during set propagation over the CFG.
- if (MI->getOpCode() == PHI) { // for a phi node
+ if (MI->getOpCode() == V9::PHI) { // for a phi node
const Value *ArgVal = Op;
const BasicBlock *PredBB = cast<BasicBlock>(*++OpI); // next ptr is BB
if (DEBUG_LV >= LV_DEBUG_Verbose)
cerr << " - phi operand " << RAV(ArgVal) << " came from BB "
- << RAV(PredBB) << endl;
+ << RAV(PredBB) << "\n";
} // if( IsPhi )
else {
// It is not a Phi use: add to regular use set and remove later defs.
// do for implicit operands as well
for (unsigned i = 0; i < MI->getNumImplicitRefs(); ++i) {
- assert(MI->getOpCode() != PHI && "Phi cannot have implicit opeands");
+ assert(MI->getOpCode() != V9::PHI && "Phi cannot have implicit operands");
const Value *Op = MI->getImplicitRef(i);
if (Op->getType() == Type::LabelTy) // don't process labels
continue;
- if (!MI->implicitRefIsDefined(i))
+ if (MI->getImplicitOp(i).opIsUse() || MI->getImplicitOp(i).opIsDefAndUse())
addUse(Op);
}
} // for all machine instructions
//-----------------------------------------------------------------------------
// To add an operand which is a def
//-----------------------------------------------------------------------------
-void BBLiveVar::addDef(const Value *Op) {
+void BBLiveVar::addDef(const Value *Op) {
DefSet.insert(Op); // operand is a def - so add to def set
InSet.erase(Op); // this definition kills any later uses
InSetChanged = true;
//-----------------------------------------------------------------------------
-// propogates in set to OutSets of PREDECESSORs
+// propagates in set to OutSets of PREDECESSORs
//-----------------------------------------------------------------------------
bool BBLiveVar::applyFlowFunc() {
//
bool needAnotherIt = false;
- for (pred_const_iterator PI = pred_begin(BB), PE = pred_end(BB);
+ for (pred_const_iterator PI = pred_begin(&BB), PE = pred_end(&BB);
PI != PE ; ++PI) {
- BBLiveVar *PredLVBB = BBLiveVar::GetFromBB(*PI);
+ BBLiveVar *PredLVBB = BBLiveVar::GetFromBB(**PI);
// do set union
if (setPropagate(&PredLVBB->OutSet, &InSet, *PI)) {