Changed llvm_ostream et all to OStream. llvm_cerr, llvm_cout, llvm_null, are
[oota-llvm.git] / lib / Transforms / Instrumentation / ProfilingUtils.cpp
index 3c22b4bf42eb877d90e0216ea5316cc1c20b1edb..887de5bfe2f1aa695e717ac058ad39dd9e8bb3f0 100644 (file)
@@ -1,10 +1,10 @@
 //===- 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
@@ -26,7 +26,8 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName,
   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.
@@ -42,8 +43,7 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName,
   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 {
@@ -51,43 +51,44 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName,
     // 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))
@@ -96,7 +97,7 @@ void llvm::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum,
   // 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.