diff options
| author | Brian Gaeke <gaeke@uiuc.edu> | 2004-05-03 22:06:33 +0000 |
|---|---|---|
| committer | Brian Gaeke <gaeke@uiuc.edu> | 2004-05-03 22:06:33 +0000 |
| commit | e96196081e76c6476ae847cda11110b2c3768ee4 (patch) | |
| tree | 45165ef81d266cc4c83b13e084b0bbeaae2685aa /llvm/lib/Transforms/Instrumentation/ProfilingUtils.cpp | |
| parent | 088dd3e121d1a9c6d1981f443e729e29a6609c03 (diff) | |
| download | bcm5719-llvm-e96196081e76c6476ae847cda11110b2c3768ee4.tar.gz bcm5719-llvm-e96196081e76c6476ae847cda11110b2c3768ee4.zip | |
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.
llvm-svn: 13336
Diffstat (limited to 'llvm/lib/Transforms/Instrumentation/ProfilingUtils.cpp')
| -rw-r--r-- | llvm/lib/Transforms/Instrumentation/ProfilingUtils.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/ProfilingUtils.cpp b/llvm/lib/Transforms/Instrumentation/ProfilingUtils.cpp index 4cdcb9e5119..3c22b4bf42e 100644 --- a/llvm/lib/Transforms/Instrumentation/ProfilingUtils.cpp +++ b/llvm/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); |

