diff --git a/lib/llvm/Transforms/VhlsLLVMRewriter.cc b/lib/llvm/Transforms/VhlsLLVMRewriter.cc index 68eeffc81bb..55ed9f72f8e 100644 --- a/lib/llvm/Transforms/VhlsLLVMRewriter.cc +++ b/lib/llvm/Transforms/VhlsLLVMRewriter.cc @@ -1158,7 +1158,8 @@ static void convertMemRefToArray(Module &M, bool ranked = false) { // Erase the original caller. Caller->eraseFromParent(); for (Instruction *inst : toErase) - inst->eraseFromParent(); + if (inst->getNumUses() == 0) + inst->eraseFromParent(); } FuncToNew[F] = replaceFunction(F, NewFunc); @@ -1589,6 +1590,9 @@ static void generateXlnTBDummy(Function &F, StringRef fileName) { // Main definition - XlnTBDummy << "int main() {\n"; + // Prepend the `static' keyword to mitigate segmentfault. + for (auto &argDecl : argDeclList) + argDecl = std::string("static ") + argDecl; // Value declaration interleave(argDeclList, XlnTBDummy, ";\n"); if (!argDeclList.empty()) diff --git a/test/llvm/Transforms/VhlsLLVMRewriter/array1d.ll b/test/llvm/Transforms/VhlsLLVMRewriter/mem2arr/array1d.ll similarity index 100% rename from test/llvm/Transforms/VhlsLLVMRewriter/array1d.ll rename to test/llvm/Transforms/VhlsLLVMRewriter/mem2arr/array1d.ll diff --git a/test/llvm/Transforms/VhlsLLVMRewriter/array1d_multiargs.ll b/test/llvm/Transforms/VhlsLLVMRewriter/mem2arr/array1d_multiargs.ll similarity index 100% rename from test/llvm/Transforms/VhlsLLVMRewriter/array1d_multiargs.ll rename to test/llvm/Transforms/VhlsLLVMRewriter/mem2arr/array1d_multiargs.ll diff --git a/test/llvm/Transforms/VhlsLLVMRewriter/array2d.ll b/test/llvm/Transforms/VhlsLLVMRewriter/mem2arr/array2d.ll similarity index 100% rename from test/llvm/Transforms/VhlsLLVMRewriter/array2d.ll rename to test/llvm/Transforms/VhlsLLVMRewriter/mem2arr/array2d.ll diff --git a/test/llvm/Transforms/VhlsLLVMRewriter/arraynd_mixed.ll b/test/llvm/Transforms/VhlsLLVMRewriter/mem2arr/arraynd_mixed.ll similarity index 100% rename from test/llvm/Transforms/VhlsLLVMRewriter/arraynd_mixed.ll rename to test/llvm/Transforms/VhlsLLVMRewriter/mem2arr/arraynd_mixed.ll diff --git a/test/llvm/Transforms/VhlsLLVMRewriter/malloc.ll b/test/llvm/Transforms/VhlsLLVMRewriter/mem2arr/malloc.ll similarity index 100% rename from test/llvm/Transforms/VhlsLLVMRewriter/malloc.ll rename to test/llvm/Transforms/VhlsLLVMRewriter/mem2arr/malloc.ll diff --git a/test/llvm/Transforms/VhlsLLVMRewriter/matmul.mlir b/test/llvm/Transforms/VhlsLLVMRewriter/mem2arr/matmul.mlir similarity index 100% rename from test/llvm/Transforms/VhlsLLVMRewriter/matmul.mlir rename to test/llvm/Transforms/VhlsLLVMRewriter/mem2arr/matmul.mlir diff --git a/test/llvm/Transforms/VhlsLLVMRewriter/mem2arr/multicalls.mlir b/test/llvm/Transforms/VhlsLLVMRewriter/mem2arr/multicalls.mlir new file mode 100644 index 00000000000..4256e831d19 --- /dev/null +++ b/test/llvm/Transforms/VhlsLLVMRewriter/mem2arr/multicalls.mlir @@ -0,0 +1,29 @@ +// RUN: mlir-opt -lower-affine -convert-scf-to-std -convert-memref-to-llvm -convert-arith-to-llvm -convert-std-to-llvm='use-bare-ptr-memref-call-conv=1' -reconcile-unrealized-casts %s | mlir-translate -mlir-to-llvmir | opt -enable-new-pm=0 -load ${PHISM_LIBS_DIR}/VhlsLLVMRewriter.so -strip-debug -mem2arr -S | FileCheck %s + +func @foo(%A: memref<10xf32>) { + %c0 = arith.constant 0: index + %0 = memref.load %A[%c0] : memref<10xf32> + return +} +func @bar(%A: memref<10xf32>) { + %c0 = arith.constant 0: index + %0 = memref.load %A[%c0] : memref<10xf32> + return +} +func @main() { + %A = memref.alloc() : memref<10xf32> + call @foo(%A): (memref<10xf32>) -> () + call @bar(%A): (memref<10xf32>) -> () + return +} + +// CHECK: define void @bar([10 x float]* %{{.*}}) + +// CHECK: define void @foo([10 x float]* %{{.*}}) + +// CHECK: define void @main() +// CHECK-NEXT: %[[v1:.*]] = call i8* @malloc(i64 ptrtoint (float* getelementptr (float, float* null, i64 10) to i64)) +// CHECK-NEXT: %[[v2:.*]] = bitcast i8* %[[v1]] to [10 x float]* +// CHECK-NEXT: %[[v3:.*]] = bitcast i8* %[[v1]] to [10 x float]* +// CHECK-NEXT: call void @foo([10 x float]* %[[v2]]) +// CHECK-NEXT: call void @bar([10 x float]* %[[v3]]) diff --git a/test/llvm/Transforms/VhlsLLVMRewriter/xlntbgen/test_dummy_c_multi_arrays.ll b/test/llvm/Transforms/VhlsLLVMRewriter/xlntbgen/test_dummy_c_multi_arrays.ll index 03c37c7f029..6eee7397eca 100644 --- a/test/llvm/Transforms/VhlsLLVMRewriter/xlntbgen/test_dummy_c_multi_arrays.ll +++ b/test/llvm/Transforms/VhlsLLVMRewriter/xlntbgen/test_dummy_c_multi_arrays.ll @@ -9,9 +9,9 @@ define void @foo(i32 %n, [32 x float]* %A, [4 x [8 x i32]]* %B) { ; CHECK: B[n + 1][n + 1] += B[n][n]; ; CHECK: } ; CHECK: int main() { -; CHECK: int n; -; CHECK: float A[32]; -; CHECK: int B[4][8]; +; CHECK: static int n; +; CHECK: static float A[32]; +; CHECK: static int B[4][8]; ; CHECK: foo(n, A, B); ; CHECK: return 0; ; CHECK: } diff --git a/test/llvm/Transforms/VhlsLLVMRewriter/xlntbgen/test_dummy_c_no_array.ll b/test/llvm/Transforms/VhlsLLVMRewriter/xlntbgen/test_dummy_c_no_array.ll index 2bf5ba74007..f00c1cba6bd 100644 --- a/test/llvm/Transforms/VhlsLLVMRewriter/xlntbgen/test_dummy_c_no_array.ll +++ b/test/llvm/Transforms/VhlsLLVMRewriter/xlntbgen/test_dummy_c_no_array.ll @@ -7,7 +7,7 @@ define void @foo(i32 %n) { ; CHECK: void foo(int n) { ; CHECK: } ; CHECK: int main() { -; CHECK: int n; +; CHECK: static int n; ; CHECK: foo(n); ; CHECK: return 0; ; CHECK: } diff --git a/test/llvm/Transforms/VhlsLLVMRewriter/xlntbgen/test_dummy_c_single_array.ll b/test/llvm/Transforms/VhlsLLVMRewriter/xlntbgen/test_dummy_c_single_array.ll index 9360a284c13..d33573f0294 100644 --- a/test/llvm/Transforms/VhlsLLVMRewriter/xlntbgen/test_dummy_c_single_array.ll +++ b/test/llvm/Transforms/VhlsLLVMRewriter/xlntbgen/test_dummy_c_single_array.ll @@ -8,8 +8,8 @@ define void @foo(i32 %n, [32 x float]* %A) { ; CHECK: A[n + 1] += A[n]; ; CHECK: } ; CHECK: int main() { -; CHECK: int n; -; CHECK: float A[32]; +; CHECK: static int n; +; CHECK: static float A[32]; ; CHECK: foo(n, A); ; CHECK: return 0; ; CHECK: } diff --git a/test/llvm/Transforms/VhlsLLVMRewriter/xlntbgen/test_dummy_c_single_array_nd.ll b/test/llvm/Transforms/VhlsLLVMRewriter/xlntbgen/test_dummy_c_single_array_nd.ll index 06364f5760b..d125be3ae7a 100644 --- a/test/llvm/Transforms/VhlsLLVMRewriter/xlntbgen/test_dummy_c_single_array_nd.ll +++ b/test/llvm/Transforms/VhlsLLVMRewriter/xlntbgen/test_dummy_c_single_array_nd.ll @@ -8,7 +8,7 @@ define void @foo(i32 %n, [32 x [24 x float]]* %A) { ; CHECK: A[n + 1][n + 1] += A[n][n]; ; CHECK: } ; CHECK: int main() { -; CHECK: int n; +; CHECK: static int n; ; CHECK: float A[32][24]; ; CHECK: foo(n, A); ; CHECK: return 0; diff --git a/test/llvm/Transforms/VhlsLLVMRewriter/xlntbgen/test_dummy_c_single_array_no_int.ll b/test/llvm/Transforms/VhlsLLVMRewriter/xlntbgen/test_dummy_c_single_array_no_int.ll index 57228620ab2..423e46d4fd2 100644 --- a/test/llvm/Transforms/VhlsLLVMRewriter/xlntbgen/test_dummy_c_single_array_no_int.ll +++ b/test/llvm/Transforms/VhlsLLVMRewriter/xlntbgen/test_dummy_c_single_array_no_int.ll @@ -7,7 +7,7 @@ define void @foo([32 x float]* %A) { ; CHECK: void foo(float A[32]) { ; CHECK: } ; CHECK: int main() { -; CHECK: float A[32]; +; CHECK: static float A[32]; ; CHECK: foo(A); ; CHECK: return 0; ; CHECK: }