[MLIR] Apply clang-tidy fixes for misc-use-internal-linkage in toy Tutorial (NFC)

This commit is contained in:
Mehdi Amini 2025-08-21 04:14:12 -07:00
parent d2dee948a4
commit a8aacb1b66
14 changed files with 49 additions and 42 deletions

View File

@ -120,7 +120,7 @@ void ASTDumper::dump(NumberExprAST *num) {
/// [ [ 1, 2 ], [ 3, 4 ] ] /// [ [ 1, 2 ], [ 3, 4 ] ]
/// We print out such array with the dimensions spelled out at every level: /// We print out such array with the dimensions spelled out at every level:
/// <2,2>[<2>[ 1, 2 ], <2>[ 3, 4 ] ] /// <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 // Inside a literal expression we can have either a number or another literal
if (auto *num = llvm::dyn_cast<NumberExprAST>(litOrNum)) { if (auto *num = llvm::dyn_cast<NumberExprAST>(litOrNum)) {
llvm::errs() << num->getValue(); llvm::errs() << num->getValue();

View File

@ -39,7 +39,8 @@ static cl::opt<enum Action>
cl::values(clEnumValN(DumpAST, "ast", "output the AST dump"))); cl::values(clEnumValN(DumpAST, "ast", "output the AST dump")));
/// Returns a Toy AST resulting from parsing the file or a nullptr on error. /// Returns a Toy AST resulting from parsing the file or a nullptr on error.
std::unique_ptr<toy::ModuleAST> parseInputFile(llvm::StringRef filename) { static std::unique_ptr<toy::ModuleAST>
parseInputFile(llvm::StringRef filename) {
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> fileOrErr = llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> fileOrErr =
llvm::MemoryBuffer::getFileOrSTDIN(filename); llvm::MemoryBuffer::getFileOrSTDIN(filename);
if (std::error_code ec = fileOrErr.getError()) { if (std::error_code ec = fileOrErr.getError()) {

View File

@ -120,7 +120,7 @@ void ASTDumper::dump(NumberExprAST *num) {
/// [ [ 1, 2 ], [ 3, 4 ] ] /// [ [ 1, 2 ], [ 3, 4 ] ]
/// We print out such array with the dimensions spelled out at every level: /// We print out such array with the dimensions spelled out at every level:
/// <2,2>[<2>[ 1, 2 ], <2>[ 3, 4 ] ] /// <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 // Inside a literal expression we can have either a number or another literal
if (auto *num = llvm::dyn_cast<NumberExprAST>(litOrNum)) { if (auto *num = llvm::dyn_cast<NumberExprAST>(litOrNum)) {
llvm::errs() << num->getValue(); llvm::errs() << num->getValue();

View File

@ -58,7 +58,8 @@ static cl::opt<enum Action> emitAction(
cl::values(clEnumValN(DumpMLIR, "mlir", "output the MLIR dump"))); cl::values(clEnumValN(DumpMLIR, "mlir", "output the MLIR dump")));
/// Returns a Toy AST resulting from parsing the file or a nullptr on error. /// Returns a Toy AST resulting from parsing the file or a nullptr on error.
std::unique_ptr<toy::ModuleAST> parseInputFile(llvm::StringRef filename) { static std::unique_ptr<toy::ModuleAST>
parseInputFile(llvm::StringRef filename) {
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> fileOrErr = llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> fileOrErr =
llvm::MemoryBuffer::getFileOrSTDIN(filename); llvm::MemoryBuffer::getFileOrSTDIN(filename);
if (std::error_code ec = fileOrErr.getError()) { if (std::error_code ec = fileOrErr.getError()) {
@ -71,7 +72,7 @@ std::unique_ptr<toy::ModuleAST> parseInputFile(llvm::StringRef filename) {
return parser.parseModule(); return parser.parseModule();
} }
int dumpMLIR() { static int dumpMLIR() {
mlir::MLIRContext context; mlir::MLIRContext context;
// Load our Dialect in this MLIR Context. // Load our Dialect in this MLIR Context.
context.getOrLoadDialect<mlir::toy::ToyDialect>(); context.getOrLoadDialect<mlir::toy::ToyDialect>();
@ -112,7 +113,7 @@ int dumpMLIR() {
return 0; return 0;
} }
int dumpAST() { static int dumpAST() {
if (inputType == InputType::MLIR) { if (inputType == InputType::MLIR) {
llvm::errs() << "Can't dump a Toy AST when the input is MLIR\n"; llvm::errs() << "Can't dump a Toy AST when the input is MLIR\n";
return 5; return 5;

View File

@ -120,7 +120,7 @@ void ASTDumper::dump(NumberExprAST *num) {
/// [ [ 1, 2 ], [ 3, 4 ] ] /// [ [ 1, 2 ], [ 3, 4 ] ]
/// We print out such array with the dimensions spelled out at every level: /// We print out such array with the dimensions spelled out at every level:
/// <2,2>[<2>[ 1, 2 ], <2>[ 3, 4 ] ] /// <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 // Inside a literal expression we can have either a number or another literal
if (auto *num = llvm::dyn_cast<NumberExprAST>(litOrNum)) { if (auto *num = llvm::dyn_cast<NumberExprAST>(litOrNum)) {
llvm::errs() << num->getValue(); llvm::errs() << num->getValue();

View File

@ -64,7 +64,8 @@ static cl::opt<enum Action> emitAction(
static cl::opt<bool> enableOpt("opt", cl::desc("Enable optimizations")); static cl::opt<bool> enableOpt("opt", cl::desc("Enable optimizations"));
/// Returns a Toy AST resulting from parsing the file or a nullptr on error. /// Returns a Toy AST resulting from parsing the file or a nullptr on error.
std::unique_ptr<toy::ModuleAST> parseInputFile(llvm::StringRef filename) { static std::unique_ptr<toy::ModuleAST>
parseInputFile(llvm::StringRef filename) {
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> fileOrErr = llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> fileOrErr =
llvm::MemoryBuffer::getFileOrSTDIN(filename); llvm::MemoryBuffer::getFileOrSTDIN(filename);
if (std::error_code ec = fileOrErr.getError()) { if (std::error_code ec = fileOrErr.getError()) {
@ -77,7 +78,7 @@ std::unique_ptr<toy::ModuleAST> parseInputFile(llvm::StringRef filename) {
return parser.parseModule(); return parser.parseModule();
} }
int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context, static int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context,
mlir::OwningOpRef<mlir::ModuleOp> &module) { mlir::OwningOpRef<mlir::ModuleOp> &module) {
// Handle '.toy' input to the compiler. // Handle '.toy' input to the compiler.
if (inputType != InputType::MLIR && if (inputType != InputType::MLIR &&
@ -107,7 +108,7 @@ int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context,
return 0; return 0;
} }
int dumpMLIR() { static int dumpMLIR() {
mlir::MLIRContext context; mlir::MLIRContext context;
// Load our Dialect in this MLIR Context. // Load our Dialect in this MLIR Context.
context.getOrLoadDialect<mlir::toy::ToyDialect>(); context.getOrLoadDialect<mlir::toy::ToyDialect>();
@ -134,7 +135,7 @@ int dumpMLIR() {
return 0; return 0;
} }
int dumpAST() { static int dumpAST() {
if (inputType == InputType::MLIR) { if (inputType == InputType::MLIR) {
llvm::errs() << "Can't dump a Toy AST when the input is MLIR\n"; llvm::errs() << "Can't dump a Toy AST when the input is MLIR\n";
return 5; return 5;

View File

@ -120,7 +120,7 @@ void ASTDumper::dump(NumberExprAST *num) {
/// [ [ 1, 2 ], [ 3, 4 ] ] /// [ [ 1, 2 ], [ 3, 4 ] ]
/// We print out such array with the dimensions spelled out at every level: /// We print out such array with the dimensions spelled out at every level:
/// <2,2>[<2>[ 1, 2 ], <2>[ 3, 4 ] ] /// <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 // Inside a literal expression we can have either a number or another literal
if (auto *num = llvm::dyn_cast<NumberExprAST>(litOrNum)) { if (auto *num = llvm::dyn_cast<NumberExprAST>(litOrNum)) {
llvm::errs() << num->getValue(); llvm::errs() << num->getValue();

View File

@ -65,7 +65,8 @@ static cl::opt<enum Action> emitAction(
static cl::opt<bool> enableOpt("opt", cl::desc("Enable optimizations")); static cl::opt<bool> enableOpt("opt", cl::desc("Enable optimizations"));
/// Returns a Toy AST resulting from parsing the file or a nullptr on error. /// Returns a Toy AST resulting from parsing the file or a nullptr on error.
std::unique_ptr<toy::ModuleAST> parseInputFile(llvm::StringRef filename) { static std::unique_ptr<toy::ModuleAST>
parseInputFile(llvm::StringRef filename) {
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> fileOrErr = llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> fileOrErr =
llvm::MemoryBuffer::getFileOrSTDIN(filename); llvm::MemoryBuffer::getFileOrSTDIN(filename);
if (std::error_code ec = fileOrErr.getError()) { if (std::error_code ec = fileOrErr.getError()) {
@ -78,7 +79,7 @@ std::unique_ptr<toy::ModuleAST> parseInputFile(llvm::StringRef filename) {
return parser.parseModule(); return parser.parseModule();
} }
int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context, static int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context,
mlir::OwningOpRef<mlir::ModuleOp> &module) { mlir::OwningOpRef<mlir::ModuleOp> &module) {
// Handle '.toy' input to the compiler. // Handle '.toy' input to the compiler.
if (inputType != InputType::MLIR && if (inputType != InputType::MLIR &&
@ -108,7 +109,7 @@ int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context,
return 0; return 0;
} }
int dumpMLIR() { static int dumpMLIR() {
mlir::MLIRContext context; mlir::MLIRContext context;
// Load our Dialect in this MLIR Context. // Load our Dialect in this MLIR Context.
context.getOrLoadDialect<mlir::toy::ToyDialect>(); context.getOrLoadDialect<mlir::toy::ToyDialect>();
@ -143,7 +144,7 @@ int dumpMLIR() {
return 0; return 0;
} }
int dumpAST() { static int dumpAST() {
if (inputType == InputType::MLIR) { if (inputType == InputType::MLIR) {
llvm::errs() << "Can't dump a Toy AST when the input is MLIR\n"; llvm::errs() << "Can't dump a Toy AST when the input is MLIR\n";
return 5; return 5;

View File

@ -120,7 +120,7 @@ void ASTDumper::dump(NumberExprAST *num) {
/// [ [ 1, 2 ], [ 3, 4 ] ] /// [ [ 1, 2 ], [ 3, 4 ] ]
/// We print out such array with the dimensions spelled out at every level: /// We print out such array with the dimensions spelled out at every level:
/// <2,2>[<2>[ 1, 2 ], <2>[ 3, 4 ] ] /// <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 // Inside a literal expression we can have either a number or another literal
if (auto *num = llvm::dyn_cast<NumberExprAST>(litOrNum)) { if (auto *num = llvm::dyn_cast<NumberExprAST>(litOrNum)) {
llvm::errs() << num->getValue(); llvm::errs() << num->getValue();

View File

@ -71,7 +71,8 @@ static cl::opt<enum Action> emitAction(
static cl::opt<bool> enableOpt("opt", cl::desc("Enable optimizations")); static cl::opt<bool> enableOpt("opt", cl::desc("Enable optimizations"));
/// Returns a Toy AST resulting from parsing the file or a nullptr on error. /// Returns a Toy AST resulting from parsing the file or a nullptr on error.
std::unique_ptr<toy::ModuleAST> parseInputFile(llvm::StringRef filename) { static std::unique_ptr<toy::ModuleAST>
parseInputFile(llvm::StringRef filename) {
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> fileOrErr = llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> fileOrErr =
llvm::MemoryBuffer::getFileOrSTDIN(filename); llvm::MemoryBuffer::getFileOrSTDIN(filename);
if (std::error_code ec = fileOrErr.getError()) { if (std::error_code ec = fileOrErr.getError()) {
@ -84,7 +85,7 @@ std::unique_ptr<toy::ModuleAST> parseInputFile(llvm::StringRef filename) {
return parser.parseModule(); return parser.parseModule();
} }
int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context, static int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context,
mlir::OwningOpRef<mlir::ModuleOp> &module) { mlir::OwningOpRef<mlir::ModuleOp> &module) {
// Handle '.toy' input to the compiler. // Handle '.toy' input to the compiler.
if (inputType != InputType::MLIR && if (inputType != InputType::MLIR &&
@ -114,7 +115,7 @@ int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context,
return 0; return 0;
} }
int dumpMLIR() { static int dumpMLIR() {
mlir::DialectRegistry registry; mlir::DialectRegistry registry;
mlir::func::registerAllExtensions(registry); mlir::func::registerAllExtensions(registry);
@ -171,7 +172,7 @@ int dumpMLIR() {
return 0; return 0;
} }
int dumpAST() { static int dumpAST() {
if (inputType == InputType::MLIR) { if (inputType == InputType::MLIR) {
llvm::errs() << "Can't dump a Toy AST when the input is MLIR\n"; llvm::errs() << "Can't dump a Toy AST when the input is MLIR\n";
return 5; return 5;

View File

@ -120,7 +120,7 @@ void ASTDumper::dump(NumberExprAST *num) {
/// [ [ 1, 2 ], [ 3, 4 ] ] /// [ [ 1, 2 ], [ 3, 4 ] ]
/// We print out such array with the dimensions spelled out at every level: /// We print out such array with the dimensions spelled out at every level:
/// <2,2>[<2>[ 1, 2 ], <2>[ 3, 4 ] ] /// <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 // Inside a literal expression we can have either a number or another literal
if (auto *num = llvm::dyn_cast<NumberExprAST>(litOrNum)) { if (auto *num = llvm::dyn_cast<NumberExprAST>(litOrNum)) {
llvm::errs() << num->getValue(); llvm::errs() << num->getValue();

View File

@ -96,7 +96,8 @@ static cl::opt<enum Action> emitAction(
static cl::opt<bool> enableOpt("opt", cl::desc("Enable optimizations")); static cl::opt<bool> enableOpt("opt", cl::desc("Enable optimizations"));
/// Returns a Toy AST resulting from parsing the file or a nullptr on error. /// Returns a Toy AST resulting from parsing the file or a nullptr on error.
std::unique_ptr<toy::ModuleAST> parseInputFile(llvm::StringRef filename) { static std::unique_ptr<toy::ModuleAST>
parseInputFile(llvm::StringRef filename) {
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> fileOrErr = llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> fileOrErr =
llvm::MemoryBuffer::getFileOrSTDIN(filename); llvm::MemoryBuffer::getFileOrSTDIN(filename);
if (std::error_code ec = fileOrErr.getError()) { if (std::error_code ec = fileOrErr.getError()) {
@ -109,7 +110,7 @@ std::unique_ptr<toy::ModuleAST> parseInputFile(llvm::StringRef filename) {
return parser.parseModule(); return parser.parseModule();
} }
int loadMLIR(mlir::MLIRContext &context, static int loadMLIR(mlir::MLIRContext &context,
mlir::OwningOpRef<mlir::ModuleOp> &module) { mlir::OwningOpRef<mlir::ModuleOp> &module) {
// Handle '.toy' input to the compiler. // Handle '.toy' input to the compiler.
if (inputType != InputType::MLIR && if (inputType != InputType::MLIR &&
@ -140,7 +141,7 @@ int loadMLIR(mlir::MLIRContext &context,
return 0; return 0;
} }
int loadAndProcessMLIR(mlir::MLIRContext &context, static int loadAndProcessMLIR(mlir::MLIRContext &context,
mlir::OwningOpRef<mlir::ModuleOp> &module) { mlir::OwningOpRef<mlir::ModuleOp> &module) {
if (int error = loadMLIR(context, module)) if (int error = loadMLIR(context, module))
return error; return error;
@ -196,7 +197,7 @@ int loadAndProcessMLIR(mlir::MLIRContext &context,
return 0; return 0;
} }
int dumpAST() { static int dumpAST() {
if (inputType == InputType::MLIR) { if (inputType == InputType::MLIR) {
llvm::errs() << "Can't dump a Toy AST when the input is MLIR\n"; llvm::errs() << "Can't dump a Toy AST when the input is MLIR\n";
return 5; return 5;
@ -210,7 +211,7 @@ int dumpAST() {
return 0; return 0;
} }
int dumpLLVMIR(mlir::ModuleOp module) { static int dumpLLVMIR(mlir::ModuleOp module) {
// Register the translation to LLVM IR with the MLIR context. // Register the translation to LLVM IR with the MLIR context.
mlir::registerBuiltinDialectTranslation(*module->getContext()); mlir::registerBuiltinDialectTranslation(*module->getContext());
mlir::registerLLVMDialectTranslation(*module->getContext()); mlir::registerLLVMDialectTranslation(*module->getContext());
@ -254,7 +255,7 @@ int dumpLLVMIR(mlir::ModuleOp module) {
return 0; return 0;
} }
int runJit(mlir::ModuleOp module) { static int runJit(mlir::ModuleOp module) {
// Initialize LLVM targets. // Initialize LLVM targets.
llvm::InitializeNativeTarget(); llvm::InitializeNativeTarget();
llvm::InitializeNativeTargetAsmPrinter(); llvm::InitializeNativeTargetAsmPrinter();

View File

@ -123,7 +123,7 @@ void ASTDumper::dump(NumberExprAST *num) {
/// [ [ 1, 2 ], [ 3, 4 ] ] /// [ [ 1, 2 ], [ 3, 4 ] ]
/// We print out such array with the dimensions spelled out at every level: /// We print out such array with the dimensions spelled out at every level:
/// <2,2>[<2>[ 1, 2 ], <2>[ 3, 4 ] ] /// <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 // Inside a literal expression we can have either a number or another literal
if (auto *num = llvm::dyn_cast<NumberExprAST>(litOrNum)) { if (auto *num = llvm::dyn_cast<NumberExprAST>(litOrNum)) {
llvm::errs() << num->getValue(); llvm::errs() << num->getValue();

View File

@ -96,7 +96,8 @@ static cl::opt<enum Action> emitAction(
static cl::opt<bool> enableOpt("opt", cl::desc("Enable optimizations")); static cl::opt<bool> enableOpt("opt", cl::desc("Enable optimizations"));
/// Returns a Toy AST resulting from parsing the file or a nullptr on error. /// Returns a Toy AST resulting from parsing the file or a nullptr on error.
std::unique_ptr<toy::ModuleAST> parseInputFile(llvm::StringRef filename) { static std::unique_ptr<toy::ModuleAST>
parseInputFile(llvm::StringRef filename) {
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> fileOrErr = llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> fileOrErr =
llvm::MemoryBuffer::getFileOrSTDIN(filename); llvm::MemoryBuffer::getFileOrSTDIN(filename);
if (std::error_code ec = fileOrErr.getError()) { if (std::error_code ec = fileOrErr.getError()) {
@ -109,7 +110,7 @@ std::unique_ptr<toy::ModuleAST> parseInputFile(llvm::StringRef filename) {
return parser.parseModule(); return parser.parseModule();
} }
int loadMLIR(mlir::MLIRContext &context, static int loadMLIR(mlir::MLIRContext &context,
mlir::OwningOpRef<mlir::ModuleOp> &module) { mlir::OwningOpRef<mlir::ModuleOp> &module) {
// Handle '.toy' input to the compiler. // Handle '.toy' input to the compiler.
if (inputType != InputType::MLIR && if (inputType != InputType::MLIR &&
@ -140,7 +141,7 @@ int loadMLIR(mlir::MLIRContext &context,
return 0; return 0;
} }
int loadAndProcessMLIR(mlir::MLIRContext &context, static int loadAndProcessMLIR(mlir::MLIRContext &context,
mlir::OwningOpRef<mlir::ModuleOp> &module) { mlir::OwningOpRef<mlir::ModuleOp> &module) {
if (int error = loadMLIR(context, module)) if (int error = loadMLIR(context, module))
return error; return error;
@ -197,7 +198,7 @@ int loadAndProcessMLIR(mlir::MLIRContext &context,
return 0; return 0;
} }
int dumpAST() { static int dumpAST() {
if (inputType == InputType::MLIR) { if (inputType == InputType::MLIR) {
llvm::errs() << "Can't dump a Toy AST when the input is MLIR\n"; llvm::errs() << "Can't dump a Toy AST when the input is MLIR\n";
return 5; return 5;
@ -211,7 +212,7 @@ int dumpAST() {
return 0; return 0;
} }
int dumpLLVMIR(mlir::ModuleOp module) { static int dumpLLVMIR(mlir::ModuleOp module) {
// Register the translation to LLVM IR with the MLIR context. // Register the translation to LLVM IR with the MLIR context.
mlir::registerBuiltinDialectTranslation(*module->getContext()); mlir::registerBuiltinDialectTranslation(*module->getContext());
mlir::registerLLVMDialectTranslation(*module->getContext()); mlir::registerLLVMDialectTranslation(*module->getContext());
@ -255,7 +256,7 @@ int dumpLLVMIR(mlir::ModuleOp module) {
return 0; return 0;
} }
int runJit(mlir::ModuleOp module) { static int runJit(mlir::ModuleOp module) {
// Initialize LLVM targets. // Initialize LLVM targets.
llvm::InitializeNativeTarget(); llvm::InitializeNativeTarget();
llvm::InitializeNativeTargetAsmPrinter(); llvm::InitializeNativeTargetAsmPrinter();