[clang] [clang] Allow __attribute__((swiftcall)) on all targets (PR #71986)

via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 10 13:37:07 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Kuba (Brecka) Mracek (kubamracek)

<details>
<summary>Changes</summary>

With Embedded Swift, <https://forums.swift.org/t/embedded-swift/67057>, it becomes possible and useful to produce Swift code for a whole range of CPU targets. This change allows using the 'swiftcall' and 'swiftasynccall)' attributes on any Clang supported target. This isn't in any way adding complete support for those calling conventions for all targets, it's merely removing one obstacle from adding new targets to Swift.

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


4 Files Affected:

- (modified) clang/include/clang/Basic/TargetInfo.h (+2) 
- (modified) clang/lib/CodeGen/ABIInfo.cpp (+4) 
- (modified) clang/lib/CodeGen/ABIInfo.h (+1) 
- (modified) clang/lib/CodeGen/TargetInfo.cpp (+3-1) 


``````````diff
diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h
index 41f3c2e403cbef6..308d2ae830bf263 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1606,6 +1606,8 @@ class TargetInfo : public TransferrableTargetInfo,
       default:
         return CCCR_Warning;
       case CC_C:
+      case CC_Swift:
+      case CC_SwiftAsync:
         return CCCR_OK;
     }
   }
diff --git a/clang/lib/CodeGen/ABIInfo.cpp b/clang/lib/CodeGen/ABIInfo.cpp
index 1b56cf7c596d067..86897504b0ad267 100644
--- a/clang/lib/CodeGen/ABIInfo.cpp
+++ b/clang/lib/CodeGen/ABIInfo.cpp
@@ -33,6 +33,10 @@ const CodeGenOptions &ABIInfo::getCodeGenOpts() const {
   return CGT.getCodeGenOpts();
 }
 
+CodeGen::CodeGenTypes &ABIInfo::getCodeGenTypes() const {
+  return CGT;
+}
+
 bool ABIInfo::isAndroid() const { return getTarget().getTriple().isAndroid(); }
 
 bool ABIInfo::isOHOSFamily() const {
diff --git a/clang/lib/CodeGen/ABIInfo.h b/clang/lib/CodeGen/ABIInfo.h
index b9a5ef6e4366936..99b262bdb529684 100644
--- a/clang/lib/CodeGen/ABIInfo.h
+++ b/clang/lib/CodeGen/ABIInfo.h
@@ -60,6 +60,7 @@ class ABIInfo {
   const llvm::DataLayout &getDataLayout() const;
   const TargetInfo &getTarget() const;
   const CodeGenOptions &getCodeGenOpts() const;
+  CodeGen::CodeGenTypes &getCodeGenTypes() const;
 
   /// Return the calling convention to use for system runtime
   /// functions.
diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp
index 3d79f92137abc79..fdcf77ef9ce547c 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -67,7 +67,9 @@ LLVM_DUMP_METHOD void ABIArgInfo::dump() const {
 }
 
 TargetCodeGenInfo::TargetCodeGenInfo(std::unique_ptr<ABIInfo> Info)
-    : Info(std::move(Info)) {}
+    : Info(std::move(Info)),
+      SwiftInfo(std::make_unique<SwiftABIInfo>(
+          this->Info->getCodeGenTypes(), /*SwiftErrorInRegister*/ false)) {}
 
 TargetCodeGenInfo::~TargetCodeGenInfo() = default;
 

``````````

</details>


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


More information about the cfe-commits mailing list