Skip to content

Commit 21d4383

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 b9079ba commit 21d4383

File tree

89 files changed

+232
-198
lines changed

Some content is hidden

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

89 files changed

+232
-198
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: 7 additions & 7 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"
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/CMakeLists.txt

Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
add_subdirectory(GlobalISel)
1+
# Basic utilities which is the strict minimum needed to build
2+
# llvm-min-tblgen.
3+
add_subdirectory(Basic)
4+
# Common utilities are all of the reusable components and helper
5+
# code needed by the backends.
6+
add_subdirectory(Common)
27

3-
add_llvm_library(LLVMTableGenCommon STATIC OBJECT EXCLUDE_FROM_ALL
8+
set(LLVM_LINK_COMPONENTS Support)
9+
10+
# llvm-min-tablegen only contains a subset of backends necessary to
11+
# build llvm/include. It must not depend on TableGenCommon, as
12+
# TableGenCommon depends on this already to generate things such as
13+
# ValueType definitions.
14+
add_tablegen(llvm-min-tblgen LLVM_HEADERS
15+
TableGen.cpp
416
Attributes.cpp
5-
CodeGenIntrinsics.cpp
617
DirectiveEmitter.cpp
718
IntrinsicEmitter.cpp
819
RISCVTargetDefEmitter.cpp
9-
SDNodeProperties.cpp
1020
VTEmitter.cpp
11-
PARTIAL_SOURCES_INTENDED
12-
13-
LINK_COMPONENTS
14-
Support
15-
TableGen
16-
)
17-
set_target_properties(LLVMTableGenCommon PROPERTIES FOLDER "Tablegenning")
21+
$<TARGET_OBJECTS:obj.LLVMTableGenBasic>
1822

19-
set(LLVM_LINK_COMPONENTS Support)
20-
21-
add_tablegen(llvm-min-tblgen LLVM_HEADERS
22-
TableGen.cpp
23-
$<TARGET_OBJECTS:obj.LLVMTableGenCommon>
2423
PARTIAL_SOURCES_INTENDED
2524
)
2625
set_target_properties(llvm-min-tblgen PROPERTIES FOLDER "Tablegenning")
@@ -35,63 +34,51 @@ add_tablegen(llvm-tblgen LLVM
3534
EXPORT LLVM
3635
AsmMatcherEmitter.cpp
3736
AsmWriterEmitter.cpp
38-
AsmWriterInst.cpp
39-
CTagsEmitter.cpp
37+
Attributes.cpp
4038
CallingConvEmitter.cpp
4139
CodeEmitterGen.cpp
42-
CodeGenDAGPatterns.cpp
43-
CodeGenHwModes.cpp
44-
CodeGenInstAlias.cpp
45-
CodeGenInstruction.cpp
4640
CodeGenMapTable.cpp
47-
CodeGenRegisters.cpp
48-
CodeGenSchedule.cpp
49-
CodeGenTarget.cpp
41+
CompressInstEmitter.cpp
42+
CTagsEmitter.cpp
5043
DAGISelEmitter.cpp
5144
DAGISelMatcherEmitter.cpp
5245
DAGISelMatcherGen.cpp
5346
DAGISelMatcherOpt.cpp
54-
DAGISelMatcher.cpp
5547
DecoderEmitter.cpp
5648
DFAEmitter.cpp
5749
DFAPacketizerEmitter.cpp
50+
DirectiveEmitter.cpp
5851
DisassemblerEmitter.cpp
5952
DXILEmitter.cpp
6053
ExegesisEmitter.cpp
6154
FastISelEmitter.cpp
6255
GlobalISelCombinerEmitter.cpp
6356
GlobalISelEmitter.cpp
64-
GlobalISelMatchTable.cpp
65-
GlobalISelMatchTableExecutorEmitter.cpp
66-
InfoByHwMode.cpp
67-
InstrInfoEmitter.cpp
6857
InstrDocsEmitter.cpp
69-
OptEmitter.cpp
58+
InstrInfoEmitter.cpp
59+
IntrinsicEmitter.cpp
60+
MacroFusionPredicatorEmitter.cpp
7061
OptParserEmitter.cpp
7162
OptRSTEmitter.cpp
72-
PredicateExpander.cpp
7363
PseudoLoweringEmitter.cpp
74-
CompressInstEmitter.cpp
75-
MacroFusionPredicatorEmitter.cpp
7664
RegisterBankEmitter.cpp
7765
RegisterInfoEmitter.cpp
66+
RISCVTargetDefEmitter.cpp
7867
SearchableTableEmitter.cpp
7968
SubtargetEmitter.cpp
80-
SubtargetFeatureInfo.cpp
8169
TableGen.cpp
82-
Types.cpp
83-
VarLenCodeEmitterGen.cpp
84-
X86DisassemblerTables.cpp
70+
VTEmitter.cpp
71+
WebAssemblyDisassemblerEmitter.cpp
8572
X86CompressEVEXTablesEmitter.cpp
73+
X86DisassemblerTables.cpp
8674
X86FoldTablesEmitter.cpp
8775
X86MnemonicTables.cpp
8876
X86ModRMFilters.cpp
8977
X86RecognizableInstr.cpp
90-
WebAssemblyDisassemblerEmitter.cpp
9178
$<TARGET_OBJECTS:obj.LLVMTableGenCommon>
9279

9380
DEPENDS
9481
intrinsics_gen # via llvm-min-tablegen
9582
)
96-
target_link_libraries(llvm-tblgen PRIVATE LLVMTableGenGlobalISel)
83+
target_link_libraries(llvm-tblgen PRIVATE LLVMTableGenCommon)
9784
set_target_properties(llvm-tblgen PROPERTIES FOLDER "Tablegenning")

llvm/utils/TableGen/CallingConvEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14-
#include "CodeGenTarget.h"
14+
#include "Common/CodeGenTarget.h"
1515
#include "llvm/TableGen/Error.h"
1616
#include "llvm/TableGen/Record.h"
1717
#include "llvm/TableGen/TableGenBackend.h"

llvm/utils/TableGen/CodeEmitterGen.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
//
2323
//===----------------------------------------------------------------------===//
2424

25-
#include "CodeGenHwModes.h"
26-
#include "CodeGenInstruction.h"
27-
#include "CodeGenTarget.h"
28-
#include "InfoByHwMode.h"
29-
#include "VarLenCodeEmitterGen.h"
25+
#include "Common/CodeGenHwModes.h"
26+
#include "Common/CodeGenInstruction.h"
27+
#include "Common/CodeGenTarget.h"
28+
#include "Common/InfoByHwMode.h"
29+
#include "Common/VarLenCodeEmitterGen.h"
3030
#include "llvm/ADT/APInt.h"
3131
#include "llvm/ADT/ArrayRef.h"
3232
#include "llvm/ADT/StringExtras.h"

llvm/utils/TableGen/CodeGenMapTable.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@
7575
//
7676
//===----------------------------------------------------------------------===//
7777

78-
#include "CodeGenInstruction.h"
79-
#include "CodeGenTarget.h"
78+
#include "Common/CodeGenInstruction.h"
79+
#include "Common/CodeGenTarget.h"
8080
#include "llvm/TableGen/Error.h"
8181
#include "llvm/TableGen/Record.h"
8282
using namespace llvm;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# The common library is similar to the basic library except it can
2+
# depend on vt_gen.
3+
#
4+
# This library contains the bulk of the supporting code for all
5+
# TableGen backends. It's split off as a separate library to
6+
# allow unit-testing those components.
7+
8+
set(LLVM_LINK_COMPONENTS
9+
Support
10+
TableGen
11+
)
12+
13+
add_llvm_library(LLVMTableGenCommon STATIC OBJECT EXCLUDE_FROM_ALL
14+
GlobalISel/CodeExpander.cpp
15+
GlobalISel/CXXPredicates.cpp
16+
GlobalISel/GlobalISelMatchTable.cpp
17+
GlobalISel/GlobalISelMatchTableExecutorEmitter.cpp
18+
GlobalISel/MatchDataInfo.cpp
19+
GlobalISel/Patterns.cpp
20+
21+
AsmWriterInst.cpp
22+
CodeGenDAGPatterns.cpp
23+
CodeGenHwModes.cpp
24+
CodeGenInstAlias.cpp
25+
CodeGenInstruction.cpp
26+
CodeGenRegisters.cpp
27+
CodeGenSchedule.cpp
28+
CodeGenTarget.cpp
29+
DAGISelMatcher.cpp
30+
InfoByHwMode.cpp
31+
OptEmitter.cpp
32+
PredicateExpander.cpp
33+
SubtargetFeatureInfo.cpp
34+
Types.cpp
35+
VarLenCodeEmitterGen.cpp
36+
$<TARGET_OBJECTS:obj.LLVMTableGenBasic>
37+
38+
DEPENDS
39+
vt_gen
40+
)
41+
set_target_properties(LLVMTableGenCommon PROPERTIES FOLDER "Tablegenning")
42+
target_link_libraries(LLVMTableGenCommon PUBLIC LLVMTableGenBasic)
43+
44+
# Users may include its headers as "Common/*.h"
45+
target_include_directories(LLVMTableGenCommon
46+
PUBLIC
47+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
48+
)

llvm/utils/TableGen/CodeGenDAGPatterns.h renamed to llvm/utils/TableGen/Common/CodeGenDAGPatterns.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
#ifndef LLVM_UTILS_TABLEGEN_CODEGENDAGPATTERNS_H
1515
#define LLVM_UTILS_TABLEGEN_CODEGENDAGPATTERNS_H
1616

17-
#include "CodeGenIntrinsics.h"
17+
#include "Basic/CodeGenIntrinsics.h"
18+
#include "Basic/SDNodeProperties.h"
1819
#include "CodeGenTarget.h"
19-
#include "SDNodeProperties.h"
2020
#include "llvm/ADT/IntrusiveRefCntPtr.h"
2121
#include "llvm/ADT/MapVector.h"
2222
#include "llvm/ADT/PointerUnion.h"

llvm/utils/TableGen/CodeGenTarget.h renamed to llvm/utils/TableGen/Common/CodeGenTarget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "CodeGenHwModes.h"
2020
#include "CodeGenInstruction.h"
2121
#include "InfoByHwMode.h"
22-
#include "SDNodeProperties.h"
22+
#include "Basic/SDNodeProperties.h"
2323
#include "llvm/ADT/ArrayRef.h"
2424
#include "llvm/ADT/DenseMap.h"
2525
#include "llvm/ADT/SmallVector.h"

llvm/utils/TableGen/GlobalISelMatchTable.cpp renamed to llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp

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

99
#include "GlobalISelMatchTable.h"
10-
#include "CodeGenInstruction.h"
11-
#include "CodeGenRegisters.h"
10+
#include "Common/CodeGenInstruction.h"
11+
#include "Common/CodeGenRegisters.h"
1212
#include "llvm/ADT/Statistic.h"
1313
#include "llvm/Support/Debug.h"
1414
#include "llvm/Support/LEB128.h"

llvm/utils/TableGen/GlobalISelMatchTable.h renamed to llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#ifndef LLVM_UTILS_TABLEGEN_GLOBALISELMATCHTABLE_H
1717
#define LLVM_UTILS_TABLEGEN_GLOBALISELMATCHTABLE_H
1818

19-
#include "CodeGenDAGPatterns.h"
19+
#include "Common/CodeGenDAGPatterns.h"
2020
#include "llvm/ADT/ArrayRef.h"
2121
#include "llvm/ADT/DenseMap.h"
2222
#include "llvm/ADT/SmallPtrSet.h"

llvm/utils/TableGen/GlobalISelMatchTableExecutorEmitter.h renamed to llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTableExecutorEmitter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#ifndef LLVM_UTILS_TABLEGEN_GLOBALISELMATCHTABLEEXECUTOREMITTER_H
1616
#define LLVM_UTILS_TABLEGEN_GLOBALISELMATCHTABLEEXECUTOREMITTER_H
1717

18-
#include "SubtargetFeatureInfo.h"
18+
#include "Common/SubtargetFeatureInfo.h"
1919
#include "llvm/ADT/ArrayRef.h"
2020
#include "llvm/ADT/StringRef.h"
2121
#include "llvm/ADT/Twine.h"

llvm/utils/TableGen/GlobalISel/Patterns.cpp renamed to llvm/utils/TableGen/Common/GlobalISel/Patterns.cpp

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

99
#include "Patterns.h"
10-
#include "../CodeGenInstruction.h"
11-
#include "../CodeGenIntrinsics.h"
10+
#include "Basic/CodeGenIntrinsics.h"
1211
#include "CXXPredicates.h"
1312
#include "CodeExpander.h"
1413
#include "CodeExpansions.h"
14+
#include "Common/CodeGenInstruction.h"
1515
#include "llvm/ADT/StringSet.h"
1616
#include "llvm/Support/Debug.h"
1717
#include "llvm/Support/raw_ostream.h"
File renamed without changes.
File renamed without changes.

llvm/utils/TableGen/CompressInstEmitter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@
6464

6565
//===----------------------------------------------------------------------===//
6666

67-
#include "CodeGenInstruction.h"
68-
#include "CodeGenRegisters.h"
69-
#include "CodeGenTarget.h"
67+
#include "Common/CodeGenInstruction.h"
68+
#include "Common/CodeGenRegisters.h"
69+
#include "Common/CodeGenTarget.h"
7070
#include "llvm/ADT/IndexedMap.h"
7171
#include "llvm/ADT/SmallVector.h"
7272
#include "llvm/ADT/StringMap.h"

llvm/utils/TableGen/DAGISelEmitter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#include "CodeGenDAGPatterns.h"
14-
#include "CodeGenInstruction.h"
15-
#include "CodeGenTarget.h"
16-
#include "DAGISelMatcher.h"
13+
#include "Common/CodeGenDAGPatterns.h"
14+
#include "Common/CodeGenInstruction.h"
15+
#include "Common/CodeGenTarget.h"
16+
#include "Common/DAGISelMatcher.h"
1717
#include "llvm/Support/Debug.h"
1818
#include "llvm/TableGen/Record.h"
1919
#include "llvm/TableGen/TableGenBackend.h"

llvm/utils/TableGen/DAGISelMatcherEmitter.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#include "CodeGenDAGPatterns.h"
14-
#include "CodeGenInstruction.h"
15-
#include "CodeGenRegisters.h"
16-
#include "CodeGenTarget.h"
17-
#include "DAGISelMatcher.h"
18-
#include "SDNodeProperties.h"
13+
#include "Basic/SDNodeProperties.h"
14+
#include "Common/CodeGenDAGPatterns.h"
15+
#include "Common/CodeGenInstruction.h"
16+
#include "Common/CodeGenRegisters.h"
17+
#include "Common/CodeGenTarget.h"
18+
#include "Common/DAGISelMatcher.h"
1919
#include "llvm/ADT/DenseMap.h"
2020
#include "llvm/ADT/MapVector.h"
2121
#include "llvm/ADT/StringMap.h"

0 commit comments

Comments
 (0)