Skip to content

Commit 5052832

Browse files
committed
[MLIR][LLVM] Add unsafe-fp-math attribute support
1 parent 33ecef9 commit 5052832

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1428,7 +1428,8 @@ def LLVM_LLVMFuncOp : LLVM_Op<"func", [
14281428
OptionalAttr<LLVM_VScaleRangeAttr>:$vscale_range,
14291429
OptionalAttr<FramePointerKindAttr>:$frame_pointer,
14301430
OptionalAttr<StrAttr>:$target_cpu,
1431-
OptionalAttr<LLVM_TargetFeaturesAttr>:$target_features
1431+
OptionalAttr<LLVM_TargetFeaturesAttr>:$target_features,
1432+
OptionalAttr<BoolAttr>:$unsafe_fp_math
14321433
);
14331434

14341435
let regions = (region AnyRegion:$body);

mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
#include "llvm/ADT/PostOrderIterator.h"
3939
#include "llvm/ADT/SetVector.h"
40+
#include "llvm/ADT/StringExtras.h"
4041
#include "llvm/ADT/TypeSwitch.h"
4142
#include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
4243
#include "llvm/IR/BasicBlock.h"
@@ -1214,6 +1215,9 @@ LogicalResult ModuleTranslation::convertOneFunction(LLVMFuncOp func) {
12141215
getLLVMContext(), attr->getMinRange().getInt(),
12151216
attr->getMaxRange().getInt()));
12161217

1218+
if (auto unsafeFpMath = func.getUnsafeFpMath())
1219+
llvmFunc->addFnAttr("unsafe-fp-math", llvm::toStringRef(*unsafeFpMath));
1220+
12171221
// Add function attribute frame-pointer, if found.
12181222
if (FramePointerKindAttr attr = func.getFramePointerAttr())
12191223
llvmFunc->addFnAttr("frame-pointer",

mlir/test/Dialect/LLVMIR/func.mlir

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,12 @@ module {
257257
llvm.func @frame_pointer_roundtrip() attributes {frame_pointer = #llvm.framePointerKind<"non-leaf">} {
258258
llvm.return
259259
}
260+
261+
llvm.func @unsafe_fp_math_roundtrip() attributes {unsafe_fp_math = true} {
262+
// CHECK: @unsafe_fp_math_roundtrip
263+
// CHECK-SAME: attributes {unsafe_fp_math = true}
264+
llvm.return
265+
}
260266
}
261267

262268
// -----

0 commit comments

Comments
 (0)