[PATCH] D70650: [MC] Rewrite tablegen for printInstrAlias to comiple faster, NFC

Reid Kleckner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 25 13:51:42 PST 2019


rnk added a comment.

Here's an example of the generated output for easier code review:
https://reviews.llvm.org/P8172



================
Comment at: llvm/utils/TableGen/AsmWriterEmitter.cpp:678
 
-  void print(raw_ostream &O) {
-    if (Conds.empty()) {
-      O.indent(6) << "return true;\n";
-      return;
-    }
-
-    O << "if (";
-
-    for (std::vector<std::string>::iterator
-           I = Conds.begin(), E = Conds.end(); I != E; ++I) {
-      if (I != Conds.begin()) {
-        O << " &&\n";
-        O.indent(8);
-      }
-
-      O << *I;
-    }
-
-    O << ") {\n";
-    O.indent(6) << "// " << Result << "\n";
-
+  std::string print(uint32_t &UnescapedSize) {
     // Directly mangle mapped operands into the string. Each operand is
----------------
craig.topper wrote:
> Should we rename this since it doesn't print to a stream anymore?
Yeah. I named it formatAliasString.


================
Comment at: llvm/utils/TableGen/AsmWriterEmitter.cpp:819
         NumMIOps += ResultInstOpnd.MINumOperands;
-
-      std::string Cond;
-      Cond = std::string("MI->getNumOperands() == ") + utostr(NumMIOps);
-      IAP.addCond(Cond);
+      IAP.setNumMIOps(NumMIOps);
 
----------------
craig.topper wrote:
> Can we move the IAP object down and pass this to the constructor?
Sure.


================
Comment at: llvm/utils/TableGen/AsmWriterEmitter.cpp:955
+          bool IsNeg = Op[0] == '!';
+          StringRef Feature = StringRef(Op).drop_front(IsNeg ? 1 : 0);
+          IAP.addCond(formatv("AliasPatternCond::K_{0}Feature, {1}::{2}",
----------------
craig.topper wrote:
> Why StringRef(Op)? Isn't Op already a StringRef?
True, it is. This code uses std::string a lot, so I think I assumed I needed to convert first.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70650





More information about the llvm-commits mailing list