1 //===- llvm.c - Test of llvm APIs -----------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 4 // Exceptions. 5 // See https://llvm.org/LICENSE.txt for license information. 6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 // 8 //===----------------------------------------------------------------------===// 9 10 // RUN: mlir-capi-llvm-test 2>&1 | FileCheck %s 11 12 #include "mlir-c/Dialect/LLVM.h" 13 #include "mlir-c/IR.h" 14 #include "mlir-c/BuiltinTypes.h" 15 16 #include <assert.h> 17 #include <math.h> 18 #include <stdio.h> 19 #include <stdlib.h> 20 #include <string.h> 21 22 // CHECK-LABEL: testTypeCreation() 23 static void testTypeCreation(MlirContext ctx) { 24 fprintf(stderr, "testTypeCreation()\n"); 25 MlirType i8 = mlirIntegerTypeGet(ctx, 8); 26 MlirType i32 = mlirIntegerTypeGet(ctx, 32); 27 MlirType i64 = mlirIntegerTypeGet(ctx, 64); 28 29 const char *i32p_text = "!llvm.ptr<i32>"; 30 MlirType i32p = mlirLLVMPointerTypeGet(i32, 0); 31 MlirType i32p_ref = mlirTypeParseGet(ctx, mlirStringRefCreateFromCString(i32p_text)); 32 // CHECK: !llvm.ptr<i32>: 1 33 fprintf(stderr, "%s: %d\n", i32p_text, mlirTypeEqual(i32p, i32p_ref)); 34 35 const char *i32p4_text = "!llvm.ptr<i32, 4>"; 36 MlirType i32p4 = mlirLLVMPointerTypeGet(i32, 4); 37 MlirType i32p4_ref = mlirTypeParseGet(ctx, mlirStringRefCreateFromCString(i32p4_text)); 38 // CHECK: !llvm.ptr<i32, 4>: 1 39 fprintf(stderr, "%s: %d\n", i32p4_text, mlirTypeEqual(i32p4, i32p4_ref)); 40 41 const char *voidt_text = "!llvm.void"; 42 MlirType voidt = mlirLLVMVoidTypeGet(ctx); 43 MlirType voidt_ref = 44 mlirTypeParseGet(ctx, mlirStringRefCreateFromCString(voidt_text)); 45 // CHECK: !llvm.void: 1 46 fprintf(stderr, "%s: %d\n", voidt_text, mlirTypeEqual(voidt, voidt_ref)); 47 48 const char *i32_4_text = "!llvm.array<4xi32>"; 49 MlirType i32_4 = mlirLLVMArrayTypeGet(i32, 4); 50 MlirType i32_4_ref = 51 mlirTypeParseGet(ctx, mlirStringRefCreateFromCString(i32_4_text)); 52 // CHECK: !llvm.array<4xi32>: 1 53 fprintf(stderr, "%s: %d\n", i32_4_text, mlirTypeEqual(i32_4, i32_4_ref)); 54 55 const char *i8_i32_i64_text = "!llvm.func<i8 (i32, i64)>"; 56 const MlirType i32_i64_arr[] = {i32, i64}; 57 MlirType i8_i32_i64 = mlirLLVMFunctionTypeGet(i8, 2, i32_i64_arr, false); 58 MlirType i8_i32_i64_ref = 59 mlirTypeParseGet(ctx, mlirStringRefCreateFromCString(i8_i32_i64_text)); 60 // CHECK: !llvm.func<i8 (i32, i64)>: 1 61 fprintf(stderr, "%s: %d\n", i8_i32_i64_text, 62 mlirTypeEqual(i8_i32_i64, i8_i32_i64_ref)); 63 64 const char *i32_i64_s_text = "!llvm.struct<(i32, i64)>"; 65 MlirType i32_i64_s = mlirLLVMStructTypeLiteralGet(ctx, 2, i32_i64_arr, false); 66 MlirType i32_i64_s_ref = 67 mlirTypeParseGet(ctx, mlirStringRefCreateFromCString(i32_i64_s_text)); 68 // CHECK: !llvm.struct<(i32, i64)>: 1 69 fprintf(stderr, "%s: %d\n", i32_i64_s_text, 70 mlirTypeEqual(i32_i64_s, i32_i64_s_ref)); 71 } 72 73 int main() { 74 MlirContext ctx = mlirContextCreate(); 75 mlirDialectHandleRegisterDialect(mlirGetDialectHandle__llvm__(), ctx); 76 mlirContextGetOrLoadDialect(ctx, mlirStringRefCreateFromCString("llvm")); 77 testTypeCreation(ctx); 78 mlirContextDestroy(ctx); 79 return 0; 80 } 81 82