diff --git a/lib/Debugger/ProgramInfo.cpp b/lib/Debugger/ProgramInfo.cpp index a3e55a3aef1..c08a8aaa647 100644 --- a/lib/Debugger/ProgramInfo.cpp +++ b/lib/Debugger/ProgramInfo.cpp @@ -61,8 +61,8 @@ static std::string getStringValue(Value *V, unsigned Offset = 0) { } } } else if (Constant *C = dyn_cast(V)) { - if (ConstantPointerRef *CPR = dyn_cast(C)) - return getStringValue(CPR->getValue(), Offset); + if (GlobalValue *GV = dyn_cast(C)) + return getStringValue(GV, Offset); else if (ConstantExpr *CE = dyn_cast(C)) { if (CE->getOpcode() == Instruction::GetElementPtr) { // 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(CI->getOperand(3))) CurColNo = C->getRawValue(); const Value *Op = CI->getOperand(4); - if (const ConstantPointerRef *CPR = dyn_cast(Op)) - Op = CPR->getValue(); if ((CurDesc = dyn_cast(Op)) && (LineNo < LastLineNo || @@ -192,11 +190,9 @@ SourceFunctionInfo::SourceFunctionInfo(ProgramInfo &PI, if (ConstantStruct *CS = dyn_cast(Desc->getInitializer())) if (CS->getNumOperands() > 2) { // Entry #1 is the file descriptor. - if (const ConstantPointerRef *CPR = - dyn_cast(CS->getOperand(1))) - if (const GlobalVariable *GV = - dyn_cast(CPR->getValue())) - SourceFile = &PI.getSourceFile(GV); + if (const GlobalVariable *GV = + dyn_cast(CS->getOperand(1))) + SourceFile = &PI.getSourceFile(GV); // Entry #2 is the function name. Name = getStringValue(CS->getOperand(2)); @@ -366,9 +362,9 @@ ProgramInfo::getFunction(const GlobalVariable *Desc) { if (Desc && Desc->hasInitializer()) if (ConstantStruct *CS = dyn_cast(Desc->getInitializer())) if (CS->getNumOperands() > 0) - if (const ConstantPointerRef *CPR = - dyn_cast(CS->getOperand(1))) - SourceFileDesc = dyn_cast(CPR->getValue()); + if (const GlobalVariable *GV = + dyn_cast(CS->getOperand(1))) + SourceFileDesc = GV; const SourceLanguage &Lang = getSourceFile(SourceFileDesc).getLanguage(); return *(Result = Lang.createSourceFunctionInfo(Desc, *this)); diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index 139320f6403..c1cd657cf22 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -620,8 +620,8 @@ void CWriter::printConstant(Constant *CPV) { printType(Out, CPV->getType()); Out << ")/*NULL*/0)"; break; - } else if (ConstantPointerRef *CPR = dyn_cast(CPV)) { - writeOperand(CPR->getValue()); + } else if (GlobalValue *GV = dyn_cast(CPV)) { + writeOperand(GV); break; } // FALL THROUGH @@ -641,7 +641,8 @@ void CWriter::writeOperandInternal(Value *Operand) { return; } - if (Constant *CPV = dyn_cast(Operand)) { + Constant* CPV = dyn_cast(Operand); + if (CPV && !isa(CPV)) { printConstant(CPV); } else { 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 (GlobalValue *V = dyn_cast(Ptr)) { HasImplicitAddress = true; - } else if (ConstantPointerRef *CPR = dyn_cast(Ptr)) { - HasImplicitAddress = true; - Ptr = CPR->getValue(); // Get to the global... } else if (isDirectAlloca(Ptr)) { HasImplicitAddress = true; } diff --git a/lib/Target/CBackend/Writer.cpp b/lib/Target/CBackend/Writer.cpp index 139320f6403..c1cd657cf22 100644 --- a/lib/Target/CBackend/Writer.cpp +++ b/lib/Target/CBackend/Writer.cpp @@ -620,8 +620,8 @@ void CWriter::printConstant(Constant *CPV) { printType(Out, CPV->getType()); Out << ")/*NULL*/0)"; break; - } else if (ConstantPointerRef *CPR = dyn_cast(CPV)) { - writeOperand(CPR->getValue()); + } else if (GlobalValue *GV = dyn_cast(CPV)) { + writeOperand(GV); break; } // FALL THROUGH @@ -641,7 +641,8 @@ void CWriter::writeOperandInternal(Value *Operand) { return; } - if (Constant *CPV = dyn_cast(Operand)) { + Constant* CPV = dyn_cast(Operand); + if (CPV && !isa(CPV)) { printConstant(CPV); } else { 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 (GlobalValue *V = dyn_cast(Ptr)) { HasImplicitAddress = true; - } else if (ConstantPointerRef *CPR = dyn_cast(Ptr)) { - HasImplicitAddress = true; - Ptr = CPR->getValue(); // Get to the global... } else if (isDirectAlloca(Ptr)) { HasImplicitAddress = true; } diff --git a/lib/Target/SparcV9/InternalGlobalMapper.cpp b/lib/Target/SparcV9/InternalGlobalMapper.cpp index 7d4a40a13be..0cd2faa7c31 100644 --- a/lib/Target/SparcV9/InternalGlobalMapper.cpp +++ b/lib/Target/SparcV9/InternalGlobalMapper.cpp @@ -42,7 +42,7 @@ static void maybeAddInternalValueToVector (GVVectorTy &Vector, GlobalValue &GV){ // add a null. if (GV.hasInternalLinkage () && GV.hasName ()) Vector.push_back (ConstantExpr::getCast - (ConstantPointerRef::get (&GV), PointerType::get (Type::SByteTy))); + (&GV, PointerType::get (Type::SByteTy))); else Vector.push_back (ConstantPointerNull::get (PointerType::get (Type::SByteTy))); diff --git a/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp b/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp index a153871d80c..6aebcb5f841 100644 --- a/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp +++ b/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp @@ -1289,7 +1289,7 @@ void PhyRegAlloc::finishSavingState (Module &M) { // Have: { uint, [Size 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); } } diff --git a/lib/Target/SparcV9/SparcV9AsmPrinter.cpp b/lib/Target/SparcV9/SparcV9AsmPrinter.cpp index aa183452553..addcbdcc0c1 100644 --- a/lib/Target/SparcV9/SparcV9AsmPrinter.cpp +++ b/lib/Target/SparcV9/SparcV9AsmPrinter.cpp @@ -317,11 +317,8 @@ void AsmPrinter::printSingleConstantValue(const Constant* CV) { toAsm << "\t" << TypeToDataDirective(CV->getType()) << "\t"; - if (const ConstantPointerRef* CPR = dyn_cast(CV)) { - // This is a constant address for a global variable or method. - // Use the name of the variable or method as the address value. - assert(isa(CPR->getValue()) && "Unexpected non-global"); - toAsm << getID(CPR->getValue()) << "\n"; + if (const GlobalValue* GV = dyn_cast(CV)) { + toAsm << getID(GV) << "\n"; } else if (isa(CV)) { // Null pointer value toAsm << "0\n"; @@ -480,7 +477,9 @@ std::string AsmPrinter::valToExprString(const Value* V, const TargetMachine& target) { std::string S; bool failed = false; - if (const Constant* CV = dyn_cast(V)) { // symbolic or known + if (const GlobalValue* GV = dyn_cast(V)) { + S += getID(GV); + } else if (const Constant* CV = dyn_cast(V)) { // symbolic or known if (const ConstantBool *CB = dyn_cast(CV)) S += std::string(CB == ConstantBool::True ? "1" : "0"); else if (const ConstantSInt *CI = dyn_cast(CV)) @@ -491,14 +490,10 @@ std::string AsmPrinter::valToExprString(const Value* V, S += ftostr(CFP->getValue()); else if (isa(CV)) S += "0"; - else if (const ConstantPointerRef *CPR = dyn_cast(CV)) - S += valToExprString(CPR->getValue(), target); else if (const ConstantExpr *CE = dyn_cast(CV)) S += ConstantExprToString(CE, target); else failed = true; - } else if (const GlobalValue* GV = dyn_cast(V)) { - S += getID(GV); } else failed = true; diff --git a/lib/Transforms/IPO/FunctionResolution.cpp b/lib/Transforms/IPO/FunctionResolution.cpp index 303cad1e7d2..695287f7c44 100644 --- a/lib/Transforms/IPO/FunctionResolution.cpp +++ b/lib/Transforms/IPO/FunctionResolution.cpp @@ -101,8 +101,7 @@ static bool ResolveFunctions(Module &M, std::vector &Globals, if (!Old->use_empty()) { // Avoid making the CPR unless we really need it Value *Replacement = Concrete; if (Concrete->getType() != Old->getType()) - Replacement = ConstantExpr::getCast(ConstantPointerRef::get(Concrete), - Old->getType()); + Replacement = ConstantExpr::getCast(Concrete,Old->getType()); NumResolved += Old->use_size(); Old->replaceAllUsesWith(Replacement); } @@ -118,11 +117,10 @@ static bool ResolveGlobalVariables(Module &M, std::vector &Globals, GlobalVariable *Concrete) { bool Changed = false; - Constant *CCPR = ConstantPointerRef::get(Concrete); for (unsigned i = 0; i != Globals.size(); ++i) if (Globals[i] != Concrete) { - Constant *Cast = ConstantExpr::getCast(CCPR, Globals[i]->getType()); + Constant *Cast = ConstantExpr::getCast(Concrete, Globals[i]->getType()); Globals[i]->replaceAllUsesWith(Cast); // 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) { if (F.getReturnType() == Type::VoidTy) return true; for (Value::use_iterator I = F.use_begin(), E = F.use_end(); I != E; ++I) { - if (ConstantPointerRef *CPR = dyn_cast(*I)) { - for (Value::use_iterator I = CPR->use_begin(), E = CPR->use_end(); + if (GlobalValue *GV = dyn_cast(*I)) { + for (Value::use_iterator I = GV->use_begin(), E = GV->use_end(); I != E; ++I) { CallSite CS = CallSite::get(*I); if (!CS.getInstruction() || !CS.getInstruction()->use_empty()) diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index c30ec5f47c1..3478d9de41b 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -48,8 +48,8 @@ static bool isStoredThrough(Value *V) { if (ConstantExpr *CE = dyn_cast(C)) { if (isStoredThrough(CE)) return true; - } else if (ConstantPointerRef *CPR = dyn_cast(C)) { - if (isStoredThrough(CPR)) return true; + } else if (GlobalValue *GV = dyn_cast(C)) { + if (isStoredThrough(GV)) return true; } else { // Must be an element of a constant array or something. return true; diff --git a/lib/Transforms/IPO/Inliner.cpp b/lib/Transforms/IPO/Inliner.cpp index 8fca96812b0..ed5efe22acc 100644 --- a/lib/Transforms/IPO/Inliner.cpp +++ b/lib/Transforms/IPO/Inliner.cpp @@ -14,7 +14,6 @@ //===----------------------------------------------------------------------===// #include "Inliner.h" -#include "llvm/Constants.h" // ConstantPointerRef should die #include "llvm/Module.h" #include "llvm/iOther.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 // pointer ref, remove it. if (F && F->hasOneUse()) - if (ConstantPointerRef *CPR = dyn_cast(F->use_back())) - if (CPR->use_empty()) { - CPR->destroyConstant(); + if (Function *GV = dyn_cast(F->use_back())) + if (GV->removeDeadConstantUsers()) { + delete GV; if (F->hasInternalLinkage()) { // There *MAY* be an edge from the external call node to this // function. If so, remove it. diff --git a/lib/Transforms/IPO/RaiseAllocations.cpp b/lib/Transforms/IPO/RaiseAllocations.cpp index 5302d8f7a1a..ca8b7cc5537 100644 --- a/lib/Transforms/IPO/RaiseAllocations.cpp +++ b/lib/Transforms/IPO/RaiseAllocations.cpp @@ -158,9 +158,9 @@ bool RaiseAllocations::run(Module &M) { Changed = true; ++NumRaised; } - } else if (ConstantPointerRef *CPR = dyn_cast(U)) { - Users.insert(Users.end(), CPR->use_begin(), CPR->use_end()); - EqPointers.push_back(CPR); + } else if (GlobalValue *GV = dyn_cast(U)) { + Users.insert(Users.end(), GV->use_begin(), GV->use_end()); + EqPointers.push_back(GV); } else if (ConstantExpr *CE = dyn_cast(U)) { if (CE->getOpcode() == Instruction::Cast) { Users.insert(Users.end(), CE->use_begin(), CE->use_end()); @@ -207,9 +207,9 @@ bool RaiseAllocations::run(Module &M) { Changed = true; ++NumRaised; } - } else if (ConstantPointerRef *CPR = dyn_cast(U)) { - Users.insert(Users.end(), CPR->use_begin(), CPR->use_end()); - EqPointers.push_back(CPR); + } else if (GlobalValue *GV = dyn_cast(U)) { + Users.insert(Users.end(), GV->use_begin(), GV->use_end()); + EqPointers.push_back(GV); } else if (ConstantExpr *CE = dyn_cast(U)) { if (CE->getOpcode() == Instruction::Cast) { Users.insert(Users.end(), CE->use_begin(), CE->use_end()); diff --git a/lib/Transforms/Instrumentation/BlockProfiling.cpp b/lib/Transforms/Instrumentation/BlockProfiling.cpp index b7c19e6e097..e357e841cdc 100644 --- a/lib/Transforms/Instrumentation/BlockProfiling.cpp +++ b/lib/Transforms/Instrumentation/BlockProfiling.cpp @@ -55,14 +55,12 @@ bool FunctionProfiler::run(Module &M) { new GlobalVariable(ATy, false, GlobalValue::InternalLinkage, Constant::getNullValue(ATy), "FuncProfCounters", &M); - ConstantPointerRef *CounterCPR = ConstantPointerRef::get(Counters); - // Instrument all of the functions... unsigned i = 0; for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) if (!I->isExternal()) // Insert counter at the start of the function - IncrementCounterInBlock(I->begin(), i++, CounterCPR); + IncrementCounterInBlock(I->begin(), i++, Counters); // Add the initialization call to main. InsertProfilingInitCall(Main, "llvm_start_func_profiling", Counters); @@ -96,14 +94,12 @@ bool BlockProfiler::run(Module &M) { new GlobalVariable(ATy, false, GlobalValue::InternalLinkage, Constant::getNullValue(ATy), "BlockProfCounters", &M); - ConstantPointerRef *CounterCPR = ConstantPointerRef::get(Counters); - // Instrument all of the blocks... unsigned i = 0; for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) for (Function::iterator BB = I->begin(), E = I->end(); BB != E; ++BB) // Insert counter at the start of the block - IncrementCounterInBlock(BB, i++, CounterCPR); + IncrementCounterInBlock(BB, i++, Counters); // Add the initialization call to main. InsertProfilingInitCall(Main, "llvm_start_block_profiling", Counters); diff --git a/lib/Transforms/Instrumentation/EdgeProfiling.cpp b/lib/Transforms/Instrumentation/EdgeProfiling.cpp index ef334f22f33..c584ca5dfe3 100644 --- a/lib/Transforms/Instrumentation/EdgeProfiling.cpp +++ b/lib/Transforms/Instrumentation/EdgeProfiling.cpp @@ -60,8 +60,6 @@ bool EdgeProfiler::run(Module &M) { new GlobalVariable(ATy, false, GlobalValue::InternalLinkage, Constant::getNullValue(ATy), "EdgeProfCounters", &M); - ConstantPointerRef *CounterCPR = ConstantPointerRef::get(Counters); - // Instrument all of the edges... unsigned i = 0; 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. if (TI->getNumSuccessors() == 0) { // Insert counter at the start of the block - IncrementCounterInBlock(BB, i++, CounterCPR); + IncrementCounterInBlock(BB, i++, Counters); } else { // Insert counter at the start of the block - IncrementCounterInBlock(TI->getSuccessor(s), i++, CounterCPR); + IncrementCounterInBlock(TI->getSuccessor(s), i++, Counters); } } } diff --git a/lib/Transforms/Instrumentation/EmitFunctions.cpp b/lib/Transforms/Instrumentation/EmitFunctions.cpp index 27c25875468..a1c23dab238 100644 --- a/lib/Transforms/Instrumentation/EmitFunctions.cpp +++ b/lib/Transforms/Instrumentation/EmitFunctions.cpp @@ -77,7 +77,7 @@ bool EmitFunctionTable::run(Module &M){ //std::cerr< GEPIndices(2, Constant::getNullValue(Type::IntTy)); unsigned NumElements = 0; if (Array) { - ConstantPointerRef *ArrayCPR = ConstantPointerRef::get(Array); - Args[2] = ConstantExpr::getGetElementPtr(ArrayCPR, GEPIndices); + Args[2] = ConstantExpr::getGetElementPtr(Array, GEPIndices); NumElements = cast(Array->getType()->getElementType())->getNumElements(); } else { @@ -87,7 +86,7 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName, } void llvm::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum, - ConstantPointerRef *CounterArray) { + GlobalValue *CounterArray) { // Insert the increment after any alloca or PHI instructions... BasicBlock::iterator InsertPos = BB->begin(); while (isa(InsertPos) || isa(InsertPos)) diff --git a/lib/Transforms/Instrumentation/ProfilingUtils.h b/lib/Transforms/Instrumentation/ProfilingUtils.h index 17e234806c1..c6d1b73928e 100644 --- a/lib/Transforms/Instrumentation/ProfilingUtils.h +++ b/lib/Transforms/Instrumentation/ProfilingUtils.h @@ -26,7 +26,7 @@ namespace llvm { void InsertProfilingInitCall(Function *MainFn, const char *FnName, GlobalValue *Arr = 0); void IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum, - ConstantPointerRef *CounterArray); + GlobalValue *CounterArray); } #endif diff --git a/lib/Transforms/Instrumentation/TraceValues.cpp b/lib/Transforms/Instrumentation/TraceValues.cpp index 30904a627e6..6cc46fa6c67 100644 --- a/lib/Transforms/Instrumentation/TraceValues.cpp +++ b/lib/Transforms/Instrumentation/TraceValues.cpp @@ -243,7 +243,7 @@ static void InsertPrintInst(Value *V, BasicBlock *BB, Instruction *InsertBefore, GlobalVariable *fmtVal = getStringRef(Mod, Message+getPrintfCodeFor(V)+"\n"); // Turn the format string into an sbyte * - Constant *GEP =ConstantExpr::getGetElementPtr(ConstantPointerRef::get(fmtVal), + Constant *GEP=ConstantExpr::getGetElementPtr(fmtVal, std::vector(2,Constant::getNullValue(Type::LongTy))); // Insert a call to the hash function if this is a pointer value diff --git a/lib/Transforms/Utils/LowerInvoke.cpp b/lib/Transforms/Utils/LowerInvoke.cpp index bde4ff56b06..835a5ae7892 100644 --- a/lib/Transforms/Utils/LowerInvoke.cpp +++ b/lib/Transforms/Utils/LowerInvoke.cpp @@ -135,7 +135,7 @@ bool LowerInvoke::doInitialization(Module &M) { if (MsgGV) { std::vector GEPIdx(2, Constant::getNullValue(Type::LongTy)); AbortMessage = - ConstantExpr::getGetElementPtr(ConstantPointerRef::get(MsgGV), GEPIdx); + ConstantExpr::getGetElementPtr(MsgGV, GEPIdx); } } else { @@ -154,7 +154,7 @@ bool LowerInvoke::doInitialization(Module &M) { if (MsgGV) { std::vector GEPIdx(2, Constant::getNullValue(Type::LongTy)); AbortMessage = - ConstantExpr::getGetElementPtr(ConstantPointerRef::get(MsgGV), GEPIdx); + ConstantExpr::getGetElementPtr(MsgGV, GEPIdx); } } @@ -191,7 +191,7 @@ void LowerInvoke::writeAbortMessage(Instruction *IB) { WriteFn->getParent()); std::vector GEPIdx(2, Constant::getNullValue(Type::LongTy)); AbortMessage = - ConstantExpr::getGetElementPtr(ConstantPointerRef::get(MsgGV), GEPIdx); + ConstantExpr::getGetElementPtr(MsgGV, GEPIdx); } // These are the arguments we WANT... diff --git a/lib/Transforms/Utils/ValueMapper.cpp b/lib/Transforms/Utils/ValueMapper.cpp index 7a5fcff1117..9f525565271 100644 --- a/lib/Transforms/Utils/ValueMapper.cpp +++ b/lib/Transforms/Utils/ValueMapper.cpp @@ -14,6 +14,7 @@ #include "ValueMapper.h" #include "llvm/Constants.h" +#include "llvm/GlobalValue.h" #include "llvm/Instruction.h" #include @@ -32,9 +33,8 @@ Value *llvm::MapValue(const Value *V, std::map &VM) { if (isa(C) || isa(C) || isa(C) || isa(C)) return VMSlot = C; // Primitive constants map directly - else if (ConstantPointerRef *CPR = dyn_cast(C)) { - GlobalValue *MV = cast(MapValue((Value*)CPR->getValue(),VM)); - return VMSlot = ConstantPointerRef::get(MV); + else if (GlobalValue *GV = dyn_cast(C)) { + return VMSlot = GV; } else if (ConstantArray *CA = dyn_cast(C)) { const std::vector &Vals = CA->getValues(); for (unsigned i = 0, e = Vals.size(); i != e; ++i) { diff --git a/tools/bugpoint/Miscompilation.cpp b/tools/bugpoint/Miscompilation.cpp index 222e646522e..2eedd60dd5f 100644 --- a/tools/bugpoint/Miscompilation.cpp +++ b/tools/bugpoint/Miscompilation.cpp @@ -654,8 +654,7 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test, // GetElementPtr *funcName, ulong 0, ulong 0 std::vector GEPargs(2,Constant::getNullValue(Type::IntTy)); Value *GEP = - ConstantExpr::getGetElementPtr(ConstantPointerRef::get(funcName), - GEPargs); + ConstantExpr::getGetElementPtr(funcName, GEPargs); std::vector ResolverArgs; ResolverArgs.push_back(GEP);