Two bug fixes:

(1) Make entries for Constant values in the ScalarMap.
(2) Set MOD bit for the node pointed to by the
    argument of a free instruction.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4948 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Vikram S. Adve
2002-12-06 21:17:10 +00:00
parent 2b7a92c72f
commit bac0622ef9

View File

@@ -92,7 +92,7 @@ namespace {
void visitStoreInst(StoreInst &SI); void visitStoreInst(StoreInst &SI);
void visitCallInst(CallInst &CI); void visitCallInst(CallInst &CI);
void visitSetCondInst(SetCondInst &SCI) {} // SetEQ & friends are ignored void visitSetCondInst(SetCondInst &SCI) {} // SetEQ & friends are ignored
void visitFreeInst(FreeInst &FI) {} // Ignore free instructions void visitFreeInst(FreeInst &FI);
void visitCastInst(CastInst &CI); void visitCastInst(CastInst &CI);
void visitInstruction(Instruction &I) {} void visitInstruction(Instruction &I) {}
@@ -154,34 +154,35 @@ DSNodeHandle GraphBuilder::getValueDest(Value &Val) {
if (V == Constant::getNullValue(V->getType())) if (V == Constant::getNullValue(V->getType()))
return 0; // Null doesn't point to anything, don't add to ScalarMap! return 0; // Null doesn't point to anything, don't add to ScalarMap!
DSNodeHandle &NH = ScalarMap[V];
if (NH.getNode())
return NH; // Already have a node? Just return it...
// Otherwise we need to create a new node to point to.
// Check first for constant expressions that must be traversed to
// extract the actual value.
if (Constant *C = dyn_cast<Constant>(V)) if (Constant *C = dyn_cast<Constant>(V))
if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(C)) { if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(C)) {
return getValueDest(*CPR->getValue()); return NH = getValueDest(*CPR->getValue());
} else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) { } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
if (CE->getOpcode() == Instruction::Cast) if (CE->getOpcode() == Instruction::Cast)
return getValueDest(*CE->getOperand(0)); return NH = getValueDest(*CE->getOperand(0));
if (CE->getOpcode() == Instruction::GetElementPtr) { if (CE->getOpcode() == Instruction::GetElementPtr) {
visitGetElementPtrInst(*CE); visitGetElementPtrInst(*CE);
std::map<Value*, DSNodeHandle>::iterator I = ScalarMap.find(CE); std::map<Value*, DSNodeHandle>::iterator I = ScalarMap.find(CE);
assert(I != ScalarMap.end() && "GEP didn't get processed right?"); assert(I != ScalarMap.end() && "GEP didn't get processed right?");
DSNodeHandle NH = I->second; return NH = I->second;
ScalarMap.erase(I); // Remove constant from scalarmap
return NH;
} }
// This returns a conservative unknown node for any unhandled ConstExpr // This returns a conservative unknown node for any unhandled ConstExpr
return createNode(DSNode::UnknownNode); return NH = createNode(DSNode::UnknownNode);
} else if (ConstantIntegral *CI = dyn_cast<ConstantIntegral>(C)) { } else if (ConstantIntegral *CI = dyn_cast<ConstantIntegral>(C)) {
// Random constants are unknown mem // Random constants are unknown mem
return createNode(DSNode::UnknownNode); return NH = createNode(DSNode::UnknownNode);
} else { } else {
assert(0 && "Unknown constant type!"); assert(0 && "Unknown constant type!");
} }
DSNodeHandle &NH = ScalarMap[V];
if (NH.getNode())
return NH; // Already have a node? Just return it...
// Otherwise we need to create a new node to point to... // Otherwise we need to create a new node to point to...
DSNode *N; DSNode *N;
if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) { if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
@@ -355,7 +356,7 @@ void GraphBuilder::visitStoreInst(StoreInst &SI) {
DSNodeHandle Dest = getValueDest(*SI.getOperand(1)); DSNodeHandle Dest = getValueDest(*SI.getOperand(1));
if (Dest.getNode() == 0) return; if (Dest.getNode() == 0) return;
// Make that the node is written to... // Mark that the node is written to...
Dest.getNode()->NodeType |= DSNode::Modified; Dest.getNode()->NodeType |= DSNode::Modified;
// Ensure a typerecord exists... // Ensure a typerecord exists...
@@ -391,6 +392,14 @@ void GraphBuilder::visitCallInst(CallInst &CI) {
FunctionCalls.push_back(DSCallSite(CI, RetVal, Callee, Args)); FunctionCalls.push_back(DSCallSite(CI, RetVal, Callee, Args));
} }
void GraphBuilder::visitFreeInst(FreeInst &FI) {
DSNodeHandle Dest = getValueDest(*FI.getOperand(0));
if (Dest.getNode() == 0) return;
// Mark that the node is written to...
Dest.getNode()->NodeType |= DSNode::Modified;
}
/// Handle casts... /// Handle casts...
void GraphBuilder::visitCastInst(CastInst &CI) { void GraphBuilder::visitCastInst(CastInst &CI) {
if (isPointerType(CI.getType())) if (isPointerType(CI.getType()))