llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clangir

Author: Daniel Hogan (Daniel-Hogan)

<details>
<summary>Changes</summary>

Adds implementation for SystemZ TargetCIRGenInfo (following the structure used 
in #<!-- -->215424). getTargetCIRGenInfo() had no SystemZ case so it fell 
through to x86_64 target info. 

The only hook in SystemZTargetCodeGenInfo in classic code gen that has a CIR 
equivalent is setTargetAttributes. setTargetAttributes adds the 
s390x-visible-vector-ABI module flag which CIR doesn't emit yet. This is my 
intended next PR. For now, I add a MissingFeatures marker. 

The other classic hook testFPKind has no counterpart in TargetCIRGenInfo yet. 

z/OS uses XPLINK ABI which has its own target info in classic codegen. For now, 
z/OS uses the SystemZ ELF target info as a placeholder. I marked it with 
targetCIRGenInfoOS() for follow up. 

NFC. 

This is the first step in my plan I laid out in 
https://discourse.llvm.org/t/rfc-enable-clangir-build-by-default/91730/114.

Assisted-by: Claude

---
Full diff: https://github.com/llvm/llvm-project/pull/237828.diff


5 Files Affected:

- (modified) clang/include/clang/CIR/MissingFeatures.h (+1) 
- (modified) clang/lib/CIR/CodeGen/CIRGenModule.cpp (+8) 
- (modified) clang/lib/CIR/CodeGen/CMakeLists.txt (+1) 
- (modified) clang/lib/CIR/CodeGen/TargetInfo.h (+3) 
- (added) clang/lib/CIR/CodeGen/Targets/SystemZ.cpp (+47) 


``````````diff
diff --git a/clang/include/clang/CIR/MissingFeatures.h 
b/clang/include/clang/CIR/MissingFeatures.h
index 1348206f1738ad..0b73847675be64 100644
--- a/clang/include/clang/CIR/MissingFeatures.h
+++ b/clang/include/clang/CIR/MissingFeatures.h
@@ -281,6 +281,7 @@ struct MissingFeatures {
   static bool preservedAccessIndexRegion() { return false; }
   static bool returnValueSlotFeatures() { return false; }
   static bool runCleanupsScope() { return false; }
+  static bool s390xVisibleVectorABI() { return false; }
   static bool sanitizers() { return false; }
   static bool setDLLStorageClass() { return false; }
   static bool setNonGC() { return false; }
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp 
b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
index 4e11a6555b62df..c83df2110d1d40 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -399,6 +399,14 @@ const TargetCIRGenInfo 
&CIRGenModule::getTargetCIRGenInfo() {
   case llvm::Triple::spirv64:
     theTargetCIRGenInfo = createCommonSPIRTargetCIRGenInfo(genTypes);
     return *theTargetCIRGenInfo;
+  case llvm::Triple::systemz: {
+    // z/OS XPLINK target info is not implemented yet.
+    // We just default to SystemZ ELF Target for now.
+    if (triple.isOSzOS())
+      assert(!cir::MissingFeatures::targetCIRGenInfoOS());
+    theTargetCIRGenInfo = createSystemZTargetCIRGenInfo(genTypes);
+    return *theTargetCIRGenInfo;
+  }
   }
 }
 
diff --git a/clang/lib/CIR/CodeGen/CMakeLists.txt 
b/clang/lib/CIR/CodeGen/CMakeLists.txt
index 1f4db82585c20e..f40ff409eb4def 100644
--- a/clang/lib/CIR/CodeGen/CMakeLists.txt
+++ b/clang/lib/CIR/CodeGen/CMakeLists.txt
@@ -60,6 +60,7 @@ add_clang_library(clangCIR
   Targets/AMDGPU.cpp
   Targets/NVPTX.cpp
   Targets/SPIRV.cpp
+  Targets/SystemZ.cpp
 
   DISABLE_PCH_REUSE # PCH contains private headers
   PRECOMPILE_HEADERS
diff --git a/clang/lib/CIR/CodeGen/TargetInfo.h 
b/clang/lib/CIR/CodeGen/TargetInfo.h
index 09f41fcd3cf9b7..62acf0afa80020 100644
--- a/clang/lib/CIR/CodeGen/TargetInfo.h
+++ b/clang/lib/CIR/CodeGen/TargetInfo.h
@@ -201,6 +201,9 @@ std::unique_ptr<TargetCIRGenInfo> 
createNVPTXTargetCIRGenInfo(CIRGenTypes &cgt);
 std::unique_ptr<TargetCIRGenInfo>
 createCommonSPIRTargetCIRGenInfo(CIRGenTypes &cgt);
 
+std::unique_ptr<TargetCIRGenInfo>
+createSystemZTargetCIRGenInfo(CIRGenTypes &cgt);
+
 } // namespace clang::CIRGen
 
 #endif // LLVM_CLANG_LIB_CIR_TARGETINFO_H
diff --git a/clang/lib/CIR/CodeGen/Targets/SystemZ.cpp 
b/clang/lib/CIR/CodeGen/Targets/SystemZ.cpp
new file mode 100644
index 00000000000000..73389ece694baa
--- /dev/null
+++ b/clang/lib/CIR/CodeGen/Targets/SystemZ.cpp
@@ -0,0 +1,47 @@
+//===---- SystemZ.cpp - SystemZ-specific CIR CodeGen 
----------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This provides SystemZ-specific CIR CodeGen logic.
+//
+//===----------------------------------------------------------------------===//
+
+#include "ABIInfo.h"
+#include "CIRGenModule.h"
+#include "TargetInfo.h"
+#include "clang/AST/Decl.h"
+#include "clang/CIR/MissingFeatures.h"
+
+using namespace clang;
+using namespace clang::CIRGen;
+
+namespace {
+
+class SystemZABIInfo : public ABIInfo {
+public:
+  SystemZABIInfo(CIRGenTypes &cgt) : ABIInfo(cgt) {}
+};
+
+class SystemZTargetCIRGenInfo : public TargetCIRGenInfo {
+public:
+  SystemZTargetCIRGenInfo(CIRGenTypes &cgt)
+      : TargetCIRGenInfo(std::make_unique<SystemZABIInfo>(cgt)) {}
+
+  void setTargetAttributes(const Decl *d, mlir::Operation *gv,
+                           CIRGenModule &cgm) const override {
+    if (!d)
+      return;
+    assert(!cir::MissingFeatures::s390xVisibleVectorABI());
+  }
+};
+
+} // namespace
+
+std::unique_ptr<TargetCIRGenInfo>
+clang::CIRGen::createSystemZTargetCIRGenInfo(CIRGenTypes &cgt) {
+  return std::make_unique<SystemZTargetCIRGenInfo>(cgt);
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/237828
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to