[llvm-commits] CVS: llvm/lib/Transforms/Instrumentation/ProfilingUtils.h ProfilingUtils.cpp

Brian Gaeke gaeke at cs.uiuc.edu
Mon May 3 17:06:01 PDT 2004


Changes in directory llvm/lib/Transforms/Instrumentation:

ProfilingUtils.h updated: 1.1 -> 1.2
ProfilingUtils.cpp updated: 1.2 -> 1.3

---
Log message:

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.


---
Diffs of the changes:  (+13 -7)

Index: llvm/lib/Transforms/Instrumentation/ProfilingUtils.h
diff -u llvm/lib/Transforms/Instrumentation/ProfilingUtils.h:1.1 llvm/lib/Transforms/Instrumentation/ProfilingUtils.h:1.2
--- llvm/lib/Transforms/Instrumentation/ProfilingUtils.h:1.1	Mon Mar  8 11:06:13 2004
+++ llvm/lib/Transforms/Instrumentation/ProfilingUtils.h	Mon May  3 17:06:33 2004
@@ -24,7 +24,7 @@
   class BasicBlock;
 
   void InsertProfilingInitCall(Function *MainFn, const char *FnName,
-                               GlobalValue *Arr);
+                               GlobalValue *Arr = 0);
   void IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum,
                                ConstantPointerRef *CounterArray);
 }


Index: llvm/lib/Transforms/Instrumentation/ProfilingUtils.cpp
diff -u llvm/lib/Transforms/Instrumentation/ProfilingUtils.cpp:1.2 llvm/lib/Transforms/Instrumentation/ProfilingUtils.cpp:1.3
--- llvm/lib/Transforms/Instrumentation/ProfilingUtils.cpp:1.2	Sun Apr  4 20:29:02 2004
+++ llvm/lib/Transforms/Instrumentation/ProfilingUtils.cpp	Mon May  3 17:06:33 2004
@@ -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 @@
   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);





More information about the llvm-commits mailing list