[llvm] [IR] Add new Range attribute using new ConstantRange Attribute type (PR #83171)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 6 09:17:25 PST 2024


================
@@ -2997,6 +3000,51 @@ bool LLParser::parseRequiredTypeAttr(AttrBuilder &B, lltok::Kind AttrToken,
   return false;
 }
 
+/// parseRangeAttr
+///   ::= range(<ty> <n>,<n>)
+bool LLParser::parseRangeAttr(AttrBuilder &B) {
+  Lex.Lex();
+
+  APInt Lower;
+  APInt Upper;
+  Type *Ty = nullptr;
+  LocTy TyLoc;
+
+  auto ParseAPSInt = [&](llvm::TypeSize BitWidth, APInt &Val) {
+    if (Lex.getKind() != lltok::APSInt)
+      return tokError("expected integer");
+    if (Lex.getAPSIntVal().getBitWidth() > BitWidth)
+      return tokError("integer is to large for the BitWidth");
+    Val = Lex.getAPSIntVal().extend(BitWidth);
+    Lex.Lex();
+    return false;
+  };
+
+  if (!EatIfPresent(lltok::lparen))
----------------
nikic wrote:

Use `parseToken` instead.

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


More information about the llvm-commits mailing list