[llvm-commits] [parallel] CVS: llvm/lib/Transforms/Instrumentation/BlockProfiling.cpp EmitFunctions.cpp

Misha Brukman brukman at cs.uiuc.edu
Mon Mar 1 18:02:46 PST 2004


Changes in directory llvm/lib/Transforms/Instrumentation:

BlockProfiling.cpp updated: 1.5 -> 1.5.2.1
EmitFunctions.cpp updated: 1.14 -> 1.14.4.1

---
Log message:

Merge from trunk

---
Diffs of the changes:  (+26 -19)

Index: llvm/lib/Transforms/Instrumentation/BlockProfiling.cpp
diff -u llvm/lib/Transforms/Instrumentation/BlockProfiling.cpp:1.5 llvm/lib/Transforms/Instrumentation/BlockProfiling.cpp:1.5.2.1
--- llvm/lib/Transforms/Instrumentation/BlockProfiling.cpp:1.5	Fri Jan  9 00:11:48 2004
+++ llvm/lib/Transforms/Instrumentation/BlockProfiling.cpp	Mon Mar  1 17:58:16 2004
@@ -31,7 +31,7 @@
   const Type *ArgVTy = PointerType::get(PointerType::get(Type::SByteTy));
   const Type *UIntPtr = PointerType::get(Type::UIntTy);
   Module &M = *MainFn->getParent();
-  Function *InitFn = M.getOrInsertFunction(FnName, Type::VoidTy, Type::IntTy,
+  Function *InitFn = M.getOrInsertFunction(FnName, Type::IntTy, Type::IntTy,
                                            ArgVTy, UIntPtr, Type::UIntTy, 0);
 
   // This could force argc and argv into programs that wouldn't otherwise have
@@ -45,38 +45,45 @@
   BasicBlock::iterator InsertPos = Entry->begin();
   while (isa<AllocaInst>(InsertPos)) ++InsertPos;
 
+  ConstantPointerRef *ArrayCPR = ConstantPointerRef::get(Array);
+  std::vector<Constant*> GEPIndices(2, Constant::getNullValue(Type::LongTy));
+  Args[2] = ConstantExpr::getGetElementPtr(ArrayCPR, GEPIndices);
+  
+  unsigned NumElements =
+    cast<ArrayType>(Array->getType()->getElementType())->getNumElements();
+  Args[3] = ConstantUInt::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()) {
   default:
   case 2:
     AI = MainFn->abegin(); ++AI;
     if (AI->getType() != ArgVTy) {
-      Args[1] = new CastInst(AI, ArgVTy, "argv.cast", InsertPos);
+      InitCall->setOperand(2, new CastInst(AI, ArgVTy, "argv.cast", InitCall));
     } else {
-      Args[1] = AI;
+      InitCall->setOperand(2, AI);
     }
 
   case 1:
     AI = MainFn->abegin();
+    // If the program looked at argc, have it look at the return value of the
+    // init call instead.
     if (AI->getType() != Type::IntTy) {
-      Args[0] = new CastInst(AI, Type::IntTy, "argc.cast", InsertPos);
+      if (!AI->use_empty())
+        AI->replaceAllUsesWith(new CastInst(InitCall, AI->getType(), "",
+                                            InsertPos));
+      InitCall->setOperand(1, new CastInst(AI, Type::IntTy, "argc.cast",
+                                           InitCall));
     } else {
-      Args[0] = AI;
+      AI->replaceAllUsesWith(InitCall);
+      InitCall->setOperand(1, AI);
     }
     
-  case 0:
-    break;
+  case 0: break;
   }
-
-  ConstantPointerRef *ArrayCPR = ConstantPointerRef::get(Array);
-  std::vector<Constant*> GEPIndices(2, Constant::getNullValue(Type::LongTy));
-  Args[2] = ConstantExpr::getGetElementPtr(ArrayCPR, GEPIndices);
-  
-  unsigned NumElements =
-    cast<ArrayType>(Array->getType()->getElementType())->getNumElements();
-  Args[3] = ConstantUInt::get(Type::UIntTy, NumElements);
-  
-  new CallInst(InitFn, Args, "", InsertPos);
 }
 
 static void IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum,


Index: llvm/lib/Transforms/Instrumentation/EmitFunctions.cpp
diff -u llvm/lib/Transforms/Instrumentation/EmitFunctions.cpp:1.14 llvm/lib/Transforms/Instrumentation/EmitFunctions.cpp:1.14.4.1
--- llvm/lib/Transforms/Instrumentation/EmitFunctions.cpp:1.14	Tue Nov 11 16:41:33 2003
+++ llvm/lib/Transforms/Instrumentation/EmitFunctions.cpp	Mon Mar  1 17:58:16 2004
@@ -82,14 +82,14 @@
     }
   
   StructType *sttype = StructType::get(vType);
-  ConstantStruct *cstruct = ConstantStruct::get(sttype, vConsts);
+  Constant *cstruct = ConstantStruct::get(sttype, vConsts);
 
   GlobalVariable *gb = new GlobalVariable(cstruct->getType(), true,
                                           GlobalValue::ExternalLinkage, 
                                           cstruct, "llvmFunctionTable");
   M.getGlobalList().push_back(gb);
 
-  ConstantArray *constArray = ConstantArray::get(ArrayType::get(Type::SByteTy, 
+  Constant *constArray = ConstantArray::get(ArrayType::get(Type::SByteTy, 
 								sBCons.size()),
 						 sBCons);
 





More information about the llvm-commits mailing list