[llvm] [RFC][TableGen] Restructure TableGen Source (PR #80847)

via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 6 07:22:19 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-directx

Author: Pierre van Houtryve (Pierre-vh)

<details>
<summary>Changes</summary>

Lately, while trying to move as much code out of the GlobalISel Combiner Backend, I've been hitting more and more linker issues. I've had to revert one of my recent patches because a buildbot just wouldn't let it slide due to weirdness in how the dependencies were declared. It seems like the library structure was due for an overhaul, so I created #<!-- -->80647

I'm proposing this refactor of the llvm-tblgen source into:
- a "Basic" library, which contains the bare minimum utilities to build `llvm-min-tablegen`
- a "Common" library which contains all of the helpers for TableGen backends. Such helpers can be shared by more than one backend, and even unit tested (e.g. CodeExpander is, maybe we can add more over time)

The backends remain in place and just make use of the new include paths.

I did a directory structure that I hope makes sense, but it's completely fine if it's not what we want and it needs to be redone. We can take our time reviewing this to make sure we won't need to re-do the library structure again anytime soon. This is why I'm tagging this as a RFC.

Fixes #<!-- -->80647

---

Patch is 417.68 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/80847.diff


93 Files Affected:

- (modified) llvm/unittests/TableGen/CMakeLists.txt (+1-1) 
- (modified) llvm/unittests/TableGen/CodeExpanderTest.cpp (+2-2) 
- (modified) llvm/utils/TableGen/AsmMatcherEmitter.cpp (+6-6) 
- (modified) llvm/utils/TableGen/AsmWriterEmitter.cpp (+9-9) 
- (removed) llvm/utils/TableGen/AsmWriterInst.h (-107) 
- (added) llvm/utils/TableGen/Basic/CMakeLists.txt (+21) 
- (renamed) llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp () 
- (renamed) llvm/utils/TableGen/Basic/CodeGenIntrinsics.h (+7-9) 
- (renamed) llvm/utils/TableGen/Basic/SDNodeProperties.cpp () 
- (renamed) llvm/utils/TableGen/Basic/SDNodeProperties.h (+1-1) 
- (renamed) llvm/utils/TableGen/Basic/SequenceToOffsetTable.h (+6-6) 
- (modified) llvm/utils/TableGen/CMakeLists.txt (+27-40) 
- (modified) llvm/utils/TableGen/CallingConvEmitter.cpp (+4-4) 
- (modified) llvm/utils/TableGen/CodeEmitterGen.cpp (+8-8) 
- (removed) llvm/utils/TableGen/CodeGenHwModes.h (-67) 
- (removed) llvm/utils/TableGen/CodeGenInstruction.h (-343) 
- (modified) llvm/utils/TableGen/CodeGenMapTable.cpp (+2-2) 
- (removed) llvm/utils/TableGen/CodeGenRegisters.h (-854) 
- (renamed) llvm/utils/TableGen/Common/AsmWriterInst.cpp (+36-33) 
- (added) llvm/utils/TableGen/Common/AsmWriterInst.h (+107) 
- (added) llvm/utils/TableGen/Common/CMakeLists.txt (+48) 
- (renamed) llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp (+280-299) 
- (renamed) llvm/utils/TableGen/Common/CodeGenDAGPatterns.h (+98-115) 
- (renamed) llvm/utils/TableGen/Common/CodeGenHwModes.cpp (+8-8) 
- (added) llvm/utils/TableGen/Common/CodeGenHwModes.h (+67) 
- (renamed) llvm/utils/TableGen/Common/CodeGenInstAlias.cpp () 
- (renamed) llvm/utils/TableGen/Common/CodeGenInstAlias.h () 
- (renamed) llvm/utils/TableGen/Common/CodeGenInstruction.cpp (+72-75) 
- (added) llvm/utils/TableGen/Common/CodeGenInstruction.h (+339) 
- (renamed) llvm/utils/TableGen/Common/CodeGenRegisters.cpp (+148-138) 
- (added) llvm/utils/TableGen/Common/CodeGenRegisters.h (+842) 
- (renamed) llvm/utils/TableGen/Common/CodeGenSchedule.cpp (+166-172) 
- (renamed) llvm/utils/TableGen/Common/CodeGenSchedule.h (+25-24) 
- (renamed) llvm/utils/TableGen/Common/CodeGenTarget.cpp (+30-32) 
- (renamed) llvm/utils/TableGen/Common/CodeGenTarget.h (+22-18) 
- (renamed) llvm/utils/TableGen/Common/DAGISelMatcher.cpp (+35-39) 
- (renamed) llvm/utils/TableGen/Common/DAGISelMatcher.h (+249-269) 
- (renamed) llvm/utils/TableGen/Common/GlobalISel/CXXPredicates.cpp () 
- (renamed) llvm/utils/TableGen/Common/GlobalISel/CXXPredicates.h () 
- (renamed) llvm/utils/TableGen/Common/GlobalISel/CodeExpander.cpp () 
- (renamed) llvm/utils/TableGen/Common/GlobalISel/CodeExpander.h () 
- (renamed) llvm/utils/TableGen/Common/GlobalISel/CodeExpansions.h () 
- (renamed) llvm/utils/TableGen/Common/GlobalISel/CombinerUtils.h () 
- (renamed) llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp (+2-2) 
- (renamed) llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.h (+1-1) 
- (renamed) llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTableExecutorEmitter.cpp () 
- (renamed) llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTableExecutorEmitter.h (+1-1) 
- (renamed) llvm/utils/TableGen/Common/GlobalISel/MatchDataInfo.cpp () 
- (renamed) llvm/utils/TableGen/Common/GlobalISel/MatchDataInfo.h () 
- (renamed) llvm/utils/TableGen/Common/GlobalISel/Patterns.cpp (+2-2) 
- (renamed) llvm/utils/TableGen/Common/GlobalISel/Patterns.h () 
- (renamed) llvm/utils/TableGen/Common/InfoByHwMode.cpp (+30-33) 
- (renamed) llvm/utils/TableGen/Common/InfoByHwMode.h (+17-24) 
- (renamed) llvm/utils/TableGen/Common/OptEmitter.cpp () 
- (renamed) llvm/utils/TableGen/Common/OptEmitter.h () 
- (renamed) llvm/utils/TableGen/Common/PredicateExpander.cpp (+2-2) 
- (renamed) llvm/utils/TableGen/Common/PredicateExpander.h () 
- (renamed) llvm/utils/TableGen/Common/SubtargetFeatureInfo.cpp (+1-1) 
- (renamed) llvm/utils/TableGen/Common/SubtargetFeatureInfo.h (+2-1) 
- (renamed) llvm/utils/TableGen/Common/Types.cpp (+3-1) 
- (renamed) llvm/utils/TableGen/Common/Types.h (+1-1) 
- (renamed) llvm/utils/TableGen/Common/VarLenCodeEmitterGen.cpp () 
- (renamed) llvm/utils/TableGen/Common/VarLenCodeEmitterGen.h () 
- (modified) llvm/utils/TableGen/CompressInstEmitter.cpp (+3-3) 
- (modified) llvm/utils/TableGen/DAGISelEmitter.cpp (+4-4) 
- (modified) llvm/utils/TableGen/DAGISelMatcherEmitter.cpp (+6-6) 
- (modified) llvm/utils/TableGen/DAGISelMatcherGen.cpp (+7-7) 
- (modified) llvm/utils/TableGen/DAGISelMatcherOpt.cpp (+3-3) 
- (modified) llvm/utils/TableGen/DFAEmitter.cpp (+1-1) 
- (modified) llvm/utils/TableGen/DFAPacketizerEmitter.cpp (+2-2) 
- (modified) llvm/utils/TableGen/DXILEmitter.cpp (+1-1) 
- (modified) llvm/utils/TableGen/DecoderEmitter.cpp (+5-5) 
- (modified) llvm/utils/TableGen/DisassemblerEmitter.cpp (+1-1) 
- (modified) llvm/utils/TableGen/FastISelEmitter.cpp (+5-5) 
- (removed) llvm/utils/TableGen/GlobalISel/CMakeLists.txt (-20) 
- (modified) llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp (+12-12) 
- (modified) llvm/utils/TableGen/GlobalISelEmitter.cpp (+9-9) 
- (modified) llvm/utils/TableGen/InstrDocsEmitter.cpp (+3-3) 
- (modified) llvm/utils/TableGen/InstrInfoEmitter.cpp (+8-8) 
- (modified) llvm/utils/TableGen/IntrinsicEmitter.cpp (+2-2) 
- (modified) llvm/utils/TableGen/MacroFusionPredicatorEmitter.cpp (+2-2) 
- (modified) llvm/utils/TableGen/OptParserEmitter.cpp (+1-1) 
- (modified) llvm/utils/TableGen/OptRSTEmitter.cpp (+1-1) 
- (modified) llvm/utils/TableGen/PseudoLoweringEmitter.cpp (+2-2) 
- (modified) llvm/utils/TableGen/RegisterBankEmitter.cpp (+3-3) 
- (modified) llvm/utils/TableGen/RegisterInfoEmitter.cpp (+6-6) 
- (modified) llvm/utils/TableGen/SearchableTableEmitter.cpp (+19-19) 
- (modified) llvm/utils/TableGen/SubtargetEmitter.cpp (+4-4) 
- (modified) llvm/utils/TableGen/WebAssemblyDisassemblerEmitter.cpp (+1-1) 
- (modified) llvm/utils/TableGen/X86CompressEVEXTablesEmitter.cpp (+2-2) 
- (modified) llvm/utils/TableGen/X86FoldTablesEmitter.cpp (+2-2) 
- (modified) llvm/utils/TableGen/X86MnemonicTables.cpp (+2-2) 
- (modified) llvm/utils/TableGen/X86RecognizableInstr.h (+1-1) 


``````````diff
diff --git a/llvm/unittests/TableGen/CMakeLists.txt b/llvm/unittests/TableGen/CMakeLists.txt
index 7830e021804589..fae0eee06e4b0c 100644
--- a/llvm/unittests/TableGen/CMakeLists.txt
+++ b/llvm/unittests/TableGen/CMakeLists.txt
@@ -15,4 +15,4 @@ add_llvm_unittest(TableGenTests DISABLE_LLVM_LINK_LLVM_DYLIB
   ParserEntryPointTest.cpp
   )
 
-target_link_libraries(TableGenTests PRIVATE LLVMTableGenGlobalISel LLVMTableGen)
+target_link_libraries(TableGenTests PRIVATE LLVMTableGenCommon LLVMTableGen)
diff --git a/llvm/unittests/TableGen/CodeExpanderTest.cpp b/llvm/unittests/TableGen/CodeExpanderTest.cpp
index 4a9a0e8c114bc0..1528884ffdf65b 100644
--- a/llvm/unittests/TableGen/CodeExpanderTest.cpp
+++ b/llvm/unittests/TableGen/CodeExpanderTest.cpp
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "GlobalISel/CodeExpander.h"
-#include "GlobalISel/CodeExpansions.h"
+#include "Common/GlobalISel/CodeExpander.h"
+#include "Common/GlobalISel/CodeExpansions.h"
 
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TableGen/Error.h"
diff --git a/llvm/utils/TableGen/AsmMatcherEmitter.cpp b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
index 011d96a48d61da..13e8a8a62fa572 100644
--- a/llvm/utils/TableGen/AsmMatcherEmitter.cpp
+++ b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
@@ -95,12 +95,12 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "CodeGenInstAlias.h"
-#include "CodeGenInstruction.h"
-#include "CodeGenRegisters.h"
-#include "CodeGenTarget.h"
-#include "SubtargetFeatureInfo.h"
-#include "Types.h"
+#include "Common/CodeGenInstAlias.h"
+#include "Common/CodeGenInstruction.h"
+#include "Common/CodeGenRegisters.h"
+#include "Common/CodeGenTarget.h"
+#include "Common/SubtargetFeatureInfo.h"
+#include "Common/Types.h"
 #include "llvm/ADT/CachedHashString.h"
 #include "llvm/ADT/PointerUnion.h"
 #include "llvm/ADT/STLExtras.h"
diff --git a/llvm/utils/TableGen/AsmWriterEmitter.cpp b/llvm/utils/TableGen/AsmWriterEmitter.cpp
index e0cd5fad3254de..9a7956d9124a33 100644
--- a/llvm/utils/TableGen/AsmWriterEmitter.cpp
+++ b/llvm/utils/TableGen/AsmWriterEmitter.cpp
@@ -11,13 +11,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "AsmWriterInst.h"
-#include "CodeGenInstAlias.h"
-#include "CodeGenInstruction.h"
-#include "CodeGenRegisters.h"
-#include "CodeGenTarget.h"
-#include "SequenceToOffsetTable.h"
-#include "Types.h"
+#include "Basic/SequenceToOffsetTable.h"
+#include "Common/AsmWriterInst.h"
+#include "Common/CodeGenInstAlias.h"
+#include "Common/CodeGenInstruction.h"
+#include "Common/CodeGenRegisters.h"
+#include "Common/CodeGenTarget.h"
+#include "Common/Types.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/STLExtras.h"
@@ -1262,14 +1262,14 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) {
         << "    break;\n";
     }
     O << "  }\n";
-  }    
+  }
   O << "}\n\n";
 
   if (!MCOpPredicates.empty()) {
     O << "static bool " << Target.getName() << ClassName
       << "ValidateMCOperand(const MCOperand &MCOp,\n"
       << "                  const MCSubtargetInfo &STI,\n"
-      << "                  unsigned PredicateIndex) {\n"      
+      << "                  unsigned PredicateIndex) {\n"
       << "  switch (PredicateIndex) {\n"
       << "  default:\n"
       << "    llvm_unreachable(\"Unknown MCOperandPredicate kind\");\n"
diff --git a/llvm/utils/TableGen/AsmWriterInst.h b/llvm/utils/TableGen/AsmWriterInst.h
deleted file mode 100644
index 9c93e82b611b6b..00000000000000
--- a/llvm/utils/TableGen/AsmWriterInst.h
+++ /dev/null
@@ -1,107 +0,0 @@
-//===- AsmWriterInst.h - Classes encapsulating a printable inst -*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// These classes implement a parser for assembly strings.  The parser splits
-// the string into operands, which can be literal strings (the constant bits of
-// the string), actual operands (i.e., operands from the MachineInstr), and
-// dynamically-generated text, specified by raw C++ code.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_UTILS_TABLEGEN_ASMWRITERINST_H
-#define LLVM_UTILS_TABLEGEN_ASMWRITERINST_H
-
-#include <string>
-#include <vector>
-
-namespace llvm {
-  class CodeGenInstruction;
-
-  struct AsmWriterOperand {
-    enum OpType {
-      // Output this text surrounded by quotes to the asm.
-      isLiteralTextOperand,
-      // This is the name of a routine to call to print the operand.
-      isMachineInstrOperand,
-      // Output this text verbatim to the asm writer.  It is code that
-      // will output some text to the asm.
-      isLiteralStatementOperand
-    } OperandType;
-
-    /// MiOpNo - For isMachineInstrOperand, this is the operand number of the
-    /// machine instruction.
-    unsigned MIOpNo = 0;
-
-    /// Str - For isLiteralTextOperand, this IS the literal text.  For
-    /// isMachineInstrOperand, this is the PrinterMethodName for the operand..
-    /// For isLiteralStatementOperand, this is the code to insert verbatim
-    /// into the asm writer.
-    std::string Str;
-
-    /// MiModifier - For isMachineInstrOperand, this is the modifier string for
-    /// an operand, specified with syntax like ${opname:modifier}.
-    std::string MiModifier;
-
-    bool PCRel = false;
-
-    // To make VS STL happy
-    AsmWriterOperand(OpType op = isLiteralTextOperand):OperandType(op) {}
-
-    AsmWriterOperand(const std::string &LitStr,
-                     OpType op = isLiteralTextOperand)
-    : OperandType(op), Str(LitStr) {}
-
-    AsmWriterOperand(const std::string &Printer, unsigned _MIOpNo,
-                     const std::string &Modifier,
-                     OpType op = isMachineInstrOperand, bool PCRel = false)
-        : OperandType(op), MIOpNo(_MIOpNo), Str(Printer), MiModifier(Modifier),
-          PCRel(PCRel) {}
-
-    bool operator!=(const AsmWriterOperand &Other) const {
-      if (OperandType != Other.OperandType || Str != Other.Str) return true;
-      if (OperandType == isMachineInstrOperand)
-        return MIOpNo != Other.MIOpNo || MiModifier != Other.MiModifier ||
-               PCRel != Other.PCRel;
-      return false;
-    }
-    bool operator==(const AsmWriterOperand &Other) const {
-      return !operator!=(Other);
-    }
-
-    /// getCode - Return the code that prints this operand.
-    std::string getCode(bool PassSubtarget) const;
-  };
-
-  class AsmWriterInst {
-  public:
-    std::vector<AsmWriterOperand> Operands;
-    const CodeGenInstruction *CGI;
-    unsigned CGIIndex;
-
-    AsmWriterInst(const CodeGenInstruction &CGI, unsigned CGIIndex,
-                  unsigned Variant);
-
-    /// MatchesAllButOneOp - If this instruction is exactly identical to the
-    /// specified instruction except for one differing operand, return the
-    /// differing operand number.  Otherwise return ~0.
-    unsigned MatchesAllButOneOp(const AsmWriterInst &Other) const;
-
-  private:
-    void AddLiteralString(const std::string &Str) {
-      // If the last operand was already a literal text string, append this to
-      // it, otherwise add a new operand.
-      if (!Operands.empty() &&
-          Operands.back().OperandType == AsmWriterOperand::isLiteralTextOperand)
-        Operands.back().Str.append(Str);
-      else
-        Operands.push_back(AsmWriterOperand(Str));
-    }
-  };
-}
-
-#endif
diff --git a/llvm/utils/TableGen/Basic/CMakeLists.txt b/llvm/utils/TableGen/Basic/CMakeLists.txt
new file mode 100644
index 00000000000000..f2927d05c175c3
--- /dev/null
+++ b/llvm/utils/TableGen/Basic/CMakeLists.txt
@@ -0,0 +1,21 @@
+# The basic TableGen library contains as little dependencies as possible.
+# In particular, it does not depend on vt_gen -> it does not use ValueTypes.
+#
+# This library is the only thing included in `llvm-min-tablegen`.
+
+set(LLVM_LINK_COMPONENTS
+  Support
+  TableGen
+  )
+
+add_llvm_library(LLVMTableGenBasic STATIC OBJECT EXCLUDE_FROM_ALL
+  CodeGenIntrinsics.cpp
+  SDNodeProperties.cpp
+)
+set_target_properties(LLVMTableGenBasic PROPERTIES FOLDER "Tablegenning")
+
+# Users may include its headers as "Basic/*.h"
+target_include_directories(LLVMTableGenBasic
+  INTERFACE
+  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
+  )
diff --git a/llvm/utils/TableGen/CodeGenIntrinsics.cpp b/llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp
similarity index 100%
rename from llvm/utils/TableGen/CodeGenIntrinsics.cpp
rename to llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp
diff --git a/llvm/utils/TableGen/CodeGenIntrinsics.h b/llvm/utils/TableGen/Basic/CodeGenIntrinsics.h
similarity index 91%
rename from llvm/utils/TableGen/CodeGenIntrinsics.h
rename to llvm/utils/TableGen/Basic/CodeGenIntrinsics.h
index f3452f5acea804..da9e386d64d18b 100644
--- a/llvm/utils/TableGen/CodeGenIntrinsics.h
+++ b/llvm/utils/TableGen/Basic/CodeGenIntrinsics.h
@@ -25,12 +25,12 @@ class Record;
 class RecordKeeper;
 
 struct CodeGenIntrinsic {
-  Record *TheDef;             // The actual record defining this intrinsic.
-  std::string Name;           // The name of the LLVM function "llvm.bswap.i32"
-  std::string EnumName;       // The name of the enum "bswap_i32"
+  Record *TheDef;       // The actual record defining this intrinsic.
+  std::string Name;     // The name of the LLVM function "llvm.bswap.i32"
+  std::string EnumName; // The name of the enum "bswap_i32"
   std::string ClangBuiltinName; // Name of the corresponding GCC builtin, or "".
-  std::string MSBuiltinName;  // Name of the corresponding MS builtin, or "".
-  std::string TargetPrefix;   // Target prefix, e.g. "ppc" for t-s intrinsics.
+  std::string MSBuiltinName;    // Name of the corresponding MS builtin, or "".
+  std::string TargetPrefix;     // Target prefix, e.g. "ppc" for t-s intrinsics.
 
   /// This structure holds the return values and parameter values of an
   /// intrinsic. If the number of return values is > 1, then the intrinsic
@@ -136,9 +136,7 @@ struct CodeGenIntrinsic {
 
   void addArgAttribute(unsigned Idx, ArgAttrKind AK, uint64_t V = 0);
 
-  bool hasProperty(enum SDNP Prop) const {
-    return Properties & (1 << Prop);
-  }
+  bool hasProperty(enum SDNP Prop) const { return Properties & (1 << Prop); }
 
   /// Goes through all IntrProperties that have IsDefault
   /// value set and sets the property.
@@ -182,6 +180,6 @@ class CodeGenIntrinsicTable {
     return Intrinsics[Pos];
   }
 };
-}
+} // namespace llvm
 
 #endif
diff --git a/llvm/utils/TableGen/SDNodeProperties.cpp b/llvm/utils/TableGen/Basic/SDNodeProperties.cpp
similarity index 100%
rename from llvm/utils/TableGen/SDNodeProperties.cpp
rename to llvm/utils/TableGen/Basic/SDNodeProperties.cpp
diff --git a/llvm/utils/TableGen/SDNodeProperties.h b/llvm/utils/TableGen/Basic/SDNodeProperties.h
similarity index 98%
rename from llvm/utils/TableGen/SDNodeProperties.h
rename to llvm/utils/TableGen/Basic/SDNodeProperties.h
index 66a04e63150c40..5715423285249f 100644
--- a/llvm/utils/TableGen/SDNodeProperties.h
+++ b/llvm/utils/TableGen/Basic/SDNodeProperties.h
@@ -34,6 +34,6 @@ enum SDNP {
 
 unsigned parseSDPatternOperatorProperties(Record *R);
 
-}
+} // namespace llvm
 
 #endif
diff --git a/llvm/utils/TableGen/SequenceToOffsetTable.h b/llvm/utils/TableGen/Basic/SequenceToOffsetTable.h
similarity index 93%
rename from llvm/utils/TableGen/SequenceToOffsetTable.h
rename to llvm/utils/TableGen/Basic/SequenceToOffsetTable.h
index 77a404d07b7d39..7db39a9af72092 100644
--- a/llvm/utils/TableGen/SequenceToOffsetTable.h
+++ b/llvm/utils/TableGen/Basic/SequenceToOffsetTable.h
@@ -44,7 +44,7 @@ static inline void printChar(raw_ostream &OS, char C) {
 ///
 /// @tparam SeqT The sequence container. (vector or string).
 /// @tparam Less A stable comparator for SeqT elements.
-template<typename SeqT, typename Less = std::less<typename SeqT::value_type> >
+template <typename SeqT, typename Less = std::less<typename SeqT::value_type>>
 class SequenceToOffsetTable {
   typedef typename SeqT::value_type ElemT;
 
@@ -53,8 +53,8 @@ class SequenceToOffsetTable {
   struct SeqLess {
     Less L;
     bool operator()(const SeqT &A, const SeqT &B) const {
-      return std::lexicographical_compare(A.rbegin(), A.rend(),
-                                          B.rbegin(), B.rend(), L);
+      return std::lexicographical_compare(A.rbegin(), A.rend(), B.rbegin(),
+                                          B.rend(), L);
     }
   };
 
@@ -153,15 +153,15 @@ class SequenceToOffsetTable {
 
   /// emit - Print out the table as the body of an array initializer.
   /// Use the Print function to print elements.
-  void emit(raw_ostream &OS,
-            void (*Print)(raw_ostream&, ElemT),
+  void emit(raw_ostream &OS, void (*Print)(raw_ostream &, ElemT),
             const char *Term = "0") const {
     assert((empty() || Entries) && "Call layout() before emit()");
     for (typename SeqMap::const_iterator I = Seqs.begin(), E = Seqs.end();
          I != E; ++I) {
       OS << "  /* " << I->second << " */ ";
       for (typename SeqT::const_iterator SI = I->first.begin(),
-             SE = I->first.end(); SI != SE; ++SI) {
+                                         SE = I->first.end();
+           SI != SE; ++SI) {
         Print(OS, *SI);
         OS << ", ";
       }
diff --git a/llvm/utils/TableGen/CMakeLists.txt b/llvm/utils/TableGen/CMakeLists.txt
index 0100bf345ec29e..14690329cabf70 100644
--- a/llvm/utils/TableGen/CMakeLists.txt
+++ b/llvm/utils/TableGen/CMakeLists.txt
@@ -1,26 +1,25 @@
-add_subdirectory(GlobalISel)
+# Basic utilities which is the strict minimum needed to build
+# llvm-min-tblgen.
+add_subdirectory(Basic)
+# Common utilities are all of the reusable components and helper
+# code needed by the backends.
+add_subdirectory(Common)
 
-add_llvm_library(LLVMTableGenCommon STATIC OBJECT EXCLUDE_FROM_ALL
+set(LLVM_LINK_COMPONENTS Support)
+
+# llvm-min-tablegen only contains a subset of backends necessary to
+# build llvm/include. It must not depend on TableGenCommon, as
+# TableGenCommon depends on this already to generate things such as
+# ValueType definitions.
+add_tablegen(llvm-min-tblgen LLVM_HEADERS
+  TableGen.cpp
   Attributes.cpp
-  CodeGenIntrinsics.cpp
   DirectiveEmitter.cpp
   IntrinsicEmitter.cpp
   RISCVTargetDefEmitter.cpp
-  SDNodeProperties.cpp
   VTEmitter.cpp
-  PARTIAL_SOURCES_INTENDED
-
-  LINK_COMPONENTS
-  Support
-  TableGen
-  )
-set_target_properties(LLVMTableGenCommon PROPERTIES FOLDER "Tablegenning")
+  $<TARGET_OBJECTS:obj.LLVMTableGenBasic>
 
-set(LLVM_LINK_COMPONENTS Support)
-
-add_tablegen(llvm-min-tblgen LLVM_HEADERS
-  TableGen.cpp
-  $<TARGET_OBJECTS:obj.LLVMTableGenCommon>
   PARTIAL_SOURCES_INTENDED
   )
 set_target_properties(llvm-min-tblgen PROPERTIES FOLDER "Tablegenning")
@@ -35,63 +34,51 @@ add_tablegen(llvm-tblgen LLVM
   EXPORT LLVM
   AsmMatcherEmitter.cpp
   AsmWriterEmitter.cpp
-  AsmWriterInst.cpp
-  CTagsEmitter.cpp
+  Attributes.cpp
   CallingConvEmitter.cpp
   CodeEmitterGen.cpp
-  CodeGenDAGPatterns.cpp
-  CodeGenHwModes.cpp
-  CodeGenInstAlias.cpp
-  CodeGenInstruction.cpp
   CodeGenMapTable.cpp
-  CodeGenRegisters.cpp
-  CodeGenSchedule.cpp
-  CodeGenTarget.cpp
+  CompressInstEmitter.cpp
+  CTagsEmitter.cpp
   DAGISelEmitter.cpp
   DAGISelMatcherEmitter.cpp
   DAGISelMatcherGen.cpp
   DAGISelMatcherOpt.cpp
-  DAGISelMatcher.cpp
   DecoderEmitter.cpp
   DFAEmitter.cpp
   DFAPacketizerEmitter.cpp
+  DirectiveEmitter.cpp
   DisassemblerEmitter.cpp
   DXILEmitter.cpp
   ExegesisEmitter.cpp
   FastISelEmitter.cpp
   GlobalISelCombinerEmitter.cpp
   GlobalISelEmitter.cpp
-  GlobalISelMatchTable.cpp
-  GlobalISelMatchTableExecutorEmitter.cpp
-  InfoByHwMode.cpp
-  InstrInfoEmitter.cpp
   InstrDocsEmitter.cpp
-  OptEmitter.cpp
+  InstrInfoEmitter.cpp
+  IntrinsicEmitter.cpp
+  MacroFusionPredicatorEmitter.cpp
   OptParserEmitter.cpp
   OptRSTEmitter.cpp
-  PredicateExpander.cpp
   PseudoLoweringEmitter.cpp
-  CompressInstEmitter.cpp
-  MacroFusionPredicatorEmitter.cpp
   RegisterBankEmitter.cpp
   RegisterInfoEmitter.cpp
+  RISCVTargetDefEmitter.cpp
   SearchableTableEmitter.cpp
   SubtargetEmitter.cpp
-  SubtargetFeatureInfo.cpp
   TableGen.cpp
-  Types.cpp
-  VarLenCodeEmitterGen.cpp
-  X86DisassemblerTables.cpp
+  VTEmitter.cpp
+  WebAssemblyDisassemblerEmitter.cpp
   X86CompressEVEXTablesEmitter.cpp
+  X86DisassemblerTables.cpp
   X86FoldTablesEmitter.cpp
   X86MnemonicTables.cpp
   X86ModRMFilters.cpp
   X86RecognizableInstr.cpp
-  WebAssemblyDisassemblerEmitter.cpp
   $<TARGET_OBJECTS:obj.LLVMTableGenCommon>
 
   DEPENDS
   intrinsics_gen # via llvm-min-tablegen
   )
-target_link_libraries(llvm-tblgen PRIVATE LLVMTableGenGlobalISel)
+target_link_libraries(llvm-tblgen PRIVATE LLVMTableGenCommon)
 set_target_properties(llvm-tblgen PROPERTIES FOLDER "Tablegenning")
diff --git a/llvm/utils/TableGen/CallingConvEmitter.cpp b/llvm/utils/TableGen/CallingConvEmitter.cpp
index 02e7000130cde1..0d232f1c04663e 100644
--- a/llvm/utils/TableGen/CallingConvEmitter.cpp
+++ b/llvm/utils/TableGen/CallingConvEmitter.cpp
@@ -11,7 +11,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "CodeGenTarget.h"
+#include "Common/CodeGenTarget.h"
 #include "llvm/TableGen/Error.h"
 #include "llvm/TableGen/Record.h"
 #include "llvm/TableGen/TableGenBackend.h"
@@ -117,7 +117,7 @@ void CallingConvEmitter::EmitCallingConv(Record *CC, raw_ostream &O) {
     O << "\n";
     EmitAction(Action, 2, O);
   }
-  
+
   O << "\n  return true; // CC didn't match.\n";
   O << "}\n";
 }
@@ -128,7 +128,7 @@ void CallingConvEmitter::EmitAction(Record *Action,
 
   if (Action->isSubClassOf("CCPredicateAction")) {
     O << IndentStr << "if (";
-    
+
     if (Action->isSubClassOf("CCIfType")) {
       ListInit *VTs = Action->getValueAsListInit("VTs");
       for (unsigned i = 0, e = VTs->size(); i != e; ++i) {
@@ -143,7 +143,7 @@ void CallingConvEmitter::EmitAction(Record *Action,
       errs() << *Action;
       PrintFatalError(Action->getLoc(), "Unknown CCPredicateAction!");
     }
-    
+
     O << ") {\n";
     EmitAction(Action->getValueAsDef("SubAction"), Indent+2, O);
     O << IndentStr << "}\n";
diff --git a/llvm/utils/TableGen/CodeEmitterGen.cpp b/llvm/utils/TableGen/CodeEmitterGen.cpp
index 48ed319bf06f47..50a5d482ac939a 100644
--- a/llvm/utils/TableGen/CodeEmitterGen.cpp
+++ b/llvm/utils/TableGen/CodeEmitterGen.cpp
@@ -22,11 +22,11 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "CodeGenHwModes.h"
-#include "CodeGenInstruction.h"
-#include "CodeGenTarget.h"
-#include "InfoByHwMode.h"
-#include "VarLenCodeEmitterGen.h"
+#include "Common/CodeGenHwModes.h"
+#include "Common/CodeGenInstruction.h"
+#include "Common/CodeGenTarget.h"
+#include "Common/InfoByHwMode.h"
+#include "Common/VarLenCodeEmitterGen.h"
 #include "llvm/ADT/APInt.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringExtras.h"
@@ -107,10 +107,10 @@ bool CodeEmitterGen::addCodeToMergeInOperand(Record *R, BitsInit *BI,
   for (; bit >= 0; ) {
     if (getVariableBit(VarName, BI, bit) != -1)
       break;
-    
+
     --bit;
   }
-  
+
   // If we found no bits, ignore this value, otherwise emit the call to get the
   // operand encoding.
   if (bit < 0)
@@ -195,7 +195,7 @@ bool CodeEmitterGen::addCodeToMergeInOperand(Record *R, BitsInit *BI,
   unsigned BitOffset = -1;
   for (; bit >= 0; ) {
     int varBit = getVariableBit(VarName, BI, bit);
-    
+
     // If this bit isn't from a variable, skip it.
     if (varBit == -1) {
       --bit;
diff --git a/llvm/utils/TableGen/CodeGenHwModes.h b/llvm/utils/TableGen/CodeGenHwModes.h
deleted file mode 100644
index 09d20ad85c5ec1..00000000000000
--- a/llvm/utils/TableGen/CodeGenHwModes.h
+++ /dev/null
@@ -1,67 +0,0 @@
-//===--- CodeGenHwModes.h ---------------------------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exce...
[truncated]

``````````

</details>


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


More information about the llvm-commits mailing list