Skip to content

Commit 13b4604

Browse files
committed
[RFC][TableGen] Restructure TableGen Source
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 #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 #80647
1 parent d5a3de4 commit 13b4604

File tree

93 files changed

+2846
-2888
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+2846
-2888
lines changed

llvm/unittests/TableGen/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ add_llvm_unittest(TableGenTests DISABLE_LLVM_LINK_LLVM_DYLIB
1515
ParserEntryPointTest.cpp
1616
)
1717

18-
target_link_libraries(TableGenTests PRIVATE LLVMTableGenGlobalISel LLVMTableGen)
18+
target_link_libraries(TableGenTests PRIVATE LLVMTableGenCommon LLVMTableGen)

llvm/unittests/TableGen/CodeExpanderTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "GlobalISel/CodeExpander.h"
10-
#include "GlobalISel/CodeExpansions.h"
9+
#include "Common/GlobalISel/CodeExpander.h"
10+
#include "Common/GlobalISel/CodeExpansions.h"
1111

1212
#include "llvm/Support/raw_ostream.h"
1313
#include "llvm/TableGen/Error.h"

llvm/utils/TableGen/AsmMatcherEmitter.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@
9595
//
9696
//===----------------------------------------------------------------------===//
9797

98-
#include "CodeGenInstAlias.h"
99-
#include "CodeGenInstruction.h"
100-
#include "CodeGenRegisters.h"
101-
#include "CodeGenTarget.h"
102-
#include "SubtargetFeatureInfo.h"
103-
#include "Types.h"
98+
#include "Common/CodeGenInstAlias.h"
99+
#include "Common/CodeGenInstruction.h"
100+
#include "Common/CodeGenRegisters.h"
101+
#include "Common/CodeGenTarget.h"
102+
#include "Common/SubtargetFeatureInfo.h"
103+
#include "Common/Types.h"
104104
#include "llvm/ADT/CachedHashString.h"
105105
#include "llvm/ADT/PointerUnion.h"
106106
#include "llvm/ADT/STLExtras.h"

llvm/utils/TableGen/AsmWriterEmitter.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14-
#include "AsmWriterInst.h"
15-
#include "CodeGenInstAlias.h"
16-
#include "CodeGenInstruction.h"
17-
#include "CodeGenRegisters.h"
18-
#include "CodeGenTarget.h"
19-
#include "SequenceToOffsetTable.h"
20-
#include "Types.h"
14+
#include "Basic/SequenceToOffsetTable.h"
15+
#include "Common/AsmWriterInst.h"
16+
#include "Common/CodeGenInstAlias.h"
17+
#include "Common/CodeGenInstruction.h"
18+
#include "Common/CodeGenRegisters.h"
19+
#include "Common/CodeGenTarget.h"
20+
#include "Common/Types.h"
2121
#include "llvm/ADT/ArrayRef.h"
2222
#include "llvm/ADT/DenseMap.h"
2323
#include "llvm/ADT/STLExtras.h"
@@ -1262,14 +1262,14 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) {
12621262
<< " break;\n";
12631263
}
12641264
O << " }\n";
1265-
}
1265+
}
12661266
O << "}\n\n";
12671267

12681268
if (!MCOpPredicates.empty()) {
12691269
O << "static bool " << Target.getName() << ClassName
12701270
<< "ValidateMCOperand(const MCOperand &MCOp,\n"
12711271
<< " const MCSubtargetInfo &STI,\n"
1272-
<< " unsigned PredicateIndex) {\n"
1272+
<< " unsigned PredicateIndex) {\n"
12731273
<< " switch (PredicateIndex) {\n"
12741274
<< " default:\n"
12751275
<< " llvm_unreachable(\"Unknown MCOperandPredicate kind\");\n"

llvm/utils/TableGen/AsmWriterInst.h

Lines changed: 0 additions & 107 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# The basic TableGen library contains as little dependencies as possible.
2+
# In particular, it does not depend on vt_gen -> it does not use ValueTypes.
3+
#
4+
# This library is the only thing included in `llvm-min-tablegen`.
5+
6+
set(LLVM_LINK_COMPONENTS
7+
Support
8+
TableGen
9+
)
10+
11+
add_llvm_library(LLVMTableGenBasic STATIC OBJECT EXCLUDE_FROM_ALL
12+
CodeGenIntrinsics.cpp
13+
SDNodeProperties.cpp
14+
)
15+
set_target_properties(LLVMTableGenBasic PROPERTIES FOLDER "Tablegenning")
16+
17+
# Users may include its headers as "Basic/*.h"
18+
target_include_directories(LLVMTableGenBasic
19+
INTERFACE
20+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
21+
)

llvm/utils/TableGen/CodeGenIntrinsics.h renamed to llvm/utils/TableGen/Basic/CodeGenIntrinsics.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ class Record;
2525
class RecordKeeper;
2626

2727
struct CodeGenIntrinsic {
28-
Record *TheDef; // The actual record defining this intrinsic.
29-
std::string Name; // The name of the LLVM function "llvm.bswap.i32"
30-
std::string EnumName; // The name of the enum "bswap_i32"
28+
Record *TheDef; // The actual record defining this intrinsic.
29+
std::string Name; // The name of the LLVM function "llvm.bswap.i32"
30+
std::string EnumName; // The name of the enum "bswap_i32"
3131
std::string ClangBuiltinName; // Name of the corresponding GCC builtin, or "".
32-
std::string MSBuiltinName; // Name of the corresponding MS builtin, or "".
33-
std::string TargetPrefix; // Target prefix, e.g. "ppc" for t-s intrinsics.
32+
std::string MSBuiltinName; // Name of the corresponding MS builtin, or "".
33+
std::string TargetPrefix; // Target prefix, e.g. "ppc" for t-s intrinsics.
3434

3535
/// This structure holds the return values and parameter values of an
3636
/// intrinsic. If the number of return values is > 1, then the intrinsic
@@ -136,9 +136,7 @@ struct CodeGenIntrinsic {
136136

137137
void addArgAttribute(unsigned Idx, ArgAttrKind AK, uint64_t V = 0);
138138

139-
bool hasProperty(enum SDNP Prop) const {
140-
return Properties & (1 << Prop);
141-
}
139+
bool hasProperty(enum SDNP Prop) const { return Properties & (1 << Prop); }
142140

143141
/// Goes through all IntrProperties that have IsDefault
144142
/// value set and sets the property.
@@ -182,6 +180,6 @@ class CodeGenIntrinsicTable {
182180
return Intrinsics[Pos];
183181
}
184182
};
185-
}
183+
} // namespace llvm
186184

187185
#endif

llvm/utils/TableGen/SDNodeProperties.h renamed to llvm/utils/TableGen/Basic/SDNodeProperties.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ enum SDNP {
3434

3535
unsigned parseSDPatternOperatorProperties(Record *R);
3636

37-
}
37+
} // namespace llvm
3838

3939
#endif

llvm/utils/TableGen/SequenceToOffsetTable.h renamed to llvm/utils/TableGen/Basic/SequenceToOffsetTable.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static inline void printChar(raw_ostream &OS, char C) {
4444
///
4545
/// @tparam SeqT The sequence container. (vector or string).
4646
/// @tparam Less A stable comparator for SeqT elements.
47-
template<typename SeqT, typename Less = std::less<typename SeqT::value_type> >
47+
template <typename SeqT, typename Less = std::less<typename SeqT::value_type>>
4848
class SequenceToOffsetTable {
4949
typedef typename SeqT::value_type ElemT;
5050

@@ -53,8 +53,8 @@ class SequenceToOffsetTable {
5353
struct SeqLess {
5454
Less L;
5555
bool operator()(const SeqT &A, const SeqT &B) const {
56-
return std::lexicographical_compare(A.rbegin(), A.rend(),
57-
B.rbegin(), B.rend(), L);
56+
return std::lexicographical_compare(A.rbegin(), A.rend(), B.rbegin(),
57+
B.rend(), L);
5858
}
5959
};
6060

@@ -153,15 +153,15 @@ class SequenceToOffsetTable {
153153

154154
/// emit - Print out the table as the body of an array initializer.
155155
/// Use the Print function to print elements.
156-
void emit(raw_ostream &OS,
157-
void (*Print)(raw_ostream&, ElemT),
156+
void emit(raw_ostream &OS, void (*Print)(raw_ostream &, ElemT),
158157
const char *Term = "0") const {
159158
assert((empty() || Entries) && "Call layout() before emit()");
160159
for (typename SeqMap::const_iterator I = Seqs.begin(), E = Seqs.end();
161160
I != E; ++I) {
162161
OS << " /* " << I->second << " */ ";
163162
for (typename SeqT::const_iterator SI = I->first.begin(),
164-
SE = I->first.end(); SI != SE; ++SI) {
163+
SE = I->first.end();
164+
SI != SE; ++SI) {
165165
Print(OS, *SI);
166166
OS << ", ";
167167
}

0 commit comments

Comments
 (0)