[mlir:LLVM] Fix minor bug, missing cconv translation
authorHendrik Greving <hgreving@google.com>
Wed, 11 Jan 2023 17:12:48 +0000 (09:12 -0800)
committerHendrik Greving <hgreving@google.com>
Mon, 16 Jan 2023 20:18:28 +0000 (12:18 -0800)
Fixes translating the calling convention to LLVM-IR, possibly missed
by https://reviews.llvm.org/D126161, and adds a test.

mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
mlir/test/Dialect/LLVMIR/func.mlir

index b5c1bef..33403b0 100644 (file)
@@ -883,6 +883,7 @@ LogicalResult ModuleTranslation::convertFunctionSignatures() {
         cast<llvm::FunctionType>(convertType(function.getFunctionType())));
     llvm::Function *llvmFunc = cast<llvm::Function>(llvmFuncCst.getCallee());
     llvmFunc->setLinkage(convertLinkageToLLVM(function.getLinkage()));
+    llvmFunc->setCallingConv(convertCConvToLLVM(function.getCConv()));
     mapFunction(function.getName(), llvmFunc);
     addRuntimePreemptionSpecifier(function.getDsoLocal(), llvmFunc);
 
index 8f34759..dedf001 100644 (file)
@@ -1,6 +1,7 @@
 // RUN: mlir-opt -split-input-file -verify-diagnostics %s | mlir-opt | FileCheck %s
 // RUN: mlir-opt -split-input-file -verify-diagnostics -mlir-print-op-generic %s | FileCheck %s --check-prefix=GENERIC
 // RUN: mlir-opt -split-input-file -verify-diagnostics %s -mlir-print-debuginfo | mlir-opt -mlir-print-debuginfo | FileCheck %s --check-prefix=LOCINFO
+// RUN: mlir-translate -mlir-to-llvmir -split-input-file -verify-diagnostics %s | FileCheck %s --check-prefix=CHECK-LLVM
 
 module {
   // GENERIC: "llvm.func"
@@ -8,7 +9,7 @@ module {
   // GENERIC-SAME: sym_name = "foo"
   // GENERIC-SAME: () -> ()
   // CHECK: llvm.func @foo()
-  "llvm.func"() ({
+  "llvm.func" () ({
   }) {sym_name = "foo", function_type = !llvm.func<void ()>} : () -> ()
 
   // GENERIC: "llvm.func"
@@ -142,6 +143,11 @@ module {
     llvm.return
   }
 
+  // CHECK-LLVM: define ptx_kernel void @calling_conv
+  llvm.func ptx_kernelcc @calling_conv() {
+    llvm.return
+  }
+
   // Omit the `external` linkage, which is the default, in the custom format.
   // Check that it is present in the generic format using its numeric value.
   //