//===- ProfilingUtils.cpp - Helper functions shared by profilers ----------===//
-//
+//
// The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
+//
//===----------------------------------------------------------------------===//
//
// This files implements a few helper functions which are used by profile
const PointerType *UIntPtr = PointerType::get(Type::UIntTy);
Module &M = *MainFn->getParent();
Function *InitFn = M.getOrInsertFunction(FnName, Type::IntTy, Type::IntTy,
- ArgVTy, UIntPtr, Type::UIntTy, 0);
+ ArgVTy, UIntPtr, Type::UIntTy,
+ (Type *)0);
// This could force argc and argv into programs that wouldn't otherwise have
// them, but instead we just pass null values in.
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 {
// pass null.
Args[2] = ConstantPointerNull::get(UIntPtr);
}
- Args[3] = ConstantUInt::get(Type::UIntTy, NumElements);
-
+ Args[3] = ConstantInt::get(Type::UIntTy, NumElements);
+
Instruction *InitCall = new CallInst(InitFn, Args, "newargc", InsertPos);
// If argc or argv are not available in main, just pass null values in.
- Function::aiterator AI;
- switch (MainFn->asize()) {
+ Function::arg_iterator AI;
+ switch (MainFn->arg_size()) {
default:
case 2:
- AI = MainFn->abegin(); ++AI;
+ AI = MainFn->arg_begin(); ++AI;
if (AI->getType() != ArgVTy) {
- InitCall->setOperand(2, new CastInst(AI, ArgVTy, "argv.cast", InitCall));
+ InitCall->setOperand(2,
+ CastInst::createInferredCast(AI, ArgVTy, "argv.cast", InitCall));
} else {
InitCall->setOperand(2, AI);
}
case 1:
- AI = MainFn->abegin();
+ AI = MainFn->arg_begin();
// If the program looked at argc, have it look at the return value of the
// init call instead.
if (AI->getType() != Type::IntTy) {
if (!AI->use_empty())
- AI->replaceAllUsesWith(new CastInst(InitCall, AI->getType(), "",
- InsertPos));
- InitCall->setOperand(1, new CastInst(AI, Type::IntTy, "argc.cast",
- InitCall));
+ AI->replaceAllUsesWith(
+ CastInst::createInferredCast(InitCall, AI->getType(), "", InsertPos));
+ InitCall->setOperand(1,
+ CastInst::createInferredCast(AI, Type::IntTy, "argc.cast", InitCall));
} else {
AI->replaceAllUsesWith(InitCall);
InitCall->setOperand(1, AI);
}
-
+
case 0: break;
}
}
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))
// Create the getelementptr constant expression
std::vector<Constant*> Indices(2);
Indices[0] = Constant::getNullValue(Type::IntTy);
- Indices[1] = ConstantSInt::get(Type::IntTy, CounterNum);
+ Indices[1] = ConstantInt::get(Type::IntTy, CounterNum);
Constant *ElementPtr = ConstantExpr::getGetElementPtr(CounterArray, Indices);
// Load, increment and store the value back.