This is an automated email from the ASF dual-hosted git repository.

tqchen pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm-tirx.git


The following commit(s) were added to refs/heads/main by this push:
     new 949e857d3 Reduce wheel size with section GC and direct LLVM pipelines 
(#75)
949e857d3 is described below

commit 949e857d3df09bffcd30917fd1262657033fe271
Author: Tianqi Chen <[email protected]>
AuthorDate: Sun Oct 25 20:56:13 2026 -0400

    Reduce wheel size with section GC and direct LLVM pipelines (#75)
    
    Enable function/data sections for Linux GNU/Clang TIRx targets and
    collect unreachable sections when linking shared libraries. Construct
    LLVM's standard optimization pipelines directly, preserving O0–O3
    vectorization tuning, analyses and target hooks.
    
    Use LLVM 23.1.1.post0 and Z3 5.3.1.post1 for the core and optional-wheel
    build requirements. Keep static-consumer link policy, other-platform
    flags and global RTTI/exception settings unchanged.
---
 ci/wheel/tvm-tirx-llvm-targets/pyproject.toml |  4 +-
 cmake/utils/Library.cmake                     | 10 +++++
 pyproject.toml                                |  8 ++--
 src/codegen/llvm/codegen_llvm.cc              | 58 +++++++++++++++------------
 4 files changed, 48 insertions(+), 32 deletions(-)

diff --git a/ci/wheel/tvm-tirx-llvm-targets/pyproject.toml 
b/ci/wheel/tvm-tirx-llvm-targets/pyproject.toml
index 8fd5aab46..453659942 100644
--- a/ci/wheel/tvm-tirx-llvm-targets/pyproject.toml
+++ b/ci/wheel/tvm-tirx-llvm-targets/pyproject.toml
@@ -25,8 +25,8 @@ dependencies = ["apache-tvm-tirx==0.1.0a2"]
 [build-system]
 requires = [
   "scikit-build-core>=0.11",
-  "mlc-llvm-static[all]==23.1.1",
-  "mlc-z3-static==5.3.1.post0",
+  "mlc-llvm-static[all]==23.1.1.post0",
+  "mlc-z3-static==5.3.1.post1",
 ]
 build-backend = "scikit_build_core.build"
 
diff --git a/cmake/utils/Library.cmake b/cmake/utils/Library.cmake
index 8319f38aa..949de140f 100644
--- a/cmake/utils/Library.cmake
+++ b/cmake/utils/Library.cmake
@@ -30,6 +30,16 @@ function(tvm_tirx_configure_target target)
     target_compile_options(${target} PRIVATE 
"$<$<COMPILE_LANGUAGE:C,CXX>:/Zc:inline>")
   endif()
 
+  # Give ELF shared libraries section-level reachability; keep static link 
policy unchanged.
+  if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_CXX_COMPILER_ID MATCHES 
"^(GNU|Clang)$")
+    target_compile_options(${target} PRIVATE
+      "$<$<COMPILE_LANGUAGE:C,CXX>:-ffunction-sections;-fdata-sections>")
+    get_target_property(_target_type ${target} TYPE)
+    if(_target_type STREQUAL "SHARED_LIBRARY")
+      target_link_options(${target} PRIVATE "LINKER:--gc-sections")
+    endif()
+  endif()
+
   # Keep shared libraries relocatable within their installation directory.
   if(APPLE)
     set_target_properties(${target} PROPERTIES BUILD_RPATH "@loader_path" 
INSTALL_RPATH "@loader_path")
diff --git a/pyproject.toml b/pyproject.toml
index 7c47448c5..a47c238c8 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -66,8 +66,8 @@ build = [
   "scikit-build-core>=0.11,!=1.1.0",
   "setuptools-scm>=8",
   "cython>=3.2.8",
-  "mlc-llvm-static[all]==23.1.1",
-  "mlc-z3-static==5.3.1.post0",
+  "mlc-llvm-static[all]==23.1.1.post0",
+  "mlc-z3-static==5.3.1.post1",
 ]
 torch = [
   "torch",
@@ -104,8 +104,8 @@ tvm-tirx-config = "tvm_tirx.config:__main__"
 # Static development SDKs are build requirements, not runtime dependencies.
 requires = [
   "scikit-build-core>=0.11",
-  "mlc-llvm-static[all]==23.1.1",
-  "mlc-z3-static==5.3.1.post0",
+  "mlc-llvm-static[all]==23.1.1.post0",
+  "mlc-z3-static==5.3.1.post1",
 ]
 build-backend = "scikit_build_core.build"
 
diff --git a/src/codegen/llvm/codegen_llvm.cc b/src/codegen/llvm/codegen_llvm.cc
index 14e411392..301ca6fa6 100644
--- a/src/codegen/llvm/codegen_llvm.cc
+++ b/src/codegen/llvm/codegen_llvm.cc
@@ -432,56 +432,61 @@ void CodeGenLLVM::Optimize() {
   bool debug_logging = false;
   bool verify_each = false;
 
-  llvm::PipelineTuningOptions pto = llvm::PipelineTuningOptions();
-  llvm::PassInstrumentationCallbacks pic;
-  llvm::PassBuilder builder(tm, pto, std::nullopt, &pic);
-
-  llvm::LoopAnalysisManager lam;
-  llvm::FunctionAnalysisManager fam;
-  llvm::CGSCCAnalysisManager cgam;
-  llvm::ModuleAnalysisManager mam;
-  builder.registerLoopAnalyses(lam);
-  builder.registerFunctionAnalyses(fam);
-  builder.registerCGSCCAnalyses(cgam);
-  builder.registerModuleAnalyses(mam);
-  builder.crossRegisterProxies(lam, fam, cgam, mam);
-
   // Construct the default pass pipeline depending on the opt level.
-  std::string pipeline;
+  llvm::OptimizationLevel optimization_level = llvm::OptimizationLevel::O3;
 #if TVM_LLVM_VERSION <= 170
   switch (llvm_target_->GetOptLevel()) {
     case llvm::CodeGenOpt::Level::None:
-      pipeline = "default<O0>";
+      optimization_level = llvm::OptimizationLevel::O0;
       break;
     case llvm::CodeGenOpt::Level::Less:
-      pipeline = "default<O1>";
+      optimization_level = llvm::OptimizationLevel::O1;
       break;
     case llvm::CodeGenOpt::Level::Default:
-      pipeline = "default<O2>";
+      optimization_level = llvm::OptimizationLevel::O2;
       break;
     default:
       // CodeGenOpt::Level::Aggressive
-      pipeline = "default<O3>";
+      optimization_level = llvm::OptimizationLevel::O3;
       break;
   }
 #else
   switch (llvm_target_->GetOptLevel()) {
     case llvm::CodeGenOptLevel::None:
-      pipeline = "default<O0>";
+      optimization_level = llvm::OptimizationLevel::O0;
       break;
     case llvm::CodeGenOptLevel::Less:
-      pipeline = "default<O1>";
+      optimization_level = llvm::OptimizationLevel::O1;
       break;
     case llvm::CodeGenOptLevel::Default:
-      pipeline = "default<O2>";
+      optimization_level = llvm::OptimizationLevel::O2;
       break;
     default:
       // CodeGenOptLevel::Aggressive
-      pipeline = "default<O3>";
+      optimization_level = llvm::OptimizationLevel::O3;
       break;
   }
 #endif
 
+  llvm::PipelineTuningOptions pto = llvm::PipelineTuningOptions();
+  // Match the vectorization tuning applied by the default<O0/O1/O2/O3> 
aliases.
+  bool enable_vectorization = optimization_level == 
llvm::OptimizationLevel::O2 ||
+                              optimization_level == 
llvm::OptimizationLevel::O3;
+  pto.LoopVectorization = enable_vectorization;
+  pto.SLPVectorization = enable_vectorization;
+  llvm::PassInstrumentationCallbacks pic;
+  llvm::PassBuilder builder(tm, pto, std::nullopt, &pic);
+
+  llvm::LoopAnalysisManager lam;
+  llvm::FunctionAnalysisManager fam;
+  llvm::CGSCCAnalysisManager cgam;
+  llvm::ModuleAnalysisManager mam;
+  builder.registerLoopAnalyses(lam);
+  builder.registerFunctionAnalyses(fam);
+  builder.registerCGSCCAnalyses(cgam);
+  builder.registerModuleAnalyses(mam);
+  builder.crossRegisterProxies(lam, fam, cgam, mam);
+
   llvm::StandardInstrumentations si(*llvm_target_->GetContext(), 
debug_logging, verify_each);
 #if LLVM_VERSION_MAJOR >= 17
   si.registerCallbacks(pic, &mam);
@@ -492,9 +497,10 @@ void CodeGenLLVM::Optimize() {
   if (verify_each) {
     mpass.addPass(llvm::VerifierPass());
   }
-  if (auto err = builder.parsePassPipeline(mpass, pipeline)) {
-    TVM_FFI_THROW(InternalError) << "error parsing pass pipeline '" << pipeline
-                                 << "':" << llvm::toString(std::move(err)) << 
'\n';
+  if (optimization_level == llvm::OptimizationLevel::O0) {
+    mpass.addPass(builder.buildO0DefaultPipeline(optimization_level));
+  } else {
+    mpass.addPass(builder.buildPerModuleDefaultPipeline(optimization_level));
   }
 
   mpass.run(*module_, mam);

Reply via email to