Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mem2arr] fix dangling users/[Dummy] add static #46

Merged
merged 1 commit into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: }