Skip to content

Commit 68f71aa

Browse files
authored
[mlir][llvmir] add llvm.sincos intrinsics (#133311)
https://llvm.org/docs/LangRef.html#llvm-frexp-intrinsic Signed-off-by: Letu Ren <[email protected]>
1 parent e3f1c46 commit 68f71aa

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,15 @@ def LLVM_CopySignOp : LLVM_BinarySameArgsIntrOpF<"copysign">;
121121
def LLVM_ExpOp : LLVM_UnaryIntrOpF<"exp">;
122122
def LLVM_Exp2Op : LLVM_UnaryIntrOpF<"exp2">;
123123
def LLVM_Exp10Op : LLVM_UnaryIntrOpF<"exp10">;
124-
def LLVM_LoadExpOp: LLVM_PowFI<"ldexp">;
124+
def LLVM_LoadExpOp : LLVM_PowFI<"ldexp">;
125+
def LLVM_FractionExpOp : LLVM_TwoResultIntrOp<"frexp", [0, 1], [],
126+
[Pure], /*requiresFastmath=*/1> {
127+
let arguments =
128+
(ins LLVM_ScalarOrVectorOf<LLVM_AnyFloat>:$val,
129+
DefaultValuedAttr<LLVM_FastmathFlagsAttr, "{}">:$fastmathFlags);
130+
let assemblyFormat = "`(` operands `)` attr-dict `:` "
131+
"functional-type(operands, results)";
132+
}
125133
def LLVM_FAbsOp : LLVM_UnaryIntrOpF<"fabs">;
126134
def LLVM_FCeilOp : LLVM_UnaryIntrOpF<"ceil">;
127135
def LLVM_FFloorOp : LLVM_UnaryIntrOpF<"floor">;

mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,23 @@ class LLVM_OneResultIntrOp<string mnem, list<int> overloadedResults = [],
448448
requiresFastmath, /*requiresOpBundles=*/0, immArgPositions,
449449
immArgAttrNames>;
450450

451+
// Base class for LLVM intrinsic operations returning two results. Places the
452+
// intrinsic into the LLVM dialect and prefixes its name with "intr.". This is
453+
// similar to LLVM_ZeroResultIntrOp but allows one to define Ops returning two
454+
// results. Additionally, the overloadedResults list should contain "0", "1"
455+
// if the result must be used to resolve overloaded intrinsics, or remain
456+
// empty otherwise.
457+
class LLVM_TwoResultIntrOp<string mnem, list<int> overloadedResults = [],
458+
list<int> overloadedOperands = [],
459+
list<Trait> traits = [],
460+
bit requiresFastmath = 0,
461+
list<int> immArgPositions = [],
462+
list<string> immArgAttrNames = []>
463+
: LLVM_IntrOp<mnem, overloadedResults, overloadedOperands, traits, 2,
464+
/*requiresAccessGroup=*/0, /*requiresAliasAnalysis=*/0,
465+
requiresFastmath, /*requiresOpBundles=*/0, immArgPositions,
466+
immArgAttrNames>;
467+
451468
def LLVM_OneResultOpBuilder :
452469
OpBuilder<(ins "Type":$resultType, "ValueRange":$operands,
453470
CArg<"ArrayRef<NamedAttribute>", "{}">:$attributes),

mlir/test/Target/LLVMIR/Import/intrinsic.ll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ define void @ldexp_test(float %0, <8 x float> %1, i32 %2) {
6060
ret void
6161
}
6262

63+
; CHECK-LABEL: llvm.func @frexp_test
64+
define void @frexp_test(float %0, <8 x float> %1) {
65+
; CHECK: llvm.intr.frexp(%{{.*}}) : (f32) -> !llvm.struct<(f32, i32)>
66+
%4 = call { float, i32 } @llvm.frexp.f32.i32(float %0)
67+
; CHECK: llvm.intr.frexp(%{{.*}}) : (vector<8xf32>) -> !llvm.struct<(vector<8xf32>, i32)>
68+
%5 = call { <8 x float>, i32 } @llvm.frexp.v8f32.i32(<8 x float> %1)
69+
ret void
70+
}
71+
6372
; CHECK-LABEL: llvm.func @log_test
6473
define void @log_test(float %0, <8 x float> %1) {
6574
; CHECK: llvm.intr.log(%{{.*}}) : (f32) -> f32
@@ -1088,6 +1097,8 @@ declare float @llvm.exp10.f32(float)
10881097
declare <8 x float> @llvm.exp10.v8f32(<8 x float>)
10891098
declare float @llvm.ldexp.f32.i32(float, i32)
10901099
declare <8 x float> @llvm.ldexp.v8f32.i32(<8 x float>, i32)
1100+
declare { float, i32 } @llvm.frexp.f32.i32(float)
1101+
declare { <8 x float>, i32 } @llvm.frexp.v8f32.i32(<8 x float>)
10911102
declare float @llvm.log.f32(float)
10921103
declare <8 x float> @llvm.log.v8f32(<8 x float>)
10931104
declare float @llvm.log10.f32(float)

mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ llvm.func @ldexp_test(%arg0: f32, %arg1: vector<8xf32>, %arg2: i32) {
5858
llvm.return
5959
}
6060

61+
// CHECK-LABEL: @frexp_test
62+
llvm.func @frexp_test(%arg0: f32, %arg1: vector<8xf32>) {
63+
// CHECK: call { float, i32 } @llvm.frexp.f32.i32(float %{{.*}})
64+
llvm.intr.frexp(%arg0) : (f32) -> !llvm.struct<(f32, i32)>
65+
// CHECK: call { <8 x float>, i32 } @llvm.frexp.v8f32.i32(<8 x float> %{{.*}})
66+
llvm.intr.frexp(%arg1) : (vector<8xf32>) -> !llvm.struct<(vector<8xf32>, i32)>
67+
llvm.return
68+
}
69+
6170
// CHECK-LABEL: @log_test
6271
llvm.func @log_test(%arg0: f32, %arg1: vector<8xf32>) {
6372
// CHECK: call float @llvm.log.f32
@@ -1195,6 +1204,14 @@ llvm.func @experimental_constrained_fpext(%s: f32, %v: vector<4xf32>) {
11951204
// CHECK-DAG: declare i1 @llvm.is.fpclass.f32(float, i32 immarg)
11961205
// CHECK-DAG: declare float @llvm.exp.f32(float)
11971206
// CHECK-DAG: declare <8 x float> @llvm.exp.v8f32(<8 x float>) #0
1207+
// CHECK-DAG: declare float @llvm.exp2.f32(float)
1208+
// CHECK-DAG: declare <8 x float> @llvm.exp2.v8f32(<8 x float>)
1209+
// CHECK-DAG: declare float @llvm.exp10.f32(float)
1210+
// CHECK-DAG: declare <8 x float> @llvm.exp10.v8f32(<8 x float>)
1211+
// CHECK-DAG: declare float @llvm.ldexp.f32.i32(float, i32)
1212+
// CHECK-DAG: declare <8 x float> @llvm.ldexp.v8f32.i32(<8 x float>, i32)
1213+
// CHECK-DAG: declare { float, i32 } @llvm.frexp.f32.i32(float)
1214+
// CHECK-DAG: declare { <8 x float>, i32 } @llvm.frexp.v8f32.i32(<8 x float>)
11981215
// CHECK-DAG: declare float @llvm.log.f32(float)
11991216
// CHECK-DAG: declare <8 x float> @llvm.log.v8f32(<8 x float>) #0
12001217
// CHECK-DAG: declare float @llvm.log10.f32(float)

0 commit comments

Comments
 (0)