[llvm] [RFC][LTO] Allow target-specific module splittting (PR #83128)

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 4 08:02:42 PST 2024


================
@@ -61,28 +100,41 @@ int main(int argc, char **argv) {
   }
 
   unsigned I = 0;
-  SplitModule(
-      *M, NumOutputs,
-      [&](std::unique_ptr<Module> MPart) {
-        std::error_code EC;
-        std::unique_ptr<ToolOutputFile> Out(new ToolOutputFile(
-            OutputFilename + utostr(I++), EC, sys::fs::OF_None));
-        if (EC) {
-          errs() << EC.message() << '\n';
-          exit(1);
-        }
-
-        if (verifyModule(*MPart, &errs())) {
-          errs() << "Broken module!\n";
-          exit(1);
-        }
-
-        WriteBitcodeToFile(*MPart, Out->os());
-
-        // Declare success.
-        Out->keep();
-      },
-      PreserveLocals);
+  const auto HandleModulePart = [&](std::unique_ptr<Module> MPart) {
+    std::error_code EC;
+    std::unique_ptr<ToolOutputFile> Out(
+        new ToolOutputFile(OutputFilename + utostr(I++), EC, sys::fs::OF_None));
+    if (EC) {
+      errs() << EC.message() << '\n';
+      exit(1);
+    }
+
+    if (verifyModule(*MPart, &errs())) {
+      errs() << "Broken module!\n";
+      exit(1);
+    }
+
+    WriteBitcodeToFile(*MPart, Out->os());
+
+    // Declare success.
+    Out->keep();
+  };
+
+  if (!TM) {
+    SplitModule(*M, NumOutputs, HandleModulePart, PreserveLocals);
+    return 0;
+  }
+
+  if (PreserveLocals) {
+    errs() << "warning: -preserve-locals has no effect when using "
+              "TargetMachine::splitModule\n";
+  }
+
+  if (!TM->splitModule(*M, NumOutputs, HandleModulePart)) {
----------------
teresajohnson wrote:

Shouldn't this be structured like in LTOBackend.cpp, i.e. where it falls back to the default SplitModule if this returns false, instead of giving an error here? I guess the tool is designed to require use of splitModule if a target is given, but allowing it to fall back would allow adding an llvm-split based test with this PR.

https://github.com/llvm/llvm-project/pull/83128


More information about the llvm-commits mailing list