Skip to content

Commit

Permalink
Merge pull request hail-is#2 from tpoterba/tp-mlir-tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
tpoterba authored Nov 3, 2022
2 parents ca3d600 + 53b1bea commit 4589597
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 6 deletions.
2 changes: 2 additions & 0 deletions query/include/Dialect/Sandbox/IR/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
set(LLVM_TARGET_DEFINITIONS SandboxOps.td)
mlir_tablegen(SandboxOpsEnums.h.inc -gen-enum-decls)
mlir_tablegen(SandboxOpsEnums.cpp.inc -gen-enum-defs)
add_mlir_dialect(SandboxOps sb)
8 changes: 7 additions & 1 deletion query/include/Dialect/Sandbox/IR/Sandbox.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#ifndef DIALECT_SANDBOX_SANDBOX_H
#define DIALECT_SANDBOX_SANDBOX_H

#include "mlir/IR/BuiltinTypes.h"

#include "mlir/IR/Dialect.h"
#include "mlir/IR/OpDefinition.h"
#include "mlir/IR/OpImplementation.h"
#include "mlir/Interfaces/CastInterfaces.h"
#include "mlir/Interfaces/SideEffectInterfaces.h"

#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Builders.h"

#include "Dialect/Sandbox/IR/SandboxOpsDialect.h.inc"
#include "Dialect/Sandbox/IR/SandboxOpsEnums.h.inc"

#define GET_TYPEDEF_CLASSES
#include "Dialect/Sandbox/IR/SandboxOpsTypes.h.inc"
Expand Down
28 changes: 26 additions & 2 deletions query/include/Dialect/Sandbox/IR/SandboxBase.td
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
include "mlir/IR/AttrTypeBase.td"
include "mlir/IR/OpBase.td"

include "mlir/IR/EnumAttr.td"


def Sandbox_Dialect : Dialect {
let name = "sb";
let summary = "Dialect for experimenting with MLIR";
Expand All @@ -19,13 +22,34 @@ class Sandbox_Type<string name, string typeMnemonic, list<Trait> traits = []>

// Here is a simple definition of an "integer" type, with a width parameter.
def Sandbox_Int : Sandbox_Type<"Int", "int"> {
let summary = "Hail 32 bit integer type";
let summary = "Sandbox 32 bit integer type";
let description = [{
Hail 32 bit integer type
Sandbox 32 bit integer type
}];

/// Indicate that our type will add additional verification to the parameters.
let genVerifyDecl = 0;
}

def Sandbox_Bool : Sandbox_Type<"Boolean", "bool"> {
let summary = "Sandbox 32 bit integer type";
let description = [{
Sandbox 32 bit integer type
}];

/// Indicate that our type will add additional verification to the parameters.
let genVerifyDecl = 0;
}

def Sandbox_CmpPredicateAttr : I64EnumAttr<
"CmpPredicate", "",
[
I64EnumAttrCase<"LT", 0, "lt">,
I64EnumAttrCase<"LTEQ", 1, "lteq">,
I64EnumAttrCase<"GT", 2, "gt">,
I64EnumAttrCase<"GTEQ", 3, "gteq">,
I64EnumAttrCase<"EQ", 4, "eq">,
]> {
}

#endif // DIALECT_SANDBOX_SANDBOXBASE
20 changes: 20 additions & 0 deletions query/include/Dialect/Sandbox/IR/SandboxOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@ def Sandbox_AddIOp : Sandbox_Op<"addi", [NoSideEffect, Commutative]> {
let hasCanonicalizer = true;
}

def BoolOp : Sandbox_Op<"bool", [ConstantLike, NoSideEffect]> {
let arguments = (ins BoolAttr:$value);
let results = (outs Sandbox_Bool:$output);
let assemblyFormat = "$value attr-dict `:` type($output)";
}


def ComparisonOp : Sandbox_Op<"compare", [NoSideEffect]> {
let arguments = (ins Sandbox_CmpPredicateAttr:$predicate, Sandbox_Int:$lhs, Sandbox_Int:$rhs);
let results = (outs Sandbox_Bool:$output);
let assemblyFormat = "$predicate `,` $lhs `,` $rhs attr-dict `:` type($output)";

let extraClassDeclaration = [{
static CmpPredicate getPredicateByName(llvm::StringRef name);
}];

let hasFolder = 0;
let hasCanonicalizer = 0;
}

def Sandbox_PrintOp : Sandbox_Op<"print"> {
let arguments = (ins Sandbox_Int:$value);
let assemblyFormat = "$value attr-dict";
Expand Down
1 change: 1 addition & 0 deletions query/lib/Dialect/Sandbox/IR/SandboxDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ mlir::Operation *SandboxDialect::materializeConstant(mlir::OpBuilder &builder, m
}

#define GET_TYPEDEF_CLASSES

#include "Dialect/Sandbox/IR/SandboxOpsTypes.cpp.inc"
#include "Dialect/Sandbox/IR/SandboxOpsDialect.cpp.inc"

Expand Down
5 changes: 4 additions & 1 deletion query/lib/Dialect/Sandbox/IR/SandboxOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
#include "mlir/IR/Location.h"
#include <cstddef>

#include "Dialect/Sandbox/IR/SandboxOpsEnums.cpp.inc"

#define GET_OP_CLASSES
#include "Dialect/Sandbox/IR/SandboxOps.cpp.inc"

#include "Dialect/Sandbox/IR/SandboxOps.cpp.inc"
namespace hail {
namespace ir{


mlir::OpFoldResult ConstantOp::fold(llvm::ArrayRef<mlir::Attribute> operands) {
return valueAttr();
}
Expand Down
6 changes: 4 additions & 2 deletions query/test/current.mlir
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
func.func @foo(%in: !sb.int) -> (!sb.int) {
func.func @foo(%in: !sb.int) -> (!sb.bool) {
%i1 = sb.constant 5 : !sb.int
%i2 = sb.constant 7 : !sb.int
%i3 = sb.addi %in %i1
%i4 = sb.addi %i3 %i2
func.return %i4 : !sb.int
%i5 = sb.constant 6 : !sb.int
%i6 = sb.compare eq, %i4, %i5 : !sb.bool
func.return %i6 : !sb.bool
}

0 comments on commit 4589597

Please sign in to comment.