Skip to content

Conversation

@svkeerthy
Copy link
Contributor

@svkeerthy svkeerthy commented Oct 17, 2025

Standardize error message formatting in llvm-ir2vec tool using WithColor for consistent error reporting.

Copy link
Contributor Author

svkeerthy commented Oct 17, 2025

@svkeerthy svkeerthy marked this pull request as ready for review October 17, 2025 23:27
@llvmbot llvmbot added the mlgo label Oct 17, 2025
@svkeerthy svkeerthy requested a review from mtrofin October 17, 2025 23:27
@llvmbot
Copy link
Member

llvmbot commented Oct 17, 2025

@llvm/pr-subscribers-mlgo

Author: S. VenkataKeerthy (svkeerthy)

Changes

Standardize error message formatting in llvm-ir2vec tool using WithColor for consistent error reporting.


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

6 Files Affected:

  • (modified) llvm/test/tools/llvm-ir2vec/embeddings-flowaware.ll (+1-1)
  • (modified) llvm/test/tools/llvm-ir2vec/embeddings-symbolic.ll (+1-1)
  • (modified) llvm/test/tools/llvm-ir2vec/embeddings-symbolic.mir (+1-1)
  • (modified) llvm/test/tools/llvm-ir2vec/error-handling.ll (+1-1)
  • (modified) llvm/test/tools/llvm-ir2vec/error-handling.mir (+4-4)
  • (modified) llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp (+28-19)
diff --git a/llvm/test/tools/llvm-ir2vec/embeddings-flowaware.ll b/llvm/test/tools/llvm-ir2vec/embeddings-flowaware.ll
index b2362f83caf4f..ade228d7a3665 100644
--- a/llvm/test/tools/llvm-ir2vec/embeddings-flowaware.ll
+++ b/llvm/test/tools/llvm-ir2vec/embeddings-flowaware.ll
@@ -49,7 +49,7 @@ entry:
 ; CHECK-FUNC-LEVEL-ABC: Function: abc
 ; CHECK-FUNC-LEVEL-NEXT-ABC:  [ 3630.00  3672.00  3714.00 ]
 
-; CHECK-FUNC-DEF: Error: Function 'def' not found
+; CHECK-FUNC-DEF: error: Function 'def' not found
 
 ; CHECK-BB-LEVEL: Function: abc
 ; CHECK-BB-LEVEL-NEXT: entry: [ 3630.00  3672.00  3714.00 ]
diff --git a/llvm/test/tools/llvm-ir2vec/embeddings-symbolic.ll b/llvm/test/tools/llvm-ir2vec/embeddings-symbolic.ll
index f9aa10817e360..9d60e12e8ab90 100644
--- a/llvm/test/tools/llvm-ir2vec/embeddings-symbolic.ll
+++ b/llvm/test/tools/llvm-ir2vec/embeddings-symbolic.ll
@@ -49,7 +49,7 @@ entry:
 ; CHECK-FUNC-LEVEL-ABC: Function: abc
 ; CHECK-FUNC-LEVEL-NEXT-ABC:  [ 878.00  889.00  900.00 ]
 
-; CHECK-FUNC-DEF: Error: Function 'def' not found
+; CHECK-FUNC-DEF: error: Function 'def' not found
 
 ; CHECK-BB-LEVEL: Function: abc
 ; CHECK-BB-LEVEL-NEXT: entry: [ 878.00  889.00  900.00 ]
diff --git a/llvm/test/tools/llvm-ir2vec/embeddings-symbolic.mir b/llvm/test/tools/llvm-ir2vec/embeddings-symbolic.mir
index e5f78bfd2090e..ef835fe302f2e 100644
--- a/llvm/test/tools/llvm-ir2vec/embeddings-symbolic.mir
+++ b/llvm/test/tools/llvm-ir2vec/embeddings-symbolic.mir
@@ -67,7 +67,7 @@ body:             |
 # CHECK-FUNC-LEVEL-ADD-NEXT: Function vector:  [ 26.50  27.10  27.70 ]
 # CHECK-FUNC-LEVEL-ADD-NOT: simple_function
 
-# CHECK-FUNC-MISSING: Error: Function 'missing_function' not found
+# CHECK-FUNC-MISSING: error: Function 'missing_function' not found
 
 # CHECK-BB-LEVEL: MIR2Vec embeddings for machine function add_function:
 # CHECK-BB-LEVEL-NEXT: Basic block vectors:
diff --git a/llvm/test/tools/llvm-ir2vec/error-handling.ll b/llvm/test/tools/llvm-ir2vec/error-handling.ll
index b944ea0eaae8b..8e9e45513434c 100644
--- a/llvm/test/tools/llvm-ir2vec/error-handling.ll
+++ b/llvm/test/tools/llvm-ir2vec/error-handling.ll
@@ -10,4 +10,4 @@ entry:
 }
 
 ; CHECK-NO-VOCAB: error: IR2Vec vocabulary file path not specified; You may need to set it using --ir2vec-vocab-path
-; CHECK-FUNC-NOT-FOUND: Error: Function 'nonexistent' not found
+; CHECK-FUNC-NOT-FOUND: error: Function 'nonexistent' not found
diff --git a/llvm/test/tools/llvm-ir2vec/error-handling.mir b/llvm/test/tools/llvm-ir2vec/error-handling.mir
index 154078c18d647..caec454c9c9d5 100644
--- a/llvm/test/tools/llvm-ir2vec/error-handling.mir
+++ b/llvm/test/tools/llvm-ir2vec/error-handling.mir
@@ -31,11 +31,11 @@ body:             |
     $eax = COPY %0
     RET 0, $eax
 
-# CHECK-NO-VOCAB: Error: Failed to load MIR2Vec vocabulary - MIR2Vec vocabulary file path not specified; set it using --mir2vec-vocab-path
+# CHECK-NO-VOCAB: error: Failed to load MIR2Vec vocabulary - MIR2Vec vocabulary file path not specified; set it using --mir2vec-vocab-path
 
-# CHECK-VOCAB-NOT-FOUND: Error: Failed to load MIR2Vec vocabulary
+# CHECK-VOCAB-NOT-FOUND: error: Failed to load MIR2Vec vocabulary
 # CHECK-VOCAB-NOT-FOUND: No such file or directory
 
-# CHECK-INVALID-VOCAB: Error: Failed to load MIR2Vec vocabulary - Missing 'Opcodes' section in vocabulary file
+# CHECK-INVALID-VOCAB: error: Failed to load MIR2Vec vocabulary - Missing 'Opcodes' section in vocabulary file
 
-# CHECK-FUNC-NOT-FOUND: Error: Function 'nonexistent_function' not found
+# CHECK-FUNC-NOT-FOUND: error: Function 'nonexistent_function' not found
diff --git a/llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp b/llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp
index c41cf20539c0d..a723d379129e6 100644
--- a/llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp
+++ b/llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp
@@ -77,6 +77,8 @@
 
 namespace llvm {
 
+static const char *ToolName = "llvm-ir2vec";
+
 // Common option category for options shared between IR2Vec and MIR2Vec
 static cl::OptionCategory CommonCategory("Common Options",
                                          "Options applicable to both IR2Vec "
@@ -258,7 +260,8 @@ class IR2VecTool {
   /// Generate embeddings for the entire module
   void generateEmbeddings(raw_ostream &OS) const {
     if (!Vocab->isValid()) {
-      OS << "Error: Vocabulary is not valid. IR2VecTool not initialized.\n";
+      WithColor::error(errs(), ToolName)
+          << "Vocabulary is not valid. IR2VecTool not initialized.\n";
       return;
     }
 
@@ -277,8 +280,8 @@ class IR2VecTool {
     assert(Vocab->isValid() && "Vocabulary is not valid");
     auto Emb = Embedder::create(IR2VecEmbeddingKind, F, *Vocab);
     if (!Emb) {
-      OS << "Error: Failed to create embedder for function " << F.getName()
-         << "\n";
+      WithColor::error(errs(), ToolName)
+          << "Failed to create embedder for function " << F.getName() << "\n";
       return;
     }
 
@@ -351,13 +354,14 @@ class MIR2VecTool {
 public:
   explicit MIR2VecTool(MachineModuleInfo &MMI) : MMI(MMI) {}
 
-  /// Initialize the MIR2Vec vocabulary
+  /// Initialize MIR2Vec vocabulary
   bool initializeVocabulary(const Module &M) {
     MIR2VecVocabProvider Provider(MMI);
     auto VocabOrErr = Provider.getVocabulary(M);
     if (!VocabOrErr) {
-      errs() << "Error: Failed to load MIR2Vec vocabulary - "
-             << toString(VocabOrErr.takeError()) << "\n";
+      WithColor::error(errs(), ToolName)
+          << "Failed to load MIR2Vec vocabulary - "
+          << toString(VocabOrErr.takeError()) << "\n";
       return false;
     }
     Vocab = std::make_unique<MIRVocabulary>(std::move(*VocabOrErr));
@@ -367,7 +371,7 @@ class MIR2VecTool {
   /// Generate embeddings for all machine functions in the module
   void generateEmbeddings(const Module &M, raw_ostream &OS) const {
     if (!Vocab) {
-      OS << "Error: Vocabulary not initialized.\n";
+      WithColor::error(errs(), ToolName) << "Vocabulary not initialized.\n";
       return;
     }
 
@@ -377,7 +381,8 @@ class MIR2VecTool {
 
       MachineFunction *MF = MMI.getMachineFunction(F);
       if (!MF) {
-        errs() << "Warning: No MachineFunction for " << F.getName() << "\n";
+        WithColor::warning(errs(), ToolName)
+            << "No MachineFunction for " << F.getName() << "\n";
         continue;
       }
 
@@ -388,13 +393,14 @@ class MIR2VecTool {
   /// Generate embeddings for a specific machine function
   void generateEmbeddings(MachineFunction &MF, raw_ostream &OS) const {
     if (!Vocab) {
-      OS << "Error: Vocabulary not initialized.\n";
+      WithColor::error(errs(), ToolName) << "Vocabulary not initialized.\n";
       return;
     }
 
     auto Emb = MIREmbedder::create(MIR2VecKind::Symbolic, MF, *Vocab);
     if (!Emb) {
-      errs() << "Error: Failed to create embedder for " << MF.getName() << "\n";
+      WithColor::error(errs(), ToolName)
+          << "Failed to create embedder for " << MF.getName() << "\n";
       return;
     }
 
@@ -456,7 +462,8 @@ int main(int argc, char **argv) {
   std::error_code EC;
   raw_fd_ostream OS(OutputFilename, EC);
   if (EC) {
-    errs() << "Error opening output file: " << EC.message() << "\n";
+    WithColor::error(errs(), ToolName)
+        << "opening output file: " << EC.message() << "\n";
     return 1;
   }
 
@@ -472,13 +479,13 @@ int main(int argc, char **argv) {
     LLVMContext Context;
     std::unique_ptr<Module> M = parseIRFile(InputFilename, Err, Context);
     if (!M) {
-      Err.print(argv[0], errs());
+      Err.print(ToolName, errs());
       return 1;
     }
 
     if (Error Err = processModule(*M, OS)) {
       handleAllErrors(std::move(Err), [&](const ErrorInfoBase &EIB) {
-        errs() << "Error: " << EIB.message() << "\n";
+        WithColor::error(errs(), ToolName) << EIB.message() << "\n";
       });
       return 1;
     }
@@ -499,7 +506,7 @@ int main(int argc, char **argv) {
 
     auto MIR = createMIRParserFromFile(InputFilename, Err, Context);
     if (!MIR) {
-      Err.print(argv[0], WithColor::error(errs(), argv[0]));
+      Err.print(ToolName, errs());
       return 1;
     }
 
@@ -511,7 +518,7 @@ int main(int argc, char **argv) {
         TheTriple.setTriple(sys::getDefaultTargetTriple());
       auto TMOrErr = codegen::createTargetMachineForTriple(TheTriple.str());
       if (!TMOrErr) {
-        Err.print(argv[0], WithColor::error(errs(), argv[0]));
+        Err.print(ToolName, errs());
         exit(1);
       }
       TM = std::move(*TMOrErr);
@@ -520,14 +527,14 @@ int main(int argc, char **argv) {
 
     std::unique_ptr<Module> M = MIR->parseIRModule(SetDataLayout);
     if (!M) {
-      Err.print(argv[0], WithColor::error(errs(), argv[0]));
+      Err.print(ToolName, errs());
       return 1;
     }
 
     // Parse machine functions
     auto MMI = std::make_unique<MachineModuleInfo>(TM.get());
     if (!MMI || MIR->parseMachineFunctions(*M, *MMI)) {
-      Err.print(argv[0], WithColor::error(errs(), argv[0]));
+      Err.print(ToolName, errs());
       return 1;
     }
 
@@ -547,13 +554,15 @@ int main(int argc, char **argv) {
       // Process single function
       Function *F = M->getFunction(FunctionName);
       if (!F) {
-        errs() << "Error: Function '" << FunctionName << "' not found\n";
+        WithColor::error(errs(), ToolName)
+            << "Function '" << FunctionName << "' not found\n";
         return 1;
       }
 
       MachineFunction *MF = MMI->getMachineFunction(*F);
       if (!MF) {
-        errs() << "Error: No MachineFunction for " << FunctionName << "\n";
+        WithColor::error(errs(), ToolName)
+            << "No MachineFunction for " << FunctionName << "\n";
         return 1;
       }
 

@svkeerthy svkeerthy force-pushed the users/svkeerthy/10-17-use_colored_error_messages branch from af3e3dd to fd9e92d Compare October 20, 2025 22:35
@svkeerthy svkeerthy force-pushed the users/svkeerthy/10-17-_llvm-ir2vec_mir2vec_support branch from 8c7612a to 210f7cc Compare October 20, 2025 22:35
@svkeerthy svkeerthy force-pushed the users/svkeerthy/10-17-use_colored_error_messages branch from fd9e92d to fc95c26 Compare October 20, 2025 23:24
@svkeerthy svkeerthy force-pushed the users/svkeerthy/10-17-_llvm-ir2vec_mir2vec_support branch 2 times, most recently from 0038f1d to a340c43 Compare October 20, 2025 23:48
@svkeerthy svkeerthy force-pushed the users/svkeerthy/10-17-use_colored_error_messages branch 2 times, most recently from a73d282 to 52ca99b Compare October 21, 2025 00:23
@svkeerthy svkeerthy force-pushed the users/svkeerthy/10-17-_llvm-ir2vec_mir2vec_support branch 2 times, most recently from 103f68b to b8aff5e Compare October 21, 2025 17:20
@svkeerthy svkeerthy force-pushed the users/svkeerthy/10-17-use_colored_error_messages branch 2 times, most recently from a3b210f to ae927bf Compare October 21, 2025 18:16
@svkeerthy svkeerthy force-pushed the users/svkeerthy/10-17-_llvm-ir2vec_mir2vec_support branch from 84d43ee to 8dfd7f0 Compare October 21, 2025 21:47
@svkeerthy svkeerthy force-pushed the users/svkeerthy/10-17-use_colored_error_messages branch 2 times, most recently from 5239e0b to 0ebad73 Compare October 21, 2025 22:58
@svkeerthy svkeerthy force-pushed the users/svkeerthy/10-17-_llvm-ir2vec_mir2vec_support branch from 8dfd7f0 to 39337b2 Compare October 21, 2025 22:58
@svkeerthy svkeerthy force-pushed the users/svkeerthy/10-17-use_colored_error_messages branch from 0ebad73 to d059588 Compare October 22, 2025 00:13
@svkeerthy svkeerthy force-pushed the users/svkeerthy/10-17-_llvm-ir2vec_mir2vec_support branch 2 times, most recently from 46b0781 to fdfb77c Compare October 22, 2025 18:00
@svkeerthy svkeerthy force-pushed the users/svkeerthy/10-17-use_colored_error_messages branch 2 times, most recently from f2335a0 to 85bc95c Compare October 22, 2025 18:01
@svkeerthy svkeerthy force-pushed the users/svkeerthy/10-17-_llvm-ir2vec_mir2vec_support branch from fdfb77c to 6daabaf Compare October 22, 2025 18:01
@svkeerthy svkeerthy force-pushed the users/svkeerthy/10-17-use_colored_error_messages branch from 85bc95c to b61393a Compare October 22, 2025 21:11
@svkeerthy svkeerthy force-pushed the users/svkeerthy/10-17-_llvm-ir2vec_mir2vec_support branch from 6daabaf to 24298cf Compare October 22, 2025 21:11
@svkeerthy svkeerthy force-pushed the users/svkeerthy/10-17-use_colored_error_messages branch from b61393a to bfad173 Compare October 22, 2025 21:53
@svkeerthy svkeerthy force-pushed the users/svkeerthy/10-17-_llvm-ir2vec_mir2vec_support branch from 24298cf to f59d788 Compare October 22, 2025 21:53
Base automatically changed from users/svkeerthy/10-17-_llvm-ir2vec_mir2vec_support to main October 22, 2025 22:25
@svkeerthy svkeerthy force-pushed the users/svkeerthy/10-17-use_colored_error_messages branch from bfad173 to 7cc2ec5 Compare October 22, 2025 22:27
@svkeerthy svkeerthy force-pushed the users/svkeerthy/10-17-use_colored_error_messages branch from 7cc2ec5 to ad0555a Compare October 22, 2025 22:51
Copy link
Contributor Author

svkeerthy commented Oct 22, 2025

Merge activity

  • Oct 22, 11:23 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Oct 22, 11:24 PM UTC: @svkeerthy merged this pull request with Graphite.

@svkeerthy svkeerthy merged commit fec3f99 into main Oct 22, 2025
9 of 10 checks passed
@svkeerthy svkeerthy deleted the users/svkeerthy/10-17-use_colored_error_messages branch October 22, 2025 23:24
mikolaj-pirog pushed a commit to mikolaj-pirog/llvm-project that referenced this pull request Oct 23, 2025
…lvm#164032)

Standardize error message formatting in llvm-ir2vec tool using WithColor for consistent error reporting.
dvbuka pushed a commit to dvbuka/llvm-project that referenced this pull request Oct 27, 2025
…lvm#164032)

Standardize error message formatting in llvm-ir2vec tool using WithColor for consistent error reporting.
Lukacma pushed a commit to Lukacma/llvm-project that referenced this pull request Oct 29, 2025
…lvm#164032)

Standardize error message formatting in llvm-ir2vec tool using WithColor for consistent error reporting.
aokblast pushed a commit to aokblast/llvm-project that referenced this pull request Oct 30, 2025
…lvm#164032)

Standardize error message formatting in llvm-ir2vec tool using WithColor for consistent error reporting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants