[llvm] [llvm-(min-)tblgen] Avoid redundant source compilation (PR #114494)

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 16 01:35:30 PST 2024


https://github.com/Meinersbur updated https://github.com/llvm/llvm-project/pull/114494

>From 94dd647c3c405f5622243aab4447cdcb0194f63d Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Fri, 1 Nov 2024 01:40:07 +0100
Subject: [PATCH 1/4] [llvm-(min-)tblgen] Avoid redundant source compilation

---
 llvm/utils/TableGen/CMakeLists.txt | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/llvm/utils/TableGen/CMakeLists.txt b/llvm/utils/TableGen/CMakeLists.txt
index ba1e4aa01b48d6..5a460034bd9fd7 100644
--- a/llvm/utils/TableGen/CMakeLists.txt
+++ b/llvm/utils/TableGen/CMakeLists.txt
@@ -7,11 +7,8 @@ add_subdirectory(Common)
 
 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
+# Sources included in llvm-min-tblgen and llvm-tblgen.
+add_llvm_library(LLVMTableGenBoth OBJECT EXCLUDE_FROM_ALL DISABLE_LLVM_LINK_LLVM_DYLIB
   TableGen.cpp
   ARMTargetDefEmitter.cpp
   Attributes.cpp
@@ -19,6 +16,16 @@ add_tablegen(llvm-min-tblgen LLVM_HEADERS
   IntrinsicEmitter.cpp
   RISCVTargetDefEmitter.cpp
   VTEmitter.cpp
+
+  PARTIAL_SOURCES_INTENDED
+  )
+
+# 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
+  $<TARGET_OBJECTS:obj.LLVMTableGenBoth>
   $<TARGET_OBJECTS:obj.LLVMTableGenBasic>
 
   PARTIAL_SOURCES_INTENDED
@@ -32,10 +39,8 @@ set(LLVM_LINK_COMPONENTS
 add_tablegen(llvm-tblgen LLVM
   DESTINATION "${LLVM_TOOLS_INSTALL_DIR}"
   EXPORT LLVM
-  ARMTargetDefEmitter.cpp
   AsmMatcherEmitter.cpp
   AsmWriterEmitter.cpp
-  Attributes.cpp
   CallingConvEmitter.cpp
   CodeEmitterGen.cpp
   CodeGenMapTable.cpp
@@ -48,7 +53,6 @@ add_tablegen(llvm-tblgen LLVM
   DecoderEmitter.cpp
   DFAEmitter.cpp
   DFAPacketizerEmitter.cpp
-  DirectiveEmitter.cpp
   DisassemblerEmitter.cpp
   DXILEmitter.cpp
   ExegesisEmitter.cpp
@@ -57,18 +61,14 @@ add_tablegen(llvm-tblgen LLVM
   GlobalISelEmitter.cpp
   InstrDocsEmitter.cpp
   InstrInfoEmitter.cpp
-  IntrinsicEmitter.cpp
   MacroFusionPredicatorEmitter.cpp
   OptionParserEmitter.cpp
   OptionRSTEmitter.cpp
   PseudoLoweringEmitter.cpp
   RegisterBankEmitter.cpp
   RegisterInfoEmitter.cpp
-  RISCVTargetDefEmitter.cpp
   SearchableTableEmitter.cpp
   SubtargetEmitter.cpp
-  TableGen.cpp
-  VTEmitter.cpp
   WebAssemblyDisassemblerEmitter.cpp
   X86InstrMappingEmitter.cpp
   X86DisassemblerTables.cpp
@@ -76,6 +76,8 @@ add_tablegen(llvm-tblgen LLVM
   X86MnemonicTables.cpp
   X86ModRMFilters.cpp
   X86RecognizableInstr.cpp
+
+  $<TARGET_OBJECTS:obj.LLVMTableGenBoth>
   $<TARGET_OBJECTS:obj.LLVMTableGenBasic>
   $<TARGET_OBJECTS:obj.LLVMTableGenCommon>
 

>From a35bd890af2e9492dfff6e2c6dc4f1ec8838949c Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Fri, 1 Nov 2024 02:04:26 +0100
Subject: [PATCH 2/4] No additional object library necessary

---
 llvm/utils/TableGen/CMakeLists.txt | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/llvm/utils/TableGen/CMakeLists.txt b/llvm/utils/TableGen/CMakeLists.txt
index 5a460034bd9fd7..ded2e228dcd6de 100644
--- a/llvm/utils/TableGen/CMakeLists.txt
+++ b/llvm/utils/TableGen/CMakeLists.txt
@@ -7,8 +7,11 @@ add_subdirectory(Common)
 
 set(LLVM_LINK_COMPONENTS Support)
 
-# Sources included in llvm-min-tblgen and llvm-tblgen.
-add_llvm_library(LLVMTableGenBoth OBJECT EXCLUDE_FROM_ALL DISABLE_LLVM_LINK_LLVM_DYLIB
+# 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
   ARMTargetDefEmitter.cpp
   Attributes.cpp
@@ -16,16 +19,6 @@ add_llvm_library(LLVMTableGenBoth OBJECT EXCLUDE_FROM_ALL DISABLE_LLVM_LINK_LLVM
   IntrinsicEmitter.cpp
   RISCVTargetDefEmitter.cpp
   VTEmitter.cpp
-
-  PARTIAL_SOURCES_INTENDED
-  )
-
-# 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
-  $<TARGET_OBJECTS:obj.LLVMTableGenBoth>
   $<TARGET_OBJECTS:obj.LLVMTableGenBasic>
 
   PARTIAL_SOURCES_INTENDED
@@ -77,7 +70,7 @@ add_tablegen(llvm-tblgen LLVM
   X86ModRMFilters.cpp
   X86RecognizableInstr.cpp
 
-  $<TARGET_OBJECTS:obj.LLVMTableGenBoth>
+  $<TARGET_OBJECTS:llvm-min-tblgen>
   $<TARGET_OBJECTS:obj.LLVMTableGenBasic>
   $<TARGET_OBJECTS:obj.LLVMTableGenCommon>
 

>From 3234b527ef3317a9014196b7d7ef906690bbc2b9 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Mon, 4 Nov 2024 17:06:43 +0100
Subject: [PATCH 3/4] Revert "No additional object library necessary"

This reverts commit a35bd890af2e9492dfff6e2c6dc4f1ec8838949c.
---
 llvm/utils/TableGen/CMakeLists.txt | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/llvm/utils/TableGen/CMakeLists.txt b/llvm/utils/TableGen/CMakeLists.txt
index ded2e228dcd6de..5a460034bd9fd7 100644
--- a/llvm/utils/TableGen/CMakeLists.txt
+++ b/llvm/utils/TableGen/CMakeLists.txt
@@ -7,11 +7,8 @@ add_subdirectory(Common)
 
 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
+# Sources included in llvm-min-tblgen and llvm-tblgen.
+add_llvm_library(LLVMTableGenBoth OBJECT EXCLUDE_FROM_ALL DISABLE_LLVM_LINK_LLVM_DYLIB
   TableGen.cpp
   ARMTargetDefEmitter.cpp
   Attributes.cpp
@@ -19,6 +16,16 @@ add_tablegen(llvm-min-tblgen LLVM_HEADERS
   IntrinsicEmitter.cpp
   RISCVTargetDefEmitter.cpp
   VTEmitter.cpp
+
+  PARTIAL_SOURCES_INTENDED
+  )
+
+# 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
+  $<TARGET_OBJECTS:obj.LLVMTableGenBoth>
   $<TARGET_OBJECTS:obj.LLVMTableGenBasic>
 
   PARTIAL_SOURCES_INTENDED
@@ -70,7 +77,7 @@ add_tablegen(llvm-tblgen LLVM
   X86ModRMFilters.cpp
   X86RecognizableInstr.cpp
 
-  $<TARGET_OBJECTS:llvm-min-tblgen>
+  $<TARGET_OBJECTS:obj.LLVMTableGenBoth>
   $<TARGET_OBJECTS:obj.LLVMTableGenBasic>
   $<TARGET_OBJECTS:obj.LLVMTableGenCommon>
 

>From 4d3124341492c1eafb22f85e3c71958f058c8962 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Mon, 4 Nov 2024 17:33:14 +0100
Subject: [PATCH 4/4] Move common files to TabeGenBasic

---
 .../{ => Basic}/ARMTargetDefEmitter.cpp       |  0
 .../utils/TableGen/{ => Basic}/Attributes.cpp |  0
 llvm/utils/TableGen/Basic/CMakeLists.txt      |  7 +++++++
 .../TableGen/{ => Basic}/DirectiveEmitter.cpp |  0
 .../TableGen/{ => Basic}/IntrinsicEmitter.cpp |  4 ++--
 .../{ => Basic}/RISCVTargetDefEmitter.cpp     |  0
 llvm/utils/TableGen/{ => Basic}/TableGen.cpp  |  0
 llvm/utils/TableGen/{ => Basic}/VTEmitter.cpp |  0
 llvm/utils/TableGen/CMakeLists.txt            | 21 +++----------------
 9 files changed, 12 insertions(+), 20 deletions(-)
 rename llvm/utils/TableGen/{ => Basic}/ARMTargetDefEmitter.cpp (100%)
 rename llvm/utils/TableGen/{ => Basic}/Attributes.cpp (100%)
 rename llvm/utils/TableGen/{ => Basic}/DirectiveEmitter.cpp (100%)
 rename llvm/utils/TableGen/{ => Basic}/IntrinsicEmitter.cpp (99%)
 rename llvm/utils/TableGen/{ => Basic}/RISCVTargetDefEmitter.cpp (100%)
 rename llvm/utils/TableGen/{ => Basic}/TableGen.cpp (100%)
 rename llvm/utils/TableGen/{ => Basic}/VTEmitter.cpp (100%)

diff --git a/llvm/utils/TableGen/ARMTargetDefEmitter.cpp b/llvm/utils/TableGen/Basic/ARMTargetDefEmitter.cpp
similarity index 100%
rename from llvm/utils/TableGen/ARMTargetDefEmitter.cpp
rename to llvm/utils/TableGen/Basic/ARMTargetDefEmitter.cpp
diff --git a/llvm/utils/TableGen/Attributes.cpp b/llvm/utils/TableGen/Basic/Attributes.cpp
similarity index 100%
rename from llvm/utils/TableGen/Attributes.cpp
rename to llvm/utils/TableGen/Basic/Attributes.cpp
diff --git a/llvm/utils/TableGen/Basic/CMakeLists.txt b/llvm/utils/TableGen/Basic/CMakeLists.txt
index 41d737e8d418e2..b058fba78eb05a 100644
--- a/llvm/utils/TableGen/Basic/CMakeLists.txt
+++ b/llvm/utils/TableGen/Basic/CMakeLists.txt
@@ -9,8 +9,15 @@ set(LLVM_LINK_COMPONENTS
   )
 
 add_llvm_library(LLVMTableGenBasic OBJECT EXCLUDE_FROM_ALL DISABLE_LLVM_LINK_LLVM_DYLIB
+  ARMTargetDefEmitter.cpp
+  Attributes.cpp
   CodeGenIntrinsics.cpp
+  DirectiveEmitter.cpp
+  IntrinsicEmitter.cpp
+  RISCVTargetDefEmitter.cpp
   SDNodeProperties.cpp
+  TableGen.cpp
+  VTEmitter.cpp
 )
 
 # Users may include its headers as "Basic/*.h"
diff --git a/llvm/utils/TableGen/DirectiveEmitter.cpp b/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
similarity index 100%
rename from llvm/utils/TableGen/DirectiveEmitter.cpp
rename to llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
diff --git a/llvm/utils/TableGen/IntrinsicEmitter.cpp b/llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp
similarity index 99%
rename from llvm/utils/TableGen/IntrinsicEmitter.cpp
rename to llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp
index 070d7522a97be9..5097efcdce4cd3 100644
--- a/llvm/utils/TableGen/IntrinsicEmitter.cpp
+++ b/llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp
@@ -10,8 +10,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "Basic/CodeGenIntrinsics.h"
-#include "Basic/SequenceToOffsetTable.h"
+#include "CodeGenIntrinsics.h"
+#include "SequenceToOffsetTable.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
diff --git a/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp b/llvm/utils/TableGen/Basic/RISCVTargetDefEmitter.cpp
similarity index 100%
rename from llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
rename to llvm/utils/TableGen/Basic/RISCVTargetDefEmitter.cpp
diff --git a/llvm/utils/TableGen/TableGen.cpp b/llvm/utils/TableGen/Basic/TableGen.cpp
similarity index 100%
rename from llvm/utils/TableGen/TableGen.cpp
rename to llvm/utils/TableGen/Basic/TableGen.cpp
diff --git a/llvm/utils/TableGen/VTEmitter.cpp b/llvm/utils/TableGen/Basic/VTEmitter.cpp
similarity index 100%
rename from llvm/utils/TableGen/VTEmitter.cpp
rename to llvm/utils/TableGen/Basic/VTEmitter.cpp
diff --git a/llvm/utils/TableGen/CMakeLists.txt b/llvm/utils/TableGen/CMakeLists.txt
index 5a460034bd9fd7..31e1cf41971340 100644
--- a/llvm/utils/TableGen/CMakeLists.txt
+++ b/llvm/utils/TableGen/CMakeLists.txt
@@ -5,27 +5,14 @@ add_subdirectory(Basic)
 # code needed by the backends.
 add_subdirectory(Common)
 
-set(LLVM_LINK_COMPONENTS Support)
-
-# Sources included in llvm-min-tblgen and llvm-tblgen.
-add_llvm_library(LLVMTableGenBoth OBJECT EXCLUDE_FROM_ALL DISABLE_LLVM_LINK_LLVM_DYLIB
-  TableGen.cpp
-  ARMTargetDefEmitter.cpp
-  Attributes.cpp
-  DirectiveEmitter.cpp
-  IntrinsicEmitter.cpp
-  RISCVTargetDefEmitter.cpp
-  VTEmitter.cpp
-
-  PARTIAL_SOURCES_INTENDED
-  )
-
 # 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.
+# Sources included in both, llvm-min-tblgen and llvm-tblgen, must be included
+# into LLVMTableGenBasic to avoid redundant compilation and problems with build
+# caches.
 add_tablegen(llvm-min-tblgen LLVM_HEADERS
-  $<TARGET_OBJECTS:obj.LLVMTableGenBoth>
   $<TARGET_OBJECTS:obj.LLVMTableGenBasic>
 
   PARTIAL_SOURCES_INTENDED
@@ -76,8 +63,6 @@ add_tablegen(llvm-tblgen LLVM
   X86MnemonicTables.cpp
   X86ModRMFilters.cpp
   X86RecognizableInstr.cpp
-
-  $<TARGET_OBJECTS:obj.LLVMTableGenBoth>
   $<TARGET_OBJECTS:obj.LLVMTableGenBasic>
   $<TARGET_OBJECTS:obj.LLVMTableGenCommon>
 



More information about the llvm-commits mailing list