diff --git a/hpvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp b/hpvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp
index d9692b691a853202ca22b9a05258099198c45528..fdd90ea03738338304a373aa5f310ed6c93ab64d 100644
--- a/hpvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp
+++ b/hpvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp
@@ -1103,8 +1103,9 @@ void CGT_NVPTX::codeGen(DFLeafNode* N) {
   // global address space
   unsigned argIndex = 0;
   std::vector<unsigned> GlobalMemArgs;
-  for(auto& Arg: F_nvptx->getArgumentList()) {
-    if (Arg.getType()->isPointerTy()) {
+  for(Function::arg_iterator ai = F_nvptx->arg_begin(), ae = F_nvptx->arg_end();
+      ai != ae; ++ai) {
+    if (ai->getType()->isPointerTy()) {    
       // If the arguement is already chosen for shared memory arguemnt list, skip.
       // Else put it in Global memory arguement list
       if(std::count(SharedMemArgs.begin(), SharedMemArgs.end(), argIndex) == 0) {
@@ -1378,7 +1379,7 @@ void CGT_NVPTX::codeGen(DFLeafNode* N) {
           Ptr = CastInst::CreatePointerCast(Ptr, Type::getInt32PtrTy(II->getContext(), PtrTy->getAddressSpace()), "", II);
         }
         AtomicRMWInst* AtomicInst = new AtomicRMWInst(getAtomicOp(II->getIntrinsicID()),
-            Ptr, Val, AtomicOrdering::SequentiallyConsistent, llvm::CrossThread, II);
+            Ptr, Val, AtomicOrdering::SequentiallyConsistent, SyncScope::System, II);
         AtomicInst->setVolatile(true);
         DEBUG(errs() << "Substitute with: " << *AtomicInst << "\n");
         II->replaceAllUsesWith(AtomicInst);
@@ -1419,8 +1420,7 @@ void CGT_NVPTX::codeGen(DFLeafNode* N) {
             FunctionType* SinCosFT = FunctionType::get(II->getType(),
                                      Type::getFloatTy(KernelM->getContext()),
                                      false);
-            Function* LibclcFunction = cast<Function>
-                                       (KernelM->getOrInsertFunction(name, SinCosFT));
+            FunctionCallee LibclcFunction = KernelM->getOrInsertFunction(name, SinCosFT);
             CallInst* CI = CallInst::Create(LibclcFunction, II->getArgOperand(0), II->getName(), II);
 
             II->replaceAllUsesWith(CI);
@@ -1555,17 +1555,19 @@ void CGT_NVPTX::fixValueAddrspace(Value* V, unsigned addrspace) {
 
 std::vector<unsigned> CGT_NVPTX::globalToConstantMemoryOpt(std::vector<unsigned>* GlobalMemArgs, Function* F) {
   std::vector<unsigned> ConstantMemArgs;
-  for(auto& arg: F->getArgumentList()) {
+   for(Function::arg_iterator ai = F->arg_begin(), ae = F->arg_end();
+      ai != ae; ++ai) {
+     Argument* arg = &*ai; 
     std::vector<unsigned>::iterator pos = std::find(GlobalMemArgs->begin(),
-        GlobalMemArgs->end(), arg.getArgNo());
+        GlobalMemArgs->end(), arg->getArgNo());
     // It has to be a global memory argument to be promotable
     if(pos == GlobalMemArgs->end())
       continue;
 
     // Check if it can/should be promoted
-    if(canBePromoted(&arg, F)) {
-      errs() << "Promoting << " << arg.getName()  << " to constant memory."<< "\n";
-      ConstantMemArgs.push_back(arg.getArgNo());
+    if(canBePromoted(arg, F)) {
+      errs() << "Promoting << " << arg->getName()  << " to constant memory."<< "\n";
+      ConstantMemArgs.push_back(arg->getArgNo());
       GlobalMemArgs->erase(pos);
     }
   }
@@ -1575,14 +1577,16 @@ std::vector<unsigned> CGT_NVPTX::globalToConstantMemoryOpt(std::vector<unsigned>
 Function* CGT_NVPTX::changeArgAddrspace(Function* F, std::vector<unsigned> &Args, unsigned addrspace) {
   unsigned idx = 0;
   std::vector<Type*> ArgTypes;
-  for(auto& arg: F->getArgumentList()) {
-    DEBUG(errs() << arg << "\n");
-    unsigned argno = arg.getArgNo();
+  for(Function::arg_iterator ai = F->arg_begin(), ae = F->arg_end();
+      ai != ae; ++ai) {
+    Argument *arg = &*ai;
+    DEBUG(errs() << *arg << "\n");
+    unsigned argno = arg->getArgNo();
     if ((idx < Args.size()) && (argno == Args[idx])) {
-      fixValueAddrspace(&arg, addrspace);
+      fixValueAddrspace(arg, addrspace);
       idx++;
     }
-    ArgTypes.push_back(arg.getType());
+    ArgTypes.push_back(arg->getType());
   }
   FunctionType* newFT = FunctionType::get(F->getReturnType(), ArgTypes, false);
 
@@ -1629,7 +1633,7 @@ void CGT_NVPTX::writeKernelsModule() {
   errs() << "Writing to File --- ";
   errs() << getKernelsModuleName(M).c_str() << "\n";
   std::error_code EC;
-  tool_output_file Out(getKernelsModuleName(M).c_str(), EC, sys::fs::F_None);
+  ToolOutputFile Out(getKernelsModuleName(M).c_str(), EC, sys::fs::F_None);
   if (EC) {
     errs() << EC.message() << '\n';
   }