From d6037276af41c8fa2073b953d2ec59e5280ebbe6 Mon Sep 17 00:00:00 2001 From: Stephan Herhut Date: Wed, 10 Apr 2019 02:27:30 -0700 Subject: [PATCH] Add conversion of StandardOps and, or and xor to LLVM dialect. -- PiperOrigin-RevId: 242831203 --- mlir/include/mlir/LLVMIR/LLVMOps.td | 3 +++ .../lib/LLVMIR/Transforms/ConvertToLLVMDialect.cpp | 26 +++++++++++++++------- mlir/test/LLVMIR/convert-to-llvmir.mlir | 12 ++++++++++ mlir/test/Target/llvmir.mlir | 13 +++++++++++ 4 files changed, 46 insertions(+), 8 deletions(-) diff --git a/mlir/include/mlir/LLVMIR/LLVMOps.td b/mlir/include/mlir/LLVMIR/LLVMOps.td index 1e1a1d1..7ab76e8 100644 --- a/mlir/include/mlir/LLVMIR/LLVMOps.td +++ b/mlir/include/mlir/LLVMIR/LLVMOps.td @@ -148,6 +148,9 @@ def LLVM_UDivOp : LLVM_ArithmeticOp<"udiv", "CreateUDiv">; def LLVM_SDivOp : LLVM_ArithmeticOp<"sdiv", "CreateSDiv">; def LLVM_URemOp : LLVM_ArithmeticOp<"urem", "CreateURem">; def LLVM_SRemOp : LLVM_ArithmeticOp<"srem", "CreateSRem">; +def LLVM_AndOp : LLVM_ArithmeticOp<"and", "CreateAnd">; +def LLVM_OrOp : LLVM_ArithmeticOp<"or", "CreateOr">; +def LLVM_XOrOp : LLVM_ArithmeticOp<"xor", "CreateXor">; // Other integer operations. def LLVM_ICmpOp : LLVM_OneResultOp<"icmp", [NoSideEffect]>, diff --git a/mlir/lib/LLVMIR/Transforms/ConvertToLLVMDialect.cpp b/mlir/lib/LLVMIR/Transforms/ConvertToLLVMDialect.cpp index 3593f09..86f03e6 100644 --- a/mlir/lib/LLVMIR/Transforms/ConvertToLLVMDialect.cpp +++ b/mlir/lib/LLVMIR/Transforms/ConvertToLLVMDialect.cpp @@ -489,6 +489,15 @@ struct RemISOpLowering : public OneToOneLLVMOpLowering { struct RemIUOpLowering : public OneToOneLLVMOpLowering { using Super::Super; }; +struct AndOpLowering : public OneToOneLLVMOpLowering { + using Super::Super; +}; +struct OrOpLowering : public OneToOneLLVMOpLowering { + using Super::Super; +}; +struct XOrOpLowering : public OneToOneLLVMOpLowering { + using Super::Super; +}; struct AddFOpLowering : public OneToOneLLVMOpLowering { using Super::Super; }; @@ -1101,14 +1110,15 @@ protected: // FIXME: this should be tablegen'ed return ConversionListBuilder< - AddFOpLowering, AddIOpLowering, AllocOpLowering, BranchOpLowering, - CallIndirectOpLowering, CallOpLowering, CmpIOpLowering, - CondBranchOpLowering, ConstLLVMOpLowering, DeallocOpLowering, - DimOpLowering, DivISOpLowering, DivIUOpLowering, DivFOpLowering, - LoadOpLowering, MemRefCastOpLowering, MulFOpLowering, MulIOpLowering, - RemISOpLowering, RemIUOpLowering, RemFOpLowering, ReturnOpLowering, - SelectOpLowering, StoreOpLowering, SubFOpLowering, - SubIOpLowering>::build(&converterStorage, *llvmDialect); + AddFOpLowering, AddIOpLowering, AndOpLowering, AllocOpLowering, + BranchOpLowering, CallIndirectOpLowering, CallOpLowering, + CmpIOpLowering, CondBranchOpLowering, ConstLLVMOpLowering, + DeallocOpLowering, DimOpLowering, DivISOpLowering, DivIUOpLowering, + DivFOpLowering, LoadOpLowering, MemRefCastOpLowering, MulFOpLowering, + MulIOpLowering, OrOpLowering, RemISOpLowering, RemIUOpLowering, + RemFOpLowering, ReturnOpLowering, SelectOpLowering, StoreOpLowering, + SubFOpLowering, SubIOpLowering, XOrOpLowering>::build(&converterStorage, + *llvmDialect); } // Convert types using the stored LLVM IR module. diff --git a/mlir/test/LLVMIR/convert-to-llvmir.mlir b/mlir/test/LLVMIR/convert-to-llvmir.mlir index 60991b4..d50ba22 100644 --- a/mlir/test/LLVMIR/convert-to-llvmir.mlir +++ b/mlir/test/LLVMIR/convert-to-llvmir.mlir @@ -375,6 +375,12 @@ func @vector_ops(vector<4xf32>, vector<4xi1>, vector<4xi64>) -> vector<4xf32> { %7 = divf %arg0, %0 : vector<4xf32> // CHECK-NEXT: %7 = llvm.frem %arg0, %0 : !llvm<"<4 x float>"> %8 = remf %arg0, %0 : vector<4xf32> +// CHECK-NEXT: %8 = llvm.and %arg2, %arg2 : !llvm<"<4 x i64>"> + %9 = and %arg2, %arg2 : vector<4xi64> +// CHECK-NEXT: %9 = llvm.or %arg2, %arg2 : !llvm<"<4 x i64>"> + %10 = or %arg2, %arg2 : vector<4xi64> +// CHECK-NEXT: %10 = llvm.xor %arg2, %arg2 : !llvm<"<4 x i64>"> + %11 = xor %arg2, %arg2 : vector<4xi64> return %1 : vector<4xf32> } @@ -401,6 +407,12 @@ func @ops(f32, f32, i32, i32) -> (f32, i32) { %9 = divf %arg0, %arg1 : f32 // CHECK-NEXT: %9 = llvm.frem %arg0, %arg1 : !llvm.float %10 = remf %arg0, %arg1 : f32 +// CHECK-NEXT: %10 = llvm.and %arg2, %arg3 : !llvm.i32 + %11 = and %arg2, %arg3 : i32 +// CHECK-NEXT: %11 = llvm.or %arg2, %arg3 : !llvm.i32 + %12 = or %arg2, %arg3 : i32 +// CHECK-NEXT: %12 = llvm.xor %arg2, %arg3 : !llvm.i32 + %13 = xor %arg2, %arg3 : i32 return %0, %4 : f32, i32 } diff --git a/mlir/test/Target/llvmir.mlir b/mlir/test/Target/llvmir.mlir index b3dcda8..15c9ffe 100644 --- a/mlir/test/Target/llvmir.mlir +++ b/mlir/test/Target/llvmir.mlir @@ -711,6 +711,12 @@ func @vector_ops(%arg0: !llvm<"<4 x float>">, %arg1: !llvm<"<4 x i1>">, %arg2: ! %7 = llvm.fdiv %arg0, %0 : !llvm<"<4 x float>"> // CHECK-NEXT: %11 = frem <4 x float> %0, %8 = llvm.frem %arg0, %0 : !llvm<"<4 x float>"> +// CHECK-NEXT: %12 = and <4 x i64> %2, %2 + %9 = llvm.and %arg2, %arg2 : !llvm<"<4 x i64>"> +// CHECK-NEXT: %13 = or <4 x i64> %2, %2 + %10 = llvm.or %arg2, %arg2 : !llvm<"<4 x i64>"> +// CHECK-NEXT: %14 = xor <4 x i64> %2, %2 + %11 = llvm.xor %arg2, %arg2 : !llvm<"<4 x i64>"> // CHECK-NEXT: ret <4 x float> %4 llvm.return %1 : !llvm<"<4 x float>"> } @@ -743,6 +749,13 @@ func @ops(%arg0: !llvm.float, %arg1: !llvm.float, %arg2: !llvm.i32, %arg3: !llvm // CHECK-NEXT: %16 = frem float %0, %1 %12 = llvm.frem %arg0, %arg1 : !llvm.float +// CHECK-NEXT: %17 = and i32 %2, %3 + %13 = llvm.and %arg2, %arg3 : !llvm.i32 +// CHECK-NEXT: %18 = or i32 %2, %3 + %14 = llvm.or %arg2, %arg3 : !llvm.i32 +// CHECK-NEXT: %19 = xor i32 %2, %3 + %15 = llvm.xor %arg2, %arg3 : !llvm.i32 + llvm.return %10 : !llvm<"{ float, i32 }"> } -- 2.7.4