brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.1 KiB · 9a7e12b Raw
108 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_if(%arg0: i1, %arg1: f32) {5  emitc.if %arg0 {6     %0 = emitc.call_opaque "func_const"(%arg1) : (f32) -> i327  }8  return9}10// CPP-DEFAULT: void test_if(bool [[V0:[^ ]*]], float [[V1:[^ ]*]]) {11// CPP-DEFAULT-NEXT: if ([[V0]]) {12// CPP-DEFAULT-NEXT: int32_t [[V2:[^ ]*]] = func_const([[V1]]);13// CPP-DEFAULT-NEXT: }14// CPP-DEFAULT-NEXT: return;15 16// CPP-DECLTOP: void test_if(bool [[V0:[^ ]*]], float [[V1:[^ ]*]]) {17// CPP-DECLTOP-NEXT: int32_t [[V2:[^ ]*]];18// CPP-DECLTOP-NEXT: if ([[V0]]) {19// CPP-DECLTOP-NEXT: [[V2]] = func_const([[V1]]);20// CPP-DECLTOP-NEXT: }21// CPP-DECLTOP-NEXT: return;22 23 24func.func @test_if_else(%arg0: i1, %arg1: f32) {25  emitc.if %arg0 {26    %0 = emitc.call_opaque "func_true"(%arg1) : (f32) -> i3227  } else {28    %0 = emitc.call_opaque "func_false"(%arg1) : (f32) -> i3229  }30  return31}32// CPP-DEFAULT: void test_if_else(bool [[V0:[^ ]*]], float [[V1:[^ ]*]]) {33// CPP-DEFAULT-NEXT: if ([[V0]]) {34// CPP-DEFAULT-NEXT: int32_t [[V2:[^ ]*]] = func_true([[V1]]);35// CPP-DEFAULT-NEXT: } else {36// CPP-DEFAULT-NEXT: int32_t [[V3:[^ ]*]] = func_false([[V1]]);37// CPP-DEFAULT-NEXT: }38// CPP-DEFAULT-NEXT: return;39 40// CPP-DECLTOP: void test_if_else(bool [[V0:[^ ]*]], float [[V1:[^ ]*]]) {41// CPP-DECLTOP-NEXT: int32_t [[V2:[^ ]*]];42// CPP-DECLTOP-NEXT: int32_t [[V3:[^ ]*]];43// CPP-DECLTOP-NEXT: if ([[V0]]) {44// CPP-DECLTOP-NEXT: [[V2]] = func_true([[V1]]);45// CPP-DECLTOP-NEXT: } else {46// CPP-DECLTOP-NEXT: [[V3]] = func_false([[V1]]);47// CPP-DECLTOP-NEXT: }48// CPP-DECLTOP-NEXT: return;49 50 51func.func @test_if_yield(%arg0: i1, %arg1: f32) {52  %0 = "emitc.constant"() <{value = 0 : i8}> : () -> i853  %x = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.lvalue<i32>54  %y = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.lvalue<f64>55  emitc.if %arg0 {56    %1 = emitc.call_opaque "func_true_1"(%arg1) : (f32) -> i3257    %2 = emitc.call_opaque "func_true_2"(%arg1) : (f32) -> f6458    emitc.assign %1 : i32 to %x : !emitc.lvalue<i32>59    emitc.assign %2 : f64 to %y : !emitc.lvalue<f64>60  } else {61    %1 = emitc.call_opaque "func_false_1"(%arg1) : (f32) -> i3262    %2 = emitc.call_opaque "func_false_2"(%arg1) : (f32) -> f6463    emitc.assign %1 : i32 to %x : !emitc.lvalue<i32>64    emitc.assign %2 : f64 to %y : !emitc.lvalue<f64>65  }66  return67}68// CPP-DEFAULT: void test_if_yield(bool [[V0:[^ ]*]], float [[V1:[^ ]*]]) {69// CPP-DEFAULT-NEXT: int8_t [[V2:[^ ]*]] = 0;70// CPP-DEFAULT-NEXT: int32_t [[V3:[^ ]*]];71// CPP-DEFAULT-NEXT: double [[V4:[^ ]*]];72// CPP-DEFAULT-NEXT: if ([[V0]]) {73// CPP-DEFAULT-NEXT: int32_t [[V5:[^ ]*]] = func_true_1([[V1]]);74// CPP-DEFAULT-NEXT: double [[V6:[^ ]*]] = func_true_2([[V1]]);75// CPP-DEFAULT-NEXT: [[V3]] = [[V5]];76// CPP-DEFAULT-NEXT: [[V4]] = [[V6]];77// CPP-DEFAULT-NEXT: } else {78// CPP-DEFAULT-NEXT: int32_t [[V7:[^ ]*]] = func_false_1([[V1]]);79// CPP-DEFAULT-NEXT: double [[V8:[^ ]*]] = func_false_2([[V1]]);80// CPP-DEFAULT-NEXT: [[V3]] = [[V7]];81// CPP-DEFAULT-NEXT: [[V4]] = [[V8]];82// CPP-DEFAULT-NEXT: }83// CPP-DEFAULT-NEXT: return;84 85// CPP-DECLTOP: void test_if_yield(bool [[V0:[^ ]*]], float [[V1:[^ ]*]]) {86// CPP-DECLTOP-NEXT: int8_t [[V2:[^ ]*]];87// CPP-DECLTOP-NEXT: int32_t [[V3:[^ ]*]];88// CPP-DECLTOP-NEXT: double [[V4:[^ ]*]];89// CPP-DECLTOP-NEXT: int32_t [[V5:[^ ]*]];90// CPP-DECLTOP-NEXT: double [[V6:[^ ]*]];91// CPP-DECLTOP-NEXT: int32_t [[V7:[^ ]*]];92// CPP-DECLTOP-NEXT: double [[V8:[^ ]*]];93// CPP-DECLTOP-NEXT: [[V2]] = 0;94// CPP-DECLTOP-NEXT: ;95// CPP-DECLTOP-NEXT: ;96// CPP-DECLTOP-NEXT: if ([[V0]]) {97// CPP-DECLTOP-NEXT: [[V5]] = func_true_1([[V1]]);98// CPP-DECLTOP-NEXT: [[V6]] = func_true_2([[V1]]);99// CPP-DECLTOP-NEXT: [[V3]] = [[V5]];100// CPP-DECLTOP-NEXT: [[V4]] = [[V6]];101// CPP-DECLTOP-NEXT: } else {102// CPP-DECLTOP-NEXT: [[V7]] = func_false_1([[V1]]);103// CPP-DECLTOP-NEXT: [[V8]] = func_false_2([[V1]]);104// CPP-DECLTOP-NEXT: [[V3]] = [[V7]];105// CPP-DECLTOP-NEXT: [[V4]] = [[V8]];106// CPP-DECLTOP-NEXT: }107// CPP-DECLTOP-NEXT: return;108