90 lines · plain
1// RUN: mlir-translate -mlir-to-cpp -declare-variables-at-top %s | FileCheck %s -check-prefix=CPP-DECLTOP2 3// simple(10, true) -> 204// simple(10, false) -> 305func.func @simple(i64, i1) -> i64 {6^bb0(%a: i64, %cond: i1):7 cf.cond_br %cond, ^bb1, ^bb28^bb1:9 cf.br ^bb3(%a: i64)10^bb2:11 %b = emitc.call_opaque "add"(%a, %a) : (i64, i64) -> i6412 cf.br ^bb3(%b: i64)13^bb3(%c: i64):14 cf.br ^bb4(%c, %a : i64, i64)15^bb4(%d : i64, %e : i64):16 %0 = emitc.call_opaque "add"(%d, %e) : (i64, i64) -> i6417 return %0 : i6418}19 // CPP-DECLTOP: int64_t simple(int64_t [[A:[^ ]*]], bool [[COND:[^ ]*]]) {20 // CPP-DECLTOP-NEXT: int64_t [[B:[^ ]*]];21 // CPP-DECLTOP-NEXT: int64_t [[V0:[^ ]*]];22 // CPP-DECLTOP-NEXT: int64_t [[C:[^ ]*]];23 // CPP-DECLTOP-NEXT: int64_t [[D:[^ ]*]];24 // CPP-DECLTOP-NEXT: int64_t [[E:[^ ]*]];25 // CPP-DECLTOP-NEXT: if ([[COND]]) {26 // CPP-DECLTOP-NEXT: goto [[BB1:[^ ]*]];27 // CPP-DECLTOP-NEXT: } else {28 // CPP-DECLTOP-NEXT: goto [[BB2:[^ ]*]];29 // CPP-DECLTOP-NEXT: }30 // CPP-DECLTOP-NEXT: [[BB1]]:31 // CPP-DECLTOP-NEXT: [[C]] = [[A]];32 // CPP-DECLTOP-NEXT: goto [[BB3:[^ ]*]];33 // CPP-DECLTOP-NEXT: [[BB2]]:34 // CPP-DECLTOP-NEXT: [[B]] = add([[A]], [[A]]);35 // CPP-DECLTOP-NEXT: [[C]] = [[B]];36 // CPP-DECLTOP-NEXT: goto [[BB3]];37 // CPP-DECLTOP-NEXT: [[BB3]]:38 // CPP-DECLTOP-NEXT: [[D]] = [[C]];39 // CPP-DECLTOP-NEXT: [[E]] = [[A]];40 // CPP-DECLTOP-NEXT: goto [[BB4:[^ ]*]];41 // CPP-DECLTOP-NEXT: [[BB4]]:42 // CPP-DECLTOP-NEXT: [[V0]] = add([[D]], [[E]]);43 // CPP-DECLTOP-NEXT: return [[V0]];44 45 46func.func @block_labels0() {47^bb1:48 cf.br ^bb249^bb2:50 return51}52// CPP-DECLTOP: void block_labels0() {53 // CPP-DECLTOP-NEXT: goto label2;54 // CPP-DECLTOP-NEXT: label2:55 // CPP-DECLTOP-NEXT: return;56 // CPP-DECLTOP-NEXT: }57 58 59// Repeat the same function to make sure the names of the block labels get reset.60func.func @block_labels1() {61^bb1:62 cf.br ^bb263^bb2:64 return65}66// CPP-DECLTOP: void block_labels1() {67 // CPP-DECLTOP-NEXT: goto label2;68 // CPP-DECLTOP-NEXT: label2:69 // CPP-DECLTOP-NEXT: return;70 // CPP-DECLTOP-NEXT: }71 72emitc.func @expression_inlining(%0 : i32, %1 : i32) {73 %2 = expression %0, %1 : (i32, i32) -> i1 {74 %3 = cmp lt, %0, %1 : (i32, i32) -> i175 yield %3 : i176 }77 cf.cond_br %2, ^bb1, ^bb178 ^bb1: // 2 preds: ^bb0, ^bb079 return80}81// CPP-DECLTOP: void expression_inlining(int32_t [[v1:v.*]], int32_t [[v2:v.*]]) {82// CPP-DECLTOP-NEXT: if ([[v1]] < [[v2]]) {83// CPP-DECLTOP-NEXT: goto label2;84// CPP-DECLTOP-NEXT: } else {85// CPP-DECLTOP-NEXT: goto label2;86// CPP-DECLTOP-NEXT: }87// CPP-DECLTOP-NEXT: label2:88// CPP-DECLTOP-NEXT: return;89// CPP-DECLTOP-NEXT: }90