summaryrefslogtreecommitdiff
path: root/lib/Transforms/Instrumentation
diff options
context:
space:
mode:
authorBrian Gaeke <gaeke@uiuc.edu>2004-05-03 22:06:33 +0000
committerBrian Gaeke <gaeke@uiuc.edu>2004-05-03 22:06:33 +0000
commitebbc0e9bbf51e4ee583d7603b033813566c62c3f (patch)
treef1914e49855993992ce68d74508094d892e55061 /lib/Transforms/Instrumentation
parentc03eb7b923d4ba40a647ffd364cd2e89fc22301d (diff)
downloadllvm-ebbc0e9bbf51e4ee583d7603b033813566c62c3f.tar.gz
llvm-ebbc0e9bbf51e4ee583d7603b033813566c62c3f.tar.bz2
llvm-ebbc0e9bbf51e4ee583d7603b033813566c62c3f.tar.xz
In InsertProfilingInitCall(), make it legal to pass in a null array, in
which case you'll get a null array and zero passed to the profiling function. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13336 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Instrumentation')
-rw-r--r--lib/Transforms/Instrumentation/ProfilingUtils.cpp18
-rw-r--r--lib/Transforms/Instrumentation/ProfilingUtils.h2
2 files changed, 13 insertions, 7 deletions
diff --git a/lib/Transforms/Instrumentation/ProfilingUtils.cpp b/lib/Transforms/Instrumentation/ProfilingUtils.cpp
index 4cdcb9e511..3c22b4bf42 100644
--- a/lib/Transforms/Instrumentation/ProfilingUtils.cpp
+++ b/lib/Transforms/Instrumentation/ProfilingUtils.cpp
@@ -23,7 +23,7 @@
void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName,
GlobalValue *Array) {
const Type *ArgVTy = PointerType::get(PointerType::get(Type::SByteTy));
- const Type *UIntPtr = PointerType::get(Type::UIntTy);
+ 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);
@@ -39,12 +39,18 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName,
BasicBlock::iterator InsertPos = Entry->begin();
while (isa<AllocaInst>(InsertPos)) ++InsertPos;
- ConstantPointerRef *ArrayCPR = ConstantPointerRef::get(Array);
std::vector<Constant*> GEPIndices(2, Constant::getNullValue(Type::IntTy));
- Args[2] = ConstantExpr::getGetElementPtr(ArrayCPR, GEPIndices);
-
- unsigned NumElements =
- cast<ArrayType>(Array->getType()->getElementType())->getNumElements();
+ unsigned NumElements = 0;
+ if (Array) {
+ ConstantPointerRef *ArrayCPR = ConstantPointerRef::get(Array);
+ Args[2] = ConstantExpr::getGetElementPtr(ArrayCPR, GEPIndices);
+ NumElements =
+ cast<ArrayType>(Array->getType()->getElementType())->getNumElements();
+ } else {
+ // If this profiling instrumentation doesn't have a constant array, just
+ // pass null.
+ Args[2] = ConstantPointerNull::get(UIntPtr);
+ }
Args[3] = ConstantUInt::get(Type::UIntTy, NumElements);
Instruction *InitCall = new CallInst(InitFn, Args, "newargc", InsertPos);
diff --git a/lib/Transforms/Instrumentation/ProfilingUtils.h b/lib/Transforms/Instrumentation/ProfilingUtils.h
index 7e8b85f4db..17e234806c 100644
--- a/lib/Transforms/Instrumentation/ProfilingUtils.h
+++ b/lib/Transforms/Instrumentation/ProfilingUtils.h
@@ -24,7 +24,7 @@ namespace llvm {
class BasicBlock;
void InsertProfilingInitCall(Function *MainFn, const char *FnName,
- GlobalValue *Arr);
+ GlobalValue *Arr = 0);
void IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum,
ConstantPointerRef *CounterArray);
}