1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00
- Replace ConstantPointerRef usage with GlobalValue usage

llvm-svn: 14953
This commit is contained in:
Reid Spencer 2004-07-18 00:44:37 +00:00
parent f687d42d99
commit 7f33869f9b
18 changed files with 50 additions and 72 deletions

View File

@ -61,8 +61,8 @@ static std::string getStringValue(Value *V, unsigned Offset = 0) {
} }
} }
} else if (Constant *C = dyn_cast<Constant>(V)) { } else if (Constant *C = dyn_cast<Constant>(V)) {
if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(C)) if (GlobalValue *GV = dyn_cast<GlobalValue>(C))
return getStringValue(CPR->getValue(), Offset); return getStringValue(GV, Offset);
else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) { else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
if (CE->getOpcode() == Instruction::GetElementPtr) { if (CE->getOpcode() == Instruction::GetElementPtr) {
// Turn a gep into the specified offset. // Turn a gep into the specified offset.
@ -108,8 +108,6 @@ static const GlobalVariable *getNextStopPoint(const Value *V, unsigned &LineNo,
if (const ConstantInt *C = dyn_cast<ConstantInt>(CI->getOperand(3))) if (const ConstantInt *C = dyn_cast<ConstantInt>(CI->getOperand(3)))
CurColNo = C->getRawValue(); CurColNo = C->getRawValue();
const Value *Op = CI->getOperand(4); const Value *Op = CI->getOperand(4);
if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(Op))
Op = CPR->getValue();
if ((CurDesc = dyn_cast<GlobalVariable>(Op)) && if ((CurDesc = dyn_cast<GlobalVariable>(Op)) &&
(LineNo < LastLineNo || (LineNo < LastLineNo ||
@ -192,10 +190,8 @@ SourceFunctionInfo::SourceFunctionInfo(ProgramInfo &PI,
if (ConstantStruct *CS = dyn_cast<ConstantStruct>(Desc->getInitializer())) if (ConstantStruct *CS = dyn_cast<ConstantStruct>(Desc->getInitializer()))
if (CS->getNumOperands() > 2) { if (CS->getNumOperands() > 2) {
// Entry #1 is the file descriptor. // Entry #1 is the file descriptor.
if (const ConstantPointerRef *CPR =
dyn_cast<ConstantPointerRef>(CS->getOperand(1)))
if (const GlobalVariable *GV = if (const GlobalVariable *GV =
dyn_cast<GlobalVariable>(CPR->getValue())) dyn_cast<GlobalVariable>(CS->getOperand(1)))
SourceFile = &PI.getSourceFile(GV); SourceFile = &PI.getSourceFile(GV);
// Entry #2 is the function name. // Entry #2 is the function name.
@ -366,9 +362,9 @@ ProgramInfo::getFunction(const GlobalVariable *Desc) {
if (Desc && Desc->hasInitializer()) if (Desc && Desc->hasInitializer())
if (ConstantStruct *CS = dyn_cast<ConstantStruct>(Desc->getInitializer())) if (ConstantStruct *CS = dyn_cast<ConstantStruct>(Desc->getInitializer()))
if (CS->getNumOperands() > 0) if (CS->getNumOperands() > 0)
if (const ConstantPointerRef *CPR = if (const GlobalVariable *GV =
dyn_cast<ConstantPointerRef>(CS->getOperand(1))) dyn_cast<GlobalVariable>(CS->getOperand(1)))
SourceFileDesc = dyn_cast<GlobalVariable>(CPR->getValue()); SourceFileDesc = GV;
const SourceLanguage &Lang = getSourceFile(SourceFileDesc).getLanguage(); const SourceLanguage &Lang = getSourceFile(SourceFileDesc).getLanguage();
return *(Result = Lang.createSourceFunctionInfo(Desc, *this)); return *(Result = Lang.createSourceFunctionInfo(Desc, *this));

View File

@ -620,8 +620,8 @@ void CWriter::printConstant(Constant *CPV) {
printType(Out, CPV->getType()); printType(Out, CPV->getType());
Out << ")/*NULL*/0)"; Out << ")/*NULL*/0)";
break; break;
} else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(CPV)) { } else if (GlobalValue *GV = dyn_cast<GlobalValue>(CPV)) {
writeOperand(CPR->getValue()); writeOperand(GV);
break; break;
} }
// FALL THROUGH // FALL THROUGH
@ -641,7 +641,8 @@ void CWriter::writeOperandInternal(Value *Operand) {
return; return;
} }
if (Constant *CPV = dyn_cast<Constant>(Operand)) { Constant* CPV = dyn_cast<Constant>(Operand);
if (CPV && !isa<GlobalValue>(CPV)) {
printConstant(CPV); printConstant(CPV);
} else { } else {
Out << Mang->getValueName(Operand); Out << Mang->getValueName(Operand);
@ -1412,9 +1413,6 @@ void CWriter::printIndexingExpression(Value *Ptr, gep_type_iterator I,
// If accessing a global value with no indexing, avoid *(&GV) syndrome // If accessing a global value with no indexing, avoid *(&GV) syndrome
if (GlobalValue *V = dyn_cast<GlobalValue>(Ptr)) { if (GlobalValue *V = dyn_cast<GlobalValue>(Ptr)) {
HasImplicitAddress = true; HasImplicitAddress = true;
} else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(Ptr)) {
HasImplicitAddress = true;
Ptr = CPR->getValue(); // Get to the global...
} else if (isDirectAlloca(Ptr)) { } else if (isDirectAlloca(Ptr)) {
HasImplicitAddress = true; HasImplicitAddress = true;
} }

View File

@ -42,7 +42,7 @@ static void maybeAddInternalValueToVector (GVVectorTy &Vector, GlobalValue &GV){
// add a null. // add a null.
if (GV.hasInternalLinkage () && GV.hasName ()) if (GV.hasInternalLinkage () && GV.hasName ())
Vector.push_back (ConstantExpr::getCast Vector.push_back (ConstantExpr::getCast
(ConstantPointerRef::get (&GV), PointerType::get (Type::SByteTy))); (&GV, PointerType::get (Type::SByteTy)));
else else
Vector.push_back (ConstantPointerNull::get (PointerType::get Vector.push_back (ConstantPointerNull::get (PointerType::get
(Type::SByteTy))); (Type::SByteTy)));

View File

@ -1289,7 +1289,7 @@ void PhyRegAlloc::finishSavingState (Module &M) {
// Have: { uint, [Size x { uint, int, uint, int }] } * // Have: { uint, [Size x { uint, int, uint, int }] } *
// Cast it to: { uint, [0 x { uint, int, uint, int }] } * // Cast it to: { uint, [0 x { uint, int, uint, int }] } *
Constant *CE = ConstantExpr::getCast (ConstantPointerRef::get (GV), PT); Constant *CE = ConstantExpr::getCast (GV, PT);
allstate.push_back (CE); allstate.push_back (CE);
} }
} }

View File

@ -317,11 +317,8 @@ void AsmPrinter::printSingleConstantValue(const Constant* CV) {
toAsm << "\t" << TypeToDataDirective(CV->getType()) << "\t"; toAsm << "\t" << TypeToDataDirective(CV->getType()) << "\t";
if (const ConstantPointerRef* CPR = dyn_cast<ConstantPointerRef>(CV)) { if (const GlobalValue* GV = dyn_cast<GlobalValue>(CV)) {
// This is a constant address for a global variable or method. toAsm << getID(GV) << "\n";
// Use the name of the variable or method as the address value.
assert(isa<GlobalValue>(CPR->getValue()) && "Unexpected non-global");
toAsm << getID(CPR->getValue()) << "\n";
} else if (isa<ConstantPointerNull>(CV)) { } else if (isa<ConstantPointerNull>(CV)) {
// Null pointer value // Null pointer value
toAsm << "0\n"; toAsm << "0\n";
@ -480,7 +477,9 @@ std::string AsmPrinter::valToExprString(const Value* V,
const TargetMachine& target) { const TargetMachine& target) {
std::string S; std::string S;
bool failed = false; bool failed = false;
if (const Constant* CV = dyn_cast<Constant>(V)) { // symbolic or known if (const GlobalValue* GV = dyn_cast<GlobalValue>(V)) {
S += getID(GV);
} else if (const Constant* CV = dyn_cast<Constant>(V)) { // symbolic or known
if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV)) if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV))
S += std::string(CB == ConstantBool::True ? "1" : "0"); S += std::string(CB == ConstantBool::True ? "1" : "0");
else if (const ConstantSInt *CI = dyn_cast<ConstantSInt>(CV)) else if (const ConstantSInt *CI = dyn_cast<ConstantSInt>(CV))
@ -491,14 +490,10 @@ std::string AsmPrinter::valToExprString(const Value* V,
S += ftostr(CFP->getValue()); S += ftostr(CFP->getValue());
else if (isa<ConstantPointerNull>(CV)) else if (isa<ConstantPointerNull>(CV))
S += "0"; S += "0";
else if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(CV))
S += valToExprString(CPR->getValue(), target);
else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV))
S += ConstantExprToString(CE, target); S += ConstantExprToString(CE, target);
else else
failed = true; failed = true;
} else if (const GlobalValue* GV = dyn_cast<GlobalValue>(V)) {
S += getID(GV);
} else } else
failed = true; failed = true;

View File

@ -101,8 +101,7 @@ static bool ResolveFunctions(Module &M, std::vector<GlobalValue*> &Globals,
if (!Old->use_empty()) { // Avoid making the CPR unless we really need it if (!Old->use_empty()) { // Avoid making the CPR unless we really need it
Value *Replacement = Concrete; Value *Replacement = Concrete;
if (Concrete->getType() != Old->getType()) if (Concrete->getType() != Old->getType())
Replacement = ConstantExpr::getCast(ConstantPointerRef::get(Concrete), Replacement = ConstantExpr::getCast(Concrete,Old->getType());
Old->getType());
NumResolved += Old->use_size(); NumResolved += Old->use_size();
Old->replaceAllUsesWith(Replacement); Old->replaceAllUsesWith(Replacement);
} }
@ -118,11 +117,10 @@ static bool ResolveGlobalVariables(Module &M,
std::vector<GlobalValue*> &Globals, std::vector<GlobalValue*> &Globals,
GlobalVariable *Concrete) { GlobalVariable *Concrete) {
bool Changed = false; bool Changed = false;
Constant *CCPR = ConstantPointerRef::get(Concrete);
for (unsigned i = 0; i != Globals.size(); ++i) for (unsigned i = 0; i != Globals.size(); ++i)
if (Globals[i] != Concrete) { if (Globals[i] != Concrete) {
Constant *Cast = ConstantExpr::getCast(CCPR, Globals[i]->getType()); Constant *Cast = ConstantExpr::getCast(Concrete, Globals[i]->getType());
Globals[i]->replaceAllUsesWith(Cast); Globals[i]->replaceAllUsesWith(Cast);
// Since there are no uses of Old anymore, remove it from the module. // Since there are no uses of Old anymore, remove it from the module.
@ -138,8 +136,8 @@ static bool ResolveGlobalVariables(Module &M,
static bool CallersAllIgnoreReturnValue(Function &F) { static bool CallersAllIgnoreReturnValue(Function &F) {
if (F.getReturnType() == Type::VoidTy) return true; if (F.getReturnType() == Type::VoidTy) return true;
for (Value::use_iterator I = F.use_begin(), E = F.use_end(); I != E; ++I) { for (Value::use_iterator I = F.use_begin(), E = F.use_end(); I != E; ++I) {
if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(*I)) { if (GlobalValue *GV = dyn_cast<GlobalValue>(*I)) {
for (Value::use_iterator I = CPR->use_begin(), E = CPR->use_end(); for (Value::use_iterator I = GV->use_begin(), E = GV->use_end();
I != E; ++I) { I != E; ++I) {
CallSite CS = CallSite::get(*I); CallSite CS = CallSite::get(*I);
if (!CS.getInstruction() || !CS.getInstruction()->use_empty()) if (!CS.getInstruction() || !CS.getInstruction()->use_empty())

View File

@ -48,8 +48,8 @@ static bool isStoredThrough(Value *V) {
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) { if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
if (isStoredThrough(CE)) if (isStoredThrough(CE))
return true; return true;
} else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(C)) { } else if (GlobalValue *GV = dyn_cast<GlobalValue>(C)) {
if (isStoredThrough(CPR)) return true; if (isStoredThrough(GV)) return true;
} else { } else {
// Must be an element of a constant array or something. // Must be an element of a constant array or something.
return true; return true;

View File

@ -14,7 +14,6 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "Inliner.h" #include "Inliner.h"
#include "llvm/Constants.h" // ConstantPointerRef should die
#include "llvm/Module.h" #include "llvm/Module.h"
#include "llvm/iOther.h" #include "llvm/iOther.h"
#include "llvm/iTerminators.h" #include "llvm/iTerminators.h"
@ -174,9 +173,9 @@ bool Inliner::doFinalization(CallGraph &CG) {
// If the only remaining use of the function is a dead constant // If the only remaining use of the function is a dead constant
// pointer ref, remove it. // pointer ref, remove it.
if (F && F->hasOneUse()) if (F && F->hasOneUse())
if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(F->use_back())) if (Function *GV = dyn_cast<Function>(F->use_back()))
if (CPR->use_empty()) { if (GV->removeDeadConstantUsers()) {
CPR->destroyConstant(); delete GV;
if (F->hasInternalLinkage()) { if (F->hasInternalLinkage()) {
// There *MAY* be an edge from the external call node to this // There *MAY* be an edge from the external call node to this
// function. If so, remove it. // function. If so, remove it.

View File

@ -158,9 +158,9 @@ bool RaiseAllocations::run(Module &M) {
Changed = true; Changed = true;
++NumRaised; ++NumRaised;
} }
} else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(U)) { } else if (GlobalValue *GV = dyn_cast<GlobalValue>(U)) {
Users.insert(Users.end(), CPR->use_begin(), CPR->use_end()); Users.insert(Users.end(), GV->use_begin(), GV->use_end());
EqPointers.push_back(CPR); EqPointers.push_back(GV);
} else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(U)) { } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(U)) {
if (CE->getOpcode() == Instruction::Cast) { if (CE->getOpcode() == Instruction::Cast) {
Users.insert(Users.end(), CE->use_begin(), CE->use_end()); Users.insert(Users.end(), CE->use_begin(), CE->use_end());
@ -207,9 +207,9 @@ bool RaiseAllocations::run(Module &M) {
Changed = true; Changed = true;
++NumRaised; ++NumRaised;
} }
} else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(U)) { } else if (GlobalValue *GV = dyn_cast<GlobalValue>(U)) {
Users.insert(Users.end(), CPR->use_begin(), CPR->use_end()); Users.insert(Users.end(), GV->use_begin(), GV->use_end());
EqPointers.push_back(CPR); EqPointers.push_back(GV);
} else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(U)) { } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(U)) {
if (CE->getOpcode() == Instruction::Cast) { if (CE->getOpcode() == Instruction::Cast) {
Users.insert(Users.end(), CE->use_begin(), CE->use_end()); Users.insert(Users.end(), CE->use_begin(), CE->use_end());

View File

@ -55,14 +55,12 @@ bool FunctionProfiler::run(Module &M) {
new GlobalVariable(ATy, false, GlobalValue::InternalLinkage, new GlobalVariable(ATy, false, GlobalValue::InternalLinkage,
Constant::getNullValue(ATy), "FuncProfCounters", &M); Constant::getNullValue(ATy), "FuncProfCounters", &M);
ConstantPointerRef *CounterCPR = ConstantPointerRef::get(Counters);
// Instrument all of the functions... // Instrument all of the functions...
unsigned i = 0; unsigned i = 0;
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
if (!I->isExternal()) if (!I->isExternal())
// Insert counter at the start of the function // Insert counter at the start of the function
IncrementCounterInBlock(I->begin(), i++, CounterCPR); IncrementCounterInBlock(I->begin(), i++, Counters);
// Add the initialization call to main. // Add the initialization call to main.
InsertProfilingInitCall(Main, "llvm_start_func_profiling", Counters); InsertProfilingInitCall(Main, "llvm_start_func_profiling", Counters);
@ -96,14 +94,12 @@ bool BlockProfiler::run(Module &M) {
new GlobalVariable(ATy, false, GlobalValue::InternalLinkage, new GlobalVariable(ATy, false, GlobalValue::InternalLinkage,
Constant::getNullValue(ATy), "BlockProfCounters", &M); Constant::getNullValue(ATy), "BlockProfCounters", &M);
ConstantPointerRef *CounterCPR = ConstantPointerRef::get(Counters);
// Instrument all of the blocks... // Instrument all of the blocks...
unsigned i = 0; unsigned i = 0;
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
for (Function::iterator BB = I->begin(), E = I->end(); BB != E; ++BB) for (Function::iterator BB = I->begin(), E = I->end(); BB != E; ++BB)
// Insert counter at the start of the block // Insert counter at the start of the block
IncrementCounterInBlock(BB, i++, CounterCPR); IncrementCounterInBlock(BB, i++, Counters);
// Add the initialization call to main. // Add the initialization call to main.
InsertProfilingInitCall(Main, "llvm_start_block_profiling", Counters); InsertProfilingInitCall(Main, "llvm_start_block_profiling", Counters);

View File

@ -60,8 +60,6 @@ bool EdgeProfiler::run(Module &M) {
new GlobalVariable(ATy, false, GlobalValue::InternalLinkage, new GlobalVariable(ATy, false, GlobalValue::InternalLinkage,
Constant::getNullValue(ATy), "EdgeProfCounters", &M); Constant::getNullValue(ATy), "EdgeProfCounters", &M);
ConstantPointerRef *CounterCPR = ConstantPointerRef::get(Counters);
// Instrument all of the edges... // Instrument all of the edges...
unsigned i = 0; unsigned i = 0;
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F)
@ -80,10 +78,10 @@ bool EdgeProfiler::run(Module &M) {
// otherwise insert it in the successor block. // otherwise insert it in the successor block.
if (TI->getNumSuccessors() == 0) { if (TI->getNumSuccessors() == 0) {
// Insert counter at the start of the block // Insert counter at the start of the block
IncrementCounterInBlock(BB, i++, CounterCPR); IncrementCounterInBlock(BB, i++, Counters);
} else { } else {
// Insert counter at the start of the block // Insert counter at the start of the block
IncrementCounterInBlock(TI->getSuccessor(s), i++, CounterCPR); IncrementCounterInBlock(TI->getSuccessor(s), i++, Counters);
} }
} }
} }

View File

@ -77,7 +77,7 @@ bool EmitFunctionTable::run(Module &M){
//std::cerr<<MI; //std::cerr<<MI;
vConsts.push_back(ConstantPointerRef::get(MI)); vConsts.push_back(MI);
sBCons.push_back(ConstantInt::get(Type::SByteTy, hasBackEdge(MI))); sBCons.push_back(ConstantInt::get(Type::SByteTy, hasBackEdge(MI)));
counter++; counter++;

View File

@ -42,8 +42,7 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName,
std::vector<Constant*> GEPIndices(2, Constant::getNullValue(Type::IntTy)); std::vector<Constant*> GEPIndices(2, Constant::getNullValue(Type::IntTy));
unsigned NumElements = 0; unsigned NumElements = 0;
if (Array) { if (Array) {
ConstantPointerRef *ArrayCPR = ConstantPointerRef::get(Array); Args[2] = ConstantExpr::getGetElementPtr(Array, GEPIndices);
Args[2] = ConstantExpr::getGetElementPtr(ArrayCPR, GEPIndices);
NumElements = NumElements =
cast<ArrayType>(Array->getType()->getElementType())->getNumElements(); cast<ArrayType>(Array->getType()->getElementType())->getNumElements();
} else { } else {
@ -87,7 +86,7 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName,
} }
void llvm::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum, void llvm::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum,
ConstantPointerRef *CounterArray) { GlobalValue *CounterArray) {
// Insert the increment after any alloca or PHI instructions... // Insert the increment after any alloca or PHI instructions...
BasicBlock::iterator InsertPos = BB->begin(); BasicBlock::iterator InsertPos = BB->begin();
while (isa<AllocaInst>(InsertPos) || isa<PHINode>(InsertPos)) while (isa<AllocaInst>(InsertPos) || isa<PHINode>(InsertPos))

View File

@ -26,7 +26,7 @@ namespace llvm {
void InsertProfilingInitCall(Function *MainFn, const char *FnName, void InsertProfilingInitCall(Function *MainFn, const char *FnName,
GlobalValue *Arr = 0); GlobalValue *Arr = 0);
void IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum, void IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum,
ConstantPointerRef *CounterArray); GlobalValue *CounterArray);
} }
#endif #endif

View File

@ -243,7 +243,7 @@ static void InsertPrintInst(Value *V, BasicBlock *BB, Instruction *InsertBefore,
GlobalVariable *fmtVal = getStringRef(Mod, Message+getPrintfCodeFor(V)+"\n"); GlobalVariable *fmtVal = getStringRef(Mod, Message+getPrintfCodeFor(V)+"\n");
// Turn the format string into an sbyte * // Turn the format string into an sbyte *
Constant *GEP =ConstantExpr::getGetElementPtr(ConstantPointerRef::get(fmtVal), Constant *GEP=ConstantExpr::getGetElementPtr(fmtVal,
std::vector<Constant*>(2,Constant::getNullValue(Type::LongTy))); std::vector<Constant*>(2,Constant::getNullValue(Type::LongTy)));
// Insert a call to the hash function if this is a pointer value // Insert a call to the hash function if this is a pointer value

View File

@ -135,7 +135,7 @@ bool LowerInvoke::doInitialization(Module &M) {
if (MsgGV) { if (MsgGV) {
std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::LongTy)); std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::LongTy));
AbortMessage = AbortMessage =
ConstantExpr::getGetElementPtr(ConstantPointerRef::get(MsgGV), GEPIdx); ConstantExpr::getGetElementPtr(MsgGV, GEPIdx);
} }
} else { } else {
@ -154,7 +154,7 @@ bool LowerInvoke::doInitialization(Module &M) {
if (MsgGV) { if (MsgGV) {
std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::LongTy)); std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::LongTy));
AbortMessage = AbortMessage =
ConstantExpr::getGetElementPtr(ConstantPointerRef::get(MsgGV), GEPIdx); ConstantExpr::getGetElementPtr(MsgGV, GEPIdx);
} }
} }
@ -191,7 +191,7 @@ void LowerInvoke::writeAbortMessage(Instruction *IB) {
WriteFn->getParent()); WriteFn->getParent());
std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::LongTy)); std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::LongTy));
AbortMessage = AbortMessage =
ConstantExpr::getGetElementPtr(ConstantPointerRef::get(MsgGV), GEPIdx); ConstantExpr::getGetElementPtr(MsgGV, GEPIdx);
} }
// These are the arguments we WANT... // These are the arguments we WANT...

View File

@ -14,6 +14,7 @@
#include "ValueMapper.h" #include "ValueMapper.h"
#include "llvm/Constants.h" #include "llvm/Constants.h"
#include "llvm/GlobalValue.h"
#include "llvm/Instruction.h" #include "llvm/Instruction.h"
#include <iostream> #include <iostream>
@ -32,9 +33,8 @@ Value *llvm::MapValue(const Value *V, std::map<const Value*, Value*> &VM) {
if (isa<ConstantIntegral>(C) || isa<ConstantFP>(C) || if (isa<ConstantIntegral>(C) || isa<ConstantFP>(C) ||
isa<ConstantPointerNull>(C) || isa<ConstantAggregateZero>(C)) isa<ConstantPointerNull>(C) || isa<ConstantAggregateZero>(C))
return VMSlot = C; // Primitive constants map directly return VMSlot = C; // Primitive constants map directly
else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(C)) { else if (GlobalValue *GV = dyn_cast<GlobalValue>(C)) {
GlobalValue *MV = cast<GlobalValue>(MapValue((Value*)CPR->getValue(),VM)); return VMSlot = GV;
return VMSlot = ConstantPointerRef::get(MV);
} else if (ConstantArray *CA = dyn_cast<ConstantArray>(C)) { } else if (ConstantArray *CA = dyn_cast<ConstantArray>(C)) {
const std::vector<Use> &Vals = CA->getValues(); const std::vector<Use> &Vals = CA->getValues();
for (unsigned i = 0, e = Vals.size(); i != e; ++i) { for (unsigned i = 0, e = Vals.size(); i != e; ++i) {

View File

@ -654,8 +654,7 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
// GetElementPtr *funcName, ulong 0, ulong 0 // GetElementPtr *funcName, ulong 0, ulong 0
std::vector<Constant*> GEPargs(2,Constant::getNullValue(Type::IntTy)); std::vector<Constant*> GEPargs(2,Constant::getNullValue(Type::IntTy));
Value *GEP = Value *GEP =
ConstantExpr::getGetElementPtr(ConstantPointerRef::get(funcName), ConstantExpr::getGetElementPtr(funcName, GEPargs);
GEPargs);
std::vector<Value*> ResolverArgs; std::vector<Value*> ResolverArgs;
ResolverArgs.push_back(GEP); ResolverArgs.push_back(GEP);