[PATCH] D142079: [TableGen] Support custom decoders for variable length instructions

Sheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 19 20:05:12 PST 2023


0x59616e added inline comments.


================
Comment at: llvm/utils/TableGen/DecoderEmitter.cpp:1896
       Operands[OpIdx].addField(CurrBitPos, EncodingSegment.BitWidth, Offset);
+      if (EncodingSegment.CustomDecoder.size())
+        Operands[OpIdx].Decoder = EncodingSegment.CustomDecoder.str();
----------------
nit: Use `!empty` for better readability.


================
Comment at: llvm/utils/TableGen/VarLenCodeEmitterGen.cpp:140-143
+    StringRef CustomEncoder, CustomDecoder;
     if (DI->getNumArgs() >= 3)
-      CustomEncoder = getCustomEncoderName(DI->getArg(2));
-    Segments.push_back(
-        {static_cast<unsigned>(NumBitsVal), OperandName, CustomEncoder});
+      std::tie(CustomEncoder, CustomDecoder) =
+          getCustomCoders(DI->getArgs().slice(2));
----------------
nit: `getCustomCoders` will return empty `StringRef` automatically if `DI->getNumArgs()` == 2. So this if statement is unnecessary.


================
Comment at: llvm/utils/TableGen/VarLenCodeEmitterGen.cpp:172-175
+    StringRef CustomEncoder, CustomDecoder;
     if (DI->getNumArgs() >= 4)
-      CustomEncoder = getCustomEncoderName(DI->getArg(3));
+      std::tie(CustomEncoder, CustomDecoder) =
+          getCustomCoders(DI->getArgs().slice(3));
----------------
ditto


================
Comment at: llvm/utils/TableGen/VarLenCodeEmitterGen.cpp:193-205
+    if (const auto *DI = dyn_cast<DagInit>(Arg)) {
+      const Init *Op = DI->getOperator();
+      // syntax: `(<encoder | decoder> "function name")`
+      if (!isa<DefInit>(Op) || !DI->getNumArgs() ||
+          !isa<StringInit>(DI->getArg(0)))
+        continue;
+      StringRef OpName = cast<DefInit>(Op)->getDef()->getName(),
----------------
Use early exit to reduce indentation for better readability.


================
Comment at: llvm/utils/TableGen/VarLenCodeEmitterGen.cpp:199-200
+        continue;
+      StringRef OpName = cast<DefInit>(Op)->getDef()->getName(),
+                FuncName = cast<StringInit>(DI->getArg(0))->getValue();
+      if (OpName == "encoder")
----------------
nit: Avoid declaring multiple variables in the same statement;


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142079/new/

https://reviews.llvm.org/D142079



More information about the llvm-commits mailing list