anemet created this revision. This is toward moving fp-contraction=fast from an LLVM TargetOption to a FastMathFlag in order to fix PR25721.
https://reviews.llvm.org/D31168 Files: lib/CodeGen/CGExprScalar.cpp Index: lib/CodeGen/CGExprScalar.cpp =================================================================== --- lib/CodeGen/CGExprScalar.cpp +++ lib/CodeGen/CGExprScalar.cpp @@ -256,8 +256,22 @@ // Visitor Methods //===--------------------------------------------------------------------===// + /// A RAII to apply the FP features from the expression to the IRBuilder. + struct ApplyFPFeatures : public CGBuilderTy::FastMathFlagGuard { + ApplyFPFeatures(llvm::IRBuilderBase &Builder, Expr *E) + : CGBuilderTy::FastMathFlagGuard(Builder) { + if (const auto *BO = dyn_cast<BinaryOperator>(E)) { + llvm::FastMathFlags FMF = Builder.getFastMathFlags(); + FMF.setAllowContract( + BO->getFPFeatures().allowFPContractAcrossStatement()); + Builder.setFastMathFlags(FMF); + } + } + }; + Value *Visit(Expr *E) { ApplyDebugLocation DL(CGF, E); + ApplyFPFeatures FPF(Builder, E); return StmtVisitor<ScalarExprEmitter, Value*>::Visit(E); }
Index: lib/CodeGen/CGExprScalar.cpp =================================================================== --- lib/CodeGen/CGExprScalar.cpp +++ lib/CodeGen/CGExprScalar.cpp @@ -256,8 +256,22 @@ // Visitor Methods //===--------------------------------------------------------------------===// + /// A RAII to apply the FP features from the expression to the IRBuilder. + struct ApplyFPFeatures : public CGBuilderTy::FastMathFlagGuard { + ApplyFPFeatures(llvm::IRBuilderBase &Builder, Expr *E) + : CGBuilderTy::FastMathFlagGuard(Builder) { + if (const auto *BO = dyn_cast<BinaryOperator>(E)) { + llvm::FastMathFlags FMF = Builder.getFastMathFlags(); + FMF.setAllowContract( + BO->getFPFeatures().allowFPContractAcrossStatement()); + Builder.setFastMathFlags(FMF); + } + } + }; + Value *Visit(Expr *E) { ApplyDebugLocation DL(CGF, E); + ApplyFPFeatures FPF(Builder, E); return StmtVisitor<ScalarExprEmitter, Value*>::Visit(E); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits