Skip to content

Commit 6d9ec43

Browse files
Support the llvm 22 (#9)
- Deleted obsolete ToyCombine.td, AST.cpp, struct-codegen.toy, and toyc.cpp files from the Ch8 example. - Updated README.md to remove references to the deleted files and examples. - Modified build_deps.sh and sync_deps.sh scripts to ensure proper dependency management. - Added explicit TypeID definitions in MyExtension classes across multiple transform examples. - Improved comments and formatting in MyExtension.td and MyExtensionTypes.td for clarity. - Updated debug logging in MyExtension.cpp to use the new logging macros.
1 parent 8a28372 commit 6d9ec43

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+553
-5607
lines changed

mlir/example/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ add_subdirectory(Ch4)
4242
add_subdirectory(Ch5)
4343
add_subdirectory(Ch6)
4444
add_subdirectory(Ch7)
45-
add_subdirectory(Ch8)
4645
add_subdirectory(transform_Ch2)
4746
add_subdirectory(transform_Ch3)
4847
add_subdirectory(transform_Ch4)

mlir/example/Ch1/include/toy/Lexer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "llvm/ADT/StringRef.h"
1717

18+
#include <cstdlib>
1819
#include <memory>
1920
#include <string>
2021

mlir/example/Ch1/parser/AST.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void ASTDumper::dump(NumberExprAST *num) {
120120
/// [ [ 1, 2 ], [ 3, 4 ] ]
121121
/// We print out such array with the dimensions spelled out at every level:
122122
/// <2,2>[<2>[ 1, 2 ], <2>[ 3, 4 ] ]
123-
void printLitHelper(ExprAST *litOrNum) {
123+
static void printLitHelper(ExprAST *litOrNum) {
124124
// Inside a literal expression we can have either a number or another literal
125125
if (auto *num = llvm::dyn_cast<NumberExprAST>(litOrNum)) {
126126
llvm::errs() << num->getValue();

mlir/example/Ch1/toyc.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ static cl::opt<enum Action>
3939
cl::values(clEnumValN(DumpAST, "ast", "output the AST dump")));
4040

4141
/// Returns a Toy AST resulting from parsing the file or a nullptr on error.
42-
std::unique_ptr<toy::ModuleAST> parseInputFile(llvm::StringRef filename) {
42+
static std::unique_ptr<toy::ModuleAST>
43+
parseInputFile(llvm::StringRef filename) {
4344
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> fileOrErr =
4445
llvm::MemoryBuffer::getFileOrSTDIN(filename);
4546
if (std::error_code ec = fileOrErr.getError()) {

mlir/example/Ch2/include/toy/Lexer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "llvm/ADT/StringRef.h"
1717

18+
#include <cstdlib>
1819
#include <memory>
1920
#include <string>
2021

mlir/example/Ch2/include/toy/Ops.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def ConstantOp : Toy_Op<"constant", [Pure]> {
7070

7171
// Add custom build methods for the constant operation. These method populates
7272
// the `state` that MLIR uses to create operations, i.e. these are used when
73-
// using `builder.create<ConstantOp>(...)`.
73+
// using `ConstantOp::create(builder, ...)`.
7474
let builders = [
7575
// Build a constant with a given constant tensor value.
7676
OpBuilder<(ins "DenseElementsAttr":$value), [{
@@ -297,7 +297,7 @@ def ReturnOp : Toy_Op<"return", [Pure, HasParent<"FuncOp">,
297297

298298
// Allow building a ReturnOp with no return operand.
299299
let builders = [
300-
OpBuilder<(ins), [{ build($_builder, $_state, std::nullopt); }]>
300+
OpBuilder<(ins), [{ build($_builder, $_state, {}); }]>
301301
];
302302

303303
// Provide extra utility definitions on the c++ operation class definition.

mlir/example/Ch2/mlir/MLIRGen.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ class MLIRGenImpl {
120120
// Arguments type are uniformly unranked tensors.
121121
llvm::SmallVector<mlir::Type, 4> argTypes(proto.getArgs().size(),
122122
getType(VarType{}));
123-
auto funcType = builder.getFunctionType(argTypes, std::nullopt);
124-
return builder.create<mlir::toy::FuncOp>(location, proto.getName(),
125-
funcType);
123+
auto funcType = builder.getFunctionType(argTypes, {});
124+
return mlir::toy::FuncOp::create(builder, location, proto.getName(),
125+
funcType);
126126
}
127127

128128
/// Emit a new function and add it to the MLIR module.
@@ -166,7 +166,7 @@ class MLIRGenImpl {
166166
if (!entryBlock.empty())
167167
returnOp = dyn_cast<ReturnOp>(entryBlock.back());
168168
if (!returnOp) {
169-
builder.create<ReturnOp>(loc(funcAST.getProto()->loc()));
169+
ReturnOp::create(builder, loc(funcAST.getProto()->loc()));
170170
} else if (returnOp.hasOperand()) {
171171
// Otherwise, if this return operation has an operand then add a result to
172172
// the function.
@@ -202,9 +202,9 @@ class MLIRGenImpl {
202202
// support '+' and '*'.
203203
switch (binop.getOp()) {
204204
case '+':
205-
return builder.create<AddOp>(location, lhs, rhs);
205+
return AddOp::create(builder, location, lhs, rhs);
206206
case '*':
207-
return builder.create<MulOp>(location, lhs, rhs);
207+
return MulOp::create(builder, location, lhs, rhs);
208208
}
209209

210210
emitError(location, "invalid binary operator '") << binop.getOp() << "'";
@@ -235,8 +235,8 @@ class MLIRGenImpl {
235235
}
236236

237237
// Otherwise, this return operation has zero operands.
238-
builder.create<ReturnOp>(location,
239-
expr ? ArrayRef(expr) : ArrayRef<mlir::Value>());
238+
ReturnOp::create(builder, location,
239+
expr ? ArrayRef(expr) : ArrayRef<mlir::Value>());
240240
return mlir::success();
241241
}
242242

@@ -264,8 +264,7 @@ class MLIRGenImpl {
264264
// The attribute is a vector with a floating point value per element
265265
// (number) in the array, see `collectData()` below for more details.
266266
std::vector<double> data;
267-
data.reserve(std::accumulate(lit.getDims().begin(), lit.getDims().end(), 1,
268-
std::multiplies<int>()));
267+
data.reserve(llvm::product_of(lit.getDims()));
269268
collectData(lit, data);
270269

271270
// The type of this attribute is tensor of 64-bit floating-point with the
@@ -280,7 +279,7 @@ class MLIRGenImpl {
280279

281280
// Build the MLIR op `toy.constant`. This invokes the `ConstantOp::build`
282281
// method.
283-
return builder.create<ConstantOp>(loc(lit.loc()), type, dataAttribute);
282+
return ConstantOp::create(builder, loc(lit.loc()), type, dataAttribute);
284283
}
285284

286285
/// Recursive helper function to accumulate the data that compose an array
@@ -325,13 +324,13 @@ class MLIRGenImpl {
325324
"does not accept multiple arguments");
326325
return nullptr;
327326
}
328-
return builder.create<TransposeOp>(location, operands[0]);
327+
return TransposeOp::create(builder, location, operands[0]);
329328
}
330329

331330
// Otherwise this is a call to a user-defined function. Calls to
332331
// user-defined functions are mapped to a custom call that takes the callee
333332
// name as an attribute.
334-
return builder.create<GenericCallOp>(location, callee, operands);
333+
return GenericCallOp::create(builder, location, callee, operands);
335334
}
336335

337336
/// Emit a print expression. It emits specific operations for two builtins:
@@ -341,13 +340,13 @@ class MLIRGenImpl {
341340
if (!arg)
342341
return mlir::failure();
343342

344-
builder.create<PrintOp>(loc(call.loc()), arg);
343+
PrintOp::create(builder, loc(call.loc()), arg);
345344
return mlir::success();
346345
}
347346

348347
/// Emit a constant for a single number (FIXME: semantic? broadcast?)
349348
mlir::Value mlirGen(NumberExprAST &num) {
350-
return builder.create<ConstantOp>(loc(num.loc()), num.getValue());
349+
return ConstantOp::create(builder, loc(num.loc()), num.getValue());
351350
}
352351

353352
/// Dispatch codegen for the right expression subclass using RTTI.
@@ -391,8 +390,8 @@ class MLIRGenImpl {
391390
// with specific shape, we emit a "reshape" operation. It will get
392391
// optimized out later as needed.
393392
if (!vardecl.getType().shape.empty()) {
394-
value = builder.create<ReshapeOp>(loc(vardecl.loc()),
395-
getType(vardecl.getType()), value);
393+
value = ReshapeOp::create(builder, loc(vardecl.loc()),
394+
getType(vardecl.getType()), value);
396395
}
397396

398397
// Register the value in the symbol table.

mlir/example/Ch2/parser/AST.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void ASTDumper::dump(NumberExprAST *num) {
120120
/// [ [ 1, 2 ], [ 3, 4 ] ]
121121
/// We print out such array with the dimensions spelled out at every level:
122122
/// <2,2>[<2>[ 1, 2 ], <2>[ 3, 4 ] ]
123-
void printLitHelper(ExprAST *litOrNum) {
123+
static void printLitHelper(ExprAST *litOrNum) {
124124
// Inside a literal expression we can have either a number or another literal
125125
if (auto *num = llvm::dyn_cast<NumberExprAST>(litOrNum)) {
126126
llvm::errs() << num->getValue();

mlir/example/Ch2/toyc.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ static cl::opt<enum Action> emitAction(
5858
cl::values(clEnumValN(DumpMLIR, "mlir", "output the MLIR dump")));
5959

6060
/// Returns a Toy AST resulting from parsing the file or a nullptr on error.
61-
std::unique_ptr<toy::ModuleAST> parseInputFile(llvm::StringRef filename) {
61+
static std::unique_ptr<toy::ModuleAST>
62+
parseInputFile(llvm::StringRef filename) {
6263
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> fileOrErr =
6364
llvm::MemoryBuffer::getFileOrSTDIN(filename);
6465
if (std::error_code ec = fileOrErr.getError()) {
@@ -71,7 +72,7 @@ std::unique_ptr<toy::ModuleAST> parseInputFile(llvm::StringRef filename) {
7172
return parser.parseModule();
7273
}
7374

74-
int dumpMLIR() {
75+
static int dumpMLIR() {
7576
mlir::MLIRContext context;
7677
// Load our Dialect in this MLIR Context.
7778
context.getOrLoadDialect<mlir::toy::ToyDialect>();
@@ -112,7 +113,7 @@ int dumpMLIR() {
112113
return 0;
113114
}
114115

115-
int dumpAST() {
116+
static int dumpAST() {
116117
if (inputType == InputType::MLIR) {
117118
llvm::errs() << "Can't dump a Toy AST when the input is MLIR\n";
118119
return 5;

mlir/example/Ch3/include/toy/Lexer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "llvm/ADT/StringRef.h"
1717

18+
#include <cstdlib>
1819
#include <memory>
1920
#include <string>
2021

0 commit comments

Comments
 (0)