From 0f974817b5a1103ce5a17450dca7f09a16a4bd13 Mon Sep 17 00:00:00 2001 From: Alex Zinenko Date: Tue, 20 Aug 2019 06:38:28 -0700 Subject: [PATCH] LLVM dialect: prefix operations that correspond to intrinsics with "intr." LLVM intrinsics have an open name space and their names can potentially overlap with names of LLVM instructions (LLVM intrinsics are functions, not instructions). In MLIR, LLVM intrinsics are modeled as operations, so it needs to make sure their names cannot clash with the instructions. Use the "intr." prefix for intrinsics in the LLVM dialect. PiperOrigin-RevId: 264372173 --- mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | 5 +++-- mlir/include/mlir/Dialect/VectorOps/VectorOps.td | 4 ++-- mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir | 4 ++-- mlir/test/Target/llvmir-intrinsics.mlir | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td index be96d8551747..10533cc72dec 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td @@ -535,9 +535,10 @@ def LLVM_ConstantOp // Operations that correspond to LLVM intrinsics. With MLIR operation set being // extendable, there is no reason to introduce a hard boundary between "core" -// operations and intrinsics. +// operations and intrinsics. However, we systematically prefix them with +// "intr." to avoid potential name clashes. -def LLVM_fmuladd : LLVM_Op<"fmuladd", [NoSideEffect]>, +def LLVM_fmuladd : LLVM_Op<"intr.fmuladd", [NoSideEffect]>, Arguments<(ins LLVM_Type:$a, LLVM_Type:$b, LLVM_Type:$c)>, Results<(outs LLVM_Type:$res)> { let llvmBuilder = [{ diff --git a/mlir/include/mlir/Dialect/VectorOps/VectorOps.td b/mlir/include/mlir/Dialect/VectorOps/VectorOps.td index e6f543ff26ea..ba8c0d1360be 100644 --- a/mlir/include/mlir/Dialect/VectorOps/VectorOps.td +++ b/mlir/include/mlir/Dialect/VectorOps/VectorOps.td @@ -80,8 +80,8 @@ def OuterProductOp : An optional extra 2-D vector argument may be specified in which case the operation returns the sum of the outer product and the extra vector. When - lowered to the LLVMIR dialect, this form emits `llvm.fmuladd`, which can - lower to actual `fma` instructions in LLVM. + lowered to the LLVMIR dialect, this form emits `llvm.intr.fmuladd`, which + can lower to actual `fma` instructions in LLVM. Examples diff --git a/mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir b/mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir index 532a4c2e3692..2d23371bd2f9 100644 --- a/mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir +++ b/mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir @@ -22,11 +22,11 @@ func @outerproduct_add(%arg0: vector<2xf32>, %arg1: vector<3xf32>, %arg2: vector // CHECK: llvm.undef : !llvm<"[2 x <3 x float>]"> // CHECK: llvm.shufflevector {{.*}} [0 : i32, 0 : i32, 0 : i32] : !llvm<"<2 x float>">, !llvm<"<2 x float>"> // CHECK: llvm.extractvalue {{.*}}[0] : !llvm<"[2 x <3 x float>]"> -// CHECK: "llvm.fmuladd"({{.*}}) : (!llvm<"<3 x float>">, !llvm<"<3 x float>">, !llvm<"<3 x float>">) -> !llvm<"<3 x float>"> +// CHECK: "llvm.intr.fmuladd"({{.*}}) : (!llvm<"<3 x float>">, !llvm<"<3 x float>">, !llvm<"<3 x float>">) -> !llvm<"<3 x float>"> // CHECK: llvm.insertvalue {{.*}}[0] : !llvm<"[2 x <3 x float>]"> // CHECK: llvm.shufflevector {{.*}} [1 : i32, 1 : i32, 1 : i32] : !llvm<"<2 x float>">, !llvm<"<2 x float>"> // CHECK: llvm.extractvalue {{.*}}[1] : !llvm<"[2 x <3 x float>]"> -// CHECK: "llvm.fmuladd"({{.*}}) : (!llvm<"<3 x float>">, !llvm<"<3 x float>">, !llvm<"<3 x float>">) -> !llvm<"<3 x float>"> +// CHECK: "llvm.intr.fmuladd"({{.*}}) : (!llvm<"<3 x float>">, !llvm<"<3 x float>">, !llvm<"<3 x float>">) -> !llvm<"<3 x float>"> // CHECK: llvm.insertvalue {{.*}}[1] : !llvm<"[2 x <3 x float>]"> // CHECK: llvm.return {{.*}} : !llvm<"[2 x <3 x float>]"> diff --git a/mlir/test/Target/llvmir-intrinsics.mlir b/mlir/test/Target/llvmir-intrinsics.mlir index 6f1baedd49b9..c804119ce6b8 100644 --- a/mlir/test/Target/llvmir-intrinsics.mlir +++ b/mlir/test/Target/llvmir-intrinsics.mlir @@ -3,9 +3,9 @@ // CHECK-LABEL: @intrinsics func @intrinsics(%arg0: !llvm.float, %arg1: !llvm.float, %arg2: !llvm<"<8 x float>">) { // CHECK: call float @llvm.fmuladd.f32.f32.f32 - "llvm.fmuladd"(%arg0, %arg1, %arg0) : (!llvm.float, !llvm.float, !llvm.float) -> !llvm.float + "llvm.intr.fmuladd"(%arg0, %arg1, %arg0) : (!llvm.float, !llvm.float, !llvm.float) -> !llvm.float // CHECK: call <8 x float> @llvm.fmuladd.v8f32.v8f32.v8f32 - "llvm.fmuladd"(%arg2, %arg2, %arg2) : (!llvm<"<8 x float>">, !llvm<"<8 x float>">, !llvm<"<8 x float>">) -> !llvm<"<8 x float>"> + "llvm.intr.fmuladd"(%arg2, %arg2, %arg2) : (!llvm<"<8 x float>">, !llvm<"<8 x float>">, !llvm<"<8 x float>">) -> !llvm<"<8 x float>"> llvm.return }