Rename the old ops of slir to mark them for removal
This commit is contained in:
parent
12c2d1d455
commit
3a3e3a4da4
|
@ -1,3 +1,26 @@
|
|||
module @some.ns {
|
||||
%1 = "serene.define" (): () -> i32
|
||||
// Value operator ----
|
||||
%0 = "serene.value"(){value= 3} : () -> i64
|
||||
// compact form
|
||||
%1 = serene.value 3 : i32
|
||||
|
||||
// Def operator ----
|
||||
%foo = "serene.def"(%0){name = "foo"}: (i64) -> !serene.symbol
|
||||
// compact form
|
||||
%bar = serene.def "bar", %0 : i64
|
||||
|
||||
// Fn operator ----
|
||||
%f1 = "serene.fn"()({
|
||||
^entry(%fnarg1 : i1, %fnarg2 : !serene.symbol, %fnarg3 : !serene.fn):
|
||||
%2 = serene.value 3 : i32
|
||||
|
||||
// Def operator ----
|
||||
%baz = "serene.def"(%0){name = "baz"}: (i64) -> !serene.symbol
|
||||
},
|
||||
{
|
||||
%3 = serene.value 4 : i32
|
||||
|
||||
// Def operator ----
|
||||
%baz1 = "serene.def"(%3){name = "baz"}: (i32) -> !serene.symbol
|
||||
}){name = "some-fn", return_type = i32} : () -> !serene.fn
|
||||
}
|
||||
|
|
|
@ -24,9 +24,11 @@
|
|||
#include <mlir/IR/BuiltinOps.h>
|
||||
#include <mlir/IR/Dialect.h>
|
||||
#include <mlir/IR/DialectRegistry.h>
|
||||
#include <mlir/IR/FunctionInterfaces.h>
|
||||
#include <mlir/Interfaces/CallInterfaces.h>
|
||||
#include <mlir/Interfaces/ControlFlowInterfaces.h>
|
||||
#include <mlir/Interfaces/InferTypeOpInterface.h>
|
||||
#include <mlir/Interfaces/SideEffectInterfaces.h>
|
||||
|
||||
// Include the auto-generated header file containing the declaration of the
|
||||
// serene's dialect.
|
||||
#include "serene/slir/dialect.h.inc"
|
||||
|
|
|
@ -1,19 +1,34 @@
|
|||
/* -*- C++ -*-
|
||||
* Serene Programming Language
|
||||
*
|
||||
* Copyright (c) 2019-2022 Sameer Rahmani <lxsameer@gnu.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 2.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SERENE_DIALECT
|
||||
#define SERENE_DIALECT
|
||||
|
||||
|
||||
include "mlir/IR/OpBase.td"
|
||||
include "mlir/IR/OpAsmInterface.td"
|
||||
include "mlir/IR/SymbolInterfaces.td"
|
||||
include "mlir/IR/AttrTypeBase.td"
|
||||
include "mlir/Interfaces/SideEffectInterfaces.td"
|
||||
include "mlir/Interfaces/CallInterfaces.td"
|
||||
include "mlir/Interfaces/CastInterfaces.td"
|
||||
include "mlir/Interfaces/SideEffectInterfaces.td"
|
||||
include "mlir/Interfaces/ControlFlowInterfaces.td"
|
||||
include "mlir/Interfaces/InferTypeOpInterface.td"
|
||||
include "mlir/Interfaces/DataLayoutInterfaces.td"
|
||||
include "mlir/Interfaces/VectorInterfaces.td"
|
||||
|
||||
|
||||
// Dialect definition. It will directly generate the SereneDialect class
|
||||
def Serene_Dialect : Dialect {
|
||||
let name = "serene";
|
||||
|
@ -31,38 +46,20 @@ def Serene_Dialect : Dialect {
|
|||
let useDefaultAttributePrinterParser = 1;
|
||||
}
|
||||
|
||||
// Base class for Serene dialect operations. This operation inherits from the base
|
||||
// `Op` class in OpBase.td, and provides:
|
||||
// * The parent dialect of the operation.
|
||||
// * The mnemonic for the operation, or the name without the dialect prefix.
|
||||
// * A list of traits for the operation.
|
||||
class Serene_Op<string mnemonic, list<Trait> traits = []> :
|
||||
Op<Serene_Dialect, mnemonic, traits>;
|
||||
|
||||
// TODO: break up the types into their own file
|
||||
// All of the types will extend this class.
|
||||
class Serene_Type<string name> : TypeDef<Serene_Dialect, name> { }
|
||||
|
||||
|
||||
def SereneSymbol : Serene_Type<"Symbol"> {
|
||||
let mnemonic = "symbol";
|
||||
|
||||
let summary = "A Lisp symbol type";
|
||||
include "types.td"
|
||||
include "ops.td"
|
||||
|
||||
// ============================================================================
|
||||
// Old operations that are we need to replace
|
||||
// ============================================================================
|
||||
def Value1Op: Serene_Op<"value1"> {
|
||||
let summary = "This operation represent a compile time value";
|
||||
let description = [{
|
||||
A Lisp symbol type
|
||||
}];
|
||||
ValueOp represent a value in compile time. For example:
|
||||
|
||||
let parameters = (ins "std::string":$ns, "std::string":$name);
|
||||
let assemblyFormat = "`<` $ns `,` $name `>`";
|
||||
}
|
||||
|
||||
|
||||
def ValueOp: Serene_Op<"value"> {
|
||||
|
||||
let summary = "This operation represent a value";
|
||||
let description = [{
|
||||
ValueOp
|
||||
```mlir
|
||||
%0 = "serene.value"(){value = 3} : () -> i64
|
||||
```
|
||||
}];
|
||||
|
||||
let arguments = (ins I64Attr:$value);
|
||||
|
@ -79,24 +76,7 @@ def ValueOp: Serene_Op<"value"> {
|
|||
];
|
||||
}
|
||||
|
||||
// Def
|
||||
def DefOp: Serene_Op<"def"> {
|
||||
|
||||
let summary = "This operation defines a global binding";
|
||||
let description = [{
|
||||
DefOp
|
||||
}];
|
||||
|
||||
let arguments = (ins StrAttr:$name,
|
||||
AnyType:$value,
|
||||
OptionalAttr<StrAttr>:$sym_visibility);
|
||||
|
||||
let results = (outs SereneSymbol);
|
||||
}
|
||||
|
||||
|
||||
// TODO: Add the FunctionLike trait here and include its header file in dialect.h
|
||||
def FnOp: Serene_Op<"fn", [
|
||||
def Fn1Op: Serene_Op<"fn1", [
|
||||
AffineScope, AutomaticAllocationScope,
|
||||
IsolatedFromAbove,
|
||||
]> {
|
||||
|
@ -113,11 +93,11 @@ def FnOp: Serene_Op<"fn", [
|
|||
OptionalAttr<StrAttr>:$sym_visibility);
|
||||
|
||||
let regions = (region AnyRegion:$body);
|
||||
let results = (outs I64);
|
||||
let results = (outs SereneFn);
|
||||
|
||||
}
|
||||
|
||||
def ReturnOp: Serene_Op<"return", [NoSideEffect, HasParent<"FnOp">,
|
||||
def Return1Op: Serene_Op<"return", [NoSideEffect, HasParent<"Fn1Op">,
|
||||
ReturnLike, Terminator]> {
|
||||
|
||||
let summary = "This operation marks the return value of a function";
|
||||
|
|
|
@ -132,7 +132,7 @@ void Fn::generateIR(serene::Namespace &ns, mlir::ModuleOp &m) {
|
|||
argSym->name, mlir::TypeAttr::get(builder.getI64Type())));
|
||||
}
|
||||
|
||||
auto fn = builder.create<slir::FnOp>(
|
||||
auto fn = builder.create<slir::Fn1Op>(
|
||||
loc, builder.getI64Type(), name,
|
||||
mlir::DictionaryAttr::get(builder.getContext(), arguments),
|
||||
builder.getStringAttr("public"));
|
||||
|
@ -148,9 +148,9 @@ void Fn::generateIR(serene::Namespace &ns, mlir::ModuleOp &m) {
|
|||
body.push_back(entryBlock);
|
||||
|
||||
builder.setInsertionPointToStart(entryBlock);
|
||||
auto retVal = builder.create<slir::ValueOp>(loc, 0).getResult();
|
||||
auto retVal = builder.create<slir::Value1Op>(loc, 0).getResult();
|
||||
|
||||
slir::ReturnOp returnOp = builder.create<slir::ReturnOp>(loc, retVal);
|
||||
slir::Return1Op returnOp = builder.create<slir::Return1Op>(loc, retVal);
|
||||
|
||||
if (!returnOp) {
|
||||
m.emitError(
|
||||
|
|
|
@ -46,7 +46,7 @@ int Number::toI64() const { return std::stoi(this->value); };
|
|||
void Number::generateIR(serene::Namespace &ns, mlir::ModuleOp &m) {
|
||||
mlir::OpBuilder builder(&ns.getContext().mlirContext);
|
||||
|
||||
auto op = builder.create<serene::slir::ValueOp>(
|
||||
auto op = builder.create<serene::slir::Value1Op>(
|
||||
serene::slir::toMLIRLocation(ns, location.start), toI64());
|
||||
|
||||
if (op) {
|
||||
|
|
|
@ -37,16 +37,16 @@ namespace serene::passes {
|
|||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ValueOp lowering to constant op
|
||||
struct ValueOpLowering : public mlir::OpRewritePattern<serene::slir::ValueOp> {
|
||||
using OpRewritePattern<serene::slir::ValueOp>::OpRewritePattern;
|
||||
struct ValueOpLowering : public mlir::OpRewritePattern<serene::slir::Value1Op> {
|
||||
using OpRewritePattern<serene::slir::Value1Op>::OpRewritePattern;
|
||||
|
||||
mlir::LogicalResult
|
||||
matchAndRewrite(serene::slir::ValueOp op,
|
||||
matchAndRewrite(serene::slir::Value1Op op,
|
||||
mlir::PatternRewriter &rewriter) const final;
|
||||
};
|
||||
|
||||
mlir::LogicalResult
|
||||
ValueOpLowering::matchAndRewrite(serene::slir::ValueOp op,
|
||||
ValueOpLowering::matchAndRewrite(serene::slir::Value1Op op,
|
||||
mlir::PatternRewriter &rewriter) const {
|
||||
auto value = op.value();
|
||||
mlir::Location loc = op.getLoc();
|
||||
|
@ -76,16 +76,16 @@ ValueOpLowering::matchAndRewrite(serene::slir::ValueOp op,
|
|||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Fn lowering pattern
|
||||
struct FnOpLowering : public mlir::OpRewritePattern<serene::slir::FnOp> {
|
||||
using OpRewritePattern<serene::slir::FnOp>::OpRewritePattern;
|
||||
struct FnOpLowering : public mlir::OpRewritePattern<serene::slir::Fn1Op> {
|
||||
using OpRewritePattern<serene::slir::Fn1Op>::OpRewritePattern;
|
||||
|
||||
mlir::LogicalResult
|
||||
matchAndRewrite(serene::slir::FnOp op,
|
||||
matchAndRewrite(serene::slir::Fn1Op op,
|
||||
mlir::PatternRewriter &rewriter) const final;
|
||||
};
|
||||
|
||||
mlir::LogicalResult
|
||||
FnOpLowering::matchAndRewrite(serene::slir::FnOp op,
|
||||
FnOpLowering::matchAndRewrite(serene::slir::Fn1Op op,
|
||||
mlir::PatternRewriter &rewriter) const {
|
||||
auto args = op.args();
|
||||
auto name = op.name();
|
||||
|
|
|
@ -24,30 +24,4 @@
|
|||
#include <mlir/IR/BuiltinAttributes.h>
|
||||
#include <mlir/IR/OperationSupport.h>
|
||||
|
||||
namespace serene::slir {
|
||||
// void FnOp::build(mlir::OpBuilder &odsBuilder, mlir::OperationState &odsState,
|
||||
// llvm::StringRef name, mlir::FunctionType type,
|
||||
// llvm::ArrayRef<mlir::NamedAttribute> attrs,
|
||||
// llvm::ArrayRef<mlir::DictionaryAttr> argAttrs) {
|
||||
// odsState.addAttribute("name", odsBuilder.getStringAttr(name));
|
||||
// llvm::SmallVector<mlir::NamedAttribute> args;
|
||||
|
||||
// for (unsigned int i = 0; i <= type.getNumInputs(); i++) {
|
||||
// odsState.addAttribute(attrName, mlir::TypeAttr::get(type.getResult(i)));
|
||||
// args.push_back(odsBuilder.getNamedAttr(,
|
||||
// mlir::IntegerAttr::get(odsBuilder.getI64Type(), type.getNumInputs())));
|
||||
// }
|
||||
|
||||
// odsState.addAttribute("xxx",
|
||||
// mlir::DictionaryAttr::get(odsBuilder.getContext(), p));
|
||||
// odsState.addAttribute("input_count",
|
||||
// mlir::IntegerAttr::get(odsBuilder.getI64Type(),
|
||||
// type.getNumInputs()));
|
||||
// // if (sym_visibility) {
|
||||
// // odsState.addAttribute("sym_visibility", sym_visibility);
|
||||
// // }
|
||||
// (void)odsState.addRegion();
|
||||
// odsState.addTypes(type);
|
||||
// };
|
||||
|
||||
} // namespace serene::slir
|
||||
namespace serene::slir {} // namespace serene::slir
|
||||
|
|
Loading…
Reference in New Issue