Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mlir/include/mlir/IR/SymbolInterfaces.td
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def Symbol : OpInterface<"SymbolOpInterface"> {
"bool", "isDeclaration", (ins), [{}],
/*defaultImplementation=*/[{
// By default, assume that the operation defines a symbol.
return false;
return false;
}]
>,
];
Expand Down
1 change: 1 addition & 0 deletions mlir/include/mlir/Interfaces/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ add_mlir_interface(InferIntRangeInterface)
add_mlir_interface(InferTypeOpInterface)
add_mlir_interface(LoopLikeInterface)
add_mlir_interface(ParallelCombiningOpInterface)
add_mlir_interface(ParametricSpecializationOpInterface)
add_mlir_interface(RuntimeVerifiableOpInterface)
add_mlir_interface(ShapedOpInterfaces)
add_mlir_interface(SideEffectInterfaces)
Expand Down
25 changes: 25 additions & 0 deletions mlir/include/mlir/Interfaces/ParametricSpecializationOpInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//===- ParametricSpecializationOpInterface.h - Parallel combining op interface
//---===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements the operation interface for ops that parallel combining
// operations.
//
//===----------------------------------------------------------------------===//

#ifndef MLIR_INTERFACES_PARAMETRICSPECIALIZATIONOPINTERFACES_H_
#define MLIR_INTERFACES_PARAMETRICSPECIALIZATIONOPINTERFACES_H_

#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/IR/OpDefinition.h"
#include "mlir/IR/SymbolTable.h"

/// Include the generated interface declarations.
#include "mlir/Interfaces/ParametricSpecializationOpInterface.h.inc"

#endif // MLIR_INTERFACES_PARAMETRICSPECIALIZATIONOPINTERFACES_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//===-- ParametricSpecializationOpInterface.td -------------*- tablegen -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef MLIR_INTERFACES_PARAMETRICSPECIALIZATIONOPINTERFACES
#define MLIR_INTERFACES_PARAMETRICSPECIALIZATIONOPINTERFACES

include "mlir/IR/OpBase.td"

def ParametricOpInterface : OpInterface<"ParametricOpInterface"> {
let cppNamespace = "::mlir";
let methods = [
InterfaceMethod<"",
"::mlir::LogicalResult", "specialize", (ins
"::mlir::DictionaryAttr":$params)>,
InterfaceMethod<"",
"::mlir::LogicalResult", "checkOperand", (ins
"::mlir::OpOperand &":$operand,
"::mlir::Type":$concreteType)>,
InterfaceMethod<"Only for symbol operation which will be cloned, mangle in-place.",
"::mlir::FailureOr<::mlir::StringAttr>", "getMangledName", (ins
"::mlir::DictionaryAttr":$metaArgs), "", [{
return failure();
}]
>,
];
}

def SpecializingOpInterface : OpInterface<"SpecializingOpInterface"> {
let cppNamespace = "::mlir";
let methods = [
InterfaceMethod<"",
"::mlir::SymbolRefAttr", "getTarget", (ins)>,
InterfaceMethod<"",
"::mlir::DictionaryAttr", "getMetaArgs", (ins)>,
InterfaceMethod<"",
"::mlir::LogicalResult", "setSpecializedTarget", (ins
"::mlir::SymbolOpInterface":$target)>,
];
}

#endif // MLIR_INTERFACES_PARAMETRICSPECIALIZATIONOPINTERFACES
11 changes: 11 additions & 0 deletions mlir/include/mlir/Transforms/ParametricSpecialization.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//===- RemoveDeadValues.h - Specialize Meta Program -----------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "mlir/IR/Operation.h"

namespace mlir {}
2 changes: 2 additions & 0 deletions mlir/lib/Interfaces/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ set(LLVM_OPTIONAL_SOURCES
LoopLikeInterface.cpp
MemorySlotInterfaces.cpp
ParallelCombiningOpInterface.cpp
ParametricSpecializationOpInterface.cpp
RuntimeVerifiableOpInterface.cpp
ShapedOpInterfaces.cpp
SideEffectInterfaces.cpp
Expand Down Expand Up @@ -80,6 +81,7 @@ add_mlir_library(MLIRLoopLikeInterface

add_mlir_interface_library(MemorySlotInterfaces)
add_mlir_interface_library(ParallelCombiningOpInterface)
add_mlir_interface_library(ParametricSpecializationOpInterface)
add_mlir_interface_library(RuntimeVerifiableOpInterface)
add_mlir_interface_library(ShapedOpInterfaces)
add_mlir_interface_library(SideEffectInterfaces)
Expand Down
13 changes: 13 additions & 0 deletions mlir/lib/Interfaces/ParametricSpecializationOpInterface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===- ParametricSpecializationOpInterface.cpp ----------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "mlir/Interfaces/ParametricSpecializationOpInterface.h"
#include "mlir/Support/LogicalResult.h"

/// Include the definitions of the interface.
#include "mlir/Interfaces/ParametricSpecializationOpInterface.cpp.inc"
2 changes: 2 additions & 0 deletions mlir/lib/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ add_mlir_library(MLIRTransforms
LoopInvariantCodeMotion.cpp
Mem2Reg.cpp
OpStats.cpp
ParametricSpecialization.cpp
PrintIR.cpp
RemoveDeadValues.cpp
SCCP.cpp
Expand All @@ -32,6 +33,7 @@ add_mlir_library(MLIRTransforms
MLIRFunctionInterfaces
MLIRLoopLikeInterface
MLIRMemorySlotInterfaces
MLIRParametricSpecializationOpInterface
MLIRPass
MLIRRuntimeVerifiableOpInterface
MLIRSideEffectInterfaces
Expand Down
13 changes: 13 additions & 0 deletions mlir/lib/Transforms/ParametricSpecialization.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===- RemoveDeadValues.cpp - Specialize Meta Program ---------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "mlir/Transforms/ParametricSpecialization.h"

using namespace mlir;

void specialize(Operation *op) {}
18 changes: 18 additions & 0 deletions mlir/test/Parametric/ops.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@


testparametric.func @callee(%arg0: !testparametric.param<"A"> ) attributes { metaParams = ["A", "B"]} {
%value = testparametric.add %arg0, %arg0 : (!testparametric.param<"A">, !testparametric.param<"A">) -> !testparametric.param<"A">
testparametric.print_attr #testparametric.param<"B">
return
}

func.func @caller() {
%cst0 = arith.constant 0 : i32
%cst1 = arith.constant 1. : f32
%cst2 = arith.constant 2. : f64
testparametric.call @callee(%cst0) meta = {"A" = i32, "B" = 32 : i64 } : (i32) -> ()
testparametric.call @callee(%cst0) meta = {"A" = i32, "B" = 32 : i64 } : (i32) -> ()
testparametric.call @callee(%cst1) meta = {"A" = f32, "B" = 64 : i64 } : (f32) -> ()
testparametric.call @callee(%cst2) meta = {"A" = f64, "B" = 128 : i64 } : (f64) -> ()
return
}
1 change: 1 addition & 0 deletions mlir/test/lib/Dialect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ add_subdirectory(SPIRV)
add_subdirectory(Tensor)
add_subdirectory(Test)
add_subdirectory(TestDyn)
add_subdirectory(TestParametric)
add_subdirectory(Tosa)
add_subdirectory(Transform)
add_subdirectory(Vector)
68 changes: 68 additions & 0 deletions mlir/test/lib/Dialect/TestParametric/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
set(LLVM_OPTIONAL_SOURCES
TestParametricDialect.cpp
)

set(LLVM_TARGET_DEFINITIONS TestParametricInterfaces.td)
mlir_tablegen(TestParametricAttrInterfaces.h.inc -gen-attr-interface-decls)
mlir_tablegen(TestParametricAttrInterfaces.cpp.inc -gen-attr-interface-defs)
mlir_tablegen(TestParametricTypeInterfaces.h.inc -gen-type-interface-decls)
mlir_tablegen(TestParametricTypeInterfaces.cpp.inc -gen-type-interface-defs)
mlir_tablegen(TestParametricOpInterfaces.h.inc -gen-op-interface-decls)
mlir_tablegen(TestParametricOpInterfaces.cpp.inc -gen-op-interface-defs)
add_public_tablegen_target(MLIRTestParametricInterfaceIncGen)

set(LLVM_TARGET_DEFINITIONS TestParametricOps.td)
mlir_tablegen(TestParametricAttrDefs.h.inc -gen-attrdef-decls)
mlir_tablegen(TestParametricAttrDefs.cpp.inc -gen-attrdef-defs)
add_public_tablegen_target(MLIRTestParametricAttrDefIncGen)

set(LLVM_TARGET_DEFINITIONS TestParametricTypeDefs.td)
mlir_tablegen(TestParametricTypeDefs.h.inc -gen-typedef-decls -typedefs-dialect=testparametric)
mlir_tablegen(TestParametricTypeDefs.cpp.inc -gen-typedef-defs -typedefs-dialect=testparametric)
add_public_tablegen_target(MLIRTestParametricTypeDefIncGen)

set(LLVM_TARGET_DEFINITIONS TestParametricOps.td)
mlir_tablegen(TestParametricOps.h.inc -gen-op-decls)
mlir_tablegen(TestParametricOps.cpp.inc -gen-op-defs)
mlir_tablegen(TestParametricOpsDialect.h.inc -gen-dialect-decls -dialect=testparametric)
mlir_tablegen(TestParametricOpsDialect.cpp.inc -gen-dialect-defs -dialect=testparametric)
add_public_tablegen_target(MLIRTestParametricOpsIncGen)

# Exclude testparametrics from libMLIR.so
add_mlir_library(MLIRTestParametricDialect
TestParametricAttributes.cpp
TestParametricDialect.cpp
TestParametricInterfaces.cpp
TestParametricTypes.cpp

EXCLUDE_FROM_LIBMLIR

DEPENDS
MLIRTestParametricAttrDefIncGen
MLIRTestParametricInterfaceIncGen
MLIRTestParametricTypeDefIncGen
MLIRTestParametricOpsIncGen

LINK_LIBS PUBLIC
MLIRControlFlowInterfaces
MLIRDataLayoutInterfaces
MLIRDerivedAttributeOpInterface
MLIRDestinationStyleOpInterface
MLIRDialect
MLIRDLTIDialect
MLIRFuncDialect
MLIRFunctionInterfaces
MLIRFuncTransforms
MLIRIR
MLIRInferIntRangeInterface
MLIRInferTypeOpInterface
MLIRLinalgDialect
MLIRLinalgTransforms
MLIRLLVMDialect
MLIRPass
MLIRReduce
MLIRTensorDialect
MLIRTransformUtils
MLIRTransforms
)

38 changes: 38 additions & 0 deletions mlir/test/lib/Dialect/TestParametric/TestParametricAttrDefs.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//===-- TestAttrDefs.td - Test dialect attr definitions ----*- tablegen -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// TableGen data attribute definitions for Test dialect.
//
//===----------------------------------------------------------------------===//

#ifndef TESTPARAMETRIC_ATTRDEFS
#define TESTPARAMETRIC_ATTRDEFS

// To get the test dialect definition.
include "TestParametricDialect.td"
include "mlir/Dialect/Utils/StructuredOpsUtils.td"
include "mlir/IR/AttrTypeBase.td"
include "mlir/IR/BuiltinAttributeInterfaces.td"
include "mlir/IR/EnumAttr.td"
include "mlir/IR/OpAsmInterface.td"

// All of the attributes will extend this class.
class TestParametric_Attr<string name, list<Trait> traits = []>
: AttrDef<TestParametric_Dialect, name, traits>;

def TestParametric_ParamAttr : TestParametric_Attr<"Param"> {
let mnemonic = "param";
// List of type parameters.
let parameters = (
ins
"::mlir::StringAttr":$ref
);
let assemblyFormat = "`<` $ref `>`";
}

#endif // TESTPARAMETRIC_ATTRDEFS
42 changes: 42 additions & 0 deletions mlir/test/lib/Dialect/TestParametric/TestParametricAttributes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//===- TestAttributes.cpp - MLIR Test Dialect Attributes --------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file contains attributes defined by the TestDialect for testing various
// features of MLIR.
//
//===----------------------------------------------------------------------===//

#include "TestParametricAttributes.h"
#include "TestParametricDialect.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/DialectImplementation.h"
#include "mlir/IR/ExtensibleDialect.h"
#include "mlir/IR/Types.h"
#include "mlir/Support/LogicalResult.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/ADT/bit.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"

using namespace mlir;
using namespace testparametric;

//===----------------------------------------------------------------------===//
// TestParametricDialect
//===----------------------------------------------------------------------===//

#define GET_ATTRDEF_CLASSES
#include "TestParametricAttrDefs.cpp.inc"

void TestParametricDialect::registerAttributes() {
addAttributes<
#define GET_ATTRDEF_LIST
#include "TestParametricAttrDefs.cpp.inc"
>();
}
33 changes: 33 additions & 0 deletions mlir/test/lib/Dialect/TestParametric/TestParametricAttributes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//===- TestTypes.h - MLIR Test Dialect Types --------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file contains types defined by the TestDialect for testing various
// features of MLIR.
//
//===----------------------------------------------------------------------===//

#ifndef MLIR_TESTPARAMETRICATTRIBUTES_H
#define MLIR_TESTPARAMETRICATTRIBUTES_H

#include <tuple>

#include "mlir/Dialect/Utils/StructuredOpsUtils.h"
#include "mlir/IR/Attributes.h"
#include "mlir/IR/Diagnostics.h"
#include "mlir/IR/Dialect.h"
#include "mlir/IR/DialectImplementation.h"

#include "TestParametricAttrInterfaces.h.inc"
#include "mlir/IR/DialectResourceBlobManager.h"

namespace testparametric {} // namespace testparametric

#define GET_ATTRDEF_CLASSES
#include "TestParametricAttrDefs.h.inc"

#endif // MLIR_TESTPARAMETRICATTRIBUTES_H
Loading