[clang] [CIR][NFC] Upstream support for FP environments and RAII options (PR #179121)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 17 09:54:50 PST 2026


================
@@ -106,6 +111,57 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
     return baseName + "." + std::to_string(recordNames[baseName]++);
   }
 
+  //
+  // Floating point specific helpers
+  // -------------------------------
+  //
+
+  /// Enable/Disable use of constrained floating point math. When enabled the
+  /// CreateF<op>() calls instead create constrained floating point intrinsic
+  /// calls. Fast math flags are unaffected by this setting.
+  void setIsFPConstrained(bool IsCon) {
+    if (IsCon)
+      llvm_unreachable("Constrained FP NYI");
+    isFPConstrained = IsCon;
+  }
+
+  /// Query for the use of constrained floating point math
+  bool getIsFPConstrained() {
+    if (isFPConstrained)
+      llvm_unreachable("Constrained FP NYI");
+    return isFPConstrained;
+  }
+
+  /// Set the exception handling to be used with constrained floating point
+  void setDefaultConstrainedExcept(cir::fp::ExceptionBehavior NewExcept) {
+#ifndef NDEBUG
+    std::optional<llvm::StringRef> ExceptStr =
+        cir::convertExceptionBehaviorToStr(NewExcept);
+    assert(ExceptStr && "Garbage strict exception behavior!");
+#endif
+    defaultConstrainedExcept = NewExcept;
+  }
+
+  /// Set the rounding mode handling to be used with constrained floating point
+  void setDefaultConstrainedRounding(llvm::RoundingMode NewRounding) {
+#ifndef NDEBUG
+    std::optional<llvm::StringRef> RoundingStr =
+        cir::convertRoundingModeToStr(NewRounding);
+    assert(RoundingStr && "Garbage strict rounding mode!");
+#endif
+    defaultConstrainedRounding = NewRounding;
+  }
+
+  /// Get the exception handling used with constrained floating point
+  cir::fp::ExceptionBehavior getDefaultConstrainedExcept() {
+    return defaultConstrainedExcept;
+  }
+
+  /// Get the rounding mode handling used with constrained floating point
+  llvm::RoundingMode getDefaultConstrainedRounding() {
----------------
andykaylor wrote:

Classic codegen is not as const-correct as we would like it to be. We shouldn't limit ourselves to following that example. These can be const, so they should be.

https://github.com/llvm/llvm-project/pull/179121


More information about the cfe-commits mailing list