From ce1287533342c08dc19fe1a0842154b8613412b5 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 24 Apr 2019 10:53:12 -0700 Subject: [PATCH] [TableGen] Refine OpTrait classes and defs to be consistent -- PiperOrigin-RevId: 245075421 --- mlir/include/mlir/IR/OpBase.td | 33 +++++++++++++++++---------------- mlir/lib/TableGen/OpTrait.cpp | 6 +++--- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td index e38d658..0e4ab44 100644 --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -720,43 +720,44 @@ class OpTrait; // NativeOpTrait corresponds to the MLIR C++ OpTrait mechanism. The // purpose to wrap around C++ symbol string with this class is to make -// traits specified for ops in TableGen less alien and more -// integrated. +// traits specified for ops in TableGen less alien and more integrated. class NativeOpTrait : OpTrait { string trait = prop; } -// Specify a trait to control op definition generator internals. -class OpGenInternalTrait : OpTrait { +// GenInternalOpTrait is an op trait that does not have direct C++ mapping but +// affects op definition generator internals, like how op builders and +// operand/attribute/result getters are generated. +class GenInternalOpTrait : OpTrait { string trait = prop; } -// Specify a trait by way of a predicate on the operation. -class PredOpTrait : OpTrait { - string desc = d; - Pred pred = p; +// PredOpTrait is an op trait implemented by way of a predicate on the op. +class PredOpTrait : OpTrait { + string description = descr; + Pred predicate = pred; } -// op supports operand broadcast behavior +// Op supports operand broadcast behavior. def Broadcastable : NativeOpTrait<"BroadcastableTwoOperandsOneResult">; // X op Y == Y op X def Commutative : NativeOpTrait<"IsCommutative">; -// op results are float or vectors/tensors thereof +// Op results are float or vectors/tensors thereof. def FloatLikeResults : NativeOpTrait<"ResultsAreFloatLike">; -// op has no side effect +// Op has no side effect. def NoSideEffect : NativeOpTrait<"HasNoSideEffect">; -// op has same operand and result shape +// Op has same operand and result shape. def SameValueShape : NativeOpTrait<"SameOperandsAndResultShape">; -// op has the same operand and result type +// Op has the same operand and result type. def SameValueType : NativeOpTrait<"SameOperandsAndResultType">; -// op is a terminator +// Op is a terminator. def Terminator : NativeOpTrait<"IsTerminator">; -// op result type is derived from the first attribute. If the attribute is an +// Op result type is derived from the first attribute. If the attribute is an // subclass of `TypeAttrBase`, its value is used, otherwise, the type of the // attribute content is used. def FirstAttrDerivedResultType : - OpGenInternalTrait<"FirstAttrDerivedResultType">; + GenInternalOpTrait<"FirstAttrDerivedResultType">; //===----------------------------------------------------------------------===// // Op definitions diff --git a/mlir/lib/TableGen/OpTrait.cpp b/mlir/lib/TableGen/OpTrait.cpp index 2c82153..2e39061 100644 --- a/mlir/lib/TableGen/OpTrait.cpp +++ b/mlir/lib/TableGen/OpTrait.cpp @@ -32,7 +32,7 @@ mlir::tblgen::OpTrait mlir::tblgen::OpTrait::create(const llvm::Init *init) { auto def = cast(init)->getDef(); if (def->isSubClassOf("PredOpTrait")) return OpTrait(Kind::Pred, def); - if (def->isSubClassOf("OpGenInternalTrait")) + if (def->isSubClassOf("GenInternalOpTrait")) return OpTrait(Kind::Internal, def); assert(def->isSubClassOf("NativeOpTrait")); return OpTrait(Kind::Native, def); @@ -50,10 +50,10 @@ llvm::StringRef mlir::tblgen::InternalOpTrait::getTrait() const { } std::string mlir::tblgen::PredOpTrait::getPredTemplate() const { - auto pred = tblgen::Pred(def->getValueInit("pred")); + auto pred = tblgen::Pred(def->getValueInit("predicate")); return pred.getCondition(); } llvm::StringRef mlir::tblgen::PredOpTrait::getDescription() const { - return def->getValueAsString("desc"); + return def->getValueAsString("description"); } -- 2.7.4