[Mlir-commits] [mlir] [mlir] Add mlirTranslateModuleToLLVMIR to MLIR-C (PR #73117)
Oleksandr Alex Zinenko
llvmlistbot at llvm.org
Wed Nov 22 06:17:56 PST 2023
================
@@ -73,11 +79,47 @@ static void testTypeCreation(MlirContext ctx) {
mlirTypeEqual(i32_i64_s, i32_i64_s_ref));
}
+// CHECK-LABEL: testToLLVMIR()
+static void testToLLVMIR(MlirContext ctx) {
+ fprintf(stderr, "testToLLVMIR()\n");
+ LLVMContextRef llvmCtx = LLVMContextCreate();
+
+ const char *moduleString = "llvm.func @add(%arg0: i64, %arg1: i64) -> i64 { \
+ %0 = llvm.add %arg0, %arg1 : i64 \
+ llvm.return %0 : i64 \
+ }";
+
+ mlirRegisterAllLLVMTranslations(ctx);
+
+ MlirModule module =
+ mlirModuleCreateParse(ctx, mlirStringRefCreateFromCString(moduleString));
+
+ MlirOperation operation = mlirModuleGetOperation(module);
+
+ LLVMModuleRef llvmModule = mlirTranslateModuleToLLVMIR(operation, llvmCtx);
+
+ // clang-format off
+ // CHECK: ; ModuleID = 'LLVMDialectModule'
+ // CHECK-NEXT: source_filename = "LLVMDialectModule"
----------------
ftynse wrote:
Let's not check parts we don't control such as debug comments.
https://github.com/llvm/llvm-project/pull/73117
More information about the Mlir-commits
mailing list