[flang-commits] [clang] [flang] [llvm] [Flang] Add code-object-version option (PR #72638)

Dominik Adamski via flang-commits flang-commits at lists.llvm.org
Wed Nov 22 02:57:55 PST 2023


================
@@ -264,6 +263,37 @@ static void addDepdendentLibs(mlir::ModuleOp &mlirModule,
   }
 }
 
+// Add to MLIR code target specific items which are dependent on target
+// configuration specified by the user
+static void addTargetSpecificMLIRItems(mlir::ModuleOp &mlirModule,
+                                       CompilerInstance &ci) {
+  const TargetOptions &targetOpts = ci.getInvocation().getTargetOpts();
+  const llvm::Triple triple(targetOpts.triple);
+  if (triple.isAMDGPU()) {
+    unsigned oclcABIVERsion;
+    const unsigned defaultOclcABIVERsion = 400;
+    mlir::OpBuilder builder(mlirModule.getContext());
+    const CodeGenOptions &codeGenOpts = ci.getInvocation().getCodeGenOpts();
+    if (codeGenOpts.CodeObjectVersion ==
+        CodeGenOptions::CodeObjectVersionKind::COV_None)
+      oclcABIVERsion = defaultOclcABIVERsion;
+    else
+      oclcABIVERsion = static_cast<unsigned>(codeGenOpts.CodeObjectVersion);
+
+    auto int32Type = builder.getI32Type();
+    auto covInfo = builder.create<mlir::LLVM::GlobalOp>(
+        mlirModule.getLoc(), int32Type, true, mlir::LLVM::Linkage::WeakODR,
+        "__oclc_ABI_version",
+        builder.getIntegerAttr(int32Type, oclcABIVERsion));
+    covInfo.setUnnamedAddr(mlir::LLVM::UnnamedAddr::Local);
+    covInfo.setAddrSpace(4);
----------------
DominikAdamski wrote:

This address space is described here: https://llvm.org/docs/AMDGPUUsage.html#address-spaces . 4 corresponds to Constant Address space. There is an enum AddrSpace which describes the address spaces. It is defined as part of Clang TargetInfo: https://github.com/llvm/llvm-project/blob/main/clang/lib/Basic/Targets/AMDGPU.h .

I will move this enum to llvm directory as the next step. Currently I added only TODO comment because TargetInfo is one of basic Clang classes and I would like to do it as separate step in case of any regression.

https://github.com/llvm/llvm-project/pull/72638


More information about the flang-commits mailing list