Skip to content

Commit

Permalink
[examples] Add the example for dialect interface: BudInlinerInterface. (
Browse files Browse the repository at this point in the history
  • Loading branch information
taiqzheng authored Aug 15, 2022
1 parent daf6daf commit e7dffc7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
16 changes: 16 additions & 0 deletions examples/BudDialect/TestInlineInterface.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
memref.global "private" @gv : memref<4x4xf32> = dense<[[0. , 1. , 2. , 3. ],
[10., 11., 12., 13.],
[20., 21., 22., 23.],
[30., 31., 32., 33.]]>

func.func private @example(%arg0: memref<4x4xf32>) -> (f32) {
%res = bud.test_array_attr %arg0 {coordinate = [0, 1]} : memref<4x4xf32>, f32
return %res : f32
}

func.func @main() {
%mem = memref.get_global @gv : memref<4x4xf32>
%1 = func.call @example(%mem) : (memref<4x4xf32>) -> (f32)
vector.print %1 : f32
return
}
4 changes: 4 additions & 0 deletions examples/BudDialect/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ bud-str-attr-lower:
bud-vector-config-lower:
@${BUDDY_OPT} ./VectorConfig.mlir \
--lower-bud -o ./log.mlir

bud-inline-interface-lower:
@${BUDDY_OPT} ./TestInlineInterface.mlir \
--inline -o ./log.mlir
24 changes: 24 additions & 0 deletions lib/Dialect/Bud/BudDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "llvm/IR/Function.h"
#include "llvm/IR/Type.h"
#include "llvm/Support/SourceMgr.h"
#include "mlir/Transforms/InliningUtils.h"

#include "Bud/BudDialect.h"
#include "Bud/BudOps.h"
Expand All @@ -39,6 +40,28 @@ using namespace buddy::bud;

#include "Bud/BudOpsDialect.cpp.inc"

//===----------------------------------------------------------------------===//
// BudDialect Interfaces
//===----------------------------------------------------------------------===//

namespace {
struct BudInlinerInterface : public DialectInlinerInterface {
using DialectInlinerInterface::DialectInlinerInterface;
// We don't have any special restrictions on what can be inlined into
// destination regions (e.g. while/conditional bodies). Always allow it.
bool isLegalToInline(Region *dest, Region *src, bool wouldBeCloned,
BlockAndValueMapping &valueMapping) const final {
return true;
}
// Operations in bud dialect are always legal to inline since they are
// pure.
bool isLegalToInline(Operation *, Region *, bool,
BlockAndValueMapping &) const final {
return true;
}
};
} // namespace

//===----------------------------------------------------------------------===//
// Bud dialect.
//===----------------------------------------------------------------------===//
Expand All @@ -52,6 +75,7 @@ void BudDialect::initialize() {
#define GET_ATTRDEF_LIST
#include "Bud/BudOpsAttributes.cpp.inc"
>();
addInterfaces<BudInlinerInterface>();
}

#include "Bud/BudOpsEnums.cpp.inc"
Expand Down

0 comments on commit e7dffc7

Please sign in to comment.