]> granicus.if.org Git - clang/commitdiff
[OPENMP] Improved codegen for outlined functions for 'parallel' directives.
authorAlexey Bataev <a.bataev@hotmail.com>
Fri, 25 Jul 2014 07:55:17 +0000 (07:55 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Fri, 25 Jul 2014 07:55:17 +0000 (07:55 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@213927 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGOpenMPRuntime.cpp

index 12a3a7790eec7408e6c5daf909a52b7ac8c95733..e5de9fc2f9a8e5f0927627ba84871176c8ef0beb 100644 (file)
@@ -128,12 +128,31 @@ llvm::Value *CGOpenMPRuntime::GetOpenMPGlobalThreadNum(CodeGenFunction &CGF,
   if (I != OpenMPGtidMap.end()) {
     GTid = I->second;
   } else {
-    // Generate "int32 .kmpc_global_thread_num.addr;"
-    CGBuilderTy::InsertPointGuard IPG(CGF.Builder);
-    CGF.Builder.SetInsertPoint(CGF.AllocaInsertPt);
-    llvm::Value *Args[] = {EmitOpenMPUpdateLocation(CGF, Loc)};
-    GTid = CGF.EmitRuntimeCall(
-        CreateRuntimeFunction(OMPRTL__kmpc_global_thread_num), Args);
+    // Check if current function is a function which has first parameter
+    // with type int32 and name ".global_tid.".
+    if (!CGF.CurFn->arg_empty() &&
+        CGF.CurFn->arg_begin()->getType()->isPointerTy() &&
+        CGF.CurFn->arg_begin()
+            ->getType()
+            ->getPointerElementType()
+            ->isIntegerTy() &&
+        CGF.CurFn->arg_begin()
+                ->getType()
+                ->getPointerElementType()
+                ->getIntegerBitWidth() == 32 &&
+        CGF.CurFn->arg_begin()->hasName() &&
+        CGF.CurFn->arg_begin()->getName() == ".global_tid.") {
+      CGBuilderTy::InsertPointGuard IPG(CGF.Builder);
+      CGF.Builder.SetInsertPoint(CGF.AllocaInsertPt);
+      GTid = CGF.Builder.CreateLoad(CGF.CurFn->arg_begin());
+    } else {
+      // Generate "int32 .kmpc_global_thread_num.addr;"
+      CGBuilderTy::InsertPointGuard IPG(CGF.Builder);
+      CGF.Builder.SetInsertPoint(CGF.AllocaInsertPt);
+      llvm::Value *Args[] = {EmitOpenMPUpdateLocation(CGF, Loc)};
+      GTid = CGF.EmitRuntimeCall(
+          CreateRuntimeFunction(OMPRTL__kmpc_global_thread_num), Args);
+    }
     OpenMPGtidMap[CGF.CurFn] = GTid;
   }
   return GTid;