Skip to content

Commit

Permalink
[Mem2arr] fix dangling users/[Dummy] add static
Browse files Browse the repository at this point in the history
  • Loading branch information
kumasento committed Oct 29, 2021
1 parent e603699 commit fd908db
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 9 deletions.
6 changes: 5 additions & 1 deletion lib/llvm/Transforms/VhlsLLVMRewriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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())
Expand Down
29 changes: 29 additions & 0 deletions test/llvm/Transforms/VhlsLLVMRewriter/mem2arr/multicalls.mlir
Original file line number Diff line number Diff line change
@@ -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]])
Original file line number Diff line number Diff line change
Expand Up @@ -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: }
Original file line number Diff line number Diff line change
Expand Up @@ -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: }
Original file line number Diff line number Diff line change
Expand Up @@ -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: }
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: }

0 comments on commit fd908db

Please sign in to comment.