Skip to content

Conversation

@tcreech-intel
Copy link
Contributor

@tcreech-intel tcreech-intel commented Oct 23, 2025

Before llvm-profdata participated in llvm-driver it directly called InitLLVM, which takes care of wildcard argument expansion for tools on Windows. When llvm-driver support was added to llvm-profdata this InitLLVM call was effectively moved into the common llvm-driver wrapper mechanism.

More recently, in #162191, llvm-driver support was temporarily backed out of llvm-profdata due to an issue with cl::opt handling. This change reintroduces the direct call to InitLLVM in order to restore wildcard expansion and also adds a test for the wildcard expansion on Windows.

Now that llvm-profdata does not participate in llvm-driver it must
directly call InitLLVM again in order to expand wildcard arguments on
Windows.

This PR reintroduces the use of InitLLVM as it was before llvm-profdata
was moved to llvm-driver and also adds a test for the wildcard expansion
on Windows.
@tcreech-intel tcreech-intel marked this pull request as ready for review October 23, 2025 00:20
@llvmbot llvmbot added the PGO Profile Guided Optimizations label Oct 23, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 23, 2025

@llvm/pr-subscribers-pgo

Author: Tim Creech (tcreech-intel)

Changes

Now that llvm-profdata does not participate in llvm-driver it makes sense to directly call InitLLVM again in order to expand wildcard arguments on Windows.

This change reintroduces the use of InitLLVM (as it was before llvm-profdata was moved to llvm-driver) and also adds a test for the wildcard expansion on Windows.


Full diff: https://github.com/llvm/llvm-project/pull/164736.diff

2 Files Affected:

  • (added) llvm/test/tools/llvm-profdata/input-wildcard.test (+15)
  • (modified) llvm/tools/llvm-profdata/llvm-profdata.cpp (+2-1)
diff --git a/llvm/test/tools/llvm-profdata/input-wildcard.test b/llvm/test/tools/llvm-profdata/input-wildcard.test
new file mode 100644
index 0000000000000..f2c46c962a817
--- /dev/null
+++ b/llvm/test/tools/llvm-profdata/input-wildcard.test
@@ -0,0 +1,15 @@
+# This test verifies that llvm-profdata will do wildcard expansion on its
+# arguments. The expansion is done by Windows-specific support in InitLLVM, so
+# we only expect this to work on Windows hosts.
+# REQUIRES: system-windows
+
+# Create two files to glob.
+RUN: echo '# empty profile 1' >  %t.prof1.proftxt
+RUN: echo '# empty profile 2' >> %t.prof2.proftxt
+
+# Prevent LIT itself from globbing by quoting the wildcard argument.
+RUN: llvm-profdata merge "%t.*.proftxt" -dump-input-file-list -o /dev/null | FileCheck %s
+
+# Verify that llvm-profdata expanded the wildcard argument.
+CHECK: 1,{{.*}}.prof1.proftxt
+CHECK-NEXT: 1,{{.*}}.prof2.proftxt
diff --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp
index 15ddb05f953ee..a356bcd0773e0 100644
--- a/llvm/tools/llvm-profdata/llvm-profdata.cpp
+++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp
@@ -34,7 +34,7 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Format.h"
 #include "llvm/Support/FormattedStream.h"
-#include "llvm/Support/LLVMDriver.h"
+#include "llvm/Support/InitLLVM.h"
 #include "llvm/Support/MD5.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
@@ -3465,6 +3465,7 @@ static int order_main() {
 }
 
 int main(int argc, const char *argv[]) {
+  InitLLVM X(argc, argv);
   StringRef ProgName(sys::path::filename(argv[0]));
 
   if (argc < 2) {

@tcreech-intel tcreech-intel requested a review from Prabhuk October 23, 2025 00:21
@petrhosek
Copy link
Member

FWIW we want to support llvm-driver in llvm-profdata, but we first need to replace the use of cl::opt with OptTable.

@Prabhuk
Copy link
Contributor

Prabhuk commented Oct 23, 2025

@tcreech-intel -- As @petrhosek mentioned, I am working on porting llvm-profdata to OptTable so that it can be added back to the llvm driver though its a bit low on my priorities right now. Will it be alright with you if I remove this InitLLVM call when I make llvm-profdata part of the llvm-driver again?

cc: @mingmingl-llvm

@tcreech-intel
Copy link
Contributor Author

Hi @Prabhuk: yes, that's completely fine by me.

When you move back to llvm-driver an InitLLVM in llvm-profdata.cpp would be redundant with this one in llvm-driver-template.cpp:

int main(int argc, char **argv) {
llvm::InitLLVM X(argc, argv);
return @TOOL_NAME@_main(argc, argv, {argv[0], nullptr, false});
}

For my purposes I'd just like to ensure that a call to InitLLVM is preserved somewhere to do the expansion. The new test should help.

@Prabhuk
Copy link
Contributor

Prabhuk commented Oct 23, 2025

Thank you @tcreech-intel

@tcreech-intel
Copy link
Contributor Author

FWIW we want to support llvm-driver in llvm-profdata, but we first need to replace the use of cl::opt with OptTable.

Thanks, @petrhosek. I'll clarify the commit message a little to reflect that the current situation is likely temporary.

@tcreech-intel tcreech-intel merged commit 1297bf2 into llvm:main Oct 24, 2025
14 checks passed
dvbuka pushed a commit to dvbuka/llvm-project that referenced this pull request Oct 27, 2025
Before llvm-profdata participated in llvm-driver it directly called
InitLLVM, which takes care of wildcard argument expansion for tools on
Windows. When llvm-driver support was added to llvm-profdata this
InitLLVM call was effectively moved into the common llvm-driver wrapper
mechanism.

More recently, in llvm#162191, llvm-driver support was temporarily backed
out of llvm-profdata due to an issue with `cl::opt` handling. This
change reintroduces the direct call to InitLLVM in order to restore
wildcard expansion and also adds a test for the wildcard expansion on
Windows.
Lukacma pushed a commit to Lukacma/llvm-project that referenced this pull request Oct 29, 2025
Before llvm-profdata participated in llvm-driver it directly called
InitLLVM, which takes care of wildcard argument expansion for tools on
Windows. When llvm-driver support was added to llvm-profdata this
InitLLVM call was effectively moved into the common llvm-driver wrapper
mechanism.

More recently, in llvm#162191, llvm-driver support was temporarily backed
out of llvm-profdata due to an issue with `cl::opt` handling. This
change reintroduces the direct call to InitLLVM in order to restore
wildcard expansion and also adds a test for the wildcard expansion on
Windows.
aokblast pushed a commit to aokblast/llvm-project that referenced this pull request Oct 30, 2025
Before llvm-profdata participated in llvm-driver it directly called
InitLLVM, which takes care of wildcard argument expansion for tools on
Windows. When llvm-driver support was added to llvm-profdata this
InitLLVM call was effectively moved into the common llvm-driver wrapper
mechanism.

More recently, in llvm#162191, llvm-driver support was temporarily backed
out of llvm-profdata due to an issue with `cl::opt` handling. This
change reintroduces the direct call to InitLLVM in order to restore
wildcard expansion and also adds a test for the wildcard expansion on
Windows.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PGO Profile Guided Optimizations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants