[TargetParser] Generate the defs for RISCV CPUs using llvm-tblgen.
authorFrancesco Petrogalli <francesco.petrogalli@apple.com>
Wed, 11 Jan 2023 09:23:55 +0000 (10:23 +0100)
committerFrancesco Petrogalli <francesco.petrogalli@apple.com>
Wed, 11 Jan 2023 10:18:44 +0000 (11:18 +0100)
commitac1ffd3caca12c254e0b8c847aa8ce8e51b6cfbf
treea2d4fcd192538df2c91ba58f125959537a03378c
parentc8ff968b8497099c68c8352c8c1a794537c3a389
[TargetParser]  Generate the defs for RISCV CPUs using llvm-tblgen.

Rework the change to prevent build failures. NFCI.

The failing code was submitted as
cf7a8305a2b4ddfd299c748136cb9a2960ef7089 and reverted via
8bd65e535fb33bc48805bafed8217b16a853e158.

The rework in this new commit prevents failures like the following:

FAILED: tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targets/RISCV.cpp.o
/usr/bin/c++  [bunch of non interesting stuff]  -c <path-to>/llvm-project/clang/lib/Basic/Targets/RISCV.cpp
In file included from <path-to>/llvm-project/clang/lib/Basic/Targets/RISCV.cpp:19:
<path-to>/llvm-project/llvm/include/llvm/TargetParser/RISCVTargetParser.h:29:10: fatal error: llvm/TargetParser/RISCVTargetParserDef.inc: No such file or directory
  29 | #include "llvm/TargetParser/RISCVTargetParserDef.inc"
     |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

These failures happen because the library LLVMTargetParser depends on
RISCVTargetParserTableGen, which is a tablegen target that generates
the list of CPUs in
llvm/TargetParser/RISCVTargetParserDef.inc. This *.inc file is
included by the public header file
llvm/TargetParser/RISCVTargetParser.h.

The header file llvm/TargetParser/RISCVTargetParser.h is also used in
components (clangDriver and clangBasic) that link into
LLVMTargetParser, but on some configurations such components might end
up being built before TargetParser is ready.

The fix is to make sure that clangDriver and clangBasic depend on the
tablegen target RISCVTargetParserTableGen, which generates the .inc
file whether or not LLVMTargetParser is ready.

WRT the original patch at https://reviews.llvm.org/D137517, this
commit is just adding RISCVTargetParserTableGen in the DEPENDS list of
clangDriver and clangBasic.
21 files changed:
clang/lib/Basic/CMakeLists.txt
clang/lib/Basic/Targets/RISCV.cpp
clang/lib/Driver/CMakeLists.txt
clang/lib/Driver/ToolChains/Arch/RISCV.cpp
llvm/include/llvm/CMakeLists.txt
llvm/include/llvm/TargetParser/CMakeLists.txt [new file with mode: 0644]
llvm/include/llvm/TargetParser/RISCVTargetParser.def [deleted file]
llvm/include/llvm/TargetParser/RISCVTargetParser.h [new file with mode: 0644]
llvm/include/llvm/TargetParser/TargetParser.h
llvm/include/llvm/module.extern.modulemap
llvm/include/llvm/module.install.modulemap
llvm/include/llvm/module.modulemap
llvm/lib/Target/RISCV/RISCV.td
llvm/lib/Target/RISCV/RISCVISelLowering.h
llvm/lib/TargetParser/CMakeLists.txt
llvm/lib/TargetParser/RISCVTargetParser.cpp [new file with mode: 0644]
llvm/lib/TargetParser/TargetParser.cpp
llvm/utils/TableGen/CMakeLists.txt
llvm/utils/TableGen/RISCVTargetDefEmitter.cpp [new file with mode: 0644]
llvm/utils/TableGen/TableGen.cpp
llvm/utils/TableGen/TableGenBackends.h