[clang] [llvm] [mlir] IR: Promote "denormal-fp-math" to a first class attribute (PR #174293)

Nikita Popov via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 3 08:25:40 PST 2026


================
@@ -2655,6 +2679,85 @@ std::optional<MemoryEffects> LLParser::parseMemoryAttr() {
   return std::nullopt;
 }
 
+std::optional<DenormalMode> LLParser::parseDenormalFPEnvEntry() {
+  std::optional<DenormalMode::DenormalModeKind> OutputMode =
+      keywordToDenormalModeKind(Lex.getKind());
+  if (!OutputMode) {
+    tokError("expected denormal behavior kind (ieee, preservesign, "
+             "positivezero, dynamic)");
+    return {};
+  }
+
+  Lex.Lex();
+
+  std::optional<DenormalMode::DenormalModeKind> InputMode;
+  if (EatIfPresent(lltok::bar)) {
+    InputMode = keywordToDenormalModeKind(Lex.getKind());
+    if (!InputMode) {
+      tokError("expected denormal behavior kind (ieee, preservesign, "
+               "positivezero, dynamic)");
+      return {};
+    }
+
+    Lex.Lex();
+  } else {
+    // Single item, input == output mode
+    InputMode = OutputMode;
+  }
+
+  return DenormalMode(*OutputMode, *InputMode);
+}
+
+std::optional<DenormalFPEnv> LLParser::parseDenormalFPEnvAttr() {
+  // We use syntax like denormal_fpenv(float: preservesign), so the colon should
+  // not be interpreted as a label terminator.
+  Lex.setIgnoreColonInIdentifiers(true);
+  llvm::scope_exit _([&] { Lex.setIgnoreColonInIdentifiers(false); });
+
+  Lex.Lex();
+
+  if (!EatIfPresent(lltok::lparen)) {
+    tokError("expected '('");
----------------
nikic wrote:

Can combine these with parseToken().

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


More information about the cfe-commits mailing list