[flang-commits] [flang] 08749a9 - [flang] Add AMDGPU target in flang

Jan Sjodin via flang-commits flang-commits at lists.llvm.org
Tue Feb 7 11:59:06 PST 2023


Author: Jan Sjodin
Date: 2023-02-07T14:48:46-05:00
New Revision: 08749a9137a562a52d3ff99aad1535e3879ecfeb

URL: https://github.com/llvm/llvm-project/commit/08749a9137a562a52d3ff99aad1535e3879ecfeb
DIFF: https://github.com/llvm/llvm-project/commit/08749a9137a562a52d3ff99aad1535e3879ecfeb.diff

LOG: [flang] Add AMDGPU target in flang

This is the first patch of several that will enable generating code for AMD
GPUs. It adds the AMDGPU target so it can be used with the --target and -mcpu
options.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D143102

Added: 
    flang/test/Driver/target-gpu-features.f90

Modified: 
    flang/lib/Optimizer/CodeGen/Target.cpp
    flang/test/Fir/target-rewrite-boxchar.fir

Removed: 
    


################################################################################
diff  --git a/flang/lib/Optimizer/CodeGen/Target.cpp b/flang/lib/Optimizer/CodeGen/Target.cpp
index 572cfef09ad65..70080883460cd 100644
--- a/flang/lib/Optimizer/CodeGen/Target.cpp
+++ b/flang/lib/Optimizer/CodeGen/Target.cpp
@@ -465,6 +465,33 @@ struct TargetRISCV64 : public GenericTarget<TargetRISCV64> {
 };
 } // namespace
 
+//===----------------------------------------------------------------------===//
+// AMDGPU linux target specifics.
+//===----------------------------------------------------------------------===//
+
+namespace {
+struct TargetAMDGPU : public GenericTarget<TargetAMDGPU> {
+  using GenericTarget::GenericTarget;
+
+  // Default size (in bits) of the index type for strings.
+  static constexpr int defaultWidth = 64;
+
+  CodeGenSpecifics::Marshalling
+  complexArgumentType(mlir::Location loc, mlir::Type eleTy) const override {
+    CodeGenSpecifics::Marshalling marshal;
+    TODO(loc, "handle complex argument types");
+    return marshal;
+  }
+
+  CodeGenSpecifics::Marshalling
+  complexReturnType(mlir::Location loc, mlir::Type eleTy) const override {
+    CodeGenSpecifics::Marshalling marshal;
+    TODO(loc, "handle complex return types");
+    return marshal;
+  }
+};
+} // namespace
+
 // Instantiate the overloaded target instance based on the triple value.
 // TODO: Add other targets to this file as needed.
 std::unique_ptr<fir::CodeGenSpecifics>
@@ -497,6 +524,9 @@ fir::CodeGenSpecifics::get(mlir::MLIRContext *ctx, llvm::Triple &&trp,
   case llvm::Triple::ArchType::riscv64:
     return std::make_unique<TargetRISCV64>(ctx, std::move(trp),
                                            std::move(kindMap));
+  case llvm::Triple::ArchType::amdgcn:
+    return std::make_unique<TargetAMDGPU>(ctx, std::move(trp),
+                                          std::move(kindMap));
   }
   TODO(mlir::UnknownLoc::get(ctx), "target not implemented");
 }

diff  --git a/flang/test/Driver/target-gpu-features.f90 b/flang/test/Driver/target-gpu-features.f90
new file mode 100644
index 0000000000000..9cc9ce4baaf4d
--- /dev/null
+++ b/flang/test/Driver/target-gpu-features.f90
@@ -0,0 +1,10 @@
+! REQUIRES: amdgpu-registered-target
+
+! Test that -mcpu are used and that the -target-cpu and -target-features
+! are also added to the fc1 command.
+
+! RUN: %flang --target=amdgcn-amd-amdhsa -mcpu=gfx902 -c %s -### 2>&1 \
+! RUN: | FileCheck %s -check-prefix=CHECK-AMDGCN
+
+! CHECK-AMDGCN: "-fc1" "-triple" "amdgcn-amd-amdhsa"
+! CHECK-AMDGCN-SAME: "-target-cpu" "gfx902"

diff  --git a/flang/test/Fir/target-rewrite-boxchar.fir b/flang/test/Fir/target-rewrite-boxchar.fir
index e1df9e06adc40..93c205986fbb5 100644
--- a/flang/test/Fir/target-rewrite-boxchar.fir
+++ b/flang/test/Fir/target-rewrite-boxchar.fir
@@ -2,6 +2,7 @@
 // RUN: fir-opt --target-rewrite="target=x86_64-unknown-linux-gnu" %s | FileCheck %s --check-prefix=INT64
 // RUN: fir-opt --target-rewrite="target=aarch64-unknown-linux-gnu" %s | FileCheck %s --check-prefix=INT64
 // RUN: fir-opt --target-rewrite="target=powerpc64le-unknown-linux-gnu" %s | FileCheck %s --check-prefix=INT64
+// RUN: fir-opt --target-rewrite="target=amdgcn-amd-amdhsa" %s | FileCheck %s --check-prefix=INT64
 
 // Test that we rewrite the signatures and bodies of functions that take boxchar
 // parameters.


        


More information about the flang-commits mailing list