*** empty log message ***

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2777 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2002-06-25 16:12:52 +00:00
parent a2204e1ff2
commit 18961504fc
43 changed files with 650 additions and 682 deletions

View File

@@ -6,7 +6,6 @@
#include "llvm/Analysis/DataStructure.h"
#include "llvm/Module.h"
#include "llvm/Function.h"
#include <fstream>
#include <algorithm>
@@ -42,9 +41,9 @@ void DataStructure::print(std::ostream &O, Module *M) const {
timeval TV1, TV2;
gettimeofday(&TV1, 0);
for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
if (!(*I)->isExternal()) {
getDSGraph(*I);
getClosedDSGraph(*I);
if (!I->isExternal() && I->getName() == "main") {
//getDSGraph(*I);
getClosedDSGraph(I);
}
gettimeofday(&TV2, 0);
cerr << "Analysis took "
@@ -53,9 +52,9 @@ void DataStructure::print(std::ostream &O, Module *M) const {
}
for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
if (!(*I)->isExternal()) {
if (!I->isExternal()) {
string Filename = "ds." + (*I)->getName() + ".dot";
string Filename = "ds." + I->getName() + ".dot";
O << "Writing '" << Filename << "'...";
ofstream F(Filename.c_str());
if (F.good()) {
@@ -65,8 +64,8 @@ void DataStructure::print(std::ostream &O, Module *M) const {
<< "\tsize=\"10,7.5\";\n"
<< "\trotate=\"90\";\n";
getDSGraph(*I).printFunction(F, "Local");
getClosedDSGraph(*I).printFunction(F, "Closed");
getDSGraph(I).printFunction(F, "Local");
getClosedDSGraph(I).printFunction(F, "Closed");
F << "}\n";
} else {
@@ -74,8 +73,8 @@ void DataStructure::print(std::ostream &O, Module *M) const {
}
if (Time)
O << " [" << getDSGraph(*I).getGraphSize() << ", "
<< getClosedDSGraph(*I).getGraphSize() << "]\n";
O << " [" << getDSGraph(I).getGraphSize() << ", "
<< getClosedDSGraph(I).getGraphSize() << "]\n";
else
O << "\n";
}

View File

@@ -68,12 +68,12 @@ void InitVisitor::visitOperand(Value *V) {
// node if the call returns a pointer value. Check to see if the call node
// uses any global variables...
//
void InitVisitor::visitCallInst(CallInst *CI) {
CallDSNode *C = new CallDSNode(CI);
void InitVisitor::visitCallInst(CallInst &CI) {
CallDSNode *C = new CallDSNode(&CI);
Rep->CallNodes.push_back(C);
Rep->CallMap[CI] = C;
Rep->CallMap[&CI] = C;
if (PointerType *PT = dyn_cast<PointerType>(CI->getType())) {
if (const PointerType *PT = dyn_cast<PointerType>(CI.getType())) {
// Create a critical shadow node to represent the memory object that the
// return value points to...
ShadowDSNode *Shad = new ShadowDSNode(PT->getElementType(),
@@ -86,17 +86,17 @@ void InitVisitor::visitCallInst(CallInst *CI) {
C->getLink(0).add(Shad);
// The call instruction returns a pointer to the shadow block...
Rep->ValueMap[CI].add(Shad, CI);
Rep->ValueMap[&CI].add(Shad, &CI);
// If the call returns a value with pointer type, add all of the users
// of the call instruction to the work list...
Rep->addAllUsesToWorkList(CI);
Rep->addAllUsesToWorkList(&CI);
}
// Loop over all of the operands of the call instruction (except the first
// one), to look for global variable references...
//
for_each(CI->op_begin(), CI->op_end(),
for_each(CI.op_begin(), CI.op_end(),
bind_obj(this, &InitVisitor::visitOperand));
}
@@ -105,22 +105,22 @@ void InitVisitor::visitCallInst(CallInst *CI) {
// allocation instructions do not take pointer arguments, they cannot refer to
// global vars...
//
void InitVisitor::visitAllocationInst(AllocationInst *AI) {
AllocDSNode *N = new AllocDSNode(AI);
void InitVisitor::visitAllocationInst(AllocationInst &AI) {
AllocDSNode *N = new AllocDSNode(&AI);
Rep->AllocNodes.push_back(N);
Rep->ValueMap[AI].add(N, AI);
Rep->ValueMap[&AI].add(N, &AI);
// Add all of the users of the malloc instruction to the work list...
Rep->addAllUsesToWorkList(AI);
Rep->addAllUsesToWorkList(&AI);
}
// Visit all other instruction types. Here we just scan, looking for uses of
// global variables...
//
void InitVisitor::visitInstruction(Instruction *I) {
for_each(I->op_begin(), I->op_end(),
void InitVisitor::visitInstruction(Instruction &I) {
for_each(I.op_begin(), I.op_end(),
bind_obj(this, &InitVisitor::visitOperand));
}
@@ -150,20 +150,18 @@ void FunctionRepBuilder::initializeWorkList(Function *Func) {
// Add all of the arguments to the method to the graph and add all users to
// the worklists...
//
for (Function::ArgumentListType::iterator I = Func->getArgumentList().begin(),
E = Func->getArgumentList().end(); I != E; ++I) {
Value *Arg = (Value*)(*I);
for (Function::aiterator I = Func->abegin(), E = Func->aend(); I != E; ++I) {
// Only process arguments that are of pointer type...
if (PointerType *PT = dyn_cast<PointerType>(Arg->getType())) {
if (const PointerType *PT = dyn_cast<PointerType>(I->getType())) {
// Add a shadow value for it to represent what it is pointing to and add
// this to the value map...
ShadowDSNode *Shad = new ShadowDSNode(PT->getElementType(),
Func->getParent());
ShadowNodes.push_back(Shad);
ValueMap[Arg].add(PointerVal(Shad), Arg);
ValueMap[I].add(PointerVal(Shad), I);
// Make sure that all users of the argument are processed...
addAllUsesToWorkList(Arg);
addAllUsesToWorkList(I);
}
}
@@ -179,15 +177,15 @@ void FunctionRepBuilder::initializeWorkList(Function *Func) {
PointerVal FunctionRepBuilder::getIndexedPointerDest(const PointerVal &InP,
const MemAccessInst *MAI) {
const MemAccessInst &MAI) {
unsigned Index = InP.Index;
const Type *SrcTy = MAI->getPointerOperand()->getType();
const Type *SrcTy = MAI.getPointerOperand()->getType();
for (MemAccessInst::const_op_iterator I = MAI->idx_begin(),
E = MAI->idx_end(); I != E; ++I)
for (MemAccessInst::const_op_iterator I = MAI.idx_begin(),
E = MAI.idx_end(); I != E; ++I)
if ((*I)->getType() == Type::UByteTy) { // Look for struct indices...
StructType *STy = cast<StructType>(SrcTy);
unsigned StructIdx = cast<ConstantUInt>(*I)->getValue();
const StructType *STy = cast<StructType>(SrcTy);
unsigned StructIdx = cast<ConstantUInt>(I->get())->getValue();
for (unsigned i = 0; i != StructIdx; ++i)
Index += countPointerFields(STy->getContainedType(i));
@@ -211,11 +209,11 @@ static PointerValSet &getField(const PointerVal &DestPtr) {
// changing. This means that the set of possible values for the GEP
// needs to be expanded.
//
void FunctionRepBuilder::visitGetElementPtrInst(GetElementPtrInst *GEP) {
PointerValSet &GEPPVS = ValueMap[GEP]; // PointerValSet to expand
void FunctionRepBuilder::visitGetElementPtrInst(GetElementPtrInst &GEP) {
PointerValSet &GEPPVS = ValueMap[&GEP]; // PointerValSet to expand
// Get the input pointer val set...
const PointerValSet &SrcPVS = ValueMap[GEP->getOperand(0)];
const PointerValSet &SrcPVS = ValueMap[GEP.getOperand(0)];
bool Changed = false; // Process each input value... propogating it.
for (unsigned i = 0, e = SrcPVS.size(); i != e; ++i) {
@@ -230,20 +228,20 @@ void FunctionRepBuilder::visitGetElementPtrInst(GetElementPtrInst *GEP) {
// If our current value set changed, notify all of the users of our
// value.
//
if (Changed) addAllUsesToWorkList(GEP);
if (Changed) addAllUsesToWorkList(&GEP);
}
void FunctionRepBuilder::visitReturnInst(ReturnInst *RI) {
RetNode.add(ValueMap[RI->getOperand(0)]);
void FunctionRepBuilder::visitReturnInst(ReturnInst &RI) {
RetNode.add(ValueMap[RI.getOperand(0)]);
}
void FunctionRepBuilder::visitLoadInst(LoadInst *LI) {
void FunctionRepBuilder::visitLoadInst(LoadInst &LI) {
// Only loads that return pointers are interesting...
const PointerType *DestTy = dyn_cast<PointerType>(LI->getType());
const PointerType *DestTy = dyn_cast<PointerType>(LI.getType());
if (DestTy == 0) return;
const PointerValSet &SrcPVS = ValueMap[LI->getOperand(0)];
PointerValSet &LIPVS = ValueMap[LI];
const PointerValSet &SrcPVS = ValueMap[LI.getOperand(0)];
PointerValSet &LIPVS = ValueMap[&LI];
bool Changed = false;
for (unsigned si = 0, se = SrcPVS.size(); si != se; ++si) {
@@ -264,18 +262,18 @@ void FunctionRepBuilder::visitLoadInst(LoadInst *LI) {
}
}
if (Changed) addAllUsesToWorkList(LI);
if (Changed) addAllUsesToWorkList(&LI);
}
void FunctionRepBuilder::visitStoreInst(StoreInst *SI) {
void FunctionRepBuilder::visitStoreInst(StoreInst &SI) {
// The only stores that are interesting are stores the store pointers
// into data structures...
//
if (!isa<PointerType>(SI->getOperand(0)->getType())) return;
if (!ValueMap.count(SI->getOperand(0))) return; // Src scalar has no values!
if (!isa<PointerType>(SI.getOperand(0)->getType())) return;
if (!ValueMap.count(SI.getOperand(0))) return; // Src scalar has no values!
const PointerValSet &SrcPVS = ValueMap[SI->getOperand(0)];
const PointerValSet &PtrPVS = ValueMap[SI->getOperand(1)];
const PointerValSet &SrcPVS = ValueMap[SI.getOperand(0)];
const PointerValSet &PtrPVS = ValueMap[SI.getOperand(1)];
for (unsigned si = 0, se = SrcPVS.size(); si != se; ++si) {
const PointerVal &SrcPtr = SrcPVS[si];
@@ -301,24 +299,24 @@ void FunctionRepBuilder::visitStoreInst(StoreInst *SI) {
}
}
void FunctionRepBuilder::visitCallInst(CallInst *CI) {
CallDSNode *DSN = CallMap[CI];
void FunctionRepBuilder::visitCallInst(CallInst &CI) {
CallDSNode *DSN = CallMap[&CI];
unsigned PtrNum = 0;
for (unsigned i = 0, e = CI->getNumOperands(); i != e; ++i)
if (isa<PointerType>(CI->getOperand(i)->getType()))
DSN->addArgValue(PtrNum++, ValueMap[CI->getOperand(i)]);
for (unsigned i = 0, e = CI.getNumOperands(); i != e; ++i)
if (isa<PointerType>(CI.getOperand(i)->getType()))
DSN->addArgValue(PtrNum++, ValueMap[CI.getOperand(i)]);
}
void FunctionRepBuilder::visitPHINode(PHINode *PN) {
assert(isa<PointerType>(PN->getType()) && "Should only update ptr phis");
void FunctionRepBuilder::visitPHINode(PHINode &PN) {
assert(isa<PointerType>(PN.getType()) && "Should only update ptr phis");
PointerValSet &PN_PVS = ValueMap[PN];
PointerValSet &PN_PVS = ValueMap[&PN];
bool Changed = false;
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
Changed |= PN_PVS.add(ValueMap[PN->getIncomingValue(i)],
PN->getIncomingValue(i));
for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i)
Changed |= PN_PVS.add(ValueMap[PN.getIncomingValue(i)],
PN.getIncomingValue(i));
if (Changed) addAllUsesToWorkList(PN);
if (Changed) addAllUsesToWorkList(&PN);
}

View File

@@ -27,9 +27,9 @@ class InitVisitor : public InstVisitor<InitVisitor> {
public:
InitVisitor(FunctionRepBuilder *R, Function *F) : Rep(R), Func(F) {}
void visitCallInst(CallInst *CI);
void visitAllocationInst(AllocationInst *AI);
void visitInstruction(Instruction *I);
void visitCallInst(CallInst &CI);
void visitAllocationInst(AllocationInst &AI);
void visitInstruction(Instruction &I);
// visitOperand - If the specified instruction operand is a global value, add
// a node for it...
@@ -90,7 +90,7 @@ public:
const map<Value*, PointerValSet> &getValueMap() const { return ValueMap; }
private:
static PointerVal getIndexedPointerDest(const PointerVal &InP,
const MemAccessInst *MAI);
const MemAccessInst &MAI);
void initializeWorkList(Function *Func);
void processWorkList() {
@@ -101,7 +101,7 @@ private:
cerr << "Processing worklist inst: " << I;
#endif
visit(I); // Dispatch to a visitXXX function based on instruction type...
visit(*I); // Dispatch to a visitXXX function based on instruction type...
#ifdef DEBUG_DATA_STRUCTURE_CONSTRUCTION
if (I->hasName() && ValueMap.count(I)) {
cerr << "Inst %" << I->getName() << " value is:\n";
@@ -117,18 +117,16 @@ private:
// Allow the visitor base class to invoke these methods...
friend class InstVisitor<FunctionRepBuilder>;
void visitGetElementPtrInst(GetElementPtrInst *GEP);
void visitReturnInst(ReturnInst *RI);
void visitLoadInst(LoadInst *LI);
void visitStoreInst(StoreInst *SI);
void visitCallInst(CallInst *CI);
void visitPHINode(PHINode *PN);
void visitSetCondInst(SetCondInst *SCI) {} // SetEQ & friends are ignored
void visitFreeInst(FreeInst *FI) {} // Ignore free instructions
void visitInstruction(Instruction *I) {
std::cerr << "\n\n\nUNKNOWN INSTRUCTION type: ";
I->dump();
std::cerr << "\n\n\n";
void visitGetElementPtrInst(GetElementPtrInst &GEP);
void visitReturnInst(ReturnInst &RI);
void visitLoadInst(LoadInst &LI);
void visitStoreInst(StoreInst &SI);
void visitCallInst(CallInst &CI);
void visitPHINode(PHINode &PN);
void visitSetCondInst(SetCondInst &SCI) {} // SetEQ & friends are ignored
void visitFreeInst(FreeInst &FI) {} // Ignore free instructions
void visitInstruction(Instruction &I) {
std::cerr << "\n\n\nUNKNOWN INSTRUCTION type: " << I << "\n\n\n";
assert(0 && "Cannot proceed");
}
};

View File

@@ -8,7 +8,6 @@
#include "llvm/Assembly/Writer.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
#include "llvm/iMemory.h"
#include "llvm/iOther.h"
#include "Support/STLExtras.h"
@@ -18,6 +17,7 @@
bool AllocDSNode::isEquivalentTo(DSNode *Node) const {
if (AllocDSNode *N = dyn_cast<AllocDSNode>(Node))
return getType() == Node->getType();
//&& isAllocaNode() == N->isAllocaNode();
return false;
}
@@ -423,12 +423,11 @@ PointerValSet FunctionDSGraph::cloneFunctionIntoSelf(const FunctionDSGraph &DSG,
// Convert over the arguments...
Function *OF = DSG.getFunction();
for (Function::ArgumentListType::iterator I = OF->getArgumentList().begin(),
E = OF->getArgumentList().end(); I != E; ++I)
if (isa<PointerType>(((Value*)*I)->getType())) {
for (Function::aiterator I = OF->abegin(), E = OF->aend(); I != E; ++I)
if (isa<PointerType>(I->getType())) {
PointerValSet ArgPVS;
assert(DSG.getValueMap().find((Value*)*I) != DSG.getValueMap().end());
MapPVS(ArgPVS, DSG.getValueMap().find((Value*)*I)->second, NodeMap);
assert(DSG.getValueMap().find(I) != DSG.getValueMap().end());
MapPVS(ArgPVS, DSG.getValueMap().find(I)->second, NodeMap);
assert(!ArgPVS.empty() && "Argument has no links!");
Args.push_back(ArgPVS);
}