[llvm] 4fe912f - Build: Move TF source file inclusion from build system to source files

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 21 10:02:48 PDT 2020


Author: Nico Weber
Date: 2020-07-21T13:02:34-04:00
New Revision: 4fe912f1868c196cce24b40d3eee21da3d7cd28c

URL: https://github.com/llvm/llvm-project/commit/4fe912f1868c196cce24b40d3eee21da3d7cd28c
DIFF: https://github.com/llvm/llvm-project/commit/4fe912f1868c196cce24b40d3eee21da3d7cd28c.diff

LOG: Build: Move TF source file inclusion from build system to source files

Outside of compiler-rt (where it's arguably an anti-pattern too),
LLVM tries to keep its build files as simple as possible. See e.g.
llvm/docs/SupportLibrary.rst, "Code Organization".

Differential Revision: https://reviews.llvm.org/D84243

Added: 
    

Modified: 
    llvm/include/llvm/Config/config.h.cmake
    llvm/lib/Analysis/CMakeLists.txt
    llvm/lib/Analysis/DevelopmentModeInlineAdvisor.cpp
    llvm/lib/Analysis/MLInlineAdvisor.cpp
    llvm/lib/Analysis/ReleaseModeModelRunner.cpp
    llvm/lib/Analysis/TFUtils.cpp
    llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
    llvm/utils/gn/secondary/llvm/lib/Analysis/BUILD.gn

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Config/config.h.cmake b/llvm/include/llvm/Config/config.h.cmake
index 290f74bd02d2..7e037fdb7075 100644
--- a/llvm/include/llvm/Config/config.h.cmake
+++ b/llvm/include/llvm/Config/config.h.cmake
@@ -347,4 +347,7 @@
 /* Whether Timers signpost passes in Xcode Instruments */
 #cmakedefine01 LLVM_SUPPORT_XCODE_SIGNPOSTS
 
+/* Define if LLVM was built with a dependency to the tensorflow compiler */
+#cmakedefine LLVM_HAVE_TF_AOT
+
 #endif

diff  --git a/llvm/lib/Analysis/CMakeLists.txt b/llvm/lib/Analysis/CMakeLists.txt
index 4f10e8de0258..4d7eeaf910eb 100644
--- a/llvm/lib/Analysis/CMakeLists.txt
+++ b/llvm/lib/Analysis/CMakeLists.txt
@@ -1,38 +1,17 @@
-set(CommonMLSources MLInlineAdvisor.cpp)
-set(ReleaseModeMLSources ReleaseModeModelRunner.cpp)
-set(DevelopmentModeMLSources
-  DevelopmentModeInlineAdvisor.cpp
-  TFUtils.cpp
-  )
-
 if (DEFINED LLVM_HAVE_TF_AOT OR DEFINED LLVM_HAVE_TF_API)
-  set(MLPolicySources ${CommonMLSources})
   if (DEFINED LLVM_HAVE_TF_AOT)
     include(TensorFlowCompile)
     tfcompile(models/inliner serve action InlinerSizeModel llvm::InlinerSizeModel)
-    list(APPEND ReleaseModeMLSources
+    list(APPEND GeneratedMLSources
       $<TARGET_OBJECTS:tf_xla_runtime_objects>
       ${GENERATED_OBJS}
     )
-    LIST(APPEND MLPolicySources ${ReleaseModeMLSources})
-  else()
-    LIST(APPEND LLVM_OPTIONAL_SOURCES ${ReleaseModeMLSources})
   endif()
 
   if (DEFINED LLVM_HAVE_TF_API)
-    LIST(APPEND MLPolicySources ${DevelopmentModeMLSources})
     LIST(APPEND MLLinkDeps ${tensorflow_c_api})
-  else()
-    LIST(APPEND LLVM_OPTIONAL_SOURCES ${DevelopmentModeMLSources})
   endif()
-else()
-  LIST(APPEND LLVM_OPTIONAL_SOURCES 
-    ${CommonMLSources}
-    ${DevelopmentModeMLSources}
-    ${ReleaseModeMLSources}
-    )
 endif()
-  
 
 add_llvm_component_library(LLVMAnalysis
   AliasAnalysis.cpp
@@ -64,6 +43,7 @@ add_llvm_component_library(LLVMAnalysis
   DemandedBits.cpp
   DependenceAnalysis.cpp
   DependenceGraphBuilder.cpp
+  DevelopmentModeInlineAdvisor.cpp
   DivergenceAnalysis.cpp
   DomPrinter.cpp
   DomTreeUpdater.cpp
@@ -98,6 +78,7 @@ add_llvm_component_library(LLVMAnalysis
   LoopUnrollAnalyzer.cpp
   LoopInfo.cpp
   LoopPass.cpp
+  MLInlineAdvisor.cpp
   MemDepPrinter.cpp
   MemDerefPrinter.cpp
   MemoryBuiltins.cpp
@@ -120,6 +101,7 @@ add_llvm_component_library(LLVMAnalysis
   RegionInfo.cpp
   RegionPass.cpp
   RegionPrinter.cpp
+  ReleaseModeModelRunner.cpp
   ScalarEvolution.cpp
   ScalarEvolutionAliasAnalysis.cpp
   ScalarEvolutionDivision.cpp
@@ -128,6 +110,7 @@ add_llvm_component_library(LLVMAnalysis
   StackSafetyAnalysis.cpp
   SyncDependenceAnalysis.cpp
   SyntheticCountsUtils.cpp
+  TFUtils.cpp
   TargetLibraryInfo.cpp
   TargetTransformInfo.cpp
   Trace.cpp
@@ -139,7 +122,7 @@ add_llvm_component_library(LLVMAnalysis
   ValueTracking.cpp
   VectorUtils.cpp
   VFABIDemangling.cpp
-  ${MLPolicySources}
+  ${GeneratedMLSources}
 
   ADDITIONAL_HEADER_DIRS
   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Analysis

diff  --git a/llvm/lib/Analysis/DevelopmentModeInlineAdvisor.cpp b/llvm/lib/Analysis/DevelopmentModeInlineAdvisor.cpp
index 954fc49a8663..ba9343543dbb 100644
--- a/llvm/lib/Analysis/DevelopmentModeInlineAdvisor.cpp
+++ b/llvm/lib/Analysis/DevelopmentModeInlineAdvisor.cpp
@@ -11,6 +11,9 @@
 // loading of a model from a command line option.
 //
 //===----------------------------------------------------------------------===//
+#include "llvm/Config/config.h"
+#if defined(LLVM_HAVE_TF_API)
+
 #include "llvm/Analysis/CallGraph.h"
 #include "llvm/Analysis/InlineSizeEstimatorAnalysis.h"
 #include "llvm/Analysis/MLInlineAdvisor.h"
@@ -482,4 +485,5 @@ std::unique_ptr<InlineAdvisor> llvm::getDevelopmentModeAdvisor(
   }
   return std::make_unique<DevelopmentModeMLInlineAdvisor>(
       M, MAM, std::move(Runner), GetDefaultAdvice, IsDoingInference);
-}
\ No newline at end of file
+}
+#endif // defined(LLVM_HAVE_TF_API)

diff  --git a/llvm/lib/Analysis/MLInlineAdvisor.cpp b/llvm/lib/Analysis/MLInlineAdvisor.cpp
index 45873f260f23..31cb43baf9a5 100644
--- a/llvm/lib/Analysis/MLInlineAdvisor.cpp
+++ b/llvm/lib/Analysis/MLInlineAdvisor.cpp
@@ -11,6 +11,9 @@
 // 'release' mode) or a runtime-loaded model (the 'development' case).
 //
 //===----------------------------------------------------------------------===//
+#include "llvm/Config/config.h"
+#if defined(LLVM_HAVE_TF_AOT) || defined(LLVM_HAVE_TF_API)
+
 #include <limits>
 #include <unordered_map>
 #include <unordered_set>
@@ -298,4 +301,5 @@ void MLInlineAdvice::recordUnattemptedInliningImpl() {
     reportContextForRemark(R);
     return R;
   });
-}
\ No newline at end of file
+}
+#endif // defined(LLVM_HAVE_TF_AOT) || defined(LLVM_HAVE_TF_API)

diff  --git a/llvm/lib/Analysis/ReleaseModeModelRunner.cpp b/llvm/lib/Analysis/ReleaseModeModelRunner.cpp
index 4c0ffbc17ff7..af300fb71b4b 100644
--- a/llvm/lib/Analysis/ReleaseModeModelRunner.cpp
+++ b/llvm/lib/Analysis/ReleaseModeModelRunner.cpp
@@ -10,6 +10,8 @@
 // Only inference is supported.
 //
 //===----------------------------------------------------------------------===//
+#include "llvm/Config/config.h"
+#if defined(LLVM_HAVE_TF_AOT)
 
 #include "llvm/Analysis/InlineModelFeatureMaps.h"
 #include "llvm/Analysis/MLInlineAdvisor.h"
@@ -85,3 +87,4 @@ llvm::getReleaseModeAdvisor(Module &M, ModuleAnalysisManager &MAM) {
   auto AOTRunner = std::make_unique<ReleaseModeModelRunner>(M.getContext());
   return std::make_unique<MLInlineAdvisor>(M, MAM, std::move(AOTRunner));
 }
+#endif // defined(LLVM_HAVE_TF_AOT)

diff  --git a/llvm/lib/Analysis/TFUtils.cpp b/llvm/lib/Analysis/TFUtils.cpp
index 19e6d626e238..a6f5b2956399 100644
--- a/llvm/lib/Analysis/TFUtils.cpp
+++ b/llvm/lib/Analysis/TFUtils.cpp
@@ -10,6 +10,8 @@
 // This file implements utilities for interfacing with tensorflow C APIs.
 //
 //===----------------------------------------------------------------------===//
+#include "llvm/Config/config.h"
+#if defined(LLVM_HAVE_TF_API)
 
 #include "llvm/Analysis/Utils/TFUtils.h"
 #include "llvm/ADT/Twine.h"
@@ -287,3 +289,4 @@ template <> int TFModelEvaluator::getModelTypeIndex<uint64_t>() {
 
 TFModelEvaluator::EvaluationResult::~EvaluationResult() {}
 TFModelEvaluator::~TFModelEvaluator() {}
+#endif // defined(LLVM_HAVE_TF_API)

diff  --git a/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn b/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
index 096812db893a..81da62eff174 100644
--- a/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
@@ -124,6 +124,7 @@ write_cmake_config("config") {
     "RETSIGTYPE=void",
     "LLVM_GISEL_COV_ENABLED=",
     "LLVM_GISEL_COV_PREFIX=",
+    "LLVM_HAVE_TF_AOT=",
     "LLVM_WITH_Z3=",
 
     # FIXME: Set to 1 on mac once the 10.14 SDK is in common use.

diff  --git a/llvm/utils/gn/secondary/llvm/lib/Analysis/BUILD.gn b/llvm/utils/gn/secondary/llvm/lib/Analysis/BUILD.gn
index 1a339b6d4cfd..c2f79568b6de 100644
--- a/llvm/utils/gn/secondary/llvm/lib/Analysis/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/lib/Analysis/BUILD.gn
@@ -41,6 +41,7 @@ static_library("Analysis") {
     "DemandedBits.cpp",
     "DependenceAnalysis.cpp",
     "DependenceGraphBuilder.cpp",
+    "DevelopmentModeInlineAdvisor.cpp",
     "DivergenceAnalysis.cpp",
     "DomPrinter.cpp",
     "DomTreeUpdater.cpp",
@@ -75,6 +76,7 @@ static_library("Analysis") {
     "LoopNestAnalysis.cpp",
     "LoopPass.cpp",
     "LoopUnrollAnalyzer.cpp",
+    "MLInlineAdvisor.cpp",
     "MemDepPrinter.cpp",
     "MemDerefPrinter.cpp",
     "MemoryBuiltins.cpp",
@@ -97,6 +99,7 @@ static_library("Analysis") {
     "RegionInfo.cpp",
     "RegionPass.cpp",
     "RegionPrinter.cpp",
+    "ReleaseModeModelRunner.cpp",
     "ScalarEvolution.cpp",
     "ScalarEvolutionAliasAnalysis.cpp",
     "ScalarEvolutionDivision.cpp",
@@ -106,6 +109,7 @@ static_library("Analysis") {
     "StackSafetyAnalysis.cpp",
     "SyncDependenceAnalysis.cpp",
     "SyntheticCountsUtils.cpp",
+    "TFUtils.cpp",
     "TargetLibraryInfo.cpp",
     "TargetTransformInfo.cpp",
     "Trace.cpp",
@@ -118,10 +122,3 @@ static_library("Analysis") {
     "VectorUtils.cpp",
   ]
 }
-
-static_library("TensorFlow") {
-  sources = [
-    "DevelopmentModeInlineAdvisor.cpp",
-    "TFUtils.cpp",
-  ]
-}


        


More information about the llvm-commits mailing list