[PATCH] D11361: [OpenMP] Target directive host codegen

Alexey Bataev a.bataev at hotmail.com
Mon Jul 20 22:50:57 PDT 2015


ABataev added inline comments.

================
Comment at: lib/CodeGen/CGOpenMPRuntime.h:188-212
@@ -179,2 +187,27 @@
   };
+
+  /// \brief Values for bit flags used to specify the mapping type for
+  /// offloading.
+  enum OpenMPOffloadMappingFlags {
+    /// \brief Only allocate memory on the device without moving any data. This
+    /// is the default if no other flags are specified.
+    OMP_MAP_ALLOC = 0x00,
+    /// \brief Allocate memory on the device and move data from host to device.
+    OMP_MAP_TO = 0x01,
+    /// \brief Allocate memory on the device and move data from device to host.
+    OMP_MAP_FROM = 0x02,
+  };
+
+  enum OpenMPOffloadingReservedDeviceIDs {
+    /// \brief Device ID if the device was not defined, runtime should get it
+    /// from environment variables in the spec.
+    OMP_DEVICEID_UNDEF = -1,
+    /// \brief Means the target region should be executed by all devices before
+    /// a regular target region atemps to run on them. Used for Ctors.
+    OMP_DEVICEID_CTORS = -2,
+    /// \brief Means target all devices that were used in the current shared
+    /// library. Used for Dtors.
+    OMP_DEVICEID_DTORS = -3
+  };
+
   CodeGenModule &CGM;
----------------
Seems to me these enums are not used right now, must be removed

================
Comment at: lib/CodeGen/CGStmt.cpp:2212-2240
@@ -2210,2 +2211,31 @@
   FunctionArgList Args;
-  Args.append(CD->param_begin(), CD->param_end());
+
+  // If this is an offload function, we need pass a reference to each captured
+  // declarations as arguments.
+  if (isOffloadFunction) {
+    DeclContext *DC = CapturedDecl::castToDeclContext(CD)->getParent();
+    auto ri = RD->field_begin();
+    for (CapturedStmt::const_capture_iterator ci = S.capture_begin(),
+                                              ce = S.capture_end();
+         ci != ce; ++ci, ++ri) {
+      StringRef Name;
+      QualType Ty;
+      if (ci->capturesVariableArrayType()) {
+        Ty = Ctx.getPointerType(ri->getType());
+        Name = "__vla_size";
+      } else if (ci->capturesThis()) {
+        Ty = ri->getType();
+        Name = "__this";
+      } else {
+        const VarDecl *VD = ci->getCapturedVar();
+        Ty = Ctx.getPointerType(VD->getType());
+        Name = VD->getName();
+      }
+
+      IdentifierInfo *ParamName = &Ctx.Idents.get(Name);
+      ImplicitParamDecl *Param =
+          ImplicitParamDecl::Create(Ctx, DC, Loc, ParamName, Ty);
+      Args.push_back(Param);
+    }
+  } else
+    Args.append(CD->param_begin(), CD->param_end());
----------------
Why do you need all this stuff here? Why you can't use variables captured in CapturedDecl?


http://reviews.llvm.org/D11361







More information about the cfe-commits mailing list