[lld] [lld][ELF] Extend profile guided function ordering to ELF binaries (PR #117514)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 29 22:53:21 PST 2024


================
@@ -1255,6 +1255,45 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
       ctx.arg.bsymbolic = BsymbolicKind::All;
   }
   ctx.arg.callGraphProfileSort = getCGProfileSortKind(ctx, args);
+  ctx.arg.irpgoProfileSortProfilePath =
+      args.getLastArgValue(OPT_irpgo_profile_sort);
+  ctx.arg.compressionSortStartupFunctions =
+      args.hasFlag(OPT_compression_sort_startup_functions,
+                   OPT_no_compression_sort_startup_functions, false);
+  if (!ctx.arg.irpgoProfileSortProfilePath.empty()) {
+    if (args.getLastArg(OPT_call_graph_ordering_file) != nullptr) {
+      ErrAlways(ctx) << "--irpgo-profile-sort is incompatible with "
+                        "--call-graph-ordering-file";
+    }
+  } else {
+    if (ctx.arg.compressionSortStartupFunctions)
+      ErrAlways(ctx)
+          << "--compression-sort-startup-functions must be used with "
+             "--irpgo-profile-sort";
+  }
+
+  if (auto *arg = args.getLastArg(OPT_compression_sort)) {
+    StringRef compressionSortStr = arg->getValue();
+    if (compressionSortStr == "function") {
+      ctx.arg.functionOrderForCompression = true;
+    } else if (compressionSortStr == "data") {
+      ctx.arg.dataOrderForCompression = true;
+    } else if (compressionSortStr == "both") {
+      ctx.arg.functionOrderForCompression = true;
+      ctx.arg.dataOrderForCompression = true;
+    } else if (compressionSortStr != "none") {
+      ErrAlways(ctx) << "unknown value `" + compressionSortStr + "` for " +
----------------
MaskRay wrote:

we use single quotes 

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


More information about the llvm-commits mailing list