-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[RFC][TableGen] Restructure TableGen Source #80847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-llvm-globalisel @llvm/pr-subscribers-backend-directx Author: Pierre van Houtryve (Pierre-vh) ChangesLately, 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:
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:
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]
|
@llvm/pr-subscribers-backend-x86 Author: Pierre van Houtryve (Pierre-vh) ChangesLately, 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:
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:
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]
|
@llvm/pr-subscribers-llvm-selectiondag Author: Pierre van Houtryve (Pierre-vh) ChangesLately, 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:
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:
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]
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the diff seems to just clang-format changes
CodeGenIntrinsics.cpp | ||
SDNodeProperties.cpp | ||
) | ||
set_target_properties(LLVMTableGenBasic PROPERTIES FOLDER "Tablegenning") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Tablegenning"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I just copy pasted that. It seems like we tend to set that properties for tablegen-related stuff. Not sure why
Indeed, it seems like git clang-format formatted the whole files when I moved them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excuse me, it will take longer time for me to review. I am dubious a bit to this direction.
Re. formatting changes, It's good thing to reformat files to be moved. Then I suggest you to split reformatting commits in advance before merging this.
CompressInstEmitter.cpp | ||
CTagsEmitter.cpp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we prefer reordering the file list by character code case sensitive. Could you follow?
(I didn't do in the last time since I worked to be less intrusive)
@@ -1262,14 +1262,14 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) { | |||
<< " break;\n"; | |||
} | |||
O << " }\n"; | |||
} | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you avoid irrelevant partial reformattings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'll clang format the whole folder and create a PR for it.
``` find llvm/utils/TableGen -iname "*.h" -o -iname "*.cpp" | xargs clang-format-16 -i ``` Split from #80847
13b4604
to
21d4383
Compare
I landed the clang-forrmat patch and now this should be easier to review. Seems like git correctly picks up all files as being renamed with slight changes instead of thinking some were deleted. |
You can test this locally with the following command:git-clang-format --diff 373e77b4c0ad9b0bf370f0e5a32a4100a5459d82 e2e6e79b7cd1f6a42c67e4d12f047cd5dec15250 -- llvm/unittests/TableGen/CodeExpanderTest.cpp llvm/utils/TableGen/AsmMatcherEmitter.cpp llvm/utils/TableGen/AsmWriterEmitter.cpp llvm/utils/TableGen/CallingConvEmitter.cpp llvm/utils/TableGen/CodeEmitterGen.cpp llvm/utils/TableGen/CodeGenMapTable.cpp llvm/utils/TableGen/CompressInstEmitter.cpp llvm/utils/TableGen/DAGISelEmitter.cpp llvm/utils/TableGen/DAGISelMatcherEmitter.cpp llvm/utils/TableGen/DAGISelMatcherGen.cpp llvm/utils/TableGen/DAGISelMatcherOpt.cpp llvm/utils/TableGen/DFAEmitter.cpp llvm/utils/TableGen/DFAPacketizerEmitter.cpp llvm/utils/TableGen/DXILEmitter.cpp llvm/utils/TableGen/DecoderEmitter.cpp llvm/utils/TableGen/DisassemblerEmitter.cpp llvm/utils/TableGen/FastISelEmitter.cpp llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp llvm/utils/TableGen/GlobalISelEmitter.cpp llvm/utils/TableGen/InstrDocsEmitter.cpp llvm/utils/TableGen/InstrInfoEmitter.cpp llvm/utils/TableGen/IntrinsicEmitter.cpp llvm/utils/TableGen/MacroFusionPredicatorEmitter.cpp llvm/utils/TableGen/OptParserEmitter.cpp llvm/utils/TableGen/OptRSTEmitter.cpp llvm/utils/TableGen/PseudoLoweringEmitter.cpp llvm/utils/TableGen/RegisterBankEmitter.cpp llvm/utils/TableGen/RegisterInfoEmitter.cpp llvm/utils/TableGen/SearchableTableEmitter.cpp llvm/utils/TableGen/SubtargetEmitter.cpp llvm/utils/TableGen/WebAssemblyDisassemblerEmitter.cpp llvm/utils/TableGen/X86CompressEVEXTablesEmitter.cpp llvm/utils/TableGen/X86FoldTablesEmitter.cpp llvm/utils/TableGen/X86MnemonicTables.cpp llvm/utils/TableGen/X86RecognizableInstr.h llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp llvm/utils/TableGen/Basic/CodeGenIntrinsics.h llvm/utils/TableGen/Basic/SDNodeProperties.cpp llvm/utils/TableGen/Basic/SDNodeProperties.h llvm/utils/TableGen/Basic/SequenceToOffsetTable.h llvm/utils/TableGen/Common/AsmWriterInst.cpp llvm/utils/TableGen/Common/AsmWriterInst.h llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp llvm/utils/TableGen/Common/CodeGenDAGPatterns.h llvm/utils/TableGen/Common/CodeGenHwModes.cpp llvm/utils/TableGen/Common/CodeGenHwModes.h llvm/utils/TableGen/Common/CodeGenInstAlias.cpp llvm/utils/TableGen/Common/CodeGenInstAlias.h llvm/utils/TableGen/Common/CodeGenInstruction.cpp llvm/utils/TableGen/Common/CodeGenInstruction.h llvm/utils/TableGen/Common/CodeGenRegisters.cpp llvm/utils/TableGen/Common/CodeGenRegisters.h llvm/utils/TableGen/Common/CodeGenSchedule.cpp llvm/utils/TableGen/Common/CodeGenSchedule.h llvm/utils/TableGen/Common/CodeGenTarget.cpp llvm/utils/TableGen/Common/CodeGenTarget.h llvm/utils/TableGen/Common/DAGISelMatcher.cpp llvm/utils/TableGen/Common/DAGISelMatcher.h llvm/utils/TableGen/Common/GlobalISel/CXXPredicates.cpp llvm/utils/TableGen/Common/GlobalISel/CXXPredicates.h llvm/utils/TableGen/Common/GlobalISel/CodeExpander.cpp llvm/utils/TableGen/Common/GlobalISel/CodeExpander.h llvm/utils/TableGen/Common/GlobalISel/CodeExpansions.h llvm/utils/TableGen/Common/GlobalISel/CombinerUtils.h llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.h llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTableExecutorEmitter.cpp llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTableExecutorEmitter.h llvm/utils/TableGen/Common/GlobalISel/MatchDataInfo.cpp llvm/utils/TableGen/Common/GlobalISel/MatchDataInfo.h llvm/utils/TableGen/Common/GlobalISel/Patterns.cpp llvm/utils/TableGen/Common/GlobalISel/Patterns.h llvm/utils/TableGen/Common/InfoByHwMode.cpp llvm/utils/TableGen/Common/InfoByHwMode.h llvm/utils/TableGen/Common/OptEmitter.cpp llvm/utils/TableGen/Common/OptEmitter.h llvm/utils/TableGen/Common/PredicateExpander.cpp llvm/utils/TableGen/Common/PredicateExpander.h llvm/utils/TableGen/Common/SubtargetFeatureInfo.cpp llvm/utils/TableGen/Common/SubtargetFeatureInfo.h llvm/utils/TableGen/Common/Types.cpp llvm/utils/TableGen/Common/Types.h llvm/utils/TableGen/Common/VarLenCodeEmitterGen.cpp llvm/utils/TableGen/Common/VarLenCodeEmitterGen.h View the diff from clang-format here.diff --git a/llvm/utils/TableGen/Common/VarLenCodeEmitterGen.cpp b/llvm/utils/TableGen/Common/VarLenCodeEmitterGen.cpp
index bfb7e5c333..4263d8f417 100644
--- a/llvm/utils/TableGen/Common/VarLenCodeEmitterGen.cpp
+++ b/llvm/utils/TableGen/Common/VarLenCodeEmitterGen.cpp
@@ -337,8 +337,8 @@ static void emitInstBits(raw_ostream &IS, raw_ostream &SS, const APInt &Bits,
return;
}
- IS.indent(4) << "{/*NumBits*/" << Bits.getBitWidth() << ", "
- << "/*Index*/" << Index << "},";
+ IS.indent(4) << "{/*NumBits*/" << Bits.getBitWidth() << ", " << "/*Index*/"
+ << Index << "},";
SS.indent(4);
for (unsigned I = 0; I < Bits.getNumWords(); ++I, ++Index)
@@ -371,8 +371,8 @@ void VarLenCodeEmitterGen::emitInstructionBaseValues(
if (ModeIt == InstIt->second.end())
ModeIt = InstIt->second.find(Universal);
if (ModeIt == InstIt->second.end()) {
- IS.indent(4) << "{/*NumBits*/0, /*Index*/0},\t"
- << "// " << R->getName() << " no encoding\n";
+ IS.indent(4) << "{/*NumBits*/0, /*Index*/0},\t" << "// " << R->getName()
+ << " no encoding\n";
continue;
}
const VarLenInst &VLI = ModeIt->second;
@@ -492,10 +492,9 @@ std::string VarLenCodeEmitterGen::getInstructionCaseForEncoding(
SS << ", /*Pos=*/" << utostr(Offset) << ", Scratch, Fixups, STI);\n";
- SS.indent(I) << "Inst.insertBits("
- << "Scratch.extractBits(" << utostr(NumBits) << ", "
- << utostr(LoBit) << ")"
- << ", " << Offset << ");\n";
+ SS.indent(I) << "Inst.insertBits(" << "Scratch.extractBits("
+ << utostr(NumBits) << ", " << utostr(LoBit) << ")" << ", "
+ << Offset << ");\n";
HighScratchAccess = std::max(HighScratchAccess, NumBits + LoBit);
}
diff --git a/llvm/utils/TableGen/DXILEmitter.cpp b/llvm/utils/TableGen/DXILEmitter.cpp
index 10440914f3..47c89df35e 100644
--- a/llvm/utils/TableGen/DXILEmitter.cpp
+++ b/llvm/utils/TableGen/DXILEmitter.cpp
@@ -11,8 +11,8 @@
//
//===----------------------------------------------------------------------===//
-#include "Common/CodeGenTarget.h"
#include "Basic/SequenceToOffsetTable.h"
+#include "Common/CodeGenTarget.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h"
|
ping |
997a9af
to
5b0028a
Compare
ping :) |
@chapuni do you need more time to review? |
ping |
5b0028a
to
78209e3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Pierre-vh, I think this looks good and @arsenm has approved.
@chapuni is based in Japan so there will be a time lag. Give him another day if he doesn't respond I'd say go ahead and merge this.
Lately, while trying to move as much code out of the GlobalISel Combiner Backend, I've been hitting more and more linker issues. It seems like the library structure was due for an overhaul, so I created llvm#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. Solves llvm#80647
78209e3
to
e2e6e79
Compare
✅ With the latest revision this PR passed the Python code formatter. |
Summary: The patch #80847 introduced some changes to how we build tablegen. Some files weren't build included properly on my build. We don't need to fish out the objects directly from an object library build, we can simply add it to the link libraries and CMake will include them for you. This fixed the issue of missings defs for me and is more canonical.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
An old wish I had back when chapuni introduced llvm-min-tblgen: It'd be nice if llvm-min-tblgen had its own directory, so that we don't need the PARTIAL_SOURCES_INTENDED
kludge. Looks like this is even easier to do after this change :)
# TableGenCommon depends on this already to generate things such as | ||
# ValueType definitions. | ||
add_tablegen(llvm-min-tblgen LLVM_HEADERS | ||
TableGen.cpp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep this source list alphabetized?
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:
llvm-min-tablegen
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