-
Notifications
You must be signed in to change notification settings - Fork 15.8k
[NFC][LLVM] Namespace cleanup in llvm-ir2vec.cpp #175252
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
Merged
Merged
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
Contributor
jurahul
commented
Jan 9, 2026
- Add "using namespace" at top of the file.
- Make some file-local functions static
Member
|
@llvm/pr-subscribers-mlgo Author: Rahul Joshi (jurahul) Changes
Full diff: https://github.com/llvm/llvm-project/pull/175252.diff 1 Files Affected:
diff --git a/llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp b/llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp
index 6b70e09518fa7..b60488b2a1b6b 100644
--- a/llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp
+++ b/llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp
@@ -89,7 +89,9 @@
#define DEBUG_TYPE "ir2vec"
-namespace llvm {
+using namespace llvm;
+using namespace llvm::ir2vec;
+using namespace llvm::mir2vec;
// Common option category for options shared between IR2Vec and MIR2Vec
static cl::OptionCategory CommonCategory("Common Options",
@@ -145,8 +147,6 @@ static cl::opt<EmbeddingLevel>
cl::init(FunctionLevel), cl::sub(EmbeddingsSubCmd),
cl::cat(CommonCategory));
-namespace ir2vec {
-
bool IR2VecTool::initializeVocabulary() {
// Register and run the IR2Vec vocabulary analysis
// The vocabulary file path is specified via --ir2vec-vocab-path global
@@ -309,7 +309,7 @@ void IR2VecTool::writeEmbeddingsToStream(const Function &F, raw_ostream &OS,
}
/// Process the module and generate output based on selected subcommand
-Error processModule(Module &M, raw_ostream &OS) {
+static Error processModule(Module &M, raw_ostream &OS) {
IR2VecTool Tool(M);
if (EmbeddingsSubCmd) {
@@ -337,9 +337,6 @@ Error processModule(Module &M, raw_ostream &OS) {
}
return Error::success();
}
-} // namespace ir2vec
-
-namespace mir2vec {
bool MIR2VecTool::initializeVocabulary(const Module &M) {
MIR2VecVocabProvider Provider(MMI);
@@ -551,7 +548,7 @@ void MIR2VecTool::writeEmbeddingsToStream(MachineFunction &MF, raw_ostream &OS,
}
/// Setup MIR context from input file
-Error setupMIRContext(const std::string &InputFile, MIRContext &Ctx) {
+static Error setupMIRContext(const std::string &InputFile, MIRContext &Ctx) {
SMDiagnostic Err;
auto MIR = createMIRParserFromFile(InputFile, Err, Ctx.Context);
@@ -596,8 +593,8 @@ Error setupMIRContext(const std::string &InputFile, MIRContext &Ctx) {
/// Generic vocabulary initialization and processing
template <typename ProcessFunc>
-Error processWithVocabulary(MIRContext &Ctx, raw_ostream &OS,
- bool useLayoutVocab, ProcessFunc processFn) {
+static Error processWithVocabulary(MIRContext &Ctx, raw_ostream &OS,
+ bool useLayoutVocab, ProcessFunc processFn) {
MIR2VecTool Tool(*Ctx.MMI);
// Initialize appropriate vocabulary type
@@ -626,7 +623,7 @@ Error processWithVocabulary(MIRContext &Ctx, raw_ostream &OS,
}
/// Process module for triplet generation
-Error processModuleForTriplets(MIRContext &Ctx, raw_ostream &OS) {
+static Error processModuleForTriplets(MIRContext &Ctx, raw_ostream &OS) {
return processWithVocabulary(Ctx, OS, /*useLayoutVocab=*/true,
[&](MIR2VecTool &Tool) -> Error {
Tool.writeTripletsToStream(*Ctx.M, OS);
@@ -635,7 +632,7 @@ Error processModuleForTriplets(MIRContext &Ctx, raw_ostream &OS) {
}
/// Process module for entity generation
-Error processModuleForEntities(MIRContext &Ctx, raw_ostream &OS) {
+static Error processModuleForEntities(MIRContext &Ctx, raw_ostream &OS) {
return processWithVocabulary(Ctx, OS, /*useLayoutVocab=*/true,
[&](MIR2VecTool &Tool) -> Error {
Tool.writeEntitiesToStream(OS);
@@ -644,7 +641,7 @@ Error processModuleForEntities(MIRContext &Ctx, raw_ostream &OS) {
}
/// Process module for embedding generation
-Error processModuleForEmbeddings(MIRContext &Ctx, raw_ostream &OS) {
+static Error processModuleForEmbeddings(MIRContext &Ctx, raw_ostream &OS) {
return processWithVocabulary(
Ctx, OS, /*useLayoutVocab=*/false, [&](MIR2VecTool &Tool) -> Error {
if (!FunctionName.empty()) {
@@ -675,7 +672,7 @@ Error processModuleForEmbeddings(MIRContext &Ctx, raw_ostream &OS) {
}
/// Main entry point for MIR processing
-Error processModule(const std::string &InputFile, raw_ostream &OS) {
+static Error processModule(const std::string &InputFile, raw_ostream &OS) {
MIRContext Ctx;
// Setup MIR context (parse file, setup target machine, etc.)
@@ -696,15 +693,7 @@ Error processModule(const std::string &InputFile, raw_ostream &OS) {
}
}
-} // namespace mir2vec
-
-} // namespace llvm
-
int main(int argc, char **argv) {
- using namespace llvm;
- using namespace llvm::ir2vec;
- using namespace llvm::mir2vec;
-
InitLLVM X(argc, argv);
// Show Common, IR2Vec and MIR2Vec option categories
cl::HideUnrelatedOptions(ArrayRef<const cl::OptionCategory *>{
@@ -758,7 +747,7 @@ int main(int argc, char **argv) {
InitializeAllAsmPrinters();
static codegen::RegisterCodeGenFlags CGF;
- if (Error Err = mir2vec::processModule(InputFilename, OS)) {
+ if (Error Err = processModule(InputFilename, OS)) {
handleAllErrors(std::move(Err), [&](const ErrorInfoBase &EIB) {
WithColor::error(errs(), ToolName) << EIB.message() << "\n";
});
|
boomanaiden154
approved these changes
Jan 10, 2026
svkeerthy
approved these changes
Jan 10, 2026
Priyanshu3820
pushed a commit
to Priyanshu3820/llvm-project
that referenced
this pull request
Jan 18, 2026
- Add "using namespace" at top of the file. - Make some file-local functions static
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.