From a8aacb1b66f1a46ac47a2c7b3a3784f57f5e291c Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Thu, 21 Aug 2025 04:14:12 -0700 Subject: [PATCH] [MLIR] Apply clang-tidy fixes for misc-use-internal-linkage in toy Tutorial (NFC) --- mlir/examples/toy/Ch1/parser/AST.cpp | 2 +- mlir/examples/toy/Ch1/toyc.cpp | 3 ++- mlir/examples/toy/Ch2/parser/AST.cpp | 2 +- mlir/examples/toy/Ch2/toyc.cpp | 7 ++++--- mlir/examples/toy/Ch3/parser/AST.cpp | 2 +- mlir/examples/toy/Ch3/toyc.cpp | 11 ++++++----- mlir/examples/toy/Ch4/parser/AST.cpp | 2 +- mlir/examples/toy/Ch4/toyc.cpp | 11 ++++++----- mlir/examples/toy/Ch5/parser/AST.cpp | 2 +- mlir/examples/toy/Ch5/toyc.cpp | 11 ++++++----- mlir/examples/toy/Ch6/parser/AST.cpp | 2 +- mlir/examples/toy/Ch6/toyc.cpp | 17 +++++++++-------- mlir/examples/toy/Ch7/parser/AST.cpp | 2 +- mlir/examples/toy/Ch7/toyc.cpp | 17 +++++++++-------- 14 files changed, 49 insertions(+), 42 deletions(-) diff --git a/mlir/examples/toy/Ch1/parser/AST.cpp b/mlir/examples/toy/Ch1/parser/AST.cpp index 2546f2a9725d..841642488db6 100644 --- a/mlir/examples/toy/Ch1/parser/AST.cpp +++ b/mlir/examples/toy/Ch1/parser/AST.cpp @@ -120,7 +120,7 @@ void ASTDumper::dump(NumberExprAST *num) { /// [ [ 1, 2 ], [ 3, 4 ] ] /// We print out such array with the dimensions spelled out at every level: /// <2,2>[<2>[ 1, 2 ], <2>[ 3, 4 ] ] -void printLitHelper(ExprAST *litOrNum) { +static void printLitHelper(ExprAST *litOrNum) { // Inside a literal expression we can have either a number or another literal if (auto *num = llvm::dyn_cast(litOrNum)) { llvm::errs() << num->getValue(); diff --git a/mlir/examples/toy/Ch1/toyc.cpp b/mlir/examples/toy/Ch1/toyc.cpp index fb7b484a92fb..b9f3a2d3ae11 100644 --- a/mlir/examples/toy/Ch1/toyc.cpp +++ b/mlir/examples/toy/Ch1/toyc.cpp @@ -39,7 +39,8 @@ static cl::opt cl::values(clEnumValN(DumpAST, "ast", "output the AST dump"))); /// Returns a Toy AST resulting from parsing the file or a nullptr on error. -std::unique_ptr parseInputFile(llvm::StringRef filename) { +static std::unique_ptr +parseInputFile(llvm::StringRef filename) { llvm::ErrorOr> fileOrErr = llvm::MemoryBuffer::getFileOrSTDIN(filename); if (std::error_code ec = fileOrErr.getError()) { diff --git a/mlir/examples/toy/Ch2/parser/AST.cpp b/mlir/examples/toy/Ch2/parser/AST.cpp index 2546f2a9725d..841642488db6 100644 --- a/mlir/examples/toy/Ch2/parser/AST.cpp +++ b/mlir/examples/toy/Ch2/parser/AST.cpp @@ -120,7 +120,7 @@ void ASTDumper::dump(NumberExprAST *num) { /// [ [ 1, 2 ], [ 3, 4 ] ] /// We print out such array with the dimensions spelled out at every level: /// <2,2>[<2>[ 1, 2 ], <2>[ 3, 4 ] ] -void printLitHelper(ExprAST *litOrNum) { +static void printLitHelper(ExprAST *litOrNum) { // Inside a literal expression we can have either a number or another literal if (auto *num = llvm::dyn_cast(litOrNum)) { llvm::errs() << num->getValue(); diff --git a/mlir/examples/toy/Ch2/toyc.cpp b/mlir/examples/toy/Ch2/toyc.cpp index e33b49b41c5a..a60738da9d4a 100644 --- a/mlir/examples/toy/Ch2/toyc.cpp +++ b/mlir/examples/toy/Ch2/toyc.cpp @@ -58,7 +58,8 @@ static cl::opt emitAction( cl::values(clEnumValN(DumpMLIR, "mlir", "output the MLIR dump"))); /// Returns a Toy AST resulting from parsing the file or a nullptr on error. -std::unique_ptr parseInputFile(llvm::StringRef filename) { +static std::unique_ptr +parseInputFile(llvm::StringRef filename) { llvm::ErrorOr> fileOrErr = llvm::MemoryBuffer::getFileOrSTDIN(filename); if (std::error_code ec = fileOrErr.getError()) { @@ -71,7 +72,7 @@ std::unique_ptr parseInputFile(llvm::StringRef filename) { return parser.parseModule(); } -int dumpMLIR() { +static int dumpMLIR() { mlir::MLIRContext context; // Load our Dialect in this MLIR Context. context.getOrLoadDialect(); @@ -112,7 +113,7 @@ int dumpMLIR() { return 0; } -int dumpAST() { +static int dumpAST() { if (inputType == InputType::MLIR) { llvm::errs() << "Can't dump a Toy AST when the input is MLIR\n"; return 5; diff --git a/mlir/examples/toy/Ch3/parser/AST.cpp b/mlir/examples/toy/Ch3/parser/AST.cpp index 2546f2a9725d..841642488db6 100644 --- a/mlir/examples/toy/Ch3/parser/AST.cpp +++ b/mlir/examples/toy/Ch3/parser/AST.cpp @@ -120,7 +120,7 @@ void ASTDumper::dump(NumberExprAST *num) { /// [ [ 1, 2 ], [ 3, 4 ] ] /// We print out such array with the dimensions spelled out at every level: /// <2,2>[<2>[ 1, 2 ], <2>[ 3, 4 ] ] -void printLitHelper(ExprAST *litOrNum) { +static void printLitHelper(ExprAST *litOrNum) { // Inside a literal expression we can have either a number or another literal if (auto *num = llvm::dyn_cast(litOrNum)) { llvm::errs() << num->getValue(); diff --git a/mlir/examples/toy/Ch3/toyc.cpp b/mlir/examples/toy/Ch3/toyc.cpp index f8aa84658226..3094935567d9 100644 --- a/mlir/examples/toy/Ch3/toyc.cpp +++ b/mlir/examples/toy/Ch3/toyc.cpp @@ -64,7 +64,8 @@ static cl::opt emitAction( static cl::opt enableOpt("opt", cl::desc("Enable optimizations")); /// Returns a Toy AST resulting from parsing the file or a nullptr on error. -std::unique_ptr parseInputFile(llvm::StringRef filename) { +static std::unique_ptr +parseInputFile(llvm::StringRef filename) { llvm::ErrorOr> fileOrErr = llvm::MemoryBuffer::getFileOrSTDIN(filename); if (std::error_code ec = fileOrErr.getError()) { @@ -77,8 +78,8 @@ std::unique_ptr parseInputFile(llvm::StringRef filename) { return parser.parseModule(); } -int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context, - mlir::OwningOpRef &module) { +static int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context, + mlir::OwningOpRef &module) { // Handle '.toy' input to the compiler. if (inputType != InputType::MLIR && !llvm::StringRef(inputFilename).ends_with(".mlir")) { @@ -107,7 +108,7 @@ int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context, return 0; } -int dumpMLIR() { +static int dumpMLIR() { mlir::MLIRContext context; // Load our Dialect in this MLIR Context. context.getOrLoadDialect(); @@ -134,7 +135,7 @@ int dumpMLIR() { return 0; } -int dumpAST() { +static int dumpAST() { if (inputType == InputType::MLIR) { llvm::errs() << "Can't dump a Toy AST when the input is MLIR\n"; return 5; diff --git a/mlir/examples/toy/Ch4/parser/AST.cpp b/mlir/examples/toy/Ch4/parser/AST.cpp index 2546f2a9725d..841642488db6 100644 --- a/mlir/examples/toy/Ch4/parser/AST.cpp +++ b/mlir/examples/toy/Ch4/parser/AST.cpp @@ -120,7 +120,7 @@ void ASTDumper::dump(NumberExprAST *num) { /// [ [ 1, 2 ], [ 3, 4 ] ] /// We print out such array with the dimensions spelled out at every level: /// <2,2>[<2>[ 1, 2 ], <2>[ 3, 4 ] ] -void printLitHelper(ExprAST *litOrNum) { +static void printLitHelper(ExprAST *litOrNum) { // Inside a literal expression we can have either a number or another literal if (auto *num = llvm::dyn_cast(litOrNum)) { llvm::errs() << num->getValue(); diff --git a/mlir/examples/toy/Ch4/toyc.cpp b/mlir/examples/toy/Ch4/toyc.cpp index ae02bc4314ba..36816f0327de 100644 --- a/mlir/examples/toy/Ch4/toyc.cpp +++ b/mlir/examples/toy/Ch4/toyc.cpp @@ -65,7 +65,8 @@ static cl::opt emitAction( static cl::opt enableOpt("opt", cl::desc("Enable optimizations")); /// Returns a Toy AST resulting from parsing the file or a nullptr on error. -std::unique_ptr parseInputFile(llvm::StringRef filename) { +static std::unique_ptr +parseInputFile(llvm::StringRef filename) { llvm::ErrorOr> fileOrErr = llvm::MemoryBuffer::getFileOrSTDIN(filename); if (std::error_code ec = fileOrErr.getError()) { @@ -78,8 +79,8 @@ std::unique_ptr parseInputFile(llvm::StringRef filename) { return parser.parseModule(); } -int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context, - mlir::OwningOpRef &module) { +static int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context, + mlir::OwningOpRef &module) { // Handle '.toy' input to the compiler. if (inputType != InputType::MLIR && !llvm::StringRef(inputFilename).ends_with(".mlir")) { @@ -108,7 +109,7 @@ int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context, return 0; } -int dumpMLIR() { +static int dumpMLIR() { mlir::MLIRContext context; // Load our Dialect in this MLIR Context. context.getOrLoadDialect(); @@ -143,7 +144,7 @@ int dumpMLIR() { return 0; } -int dumpAST() { +static int dumpAST() { if (inputType == InputType::MLIR) { llvm::errs() << "Can't dump a Toy AST when the input is MLIR\n"; return 5; diff --git a/mlir/examples/toy/Ch5/parser/AST.cpp b/mlir/examples/toy/Ch5/parser/AST.cpp index 2546f2a9725d..841642488db6 100644 --- a/mlir/examples/toy/Ch5/parser/AST.cpp +++ b/mlir/examples/toy/Ch5/parser/AST.cpp @@ -120,7 +120,7 @@ void ASTDumper::dump(NumberExprAST *num) { /// [ [ 1, 2 ], [ 3, 4 ] ] /// We print out such array with the dimensions spelled out at every level: /// <2,2>[<2>[ 1, 2 ], <2>[ 3, 4 ] ] -void printLitHelper(ExprAST *litOrNum) { +static void printLitHelper(ExprAST *litOrNum) { // Inside a literal expression we can have either a number or another literal if (auto *num = llvm::dyn_cast(litOrNum)) { llvm::errs() << num->getValue(); diff --git a/mlir/examples/toy/Ch5/toyc.cpp b/mlir/examples/toy/Ch5/toyc.cpp index afdf782d8ea4..3760a88d6f69 100644 --- a/mlir/examples/toy/Ch5/toyc.cpp +++ b/mlir/examples/toy/Ch5/toyc.cpp @@ -71,7 +71,8 @@ static cl::opt emitAction( static cl::opt enableOpt("opt", cl::desc("Enable optimizations")); /// Returns a Toy AST resulting from parsing the file or a nullptr on error. -std::unique_ptr parseInputFile(llvm::StringRef filename) { +static std::unique_ptr +parseInputFile(llvm::StringRef filename) { llvm::ErrorOr> fileOrErr = llvm::MemoryBuffer::getFileOrSTDIN(filename); if (std::error_code ec = fileOrErr.getError()) { @@ -84,8 +85,8 @@ std::unique_ptr parseInputFile(llvm::StringRef filename) { return parser.parseModule(); } -int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context, - mlir::OwningOpRef &module) { +static int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context, + mlir::OwningOpRef &module) { // Handle '.toy' input to the compiler. if (inputType != InputType::MLIR && !llvm::StringRef(inputFilename).ends_with(".mlir")) { @@ -114,7 +115,7 @@ int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context, return 0; } -int dumpMLIR() { +static int dumpMLIR() { mlir::DialectRegistry registry; mlir::func::registerAllExtensions(registry); @@ -171,7 +172,7 @@ int dumpMLIR() { return 0; } -int dumpAST() { +static int dumpAST() { if (inputType == InputType::MLIR) { llvm::errs() << "Can't dump a Toy AST when the input is MLIR\n"; return 5; diff --git a/mlir/examples/toy/Ch6/parser/AST.cpp b/mlir/examples/toy/Ch6/parser/AST.cpp index 2546f2a9725d..841642488db6 100644 --- a/mlir/examples/toy/Ch6/parser/AST.cpp +++ b/mlir/examples/toy/Ch6/parser/AST.cpp @@ -120,7 +120,7 @@ void ASTDumper::dump(NumberExprAST *num) { /// [ [ 1, 2 ], [ 3, 4 ] ] /// We print out such array with the dimensions spelled out at every level: /// <2,2>[<2>[ 1, 2 ], <2>[ 3, 4 ] ] -void printLitHelper(ExprAST *litOrNum) { +static void printLitHelper(ExprAST *litOrNum) { // Inside a literal expression we can have either a number or another literal if (auto *num = llvm::dyn_cast(litOrNum)) { llvm::errs() << num->getValue(); diff --git a/mlir/examples/toy/Ch6/toyc.cpp b/mlir/examples/toy/Ch6/toyc.cpp index 4a5e10973f0c..c31c53a229fb 100644 --- a/mlir/examples/toy/Ch6/toyc.cpp +++ b/mlir/examples/toy/Ch6/toyc.cpp @@ -96,7 +96,8 @@ static cl::opt emitAction( static cl::opt enableOpt("opt", cl::desc("Enable optimizations")); /// Returns a Toy AST resulting from parsing the file or a nullptr on error. -std::unique_ptr parseInputFile(llvm::StringRef filename) { +static std::unique_ptr +parseInputFile(llvm::StringRef filename) { llvm::ErrorOr> fileOrErr = llvm::MemoryBuffer::getFileOrSTDIN(filename); if (std::error_code ec = fileOrErr.getError()) { @@ -109,8 +110,8 @@ std::unique_ptr parseInputFile(llvm::StringRef filename) { return parser.parseModule(); } -int loadMLIR(mlir::MLIRContext &context, - mlir::OwningOpRef &module) { +static int loadMLIR(mlir::MLIRContext &context, + mlir::OwningOpRef &module) { // Handle '.toy' input to the compiler. if (inputType != InputType::MLIR && !llvm::StringRef(inputFilename).ends_with(".mlir")) { @@ -140,8 +141,8 @@ int loadMLIR(mlir::MLIRContext &context, return 0; } -int loadAndProcessMLIR(mlir::MLIRContext &context, - mlir::OwningOpRef &module) { +static int loadAndProcessMLIR(mlir::MLIRContext &context, + mlir::OwningOpRef &module) { if (int error = loadMLIR(context, module)) return error; @@ -196,7 +197,7 @@ int loadAndProcessMLIR(mlir::MLIRContext &context, return 0; } -int dumpAST() { +static int dumpAST() { if (inputType == InputType::MLIR) { llvm::errs() << "Can't dump a Toy AST when the input is MLIR\n"; return 5; @@ -210,7 +211,7 @@ int dumpAST() { return 0; } -int dumpLLVMIR(mlir::ModuleOp module) { +static int dumpLLVMIR(mlir::ModuleOp module) { // Register the translation to LLVM IR with the MLIR context. mlir::registerBuiltinDialectTranslation(*module->getContext()); mlir::registerLLVMDialectTranslation(*module->getContext()); @@ -254,7 +255,7 @@ int dumpLLVMIR(mlir::ModuleOp module) { return 0; } -int runJit(mlir::ModuleOp module) { +static int runJit(mlir::ModuleOp module) { // Initialize LLVM targets. llvm::InitializeNativeTarget(); llvm::InitializeNativeTargetAsmPrinter(); diff --git a/mlir/examples/toy/Ch7/parser/AST.cpp b/mlir/examples/toy/Ch7/parser/AST.cpp index e38a743a769c..aa2c7846329c 100644 --- a/mlir/examples/toy/Ch7/parser/AST.cpp +++ b/mlir/examples/toy/Ch7/parser/AST.cpp @@ -123,7 +123,7 @@ void ASTDumper::dump(NumberExprAST *num) { /// [ [ 1, 2 ], [ 3, 4 ] ] /// We print out such array with the dimensions spelled out at every level: /// <2,2>[<2>[ 1, 2 ], <2>[ 3, 4 ] ] -void printLitHelper(ExprAST *litOrNum) { +static void printLitHelper(ExprAST *litOrNum) { // Inside a literal expression we can have either a number or another literal if (auto *num = llvm::dyn_cast(litOrNum)) { llvm::errs() << num->getValue(); diff --git a/mlir/examples/toy/Ch7/toyc.cpp b/mlir/examples/toy/Ch7/toyc.cpp index 32208eccaba5..553ca6ba613d 100644 --- a/mlir/examples/toy/Ch7/toyc.cpp +++ b/mlir/examples/toy/Ch7/toyc.cpp @@ -96,7 +96,8 @@ static cl::opt emitAction( static cl::opt enableOpt("opt", cl::desc("Enable optimizations")); /// Returns a Toy AST resulting from parsing the file or a nullptr on error. -std::unique_ptr parseInputFile(llvm::StringRef filename) { +static std::unique_ptr +parseInputFile(llvm::StringRef filename) { llvm::ErrorOr> fileOrErr = llvm::MemoryBuffer::getFileOrSTDIN(filename); if (std::error_code ec = fileOrErr.getError()) { @@ -109,8 +110,8 @@ std::unique_ptr parseInputFile(llvm::StringRef filename) { return parser.parseModule(); } -int loadMLIR(mlir::MLIRContext &context, - mlir::OwningOpRef &module) { +static int loadMLIR(mlir::MLIRContext &context, + mlir::OwningOpRef &module) { // Handle '.toy' input to the compiler. if (inputType != InputType::MLIR && !llvm::StringRef(inputFilename).ends_with(".mlir")) { @@ -140,8 +141,8 @@ int loadMLIR(mlir::MLIRContext &context, return 0; } -int loadAndProcessMLIR(mlir::MLIRContext &context, - mlir::OwningOpRef &module) { +static int loadAndProcessMLIR(mlir::MLIRContext &context, + mlir::OwningOpRef &module) { if (int error = loadMLIR(context, module)) return error; @@ -197,7 +198,7 @@ int loadAndProcessMLIR(mlir::MLIRContext &context, return 0; } -int dumpAST() { +static int dumpAST() { if (inputType == InputType::MLIR) { llvm::errs() << "Can't dump a Toy AST when the input is MLIR\n"; return 5; @@ -211,7 +212,7 @@ int dumpAST() { return 0; } -int dumpLLVMIR(mlir::ModuleOp module) { +static int dumpLLVMIR(mlir::ModuleOp module) { // Register the translation to LLVM IR with the MLIR context. mlir::registerBuiltinDialectTranslation(*module->getContext()); mlir::registerLLVMDialectTranslation(*module->getContext()); @@ -255,7 +256,7 @@ int dumpLLVMIR(mlir::ModuleOp module) { return 0; } -int runJit(mlir::ModuleOp module) { +static int runJit(mlir::ModuleOp module) { // Initialize LLVM targets. llvm::InitializeNativeTarget(); llvm::InitializeNativeTargetAsmPrinter();