-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[NFC][llvm-ir2vec] Standardize error message format using WithColor #164032
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
svkeerthy
wants to merge
1
commit into
users/svkeerthy/10-17-_llvm-ir2vec_mir2vec_support
Choose a base branch
from
users/svkeerthy/10-17-use_colored_error_messages
base: users/svkeerthy/10-17-_llvm-ir2vec_mir2vec_support
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[NFC][llvm-ir2vec] Standardize error message format using WithColor #164032
svkeerthy
wants to merge
1
commit into
users/svkeerthy/10-17-_llvm-ir2vec_mir2vec_support
from
users/svkeerthy/10-17-use_colored_error_messages
+36
−27
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was referenced Oct 17, 2025
This was referenced Oct 17, 2025
@llvm/pr-subscribers-mlgo Author: S. VenkataKeerthy (svkeerthy) ChangesStandardize 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:
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;
}
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Standardize error message formatting in llvm-ir2vec tool using WithColor for consistent error reporting.