Update MLIR API.

PiperOrigin-RevId: 300753498
Change-Id: I0df71658d4be2801ed90e701186b82d2f68d12e0
This commit is contained in:
Tres Popp 2020-03-13 07:40:41 -07:00 committed by TensorFlower Gardener
parent 960e0d8ea8
commit 11a22c7c50
18 changed files with 95 additions and 19 deletions

View File

@ -30,6 +30,7 @@ filegroup(
"ir/tfl_ops.td",
"//tensorflow/compiler/mlir/lite/quantization:quantization_td_files",
"@llvm-project//mlir:OpBaseTdFiles",
"@llvm-project//mlir:include/mlir/Interfaces/SideEffects.td",
"@llvm-project//mlir:include/mlir/Transforms/LoopLikeInterface.td",
],
)

View File

@ -19,6 +19,7 @@ limitations under the License.
#define TFL_OPS
include "mlir/IR/OpBase.td"
include "mlir/Interfaces/SideEffects.td"
include "mlir/Transforms/LoopLikeInterface.td"
include "tensorflow/compiler/mlir/lite/ir/tfl_op_interfaces.td"
include "tensorflow/compiler/mlir/lite/quantization/quantization.td"
@ -596,7 +597,7 @@ def TFL_ConcatenationOp : TFL_Op<"concatenation",
let verifier = [{ return Verify(*this); }];
}
def TFL_ConstOp : Op<TFL_Dialect, "pseudo_const", [NoSideEffect,
def TFL_ConstOp : Op<TFL_Dialect, "pseudo_const", [ConstantLike, NoSideEffect,
FirstAttrDerivedResultType]> {
let summary = "Constant pseudo op.";

View File

@ -426,7 +426,9 @@ void PreprocessTopoSortGraph(
}
bool IsSideEffectOp(Operation* op) {
if (op->hasNoSideEffect()) return false;
// TODO(riverriddle) Properly handle region side effects.
if (MemoryEffectOpInterface::hasNoEffect(op) && op->getNumRegions() == 0)
return false;
// Identity op has no side effect.
// Check the OperationName maybe more elegant here.

View File

@ -60,7 +60,8 @@ static void UpdateFuncType(FuncOp func) {
static bool IsSideEffectFree(FuncOp func) {
return !func.getBody()
.walk([&](Operation* op) {
if (!op->isKnownTerminator() && !op->hasNoSideEffect())
if (!MemoryEffectOpInterface::hasNoEffect(op) &&
!op->isKnownTerminator())
return WalkResult::interrupt();
return WalkResult::advance();
})

View File

@ -98,7 +98,6 @@ void WhileOutlinePass::OutlineWhile(WhileOp while_op) {
extern_values.insert(extern_value);
continue;
}
assert(extern_value.getDefiningOp()->hasNoSideEffect());
if (!const_none) {
// Add constant at start of region.
auto const_builder =

View File

@ -26,6 +26,7 @@ filegroup(
"ir/tf_ops.td",
"@llvm-project//mlir:OpBaseTdFiles",
"@llvm-project//mlir:include/mlir/Interfaces/CallInterfaces.td",
"@llvm-project//mlir:include/mlir/Interfaces/SideEffects.td",
],
)
@ -801,9 +802,8 @@ cc_library(
"//tensorflow/stream_executor",
"//tensorflow/stream_executor/lib",
"@llvm-project//llvm:support",
"@llvm-project//mlir:Analysis",
"@llvm-project//mlir:IR",
"@llvm-project//mlir:Pass",
"@llvm-project//mlir:SideEffects",
"@llvm-project//mlir:Support",
],
alwayslink = 1,
@ -958,6 +958,7 @@ genrule(
name = "derived_attr_populator_inc",
srcs = [
"@llvm-project//mlir:include/mlir/Interfaces/CallInterfaces.td",
"@llvm-project//mlir:include/mlir/Interfaces/SideEffects.td",
"@llvm-project//mlir:include/mlir/IR/OpBase.td",
"ir/tf_generated_ops.td",
"ir/tf_op_base.td",

View File

@ -323,7 +323,11 @@ bool OpIsDeclaration(Operation* op,
bool OpIsKnownToHaveNoSideEffect(Operation* op) {
// TODO(riverriddle) We shouldn't treat all terminator operations as having
// side effects, this should be relaxed.
if (op->hasNoSideEffect() && op->isKnownNonTerminator()) return true;
// TODO(riverriddle) Properly handle region side effects.
if (MemoryEffectOpInterface::hasNoEffect(op) && op->isKnownNonTerminator() &&
op->getNumRegions() == 0) {
return true;
}
if (auto if_op = llvm::dyn_cast<TF::IfOp>(op)) {
return if_op.is_stateless();
}

View File

@ -85,7 +85,7 @@ class TFControlType : public Type::TypeBase<TFControlType, Type> {
// Note: Additional result corresponds to the control output.
class EnterOp
: public Op<EnterOp, OpTrait::AtLeastNOperands<1>::Impl,
OpTrait::NResults<2>::Impl, OpTrait::HasNoSideEffect> {
OpTrait::NResults<2>::Impl, MemoryEffectOpInterface::Trait> {
public:
using Op::Op;
@ -95,6 +95,9 @@ class EnterOp
void setData(Value value) { setOperand(0, value); }
LogicalResult verify();
// EnterOp has no side-effects.
void getEffects(SmallVectorImpl<MemoryEffects::EffectInstance> &) {}
};
// The "_tf.Merge" operation takes a list of input operands and returns a value
@ -198,7 +201,7 @@ class NextIterationSinkOp
// Note: Additional result corresponds to the control output.
class LoopCondOp
: public Op<LoopCondOp, OpTrait::AtLeastNOperands<1>::Impl,
OpTrait::NResults<2>::Impl, OpTrait::HasNoSideEffect> {
OpTrait::NResults<2>::Impl, MemoryEffectOpInterface::Trait> {
public:
using Op::Op;
static StringRef getOperationName() { return "_tf.LoopCond"; }
@ -207,6 +210,9 @@ class LoopCondOp
void setData(Value value) { setOperand(0, value); }
LogicalResult verify();
// LoopCondOp has no side-effects.
void getEffects(SmallVectorImpl<MemoryEffects::EffectInstance> &) {}
};
// The "_tf.Switch" operation takes a data operand and a boolean predicate
@ -261,8 +267,9 @@ class SwitchOp : public Op<SwitchOp, OpTrait::AtLeastNOperands<2>::Impl,
// (tensor<*xi32>, !_tf.control)
//
// Note: Additional result corresponds to the control output.
class ExitOp : public Op<ExitOp, OpTrait::AtLeastNOperands<1>::Impl,
OpTrait::NResults<2>::Impl, OpTrait::HasNoSideEffect> {
class ExitOp
: public Op<ExitOp, OpTrait::AtLeastNOperands<1>::Impl,
OpTrait::NResults<2>::Impl, MemoryEffectOpInterface::Trait> {
public:
using Op::Op;
static StringRef getOperationName() { return "_tf.Exit"; }
@ -271,6 +278,9 @@ class ExitOp : public Op<ExitOp, OpTrait::AtLeastNOperands<1>::Impl,
void setData(Value value) { setOperand(0, value); }
LogicalResult verify();
// ExitOp has no side-effects.
void getEffects(SmallVectorImpl<MemoryEffects::EffectInstance> &) {}
};
} // namespace TFControlFlow

View File

@ -23,6 +23,7 @@ limitations under the License.
#define TF_OP_BASE
include "mlir/IR/OpBase.td"
include "mlir/Interfaces/SideEffects.td"
include "tensorflow/compiler/mlir/tensorflow/ir/tf_op_interfaces.td"
//===----------------------------------------------------------------------===//

View File

@ -64,7 +64,7 @@ class TF_TensorListInitOp<string mnemonic> : TF_Op<mnemonic, [NoSideEffect]> {
// In MLIR, the TensorFlow tensor value is represented as an ElementsAttr, with
// its type encoding the tensor's shape and data type.
def TF_ConstOp : TF_Op<"Const", [NoSideEffect]> {
def TF_ConstOp : TF_Op<"Const", [ConstantLike, NoSideEffect]> {
let summary = "Constant tensor op";
let arguments = (ins

View File

@ -17,6 +17,7 @@ limitations under the License.
#include <algorithm>
#include "mlir/Interfaces/SideEffects.h" // TF:llvm-project
#include "tensorflow/c/eager/c_api.h"
#include "tensorflow/c/tf_status.h"
#include "tensorflow/compiler/mlir/tensorflow/ir/tf_types.h"
@ -31,7 +32,8 @@ LogicalResult ConstantFoldFallbackHook(
SmallVectorImpl<Attribute>& results) { // NOLINT
// Instructions with side effects should not be constant folded to preserve
// the original semantics.
if (!inst->hasNoSideEffect()) return failure();
if (inst->getNumRegions() != 0 || !MemoryEffectOpInterface::hasNoEffect(inst))
return failure();
// If any of the result types are variants, don't try to constant fold them.
// This creates opaque variant constants which lose information and would

View File

@ -36,6 +36,7 @@ filegroup(
"ir/lhlo_ops.td",
"@llvm-project//mlir:OpBaseTdFiles",
"@llvm-project//mlir:include/mlir/Interfaces/InferTypeOpInterface.td",
"@llvm-project//mlir:include/mlir/Interfaces/SideEffects.td",
],
)
@ -699,6 +700,7 @@ genrule(
name = "operator_writer_inc",
srcs = [
"@llvm-project//mlir:include/mlir/Interfaces/InferTypeOpInterface.td",
"@llvm-project//mlir:include/mlir/Interfaces/SideEffects.td",
"@llvm-project//mlir:include/mlir/IR/OpBase.td",
":ir/hlo_ops.td",
":ir/hlo_ops_base.td",

View File

@ -20,6 +20,7 @@ limitations under the License.
include "mlir/IR/OpBase.td"
include "mlir/Interfaces/InferTypeOpInterface.td"
include "mlir/Interfaces/SideEffects.td"
include "tensorflow/compiler/mlir/xla/ir/hlo_ops_base.td"
include "tensorflow/compiler/mlir/xla/ir/hlo_utils.td"
@ -96,7 +97,8 @@ def HLO_PredIntOrFpTensor : TensorOf<[HLO_Pred, HLO_Int, AnyFloat]>;
// XLA nullary op definitions.
//===----------------------------------------------------------------------===//
def HLO_ConstOp : HLO_Op<"constant", [NoSideEffect]>, BASE_HLO_ConstOp {
def HLO_ConstOp : HLO_Op<"constant", [ConstantLike, NoSideEffect]>,
BASE_HLO_ConstOp {
let arguments = (ins
ElementsAttr:$value
);

View File

@ -19,6 +19,7 @@ limitations under the License.
#define LHLO_OPS
include "mlir/IR/OpBase.td"
include "mlir/Interfaces/SideEffects.td"
include "tensorflow/compiler/mlir/xla/ir/hlo_ops_base.td"
def LHLO_Dialect : Dialect {

View File

@ -273,7 +273,8 @@ class VectorSupportLibrary {
llvm::Value* GetConstantFloat(llvm::Type* type, const llvm::APFloat& f) {
llvm::Constant* scalar_value = llvm::ConstantFP::get(type->getContext(), f);
if (llvm::isa<llvm::VectorType>(type)) {
return llvm::ConstantVector::getSplat(vector_size(), scalar_value);
return llvm::ConstantVector::getSplat(
llvm::ElementCount(vector_size(), /*Scalable=*/false), scalar_value);
}
return scalar_value;
}

View File

@ -597,8 +597,8 @@ def tf_repositories(path_prefix = "", tf_repo_name = ""):
)
# Check out LLVM and MLIR from llvm-project.
LLVM_COMMIT = "4016c6b07f2ade01c65750d1297f72b43f9eb244"
LLVM_SHA256 = "f67afc574c0f1bc3f43e256321c88f4feefb272d288d084ea6e99c509cb92141"
LLVM_COMMIT = "2c6c169dbd6041b4575b2234c532aad50a472e81"
LLVM_SHA256 = "2193d7972bab0e19134b32e962cfbf6581c3bb57e36c8c9c65c46f9409820796"
LLVM_URLS = [
"https://storage.googleapis.com/mirror.tensorflow.org/github.com/llvm/llvm-project/archive/{commit}.tar.gz".format(commit = LLVM_COMMIT),
"https://github.com/llvm/llvm-project/archive/{commit}.tar.gz".format(commit = LLVM_COMMIT),

View File

@ -144,6 +144,7 @@ filegroup(
srcs = [
"include/mlir/Dialect/AffineOps/AffineOps.td",
"include/mlir/Dialect/AffineOps/AffineOpsBase.td",
"include/mlir/Interfaces/SideEffects.td",
"include/mlir/Transforms/LoopLikeInterface.td",
":OpBaseTdFiles",
],
@ -173,6 +174,7 @@ filegroup(
name = "LoopOpsTdFiles",
srcs = [
"include/mlir/Dialect/LoopOps/LoopOps.td",
"include/mlir/Interfaces/SideEffects.td",
"include/mlir/Transforms/LoopLikeInterface.td",
":OpBaseTdFiles",
],
@ -540,6 +542,7 @@ filegroup(
srcs = [
"include/mlir/Dialect/GPU/GPUOps.td",
"include/mlir/Dialect/LLVMIR/LLVMOpBase.td",
"include/mlir/Interfaces/SideEffects.td",
":OpBaseTdFiles",
],
)
@ -617,6 +620,7 @@ filegroup(
"include/mlir/Dialect/LLVMIR/LLVMOpBase.td",
"include/mlir/Dialect/LLVMIR/LLVMOps.td",
"include/mlir/Interfaces/ControlFlowInterfaces.td",
"include/mlir/Interfaces/SideEffects.td",
":OpBaseTdFiles",
],
)
@ -861,6 +865,7 @@ filegroup(
srcs = [
"include/mlir/Dialect/LLVMIR/LLVMOpBase.td",
"include/mlir/Dialect/LLVMIR/NVVMOps.td",
"include/mlir/Interfaces/SideEffects.td",
":OpBaseTdFiles",
],
)
@ -928,6 +933,7 @@ filegroup(
srcs = [
"include/mlir/Dialect/LLVMIR/LLVMOpBase.td",
"include/mlir/Dialect/LLVMIR/ROCDLOps.td",
"include/mlir/Interfaces/SideEffects.td",
":OpBaseTdFiles",
],
)
@ -974,6 +980,7 @@ filegroup(
srcs = [
"include/mlir/Interfaces/CallInterfaces.td",
"include/mlir/Interfaces/ControlFlowInterfaces.td",
"include/mlir/Interfaces/SideEffects.td",
":OpBaseTdFiles",
] + glob(["include/mlir/Dialect/SPIRV/*.td"]),
)
@ -1181,6 +1188,7 @@ cc_library(
"lib/Dialect/SPIRV/SPIRVLowering.cpp",
"lib/Dialect/SPIRV/Transforms/DecorateSPIRVCompositeTypeLayoutPass.cpp",
"lib/Dialect/SPIRV/Transforms/LowerABIAttributesPass.cpp",
"lib/Dialect/SPIRV/Transforms/UpdateVCEPass.cpp",
],
hdrs = [
"include/mlir/Dialect/SPIRV/Passes.h",
@ -1290,12 +1298,50 @@ cc_library(
":IR",
":LoopLikeOpInterfaceIncGen",
":LoopOps",
":SideEffects",
":StandardOps",
":Support",
"@llvm-project//llvm:support",
],
)
gentbl(
name = "DerivedAttributeOpInterfaceIncGen",
strip_include_prefix = "include",
tbl_outs = [
(
"-gen-op-interface-decls",
"include/mlir/Interfaces/DerivedAttributeOpInterface.h.inc",
),
(
"-gen-op-interface-defs",
"include/mlir/Interfaces/DerivedAttributeOpInterface.cpp.inc",
),
],
tblgen = ":mlir-tblgen",
td_file = "include/mlir/Interfaces/DerivedAttributeOpInterface.td",
td_srcs = [
":OpBaseTdFiles",
],
)
cc_library(
name = "DerivedAttributeOpInterface",
srcs = [
"lib/Interfaces/DerivedAttributeOpInterface.cpp",
],
hdrs = [
"include/mlir/Interfaces/DerivedAttributeOpInterface.h",
],
includes = ["include"],
deps = [
":DerivedAttributeOpInterfaceIncGen",
":IR",
":Support",
"@llvm-project//llvm:support",
],
)
gentbl(
name = "LoopLikeOpInterfaceIncGen",
strip_include_prefix = "include",
@ -2154,6 +2200,7 @@ filegroup(
srcs = [
"include/mlir/Dialect/QuantOps/QuantOps.td",
"include/mlir/Dialect/QuantOps/QuantPredicates.td",
"include/mlir/Interfaces/SideEffects.td",
":OpBaseTdFiles",
],
)
@ -2220,6 +2267,7 @@ filegroup(
srcs = [
"include/mlir/Dialect/FxpMathOps/FxpMathOps.td",
"include/mlir/Dialect/QuantOps/QuantPredicates.td",
"include/mlir/Interfaces/SideEffects.td",
":OpBaseTdFiles",
],
)
@ -2686,11 +2734,11 @@ exports_files(
"include/mlir/Interfaces/CallInterfaces.td",
"include/mlir/Interfaces/ControlFlowInterfaces.h",
"include/mlir/Interfaces/ControlFlowInterfaces.td",
"include/mlir/Interfaces/SideEffects.td",
"include/mlir/Dialect/LLVMIR/LLVMOpBase.td",
"include/mlir/Dialect/StandardOps/IR/Ops.td",
"include/mlir/IR/OpAsmInterface.td",
"include/mlir/IR/OpBase.td",
"include/mlir/Interfaces/SideEffects.td",
"include/mlir/Transforms/InliningUtils.h",
],
visibility = ["@llvm-project//mlir:friends"],

View File

@ -76,10 +76,10 @@ gentbl(
td_srcs = [
"@llvm-project//mlir:OpBaseTdFiles",
"@llvm-project//mlir:include/mlir/IR/OpAsmInterface.td",
"@llvm-project//mlir:include/mlir/Interfaces/SideEffects.td",
"@llvm-project//mlir:include/mlir/Interfaces/CallInterfaces.td",
"@llvm-project//mlir:include/mlir/Interfaces/ControlFlowInterfaces.td",
"@llvm-project//mlir:include/mlir/Interfaces/InferTypeOpInterface.td",
"@llvm-project//mlir:include/mlir/Interfaces/SideEffects.td",
],
test = True,
)