From d29c6a34255e635b8ad794d21cdd0a2ed8820b68 Mon Sep 17 00:00:00 2001 From: Pengcheng Wang Date: Thu, 19 Mar 2026 18:38:43 +0800 Subject: [PATCH] [TabelGen] Use ID{n-m} for outer let statements (#187436) I found this occasionally. For outer let statements, if we want to override some bits, we specify the range list in the form of ``. But for inner let statements, we use `{n-m}`. This is inconsistent, and I can't find the reason why it is designed as this. So here we make inner/outer let statements consistent and remove the duplicated parsing functions. There is only one in-tree usage so I think the impact is small. --- llvm/docs/ReleaseNotes.md | 3 +++ llvm/docs/TableGen/ProgRef.rst | 10 +++---- llvm/lib/TableGen/TGParser.cpp | 26 +++---------------- llvm/lib/Target/RISCV/RISCVInstrInfoXRivos.td | 2 +- 4 files changed, 12 insertions(+), 29 deletions(-) diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md index e685660195bc..3e4cc625797b 100644 --- a/llvm/docs/ReleaseNotes.md +++ b/llvm/docs/ReleaseNotes.md @@ -96,6 +96,9 @@ Changes to building LLVM Changes to TableGen ------------------- +* Outer let statements use ``ID{n-m}`` instead of ``ID`` to be consistent + with inner let statements. + Changes to Interprocedural Optimizations ---------------------------------------- diff --git a/llvm/docs/TableGen/ProgRef.rst b/llvm/docs/TableGen/ProgRef.rst index 7c041ec530d0..1f42adaf6b6d 100644 --- a/llvm/docs/TableGen/ProgRef.rst +++ b/llvm/docs/TableGen/ProgRef.rst @@ -340,10 +340,10 @@ to an entity of type ``bits<4>``. .. productionlist:: Value: `SimpleValue` `ValueSuffix`* :| `Value` "#" [`Value`] - ValueSuffix: "{" `RangeList` "}" + ValueSuffix: `RangeList` :| "[" `SliceElements` "]" :| "." `TokIdentifier` - RangeList: `RangePiece` ("," `RangePiece`)* + RangeList: "{" `RangePiece` ("," `RangePiece`)* "}" RangePiece: `TokInteger` :| `TokInteger` "..." `TokInteger` :| `TokInteger` "-" `TokInteger` @@ -686,7 +686,7 @@ arguments. .. productionlist:: Body: ";" | "{" `BodyItem`* "}" BodyItem: `Type` `TokIdentifier` ["=" `Value`] ";" - :| "let" [`LetMode`] `TokIdentifier` ["{" `RangeList` "}"] "=" `Value` ";" + :| "let" [`LetMode`] `TokIdentifier` [`RangeList`] "=" `Value` ";" :| "defvar" `TokIdentifier` "=" `Value` ";" :| `Assert` LetMode: "append" | "prepend" @@ -923,7 +923,7 @@ statements within the scope of the ``let``. Let: "let" `LetList` "in" "{" `Statement`* "}" :| "let" `LetList` "in" `Statement` LetList: `LetItem` ("," `LetItem`)* - LetItem: [`LetMode`] `TokIdentifier` ["<" `RangeList` ">"] "=" `Value` + LetItem: [`LetMode`] `TokIdentifier` [`RangeList`] "=" `Value` The ``let`` statement establishes a scope, which is a sequence of statements in braces or a single statement with no braces. The bindings in the @@ -1321,7 +1321,7 @@ variable over a sequence of values. .. productionlist:: Foreach: "foreach" `ForeachIterator` "in" "{" `Statement`* "}" :| "foreach" `ForeachIterator` "in" `Statement` - ForeachIterator: `TokIdentifier` "=" ("{" `RangeList` "}" | `RangePiece` | `Value`) + ForeachIterator: `TokIdentifier` "=" (`RangeList` | `RangePiece` | `Value`) The body of the ``foreach`` is a series of statements in braces or a single statement with no braces. The statements are re-evaluated once for diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp index 74a9c789c985..f7b17500d804 100644 --- a/llvm/lib/TableGen/TGParser.cpp +++ b/llvm/lib/TableGen/TGParser.cpp @@ -1089,29 +1089,9 @@ void TGParser::ParseRangeList(SmallVectorImpl &Result) { } /// ParseOptionalRangeList - Parse either a range list in <>'s or nothing. -/// OptionalRangeList ::= '<' RangeList '>' +/// OptionalRangeList ::= '{' RangeList '}' /// OptionalRangeList ::= /*empty*/ bool TGParser::ParseOptionalRangeList(SmallVectorImpl &Ranges) { - SMLoc StartLoc = Lex.getLoc(); - if (!consume(tgtok::less)) - return false; - - // Parse the range list. - ParseRangeList(Ranges); - if (Ranges.empty()) - return true; - - if (!consume(tgtok::greater)) { - TokError("expected '>' at end of range list"); - return Error(StartLoc, "to match this '<'"); - } - return false; -} - -/// ParseOptionalBitList - Parse either a bit list in {}'s or nothing. -/// OptionalBitList ::= '{' RangeList '}' -/// OptionalBitList ::= /*empty*/ -bool TGParser::ParseOptionalBitList(SmallVectorImpl &Ranges) { SMLoc StartLoc = Lex.getLoc(); if (!consume(tgtok::l_brace)) return false; @@ -3687,7 +3667,7 @@ LetModeAndName TGParser::ParseLetModeAndName() { /// ParseBodyItem - Parse a single item within the body of a def or class. /// /// BodyItem ::= Declaration ';' -/// BodyItem ::= LET [append|prepend] ID OptionalBitList '=' Value ';' +/// BodyItem ::= LET [append|prepend] ID OptionalRangeList '=' Value ';' /// BodyItem ::= Defvar /// BodyItem ::= Dump /// BodyItem ::= Assert @@ -3721,7 +3701,7 @@ bool TGParser::ParseBodyItem(Record *CurRec) { const StringInit *FieldName = StringInit::get(Records, FieldNameStr); SmallVector BitList; - if (ParseOptionalBitList(BitList)) + if (ParseOptionalRangeList(BitList)) return true; std::reverse(BitList.begin(), BitList.end()); diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoXRivos.td b/llvm/lib/Target/RISCV/RISCVInstrInfoXRivos.td index ddd1c57f08f8..94eccf8dd450 100644 --- a/llvm/lib/Target/RISCV/RISCVInstrInfoXRivos.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoXRivos.td @@ -62,7 +62,7 @@ class CustomRivosXVI funct6, RISCVVFormat opv, dag outs, dag ins, let Predicates = [HasVendorXRivosVizip], DecoderNamespace = "XRivos", Constraints = "@earlyclobber $vd", VS1VS2Constraint = Vrgather, - Inst<6-0> = OPC_CUSTOM_2.Value, ReadsPastVL = 1, + Inst{6-0} = OPC_CUSTOM_2.Value, ReadsPastVL = 1, ElementsDependOn = EltDepsNone in { defm RI_VZIPEVEN_V : VALU_IV_V<"ri.vzipeven", 0b001100>; defm RI_VZIPODD_V : VALU_IV_V<"ri.vzipodd", 0b011100>;