2019-08-09 20:24:47 +08:00
|
|
|
// RUN: mlir-opt %s | mlir-opt | FileCheck %s
|
2019-01-16 02:53:22 +08:00
|
|
|
|
2019-04-06 14:56:49 +08:00
|
|
|
// CHECK-LABEL: func @ops(%arg0: !llvm.i32, %arg1: !llvm.float)
|
|
|
|
func @ops(%arg0 : !llvm.i32, %arg1 : !llvm.float) {
|
2019-10-21 00:44:06 +08:00
|
|
|
// Integer arithmetic binary operations.
|
2019-01-16 02:53:22 +08:00
|
|
|
//
|
2019-04-06 14:56:49 +08:00
|
|
|
// CHECK-NEXT: %0 = llvm.add %arg0, %arg0 : !llvm.i32
|
|
|
|
// CHECK-NEXT: %1 = llvm.sub %arg0, %arg0 : !llvm.i32
|
|
|
|
// CHECK-NEXT: %2 = llvm.mul %arg0, %arg0 : !llvm.i32
|
|
|
|
// CHECK-NEXT: %3 = llvm.udiv %arg0, %arg0 : !llvm.i32
|
|
|
|
// CHECK-NEXT: %4 = llvm.sdiv %arg0, %arg0 : !llvm.i32
|
|
|
|
// CHECK-NEXT: %5 = llvm.urem %arg0, %arg0 : !llvm.i32
|
|
|
|
// CHECK-NEXT: %6 = llvm.srem %arg0, %arg0 : !llvm.i32
|
|
|
|
// CHECK-NEXT: %7 = llvm.icmp "ne" %arg0, %arg0 : !llvm.i32
|
|
|
|
%0 = llvm.add %arg0, %arg0 : !llvm.i32
|
|
|
|
%1 = llvm.sub %arg0, %arg0 : !llvm.i32
|
|
|
|
%2 = llvm.mul %arg0, %arg0 : !llvm.i32
|
|
|
|
%3 = llvm.udiv %arg0, %arg0 : !llvm.i32
|
|
|
|
%4 = llvm.sdiv %arg0, %arg0 : !llvm.i32
|
|
|
|
%5 = llvm.urem %arg0, %arg0 : !llvm.i32
|
|
|
|
%6 = llvm.srem %arg0, %arg0 : !llvm.i32
|
|
|
|
%7 = llvm.icmp "ne" %arg0, %arg0 : !llvm.i32
|
2019-01-16 02:53:22 +08:00
|
|
|
|
2019-03-28 23:24:38 +08:00
|
|
|
// Floating point binary operations.
|
2019-01-16 02:53:22 +08:00
|
|
|
//
|
2019-04-06 14:56:49 +08:00
|
|
|
// CHECK-NEXT: %8 = llvm.fadd %arg1, %arg1 : !llvm.float
|
|
|
|
// CHECK-NEXT: %9 = llvm.fsub %arg1, %arg1 : !llvm.float
|
|
|
|
// CHECK-NEXT: %10 = llvm.fmul %arg1, %arg1 : !llvm.float
|
|
|
|
// CHECK-NEXT: %11 = llvm.fdiv %arg1, %arg1 : !llvm.float
|
|
|
|
// CHECK-NEXT: %12 = llvm.frem %arg1, %arg1 : !llvm.float
|
|
|
|
%8 = llvm.fadd %arg1, %arg1 : !llvm.float
|
|
|
|
%9 = llvm.fsub %arg1, %arg1 : !llvm.float
|
|
|
|
%10 = llvm.fmul %arg1, %arg1 : !llvm.float
|
|
|
|
%11 = llvm.fdiv %arg1, %arg1 : !llvm.float
|
|
|
|
%12 = llvm.frem %arg1, %arg1 : !llvm.float
|
2019-01-16 02:53:22 +08:00
|
|
|
|
2019-03-28 23:24:38 +08:00
|
|
|
// Memory-related operations.
|
2019-01-16 02:53:22 +08:00
|
|
|
//
|
2019-04-06 14:56:49 +08:00
|
|
|
// CHECK-NEXT: %13 = llvm.alloca %arg0 x !llvm.double : (!llvm.i32) -> !llvm<"double*">
|
|
|
|
// CHECK-NEXT: %14 = llvm.getelementptr %13[%arg0, %arg0] : (!llvm<"double*">, !llvm.i32, !llvm.i32) -> !llvm<"double*">
|
2019-04-03 06:33:54 +08:00
|
|
|
// CHECK-NEXT: %15 = llvm.load %14 : !llvm<"double*">
|
|
|
|
// CHECK-NEXT: llvm.store %15, %13 : !llvm<"double*">
|
|
|
|
// CHECK-NEXT: %16 = llvm.bitcast %13 : !llvm<"double*"> to !llvm<"i64*">
|
2019-04-06 14:56:49 +08:00
|
|
|
%13 = llvm.alloca %arg0 x !llvm.double : (!llvm.i32) -> !llvm<"double*">
|
|
|
|
%14 = llvm.getelementptr %13[%arg0, %arg0] : (!llvm<"double*">, !llvm.i32, !llvm.i32) -> !llvm<"double*">
|
2019-04-03 06:33:54 +08:00
|
|
|
%15 = llvm.load %14 : !llvm<"double*">
|
|
|
|
llvm.store %15, %13 : !llvm<"double*">
|
|
|
|
%16 = llvm.bitcast %13 : !llvm<"double*"> to !llvm<"i64*">
|
2019-01-16 02:53:22 +08:00
|
|
|
|
2019-03-28 23:24:38 +08:00
|
|
|
// Function call-related operations.
|
2019-01-16 02:53:22 +08:00
|
|
|
//
|
2019-04-06 14:56:49 +08:00
|
|
|
// CHECK-NEXT: %17 = llvm.call @foo(%arg0) : (!llvm.i32) -> !llvm<"{ i32, double, i32 }">
|
2019-04-03 06:33:54 +08:00
|
|
|
// CHECK-NEXT: %18 = llvm.extractvalue %17[0] : !llvm<"{ i32, double, i32 }">
|
|
|
|
// CHECK-NEXT: %19 = llvm.insertvalue %18, %17[2] : !llvm<"{ i32, double, i32 }">
|
2019-09-04 00:10:24 +08:00
|
|
|
// CHECK-NEXT: %20 = llvm.mlir.constant(@foo) : !llvm<"{ i32, double, i32 } (i32)*">
|
2019-04-06 14:56:49 +08:00
|
|
|
// CHECK-NEXT: %21 = llvm.call %20(%arg0) : (!llvm.i32) -> !llvm<"{ i32, double, i32 }">
|
|
|
|
%17 = llvm.call @foo(%arg0) : (!llvm.i32) -> !llvm<"{ i32, double, i32 }">
|
2019-04-03 06:33:54 +08:00
|
|
|
%18 = llvm.extractvalue %17[0] : !llvm<"{ i32, double, i32 }">
|
|
|
|
%19 = llvm.insertvalue %18, %17[2] : !llvm<"{ i32, double, i32 }">
|
2019-09-04 00:10:24 +08:00
|
|
|
%20 = llvm.mlir.constant(@foo) : !llvm<"{ i32, double, i32 } (i32)*">
|
2019-04-06 14:56:49 +08:00
|
|
|
%21 = llvm.call %20(%arg0) : (!llvm.i32) -> !llvm<"{ i32, double, i32 }">
|
2019-04-03 06:33:54 +08:00
|
|
|
|
2019-01-16 02:53:22 +08:00
|
|
|
|
2019-03-28 23:24:38 +08:00
|
|
|
// Terminator operations and their successors.
|
2019-01-16 02:53:22 +08:00
|
|
|
//
|
2019-04-03 06:33:54 +08:00
|
|
|
// CHECK: llvm.br ^bb1
|
|
|
|
llvm.br ^bb1
|
2019-01-16 02:53:22 +08:00
|
|
|
|
|
|
|
^bb1:
|
2019-04-03 06:33:54 +08:00
|
|
|
// CHECK: llvm.cond_br %7, ^bb2, ^bb1
|
|
|
|
llvm.cond_br %7, ^bb2, ^bb1
|
2019-01-16 02:53:22 +08:00
|
|
|
|
|
|
|
^bb2:
|
2019-09-04 00:10:24 +08:00
|
|
|
// CHECK: %22 = llvm.mlir.undef : !llvm<"{ i32, double, i32 }">
|
|
|
|
// CHECK-NEXT: %23 = llvm.mlir.constant(42 : i64) : !llvm.i47
|
|
|
|
%22 = llvm.mlir.undef : !llvm<"{ i32, double, i32 }">
|
|
|
|
%23 = llvm.mlir.constant(42) : !llvm.i47
|
2019-02-13 01:31:20 +08:00
|
|
|
|
2019-03-28 23:24:38 +08:00
|
|
|
// Misc operations.
|
2019-04-06 14:56:49 +08:00
|
|
|
// CHECK: %24 = llvm.select %7, %0, %1 : !llvm.i1, !llvm.i32
|
|
|
|
%24 = llvm.select %7, %0, %1 : !llvm.i1, !llvm.i32
|
2019-05-23 17:03:14 +08:00
|
|
|
|
|
|
|
// Integer to pointer and pointer to integer conversions.
|
|
|
|
//
|
|
|
|
// CHECK: %25 = llvm.inttoptr %arg0 : !llvm.i32 to !llvm<"i32*">
|
|
|
|
// CHECK-NEXT: %26 = llvm.ptrtoint %25 : !llvm<"i32*"> to !llvm.i32
|
|
|
|
%25 = llvm.inttoptr %arg0 : !llvm.i32 to !llvm<"i32*">
|
|
|
|
%26 = llvm.ptrtoint %25 : !llvm<"i32*"> to !llvm.i32
|
|
|
|
|
2019-10-12 09:35:02 +08:00
|
|
|
// Extended and Quad floating point
|
|
|
|
//
|
2019-10-18 03:23:47 +08:00
|
|
|
// CHECK: %27 = llvm.fpext %arg1 : !llvm.float to !llvm.x86_fp80
|
2019-10-12 09:35:02 +08:00
|
|
|
// CHECK-NEXT: %28 = llvm.fpext %arg1 : !llvm.float to !llvm.fp128
|
2019-10-18 03:23:47 +08:00
|
|
|
%27 = llvm.fpext %arg1 : !llvm.float to !llvm.x86_fp80
|
2019-10-12 09:35:02 +08:00
|
|
|
%28 = llvm.fpext %arg1 : !llvm.float to !llvm.fp128
|
|
|
|
|
2019-11-06 15:39:25 +08:00
|
|
|
// CHECK: %29 = llvm.fneg %arg1 : !llvm.float
|
|
|
|
%29 = llvm.fneg %arg1 : !llvm.float
|
|
|
|
|
2019-05-23 17:03:14 +08:00
|
|
|
// CHECK: llvm.return
|
2019-04-03 06:33:54 +08:00
|
|
|
llvm.return
|
2019-01-16 02:53:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// An larger self-contained function.
|
2019-04-06 14:56:49 +08:00
|
|
|
// CHECK-LABEL:func @foo(%arg0: !llvm.i32) -> !llvm<"{ i32, double, i32 }"> {
|
|
|
|
func @foo(%arg0: !llvm.i32) -> !llvm<"{ i32, double, i32 }"> {
|
2019-09-04 00:10:24 +08:00
|
|
|
// CHECK-NEXT: %0 = llvm.mlir.constant(3 : i64) : !llvm.i32
|
|
|
|
// CHECK-NEXT: %1 = llvm.mlir.constant(3 : i64) : !llvm.i32
|
|
|
|
// CHECK-NEXT: %2 = llvm.mlir.constant(4.200000e+01 : f64) : !llvm.double
|
|
|
|
// CHECK-NEXT: %3 = llvm.mlir.constant(4.200000e+01 : f64) : !llvm.double
|
2019-04-06 14:56:49 +08:00
|
|
|
// CHECK-NEXT: %4 = llvm.add %0, %1 : !llvm.i32
|
|
|
|
// CHECK-NEXT: %5 = llvm.mul %4, %1 : !llvm.i32
|
|
|
|
// CHECK-NEXT: %6 = llvm.fadd %2, %3 : !llvm.double
|
|
|
|
// CHECK-NEXT: %7 = llvm.fsub %3, %6 : !llvm.double
|
2019-09-04 00:10:24 +08:00
|
|
|
// CHECK-NEXT: %8 = llvm.mlir.constant(1 : i64) : !llvm.i1
|
2019-04-06 14:56:49 +08:00
|
|
|
// CHECK-NEXT: llvm.cond_br %8, ^bb1(%4 : !llvm.i32), ^bb2(%4 : !llvm.i32)
|
2019-09-04 00:10:24 +08:00
|
|
|
%0 = llvm.mlir.constant(3) : !llvm.i32
|
|
|
|
%1 = llvm.mlir.constant(3) : !llvm.i32
|
|
|
|
%2 = llvm.mlir.constant(4.200000e+01) : !llvm.double
|
|
|
|
%3 = llvm.mlir.constant(4.200000e+01) : !llvm.double
|
2019-04-06 14:56:49 +08:00
|
|
|
%4 = llvm.add %0, %1 : !llvm.i32
|
|
|
|
%5 = llvm.mul %4, %1 : !llvm.i32
|
|
|
|
%6 = llvm.fadd %2, %3 : !llvm.double
|
|
|
|
%7 = llvm.fsub %3, %6 : !llvm.double
|
2019-09-04 00:10:24 +08:00
|
|
|
%8 = llvm.mlir.constant(1) : !llvm.i1
|
2019-04-06 14:56:49 +08:00
|
|
|
llvm.cond_br %8, ^bb1(%4 : !llvm.i32), ^bb2(%4 : !llvm.i32)
|
2019-04-03 06:33:54 +08:00
|
|
|
|
2019-04-06 14:56:49 +08:00
|
|
|
// CHECK-NEXT:^bb1(%9: !llvm.i32):
|
|
|
|
// CHECK-NEXT: %10 = llvm.call @foo(%9) : (!llvm.i32) -> !llvm<"{ i32, double, i32 }">
|
2019-04-03 06:33:54 +08:00
|
|
|
// CHECK-NEXT: %11 = llvm.extractvalue %10[0] : !llvm<"{ i32, double, i32 }">
|
|
|
|
// CHECK-NEXT: %12 = llvm.extractvalue %10[1] : !llvm<"{ i32, double, i32 }">
|
|
|
|
// CHECK-NEXT: %13 = llvm.extractvalue %10[2] : !llvm<"{ i32, double, i32 }">
|
2019-09-04 00:10:24 +08:00
|
|
|
// CHECK-NEXT: %14 = llvm.mlir.undef : !llvm<"{ i32, double, i32 }">
|
2019-04-03 06:33:54 +08:00
|
|
|
// CHECK-NEXT: %15 = llvm.insertvalue %5, %14[0] : !llvm<"{ i32, double, i32 }">
|
|
|
|
// CHECK-NEXT: %16 = llvm.insertvalue %7, %15[1] : !llvm<"{ i32, double, i32 }">
|
|
|
|
// CHECK-NEXT: %17 = llvm.insertvalue %11, %16[2] : !llvm<"{ i32, double, i32 }">
|
|
|
|
// CHECK-NEXT: llvm.return %17 : !llvm<"{ i32, double, i32 }">
|
2019-04-06 14:56:49 +08:00
|
|
|
^bb1(%9: !llvm.i32):
|
|
|
|
%10 = llvm.call @foo(%9) : (!llvm.i32) -> !llvm<"{ i32, double, i32 }">
|
2019-04-03 06:33:54 +08:00
|
|
|
%11 = llvm.extractvalue %10[0] : !llvm<"{ i32, double, i32 }">
|
|
|
|
%12 = llvm.extractvalue %10[1] : !llvm<"{ i32, double, i32 }">
|
|
|
|
%13 = llvm.extractvalue %10[2] : !llvm<"{ i32, double, i32 }">
|
2019-09-04 00:10:24 +08:00
|
|
|
%14 = llvm.mlir.undef : !llvm<"{ i32, double, i32 }">
|
2019-04-03 06:33:54 +08:00
|
|
|
%15 = llvm.insertvalue %5, %14[0] : !llvm<"{ i32, double, i32 }">
|
|
|
|
%16 = llvm.insertvalue %7, %15[1] : !llvm<"{ i32, double, i32 }">
|
|
|
|
%17 = llvm.insertvalue %11, %16[2] : !llvm<"{ i32, double, i32 }">
|
|
|
|
llvm.return %17 : !llvm<"{ i32, double, i32 }">
|
|
|
|
|
2019-04-06 14:56:49 +08:00
|
|
|
// CHECK-NEXT:^bb2(%18: !llvm.i32): // pred: ^bb0
|
2019-09-04 00:10:24 +08:00
|
|
|
// CHECK-NEXT: %19 = llvm.mlir.undef : !llvm<"{ i32, double, i32 }">
|
2019-04-03 06:33:54 +08:00
|
|
|
// CHECK-NEXT: %20 = llvm.insertvalue %18, %19[0] : !llvm<"{ i32, double, i32 }">
|
|
|
|
// CHECK-NEXT: %21 = llvm.insertvalue %7, %20[1] : !llvm<"{ i32, double, i32 }">
|
|
|
|
// CHECK-NEXT: %22 = llvm.insertvalue %5, %21[2] : !llvm<"{ i32, double, i32 }">
|
|
|
|
// CHECK-NEXT: llvm.return %22 : !llvm<"{ i32, double, i32 }">
|
2019-04-06 14:56:49 +08:00
|
|
|
^bb2(%18: !llvm.i32): // pred: ^bb0
|
2019-09-04 00:10:24 +08:00
|
|
|
%19 = llvm.mlir.undef : !llvm<"{ i32, double, i32 }">
|
2019-04-03 06:33:54 +08:00
|
|
|
%20 = llvm.insertvalue %18, %19[0] : !llvm<"{ i32, double, i32 }">
|
|
|
|
%21 = llvm.insertvalue %7, %20[1] : !llvm<"{ i32, double, i32 }">
|
|
|
|
%22 = llvm.insertvalue %5, %21[2] : !llvm<"{ i32, double, i32 }">
|
|
|
|
llvm.return %22 : !llvm<"{ i32, double, i32 }">
|
2019-01-16 02:53:22 +08:00
|
|
|
}
|
2019-06-18 02:35:05 +08:00
|
|
|
|
|
|
|
// CHECK-LABEL: @casts
|
|
|
|
func @casts(%arg0: !llvm.i32, %arg1: !llvm.i64, %arg2: !llvm<"<4 x i32>">,
|
2019-11-01 22:31:33 +08:00
|
|
|
%arg3: !llvm<"<4 x i64>">, %arg4: !llvm<"i32*">) {
|
2019-06-18 02:35:05 +08:00
|
|
|
// CHECK-NEXT: = llvm.sext %arg0 : !llvm.i32 to !llvm.i56
|
|
|
|
%0 = llvm.sext %arg0 : !llvm.i32 to !llvm.i56
|
|
|
|
// CHECK-NEXT: = llvm.zext %arg0 : !llvm.i32 to !llvm.i64
|
|
|
|
%1 = llvm.zext %arg0 : !llvm.i32 to !llvm.i64
|
|
|
|
// CHECK-NEXT: = llvm.trunc %arg1 : !llvm.i64 to !llvm.i56
|
|
|
|
%2 = llvm.trunc %arg1 : !llvm.i64 to !llvm.i56
|
|
|
|
// CHECK-NEXT: = llvm.sext %arg2 : !llvm<"<4 x i32>"> to !llvm<"<4 x i56>">
|
|
|
|
%3 = llvm.sext %arg2 : !llvm<"<4 x i32>"> to !llvm<"<4 x i56>">
|
|
|
|
// CHECK-NEXT: = llvm.zext %arg2 : !llvm<"<4 x i32>"> to !llvm<"<4 x i64>">
|
|
|
|
%4 = llvm.zext %arg2 : !llvm<"<4 x i32>"> to !llvm<"<4 x i64>">
|
|
|
|
// CHECK-NEXT: = llvm.trunc %arg3 : !llvm<"<4 x i64>"> to !llvm<"<4 x i56>">
|
|
|
|
%5 = llvm.trunc %arg3 : !llvm<"<4 x i64>"> to !llvm<"<4 x i56>">
|
2019-11-01 22:31:33 +08:00
|
|
|
// CHECK-NEXT: = llvm.sitofp %arg0 : !llvm.i32 to !llvm.float
|
|
|
|
%6 = llvm.sitofp %arg0 : !llvm.i32 to !llvm.float
|
|
|
|
// CHECK-NEXT: = llvm.uitofp %arg0 : !llvm.i32 to !llvm.float
|
|
|
|
%7 = llvm.uitofp %arg0 : !llvm.i32 to !llvm.float
|
|
|
|
// CHECK-NEXT: = llvm.fptosi %7 : !llvm.float to !llvm.i32
|
|
|
|
%8 = llvm.fptosi %7 : !llvm.float to !llvm.i32
|
|
|
|
// CHECK-NEXT: = llvm.fptoui %7 : !llvm.float to !llvm.i32
|
|
|
|
%9 = llvm.fptoui %7 : !llvm.float to !llvm.i32
|
|
|
|
// CHECK-NEXT: = llvm.addrspacecast %arg4 : !llvm<"i32*"> to !llvm<"i32 addrspace(2)*">
|
|
|
|
%10 = llvm.addrspacecast %arg4 : !llvm<"i32*"> to !llvm<"i32 addrspace(2)*">
|
2019-06-18 02:35:05 +08:00
|
|
|
llvm.return
|
|
|
|
}
|
2019-08-09 20:24:47 +08:00
|
|
|
|
|
|
|
// CHECK-LABEL: @vect
|
|
|
|
func @vect(%arg0: !llvm<"<4 x float>">, %arg1: !llvm.i32, %arg2: !llvm.float) {
|
|
|
|
// CHECK-NEXT: = llvm.extractelement {{.*}} : !llvm<"<4 x float>">
|
2019-11-26 06:44:20 +08:00
|
|
|
%0 = llvm.extractelement %arg0[%arg1 : !llvm.i32] : !llvm<"<4 x float>">
|
2019-08-09 20:24:47 +08:00
|
|
|
// CHECK-NEXT: = llvm.insertelement {{.*}} : !llvm<"<4 x float>">
|
2019-11-26 06:44:20 +08:00
|
|
|
%1 = llvm.insertelement %arg2, %arg0[%arg1 : !llvm.i32] : !llvm<"<4 x float>">
|
2019-08-09 20:24:47 +08:00
|
|
|
// CHECK-NEXT: = llvm.shufflevector {{.*}} [0 : i32, 0 : i32, 0 : i32, 0 : i32, 7 : i32] : !llvm<"<4 x float>">, !llvm<"<4 x float>">
|
|
|
|
%2 = llvm.shufflevector %arg0, %arg0 [0 : i32, 0 : i32, 0 : i32, 0 : i32, 7 : i32] : !llvm<"<4 x float>">, !llvm<"<4 x float>">
|
2019-09-04 18:01:17 +08:00
|
|
|
// CHECK-NEXT: = llvm.mlir.constant(dense<1.000000e+00> : vector<4xf32>) : !llvm<"<4 x float>">
|
|
|
|
%3 = llvm.mlir.constant(dense<1.0> : vector<4xf32>) : !llvm<"<4 x float>">
|
2019-08-09 20:24:47 +08:00
|
|
|
return
|
|
|
|
}
|
2019-08-19 09:54:50 +08:00
|
|
|
|
|
|
|
// CHECK-LABEL: @alloca
|
|
|
|
func @alloca(%size : !llvm.i64) {
|
|
|
|
// CHECK: llvm.alloca %{{.*}} x !llvm.i32 : (!llvm.i64) -> !llvm<"i32*">
|
|
|
|
llvm.alloca %size x !llvm.i32 {alignment = 0} : (!llvm.i64) -> (!llvm<"i32*">)
|
|
|
|
// CHECK-NEXT: llvm.alloca %{{.*}} x !llvm.i32 {alignment = 8 : i64} : (!llvm.i64) -> !llvm<"i32*">
|
|
|
|
llvm.alloca %size x !llvm.i32 {alignment = 8} : (!llvm.i64) -> (!llvm<"i32*">)
|
|
|
|
llvm.return
|
|
|
|
}
|
2019-10-11 21:13:25 +08:00
|
|
|
|
|
|
|
// CHECK-LABEL: @null
|
|
|
|
func @null() {
|
|
|
|
// CHECK: llvm.mlir.null : !llvm<"i8*">
|
|
|
|
%0 = llvm.mlir.null : !llvm<"i8*">
|
|
|
|
// CHECK: llvm.mlir.null : !llvm<"{ void (i32, void ()*)*, i64 }*">
|
|
|
|
%1 = llvm.mlir.null : !llvm<"{void(i32, void()*)*, i64}*">
|
|
|
|
llvm.return
|
|
|
|
}
|
2020-01-18 04:09:53 +08:00
|
|
|
|
[MLIR] LLVM Dialect: add llvm.cmpxchg and improve llvm.atomicrmw custom parser
Summary:
Add a `llvm.cmpxchg` op as a counterpart to LLVM IR's `cmpxchg` instruction.
Note that the `weak`, `volatile`, and `syncscope` attributes are not yet supported.
This will be useful for upcoming parallel versions of affine.for and generally
for reduction-like semantics (especially for reductions that can't make use
of `atomicrmw`, e.g. `fmax`).
Reviewers: ftynse, nicolasvasilache
Reviewed By: ftynse
Subscribers: merge_guards_bot, jfb, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, liufengdb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D72995
2020-01-21 16:22:01 +08:00
|
|
|
// CHECK-LABEL: @atomicrmw
|
|
|
|
func @atomicrmw(%ptr : !llvm<"float*">, %val : !llvm.float) {
|
|
|
|
// CHECK: llvm.atomicrmw fadd %{{.*}}, %{{.*}} unordered : !llvm.float
|
|
|
|
%0 = llvm.atomicrmw fadd %ptr, %val unordered : !llvm.float
|
|
|
|
llvm.return
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: @cmpxchg
|
|
|
|
func @cmpxchg(%ptr : !llvm<"float*">, %cmp : !llvm.float, %new : !llvm.float) {
|
|
|
|
// CHECK: llvm.cmpxchg %{{.*}}, %{{.*}}, %{{.*}} acq_rel monotonic : !llvm.float
|
|
|
|
%0 = llvm.cmpxchg %ptr, %cmp, %new acq_rel monotonic : !llvm.float
|
2020-01-18 04:09:53 +08:00
|
|
|
llvm.return
|
|
|
|
}
|
2020-01-30 19:50:12 +08:00
|
|
|
|
|
|
|
llvm.mlir.global external constant @_ZTIi() : !llvm<"i8*">
|
|
|
|
llvm.func @bar(!llvm<"i8*">, !llvm<"i8*">, !llvm<"i8*">)
|
|
|
|
llvm.func @__gxx_personality_v0(...) -> !llvm.i32
|
|
|
|
|
|
|
|
// CHECK-LABEL: @invokeLandingpad
|
|
|
|
llvm.func @invokeLandingpad() -> !llvm.i32 {
|
|
|
|
// CHECK-NEXT: %[[a0:[0-9]+]] = llvm.mlir.constant(0 : i32) : !llvm.i32
|
|
|
|
// CHECK-NEXT: %{{[0-9]+}} = llvm.mlir.constant(3 : i32) : !llvm.i32
|
|
|
|
// CHECK-NEXT: %[[a2:[0-9]+]] = llvm.mlir.constant("\01") : !llvm<"[1 x i8]">
|
|
|
|
// CHECK-NEXT: %[[a3:[0-9]+]] = llvm.mlir.null : !llvm<"i8**">
|
|
|
|
// CHECK-NEXT: %[[a4:[0-9]+]] = llvm.mlir.null : !llvm<"i8*">
|
|
|
|
// CHECK-NEXT: %[[a5:[0-9]+]] = llvm.mlir.addressof @_ZTIi : !llvm<"i8**">
|
|
|
|
// CHECK-NEXT: %[[a6:[0-9]+]] = llvm.bitcast %[[a5]] : !llvm<"i8**"> to !llvm<"i8*">
|
|
|
|
// CHECK-NEXT: %[[a7:[0-9]+]] = llvm.mlir.constant(1 : i32) : !llvm.i32
|
|
|
|
// CHECK-NEXT: %[[a8:[0-9]+]] = llvm.alloca %[[a7]] x !llvm.i8 : (!llvm.i32) -> !llvm<"i8*">
|
|
|
|
// CHECK-NEXT: %{{[0-9]+}} = llvm.invoke @foo(%[[a7]]) to ^bb2 unwind ^bb1 : (!llvm.i32) -> !llvm<"{ i32, double, i32 }">
|
|
|
|
%0 = llvm.mlir.constant(0 : i32) : !llvm.i32
|
|
|
|
%1 = llvm.mlir.constant(3 : i32) : !llvm.i32
|
|
|
|
%2 = llvm.mlir.constant("\01") : !llvm<"[1 x i8]">
|
|
|
|
%3 = llvm.mlir.null : !llvm<"i8**">
|
|
|
|
%4 = llvm.mlir.null : !llvm<"i8*">
|
|
|
|
%5 = llvm.mlir.addressof @_ZTIi : !llvm<"i8**">
|
|
|
|
%6 = llvm.bitcast %5 : !llvm<"i8**"> to !llvm<"i8*">
|
|
|
|
%7 = llvm.mlir.constant(1 : i32) : !llvm.i32
|
|
|
|
%8 = llvm.alloca %7 x !llvm.i8 : (!llvm.i32) -> !llvm<"i8*">
|
|
|
|
%9 = llvm.invoke @foo(%7) to ^bb2 unwind ^bb1 : (!llvm.i32) -> !llvm<"{ i32, double, i32 }">
|
|
|
|
|
|
|
|
// CHECK-NEXT: ^bb1:
|
|
|
|
// CHECK-NEXT: %{{[0-9]+}} = llvm.landingpad cleanup (catch %[[a3]] : !llvm<"i8**">) (catch %[[a6]] : !llvm<"i8*">) (filter %[[a2]] : !llvm<"[1 x i8]">) : !llvm<"{ i8*, i32 }">
|
|
|
|
// CHECK-NEXT: llvm.br ^bb3
|
|
|
|
^bb1:
|
|
|
|
%10 = llvm.landingpad cleanup (catch %3 : !llvm<"i8**">) (catch %6 : !llvm<"i8*">) (filter %2 : !llvm<"[1 x i8]">) : !llvm<"{ i8*, i32 }">
|
|
|
|
llvm.br ^bb3
|
|
|
|
|
|
|
|
// CHECK-NEXT: ^bb2:
|
|
|
|
// CHECK-NEXT: llvm.return %[[a7]] : !llvm.i32
|
|
|
|
^bb2:
|
|
|
|
llvm.return %7 : !llvm.i32
|
|
|
|
|
|
|
|
// CHECK-NEXT: ^bb3:
|
|
|
|
// CHECK-NEXT: llvm.invoke @bar(%[[a8]], %[[a6]], %[[a4]]) to ^bb2 unwind ^bb1 : (!llvm<"i8*">, !llvm<"i8*">, !llvm<"i8*">) -> ()
|
|
|
|
^bb3:
|
|
|
|
llvm.invoke @bar(%8, %6, %4) to ^bb2 unwind ^bb1 : (!llvm<"i8*">, !llvm<"i8*">, !llvm<"i8*">) -> ()
|
|
|
|
|
|
|
|
// CHECK-NEXT: ^bb4:
|
|
|
|
// CHECK-NEXT: llvm.return %[[a0]] : !llvm.i32
|
|
|
|
^bb4:
|
|
|
|
llvm.return %0 : !llvm.i32
|
|
|
|
}
|
2020-03-02 17:19:57 +08:00
|
|
|
|
|
|
|
// CHECK-LABEL: @useFreezeOp
|
|
|
|
func @useFreezeOp(%arg0: !llvm.i32) {
|
|
|
|
// CHECK: = llvm.freeze %[[ARG0:.*]] : !llvm.i32
|
|
|
|
%0 = llvm.freeze %arg0 : !llvm.i32
|
|
|
|
// CHECK: %[[x:.*]] = llvm.mlir.undef : !llvm.i8
|
|
|
|
%1 = llvm.mlir.undef : !llvm.i8
|
|
|
|
// CHECK: = llvm.freeze %[[x]] : !llvm.i8
|
|
|
|
%2 = llvm.freeze %1 : !llvm.i8
|
|
|
|
return
|
2020-03-18 00:43:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: @useFenceInst
|
|
|
|
func @useFenceInst() {
|
|
|
|
// CHECK: syncscope("agent") seq_cst
|
|
|
|
llvm.fence syncscope("agent") seq_cst
|
|
|
|
// CHECK: seq_cst
|
|
|
|
llvm.fence syncscope("") seq_cst
|
|
|
|
// CHECK: release
|
|
|
|
llvm.fence release
|
|
|
|
return
|
2020-03-02 17:19:57 +08:00
|
|
|
}
|