[PATCH] D66078: Added RAII object for authomatic restore of fp state
Serge Pavlov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 14 23:56:26 PDT 2019
sepavloff updated this revision to Diff 215332.
sepavloff added a comment.
Updated patch
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D66078/new/
https://reviews.llvm.org/D66078
Files:
llvm/include/llvm/IR/IRBuilder.h
Index: llvm/include/llvm/IR/IRBuilder.h
===================================================================
--- llvm/include/llvm/IR/IRBuilder.h
+++ llvm/include/llvm/IR/IRBuilder.h
@@ -96,8 +96,14 @@
MDNode *DefaultFPMathTag;
FastMathFlags FMF;
+ /// If set, builder creates constrained floating point operations.
bool IsFPConstrained;
+
+ /// Exception behavior used by default for constrained floating point
+ /// operations.
ConstrainedFPIntrinsic::ExceptionBehavior DefaultConstrainedExcept;
+
+ /// Rounding mode used by default for constrained floating point operations.
ConstrainedFPIntrinsic::RoundingMode DefaultConstrainedRounding;
ArrayRef<OperandBundleDef> DefaultOperandBundles;
@@ -301,6 +307,36 @@
}
};
+ // RAII object that stores constrained floating point settings and
+ // restores them when the object is destroyed.
+ class FloatingPointStateSaver {
+ IRBuilderBase &Builder;
+ bool IsFPConstrainted;
+ ConstrainedFPIntrinsic::ExceptionBehavior DefaultConstrainedExcept;
+ ConstrainedFPIntrinsic::RoundingMode DefaultConstrainedRounding;
+
+ public:
+ FloatingPointStateSaver(IRBuilderBase &Builder)
+ : Builder(Builder),
+ IsFPConstrainted(Builder.getIsFPConstrained()),
+ DefaultConstrainedExcept(Builder.getDefaultConstrainedExcept()),
+ DefaultConstrainedRounding(Builder.getDefaultConstrainedRounding()) {
+ }
+ FloatingPointStateSaver(IRBuilderBase &Builder, bool NewIsFPConstrained,
+ ConstrainedFPIntrinsic::ExceptionBehavior NewDefaultConstrainedExcept,
+ ConstrainedFPIntrinsic::RoundingMode NewDefaultConstrainedRounding)
+ : FloatingPointStateSaver(Builder) {
+ Builder.setIsFPConstrained(NewIsFPConstrained);
+ Builder.setDefaultConstrainedExcept(NewDefaultConstrainedExcept);
+ Builder.setDefaultConstrainedRounding(NewDefaultConstrainedRounding);
+ }
+ ~FloatingPointStateSaver() {
+ Builder.setDefaultConstrainedRounding(DefaultConstrainedRounding);
+ Builder.setDefaultConstrainedExcept(DefaultConstrainedExcept);
+ Builder.setIsFPConstrained(IsFPConstrainted);
+ }
+ };
+
//===--------------------------------------------------------------------===//
// Miscellaneous creation methods.
//===--------------------------------------------------------------------===//
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66078.215332.patch
Type: text/x-patch
Size: 2369 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190815/c9da8447/attachment.bin>
More information about the llvm-commits
mailing list