Finish up the episode 9
This commit is contained in:
parent
664772f456
commit
1345552d27
|
@ -377,13 +377,19 @@ define i64 @main1(i64 %0, i64 %1, i64 %2) !dbg !9 {
|
||||||
- https://mlir.llvm.org/docs/LangRef
|
- https://mlir.llvm.org/docs/LangRef
|
||||||
- https://en.wikipedia.org/wiki/Basic_block
|
- https://en.wikipedia.org/wiki/Basic_block
|
||||||
|
|
||||||
* Episode 9 - Code Generation
|
* Episode 9 - IR (SLIR) generation
|
||||||
** Updates:
|
** Updates:
|
||||||
There will be an episode dedicated to eache of these
|
|
||||||
|
|
||||||
- Source manager
|
- Source manager
|
||||||
- Diagnostic Engine
|
- Diagnostic Engine
|
||||||
- JIT
|
- JIT
|
||||||
|
|
||||||
|
There will be an episode dedicated to eache of these
|
||||||
|
** How does IR generation works
|
||||||
|
- Pass around MLIR context
|
||||||
|
- Create Builder objects that creates operations in specific
|
||||||
|
locations
|
||||||
|
- ModuleOp
|
||||||
|
- Namespace
|
||||||
** How to define a new dialect
|
** How to define a new dialect
|
||||||
- Pure C++
|
- Pure C++
|
||||||
- Tablegen
|
- Tablegen
|
||||||
|
@ -392,7 +398,7 @@ There will be an episode dedicated to eache of these
|
||||||
- An IR that follows the AST
|
- An IR that follows the AST
|
||||||
- Rename?
|
- Rename?
|
||||||
*** Steps
|
*** Steps
|
||||||
- [ ] Define the new dialect
|
- [X] Define the new dialect
|
||||||
- [ ] Setup the tablegen
|
- [X] Setup the tablegen
|
||||||
- [ ] Define the operations
|
- [X] Define the operations
|
||||||
- [ ] Walk the AST and generate the operations
|
- [X] Walk the AST and generate the operations
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
set(LLVM_TARGET_DEFINITIONS dialect.td)
|
set(LLVM_TARGET_DEFINITIONS dialect.td)
|
||||||
|
|
||||||
mlir_tablegen(ops.h.inc -gen-op-decls)
|
mlir_tablegen(ops.h.inc -gen-op-decls)
|
||||||
mlir_tablegen(ops.cpp.inc -gen-op-defs)
|
mlir_tablegen(ops.cpp.inc -gen-op-defs)
|
||||||
mlir_tablegen(dialect.h.inc -gen-dialect-decls)
|
mlir_tablegen(dialect.h.inc -gen-dialect-decls)
|
||||||
mlir_tablegen(dialect.cpp.inc -gen-dialect-defs)
|
mlir_tablegen(dialect.cpp.inc -gen-dialect-defs)
|
||||||
|
|
||||||
add_public_tablegen_target(SereneDialectGen)
|
add_public_tablegen_target(SereneDialectGen)
|
||||||
|
|
|
@ -47,7 +47,7 @@ def ValueOp: Serene_Op<"value"> {
|
||||||
let arguments = (ins I64Attr:$value);
|
let arguments = (ins I64Attr:$value);
|
||||||
let results = (outs I64);
|
let results = (outs I64);
|
||||||
|
|
||||||
// let verifier = [{ return serene::sir::verify(*this); }];
|
//let verifier = [{ return serene::sir::verify(*this); }];
|
||||||
|
|
||||||
let builders = [
|
let builders = [
|
||||||
OpBuilder<(ins "int":$value), [{
|
OpBuilder<(ins "int":$value), [{
|
||||||
|
@ -80,26 +80,8 @@ def FnOp: Serene_Op<"fn", [
|
||||||
let regions = (region AnyRegion:$body);
|
let regions = (region AnyRegion:$body);
|
||||||
let results = (outs I64);
|
let results = (outs I64);
|
||||||
|
|
||||||
// let builders = [
|
|
||||||
// OpBuilder<(ins
|
|
||||||
// "llvm::StringRef":$name, "mlir::FunctionType":$type,
|
|
||||||
// CArg<"llvm::ArrayRef<mlir::NamedAttribute>", "{}">:$attrs,
|
|
||||||
// CArg<"llvm::ArrayRef<mlir::DictionaryAttr>", "{}">:$argAttrs)
|
|
||||||
// >];
|
|
||||||
|
|
||||||
// let extraClassDeclaration = [{
|
|
||||||
// static FnOp create(mlir::Location location, llvm::StringRef name, mlir::FunctionType type,
|
|
||||||
// llvm::ArrayRef<mlir::NamedAttribute> attrs = {});
|
|
||||||
// static FnOp create(mlir::Location location, llvm::StringRef name, mlir::FunctionType type,
|
|
||||||
// mlir::Operation::dialect_attr_range attrs);
|
|
||||||
// static FnOp create(mlir::Location location, llvm::StringRef name, mlir::FunctionType type,
|
|
||||||
// llvm::ArrayRef<mlir::NamedAttribute> attrs,
|
|
||||||
// llvm::ArrayRef<mlir::DictionaryAttr> argAttrs);
|
|
||||||
// }];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def ReturnOp: Serene_Op<"return", [NoSideEffect, HasParent<"FnOp">,
|
def ReturnOp: Serene_Op<"return", [NoSideEffect, HasParent<"FnOp">,
|
||||||
ReturnLike, Terminator]> {
|
ReturnLike, Terminator]> {
|
||||||
|
|
||||||
|
@ -111,18 +93,6 @@ def ReturnOp: Serene_Op<"return", [NoSideEffect, HasParent<"FnOp">,
|
||||||
let arguments = (ins AnyType:$operand);
|
let arguments = (ins AnyType:$operand);
|
||||||
let assemblyFormat =
|
let assemblyFormat =
|
||||||
[{ attr-dict $operand `:` type($operand) }];
|
[{ attr-dict $operand `:` type($operand) }];
|
||||||
|
|
||||||
// let verifier = [{ return serene::sir::verify(*this); }];
|
|
||||||
|
|
||||||
// let builders = [
|
|
||||||
// OpBuilder<(ins "int":$value), [{
|
|
||||||
// // Build from fix 64 bit int
|
|
||||||
// build(odsBuilder, odsState, odsBuilder.getI64Type(), (uint64_t) value);
|
|
||||||
// }]>,
|
|
||||||
// ];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SERENE_DIALECT
|
#endif // SERENE_DIALECT
|
||||||
|
|
|
@ -127,7 +127,6 @@ void Fn::generateIR(serene::Namespace &ns, mlir::ModuleOp &m) {
|
||||||
argSym->name, mlir::TypeAttr::get(builder.getI64Type())));
|
argSym->name, mlir::TypeAttr::get(builder.getI64Type())));
|
||||||
}
|
}
|
||||||
|
|
||||||
// auto funcType = builder.getFunctionType(arg_types, builder.getI64Type());
|
|
||||||
auto fn = builder.create<slir::FnOp>(
|
auto fn = builder.create<slir::FnOp>(
|
||||||
loc, builder.getI64Type(), name,
|
loc, builder.getI64Type(), name,
|
||||||
mlir::DictionaryAttr::get(builder.getContext(), arguments),
|
mlir::DictionaryAttr::get(builder.getContext(), arguments),
|
||||||
|
|
|
@ -111,11 +111,10 @@ void Namespace::dump() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// mlir::OpPrintingFlags flags;
|
mlir::OpPrintingFlags flags;
|
||||||
// flags.enableDebugInfo();
|
flags.enableDebugInfo();
|
||||||
|
|
||||||
// maybeModuleOp.getValue()->print(llvm::outs(), flags);
|
maybeModuleOp.getValue()->print(llvm::outs(), flags);
|
||||||
maybeModuleOp.getValue()->dump();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
MaybeModule Namespace::compileToLLVM() {
|
MaybeModule Namespace::compileToLLVM() {
|
||||||
|
@ -134,7 +133,7 @@ MaybeModule Namespace::compileToLLVM() {
|
||||||
return MaybeModule::error(true);
|
return MaybeModule::error(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
Namespace::~Namespace(){};
|
Namespace::~Namespace(){};
|
||||||
|
|
||||||
std::shared_ptr<Namespace>
|
std::shared_ptr<Namespace>
|
||||||
makeNamespace(SereneContext &ctx, llvm::StringRef name,
|
makeNamespace(SereneContext &ctx, llvm::StringRef name,
|
||||||
|
|
Loading…
Reference in New Issue