Skip to content

[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

Merged
merged 3 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/unittests/TableGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions llvm/unittests/TableGen/CodeExpanderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions llvm/utils/TableGen/AsmMatcherEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 7 additions & 7 deletions llvm/utils/TableGen/AsmWriterEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 21 additions & 0 deletions llvm/utils/TableGen/Basic/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Tablegenning"?

Copy link
Contributor Author

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


# Users may include its headers as "Basic/*.h"
target_include_directories(LLVMTableGenBasic
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
)
67 changes: 27 additions & 40 deletions llvm/utils/TableGen/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

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?

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")
Expand All @@ -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
Comment on lines +41 to +42
Copy link
Contributor

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)

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")
2 changes: 1 addition & 1 deletion llvm/utils/TableGen/CallingConvEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions llvm/utils/TableGen/CodeEmitterGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions llvm/utils/TableGen/CodeGenMapTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@
//
//===----------------------------------------------------------------------===//

#include "CodeGenInstruction.h"
#include "CodeGenTarget.h"
#include "Common/CodeGenInstruction.h"
#include "Common/CodeGenTarget.h"
#include "llvm/TableGen/Error.h"
#include "llvm/TableGen/Record.h"
using namespace llvm;
Expand Down
48 changes: 48 additions & 0 deletions llvm/utils/TableGen/Common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# The common library is similar to the basic library except it can
# depend on vt_gen.
#
# This library contains the bulk of the supporting code for all
# TableGen backends. It's split off as a separate library to
# allow unit-testing those components.

set(LLVM_LINK_COMPONENTS
Support
TableGen
)

add_llvm_library(LLVMTableGenCommon STATIC OBJECT EXCLUDE_FROM_ALL
GlobalISel/CodeExpander.cpp
GlobalISel/CXXPredicates.cpp
GlobalISel/GlobalISelMatchTable.cpp
GlobalISel/GlobalISelMatchTableExecutorEmitter.cpp
GlobalISel/MatchDataInfo.cpp
GlobalISel/Patterns.cpp

AsmWriterInst.cpp
CodeGenDAGPatterns.cpp
CodeGenHwModes.cpp
CodeGenInstAlias.cpp
CodeGenInstruction.cpp
CodeGenRegisters.cpp
CodeGenSchedule.cpp
CodeGenTarget.cpp
DAGISelMatcher.cpp
InfoByHwMode.cpp
OptEmitter.cpp
PredicateExpander.cpp
SubtargetFeatureInfo.cpp
Types.cpp
VarLenCodeEmitterGen.cpp
$<TARGET_OBJECTS:obj.LLVMTableGenBasic>

DEPENDS
vt_gen
)
set_target_properties(LLVMTableGenCommon PROPERTIES FOLDER "Tablegenning")
target_link_libraries(LLVMTableGenCommon PUBLIC LLVMTableGenBasic)

# Users may include its headers as "Common/*.h"
target_include_directories(LLVMTableGenCommon
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
#ifndef LLVM_UTILS_TABLEGEN_CODEGENDAGPATTERNS_H
#define LLVM_UTILS_TABLEGEN_CODEGENDAGPATTERNS_H

#include "CodeGenIntrinsics.h"
#include "Basic/CodeGenIntrinsics.h"
#include "Basic/SDNodeProperties.h"
#include "CodeGenTarget.h"
#include "SDNodeProperties.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/PointerUnion.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
#ifndef LLVM_UTILS_TABLEGEN_CODEGENTARGET_H
#define LLVM_UTILS_TABLEGEN_CODEGENTARGET_H

#include "Basic/SDNodeProperties.h"
#include "CodeGenHwModes.h"
#include "CodeGenInstruction.h"
#include "InfoByHwMode.h"
#include "SDNodeProperties.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallVector.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//

#include "GlobalISelMatchTable.h"
#include "CodeGenInstruction.h"
#include "CodeGenRegisters.h"
#include "Common/CodeGenInstruction.h"
#include "Common/CodeGenRegisters.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/LEB128.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#ifndef LLVM_UTILS_TABLEGEN_GLOBALISELMATCHTABLE_H
#define LLVM_UTILS_TABLEGEN_GLOBALISELMATCHTABLE_H

#include "CodeGenDAGPatterns.h"
#include "Common/CodeGenDAGPatterns.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallPtrSet.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#ifndef LLVM_UTILS_TABLEGEN_GLOBALISELMATCHTABLEEXECUTOREMITTER_H
#define LLVM_UTILS_TABLEGEN_GLOBALISELMATCHTABLEEXECUTOREMITTER_H

#include "SubtargetFeatureInfo.h"
#include "Common/SubtargetFeatureInfo.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
//===----------------------------------------------------------------------===//

#include "Patterns.h"
#include "../CodeGenInstruction.h"
#include "../CodeGenIntrinsics.h"
#include "Basic/CodeGenIntrinsics.h"
#include "CXXPredicates.h"
#include "CodeExpander.h"
#include "CodeExpansions.h"
#include "Common/CodeGenInstruction.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions llvm/utils/TableGen/CompressInstEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@

//===----------------------------------------------------------------------===//

#include "CodeGenInstruction.h"
#include "CodeGenRegisters.h"
#include "CodeGenTarget.h"
#include "Common/CodeGenInstruction.h"
#include "Common/CodeGenRegisters.h"
#include "Common/CodeGenTarget.h"
#include "llvm/ADT/IndexedMap.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
Expand Down
Loading