brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.0 KiB · 73375d5 Raw
165 lines · plain
1// RUN: mlir-translate -mlir-to-cpp %s | FileCheck --match-full-lines %s -check-prefix=CPP-DEFAULT2// RUN: mlir-translate -mlir-to-cpp -declare-variables-at-top %s | FileCheck --match-full-lines %s -check-prefix=CPP-DECLTOP3 4func.func @test_for(%arg0 : index, %arg1 : index, %arg2 : index) {5  %lb = emitc.expression %arg0, %arg1 : (index, index) -> index {6    %a = emitc.add %arg0, %arg1 : (index, index) -> index7    emitc.yield %a : index8  }9  %ub = emitc.expression %arg1, %arg2 : (index, index) -> index {10    %a = emitc.mul %arg1, %arg2 : (index, index) -> index11    emitc.yield %a : index12  }13  %step = emitc.expression %arg0, %arg2 : (index, index) -> index {14    %a = emitc.div %arg0, %arg2 : (index, index) -> index15    emitc.yield %a : index16  }17  emitc.for %i0 = %lb to %ub step %step {18    %0 = emitc.call_opaque "f"() : () -> i3219  }20  return21}22// CPP-DEFAULT: void test_for(size_t [[V1:[^ ]*]], size_t [[V2:[^ ]*]], size_t [[V3:[^ ]*]]) {23// CPP-DEFAULT-NEXT: for (size_t [[ITER:[^ ]*]] = [[V1]] + [[V2]]; [[ITER]] < ([[V2]] * [[V3]]); [[ITER]] += [[V1]] / [[V3]]) {24// CPP-DEFAULT-NEXT: int32_t [[V4:[^ ]*]] = f();25// CPP-DEFAULT-NEXT: }26// CPP-DEFAULT-NEXT: return;27 28// CPP-DECLTOP: void test_for(size_t [[V1:[^ ]*]], size_t [[V2:[^ ]*]], size_t [[V3:[^ ]*]]) {29// CPP-DECLTOP-NEXT: int32_t [[V4:[^ ]*]];30// CPP-DECLTOP-NEXT: for (size_t [[ITER:[^ ]*]] = [[V1]] + [[V2]]; [[ITER]] < ([[V2]] * [[V3]]); [[ITER]] += [[V1]] / [[V3]]) {31// CPP-DECLTOP-NEXT: [[V4]] = f();32// CPP-DECLTOP-NEXT: }33// CPP-DECLTOP-NEXT: return;34 35func.func @test_for_yield() {36  %start = "emitc.constant"() <{value = 0 : index}> : () -> index37  %stop = "emitc.constant"() <{value = 10 : index}> : () -> index38  %step = "emitc.constant"() <{value = 1 : index}> : () -> index39 40  %s0 = "emitc.constant"() <{value = 0 : i32}> : () -> i3241  %p0 = "emitc.constant"() <{value = 1.0 : f32}> : () -> f3242 43  %0 = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.lvalue<i32>44  %1 = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.lvalue<f32>45  %2 = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.lvalue<i32>46  %3 = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.lvalue<f32>47  emitc.assign %s0 : i32 to %2 : !emitc.lvalue<i32>48  emitc.assign %p0 : f32 to %3 : !emitc.lvalue<f32>49  emitc.for %iter = %start to %stop step %step {50    %4 = emitc.load %2 : !emitc.lvalue<i32>51    %sn = emitc.call_opaque "add"(%4, %iter) : (i32, index) -> i3252    %5 = emitc.load %3 : !emitc.lvalue<f32>53    %pn = emitc.call_opaque "mul"(%5, %iter) : (f32, index) -> f3254    emitc.assign %sn : i32 to %2 : !emitc.lvalue<i32>55    emitc.assign %pn : f32 to %3 : !emitc.lvalue<f32>56    emitc.yield57  }58  %6 = emitc.load %2 : !emitc.lvalue<i32>59  emitc.assign %6 : i32 to %0 : !emitc.lvalue<i32>60  %7 = emitc.load %3 : !emitc.lvalue<f32>61  emitc.assign %7 : f32 to %1 : !emitc.lvalue<f32>62 63  return64}65// CPP-DEFAULT: void test_for_yield() {66// CPP-DEFAULT-NEXT: size_t [[START:[^ ]*]] = 0;67// CPP-DEFAULT-NEXT: size_t [[STOP:[^ ]*]] = 10;68// CPP-DEFAULT-NEXT: size_t [[STEP:[^ ]*]] = 1;69// CPP-DEFAULT-NEXT: int32_t [[S0:[^ ]*]] = 0;70// CPP-DEFAULT-NEXT: float [[P0:[^ ]*]] = 1.000000000e+00f;71// CPP-DEFAULT-NEXT: int32_t [[SE:[^ ]*]];72// CPP-DEFAULT-NEXT: float [[PE:[^ ]*]];73// CPP-DEFAULT-NEXT: int32_t [[SI:[^ ]*]];74// CPP-DEFAULT-NEXT: float [[PI:[^ ]*]];75// CPP-DEFAULT-NEXT: [[SI:[^ ]*]] = [[S0]];76// CPP-DEFAULT-NEXT: [[PI:[^ ]*]] = [[P0]];77// CPP-DEFAULT-NEXT: for (size_t [[ITER:[^ ]*]] = [[START]]; [[ITER]] < [[STOP]]; [[ITER]] += [[STEP]]) {78// CPP-DEFAULT-NEXT: int32_t [[SI_LOAD:[^ ]*]] = [[SI]];79// CPP-DEFAULT-NEXT: int32_t [[SN:[^ ]*]] = add([[SI_LOAD]], [[ITER]]);80// CPP-DEFAULT-NEXT: float [[PI_LOAD:[^ ]*]] = [[PI]];81// CPP-DEFAULT-NEXT: float [[PN:[^ ]*]] = mul([[PI_LOAD]], [[ITER]]);82// CPP-DEFAULT-NEXT: [[SI]] = [[SN]];83// CPP-DEFAULT-NEXT: [[PI]] = [[PN]];84// CPP-DEFAULT-NEXT: }85// CPP-DEFAULT-NEXT: int32_t [[SI_LOAD2:[^ ]*]] = [[SI]];86// CPP-DEFAULT-NEXT: [[SE]] = [[SI_LOAD2]];87// CPP-DEFAULT-NEXT: float [[PI_LOAD2:[^ ]*]] = [[PI]];88// CPP-DEFAULT-NEXT: [[PE]] = [[PI_LOAD2]];89// CPP-DEFAULT-NEXT: return;90 91// CPP-DECLTOP: void test_for_yield() {92// CPP-DECLTOP-NEXT: size_t [[START:[^ ]*]];93// CPP-DECLTOP-NEXT: size_t [[STOP:[^ ]*]];94// CPP-DECLTOP-NEXT: size_t [[STEP:[^ ]*]];95// CPP-DECLTOP-NEXT: int32_t [[S0:[^ ]*]];96// CPP-DECLTOP-NEXT: float [[P0:[^ ]*]];97// CPP-DECLTOP-NEXT: int32_t [[SE:[^ ]*]];98// CPP-DECLTOP-NEXT: float [[PE:[^ ]*]];99// CPP-DECLTOP-NEXT: int32_t [[SI:[^ ]*]];100// CPP-DECLTOP-NEXT: float [[PI:[^ ]*]];101// CPP-DECLTOP-NEXT: int32_t [[SI_LOAD:[^ ]*]];102// CPP-DECLTOP-NEXT: int32_t [[SN:[^ ]*]];103// CPP-DECLTOP-NEXT: float [[PI_LOAD:[^ ]*]];104// CPP-DECLTOP-NEXT: float [[PN:[^ ]*]];105// CPP-DECLTOP-NEXT: int32_t [[SI_LOAD2:[^ ]*]];106// CPP-DECLTOP-NEXT: float [[PI_LOAD2:[^ ]*]];107// CPP-DECLTOP-NEXT: [[START]] = 0;108// CPP-DECLTOP-NEXT: [[STOP]] = 10;109// CPP-DECLTOP-NEXT: [[STEP]] = 1;110// CPP-DECLTOP-NEXT: [[S0]] = 0;111// CPP-DECLTOP-NEXT: [[P0]] = 1.000000000e+00f;112// CPP-DECLTOP-NEXT: ;113// CPP-DECLTOP-NEXT: ;114// CPP-DECLTOP-NEXT: ;115// CPP-DECLTOP-NEXT: ;116// CPP-DECLTOP-NEXT: [[SI]] = [[S0]];117// CPP-DECLTOP-NEXT: [[PI]] = [[P0]];118// CPP-DECLTOP-NEXT: for (size_t [[ITER:[^ ]*]] = [[START]]; [[ITER]] < [[STOP]]; [[ITER]] += [[STEP]]) {119// CPP-DECLTOP-NEXT: [[SI_LOAD]] = [[SI]];120// CPP-DECLTOP-NEXT: [[SN]] = add([[SI_LOAD]], [[ITER]]);121// CPP-DECLTOP-NEXT: [[PI_LOAD]] = [[PI]];122// CPP-DECLTOP-NEXT: [[PN]] = mul([[PI_LOAD]], [[ITER]]);123// CPP-DECLTOP-NEXT: [[SI]] = [[SN]];124// CPP-DECLTOP-NEXT: [[PI]] = [[PN]];125// CPP-DECLTOP-NEXT: }126// CPP-DECLTOP-NEXT: [[SI_LOAD2]] = [[SI]];127// CPP-DECLTOP-NEXT: [[SE]] = [[SI_LOAD2]];128// CPP-DECLTOP-NEXT: [[PI_LOAD2]] = [[PI]];129// CPP-DECLTOP-NEXT: [[PE]] = [[PI_LOAD2]];130// CPP-DECLTOP-NEXT: return;131 132func.func @test_for_yield_2() {133  %start = emitc.literal "0" : index134  %stop = emitc.literal "10" : index135  %step = emitc.literal "1" : index136 137  %s0 = emitc.literal "0" : i32138  %p0 = emitc.literal "M_PI" : f32139 140  %0 = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.lvalue<i32>141  %1 = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.lvalue<f32>142  %2 = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.lvalue<i32>143  %3 = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.lvalue<f32>144  emitc.assign %s0 : i32 to %2 : !emitc.lvalue<i32>145  emitc.assign %p0 : f32 to %3 : !emitc.lvalue<f32>146  emitc.for %iter = %start to %stop step %step {147    %4 = emitc.load %2 : !emitc.lvalue<i32>148    %sn = emitc.call_opaque "add"(%4, %iter) : (i32, index) -> i32149    %5 = emitc.load %3 : !emitc.lvalue<f32>150    %pn = emitc.call_opaque "mul"(%5, %iter) : (f32, index) -> f32151    emitc.assign %sn : i32 to %2 : !emitc.lvalue<i32>152    emitc.assign %pn : f32 to %3 : !emitc.lvalue<f32>153    emitc.yield154  }155  %6 = emitc.load %2 : !emitc.lvalue<i32>156  emitc.assign %6 : i32 to %0 : !emitc.lvalue<i32>157  %7 = emitc.load %3 : !emitc.lvalue<f32>158  emitc.assign %7 : f32 to %1 : !emitc.lvalue<f32>159 160  return161}162// CPP-DEFAULT: void test_for_yield_2() {163// CPP-DEFAULT: {{.*}}= M_PI;164// CPP-DEFAULT: for (size_t [[IN:.*]] = 0; [[IN]] < 10; [[IN]] += 1) {165