}
}
} else if (Constant *C = dyn_cast<Constant>(V)) {
- if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(C))
- return getStringValue(CPR->getValue(), Offset);
+ if (GlobalValue *GV = dyn_cast<GlobalValue>(C))
+ return getStringValue(GV, Offset);
else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
if (CE->getOpcode() == Instruction::GetElementPtr) {
// Turn a gep into the specified offset.
if (const ConstantInt *C = dyn_cast<ConstantInt>(CI->getOperand(3)))
CurColNo = C->getRawValue();
const Value *Op = CI->getOperand(4);
- if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(Op))
- Op = CPR->getValue();
if ((CurDesc = dyn_cast<GlobalVariable>(Op)) &&
(LineNo < LastLineNo ||
if (ConstantStruct *CS = dyn_cast<ConstantStruct>(Desc->getInitializer()))
if (CS->getNumOperands() > 2) {
// Entry #1 is the file descriptor.
- if (const ConstantPointerRef *CPR =
- dyn_cast<ConstantPointerRef>(CS->getOperand(1)))
- if (const GlobalVariable *GV =
- dyn_cast<GlobalVariable>(CPR->getValue()))
- SourceFile = &PI.getSourceFile(GV);
+ if (const GlobalVariable *GV =
+ dyn_cast<GlobalVariable>(CS->getOperand(1)))
+ SourceFile = &PI.getSourceFile(GV);
// Entry #2 is the function name.
Name = getStringValue(CS->getOperand(2));
if (Desc && Desc->hasInitializer())
if (ConstantStruct *CS = dyn_cast<ConstantStruct>(Desc->getInitializer()))
if (CS->getNumOperands() > 0)
- if (const ConstantPointerRef *CPR =
- dyn_cast<ConstantPointerRef>(CS->getOperand(1)))
- SourceFileDesc = dyn_cast<GlobalVariable>(CPR->getValue());
+ if (const GlobalVariable *GV =
+ dyn_cast<GlobalVariable>(CS->getOperand(1)))
+ SourceFileDesc = GV;
const SourceLanguage &Lang = getSourceFile(SourceFileDesc).getLanguage();
return *(Result = Lang.createSourceFunctionInfo(Desc, *this));
printType(Out, CPV->getType());
Out << ")/*NULL*/0)";
break;
- } else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(CPV)) {
- writeOperand(CPR->getValue());
+ } else if (GlobalValue *GV = dyn_cast<GlobalValue>(CPV)) {
+ writeOperand(GV);
break;
}
// FALL THROUGH
return;
}
- if (Constant *CPV = dyn_cast<Constant>(Operand)) {
+ Constant* CPV = dyn_cast<Constant>(Operand);
+ if (CPV && !isa<GlobalValue>(CPV)) {
printConstant(CPV);
} else {
Out << Mang->getValueName(Operand);
// If accessing a global value with no indexing, avoid *(&GV) syndrome
if (GlobalValue *V = dyn_cast<GlobalValue>(Ptr)) {
HasImplicitAddress = true;
- } else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(Ptr)) {
- HasImplicitAddress = true;
- Ptr = CPR->getValue(); // Get to the global...
} else if (isDirectAlloca(Ptr)) {
HasImplicitAddress = true;
}
printType(Out, CPV->getType());
Out << ")/*NULL*/0)";
break;
- } else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(CPV)) {
- writeOperand(CPR->getValue());
+ } else if (GlobalValue *GV = dyn_cast<GlobalValue>(CPV)) {
+ writeOperand(GV);
break;
}
// FALL THROUGH
return;
}
- if (Constant *CPV = dyn_cast<Constant>(Operand)) {
+ Constant* CPV = dyn_cast<Constant>(Operand);
+ if (CPV && !isa<GlobalValue>(CPV)) {
printConstant(CPV);
} else {
Out << Mang->getValueName(Operand);
// If accessing a global value with no indexing, avoid *(&GV) syndrome
if (GlobalValue *V = dyn_cast<GlobalValue>(Ptr)) {
HasImplicitAddress = true;
- } else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(Ptr)) {
- HasImplicitAddress = true;
- Ptr = CPR->getValue(); // Get to the global...
} else if (isDirectAlloca(Ptr)) {
HasImplicitAddress = true;
}
// 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)));
// 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);
}
}
toAsm << "\t" << TypeToDataDirective(CV->getType()) << "\t";
- if (const ConstantPointerRef* CPR = dyn_cast<ConstantPointerRef>(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<GlobalValue>(CPR->getValue()) && "Unexpected non-global");
- toAsm << getID(CPR->getValue()) << "\n";
+ if (const GlobalValue* GV = dyn_cast<GlobalValue>(CV)) {
+ toAsm << getID(GV) << "\n";
} else if (isa<ConstantPointerNull>(CV)) {
// Null pointer value
toAsm << "0\n";
const TargetMachine& target) {
std::string S;
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))
S += std::string(CB == ConstantBool::True ? "1" : "0");
else if (const ConstantSInt *CI = dyn_cast<ConstantSInt>(CV))
S += ftostr(CFP->getValue());
else if (isa<ConstantPointerNull>(CV))
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))
S += ConstantExprToString(CE, target);
else
failed = true;
- } else if (const GlobalValue* GV = dyn_cast<GlobalValue>(V)) {
- S += getID(GV);
} else
failed = true;
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);
}
std::vector<GlobalValue*> &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.
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<ConstantPointerRef>(*I)) {
- for (Value::use_iterator I = CPR->use_begin(), E = CPR->use_end();
+ if (GlobalValue *GV = dyn_cast<GlobalValue>(*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())
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
if (isStoredThrough(CE))
return true;
- } else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(C)) {
- if (isStoredThrough(CPR)) return true;
+ } else if (GlobalValue *GV = dyn_cast<GlobalValue>(C)) {
+ if (isStoredThrough(GV)) return true;
} else {
// Must be an element of a constant array or something.
return true;
//===----------------------------------------------------------------------===//
#include "Inliner.h"
-#include "llvm/Constants.h" // ConstantPointerRef should die
#include "llvm/Module.h"
#include "llvm/iOther.h"
#include "llvm/iTerminators.h"
// 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<ConstantPointerRef>(F->use_back()))
- if (CPR->use_empty()) {
- CPR->destroyConstant();
+ if (Function *GV = dyn_cast<Function>(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.
Changed = true;
++NumRaised;
}
- } else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(U)) {
- Users.insert(Users.end(), CPR->use_begin(), CPR->use_end());
- EqPointers.push_back(CPR);
+ } else if (GlobalValue *GV = dyn_cast<GlobalValue>(U)) {
+ Users.insert(Users.end(), GV->use_begin(), GV->use_end());
+ EqPointers.push_back(GV);
} else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(U)) {
if (CE->getOpcode() == Instruction::Cast) {
Users.insert(Users.end(), CE->use_begin(), CE->use_end());
Changed = true;
++NumRaised;
}
- } else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(U)) {
- Users.insert(Users.end(), CPR->use_begin(), CPR->use_end());
- EqPointers.push_back(CPR);
+ } else if (GlobalValue *GV = dyn_cast<GlobalValue>(U)) {
+ Users.insert(Users.end(), GV->use_begin(), GV->use_end());
+ EqPointers.push_back(GV);
} else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(U)) {
if (CE->getOpcode() == Instruction::Cast) {
Users.insert(Users.end(), CE->use_begin(), CE->use_end());
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);
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);
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)
// 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);
}
}
}
//std::cerr<<MI;
- vConsts.push_back(ConstantPointerRef::get(MI));
+ vConsts.push_back(MI);
sBCons.push_back(ConstantInt::get(Type::SByteTy, hasBackEdge(MI)));
counter++;
std::vector<Constant*> 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<ArrayType>(Array->getType()->getElementType())->getNumElements();
} else {
}
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<AllocaInst>(InsertPos) || isa<PHINode>(InsertPos))
void InsertProfilingInitCall(Function *MainFn, const char *FnName,
GlobalValue *Arr = 0);
void IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum,
- ConstantPointerRef *CounterArray);
+ GlobalValue *CounterArray);
}
#endif
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<Constant*>(2,Constant::getNullValue(Type::LongTy)));
// Insert a call to the hash function if this is a pointer value
if (MsgGV) {
std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::LongTy));
AbortMessage =
- ConstantExpr::getGetElementPtr(ConstantPointerRef::get(MsgGV), GEPIdx);
+ ConstantExpr::getGetElementPtr(MsgGV, GEPIdx);
}
} else {
if (MsgGV) {
std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::LongTy));
AbortMessage =
- ConstantExpr::getGetElementPtr(ConstantPointerRef::get(MsgGV), GEPIdx);
+ ConstantExpr::getGetElementPtr(MsgGV, GEPIdx);
}
}
WriteFn->getParent());
std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::LongTy));
AbortMessage =
- ConstantExpr::getGetElementPtr(ConstantPointerRef::get(MsgGV), GEPIdx);
+ ConstantExpr::getGetElementPtr(MsgGV, GEPIdx);
}
// These are the arguments we WANT...
#include "ValueMapper.h"
#include "llvm/Constants.h"
+#include "llvm/GlobalValue.h"
#include "llvm/Instruction.h"
#include <iostream>
if (isa<ConstantIntegral>(C) || isa<ConstantFP>(C) ||
isa<ConstantPointerNull>(C) || isa<ConstantAggregateZero>(C))
return VMSlot = C; // Primitive constants map directly
- else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(C)) {
- GlobalValue *MV = cast<GlobalValue>(MapValue((Value*)CPR->getValue(),VM));
- return VMSlot = ConstantPointerRef::get(MV);
+ else if (GlobalValue *GV = dyn_cast<GlobalValue>(C)) {
+ return VMSlot = GV;
} else if (ConstantArray *CA = dyn_cast<ConstantArray>(C)) {
const std::vector<Use> &Vals = CA->getValues();
for (unsigned i = 0, e = Vals.size(); i != e; ++i) {
// GetElementPtr *funcName, ulong 0, ulong 0
std::vector<Constant*> GEPargs(2,Constant::getNullValue(Type::IntTy));
Value *GEP =
- ConstantExpr::getGetElementPtr(ConstantPointerRef::get(funcName),
- GEPargs);
+ ConstantExpr::getGetElementPtr(funcName, GEPargs);
std::vector<Value*> ResolverArgs;
ResolverArgs.push_back(GEP);