[TableGen] Refine OpTrait classes and defs to be consistent
authorLei Zhang <antiagainst@google.com>
Wed, 24 Apr 2019 17:53:12 +0000 (10:53 -0700)
committerMehdi Amini <joker.eph@gmail.com>
Mon, 6 May 2019 15:16:11 +0000 (08:16 -0700)
--

PiperOrigin-RevId: 245075421

mlir/include/mlir/IR/OpBase.td
mlir/lib/TableGen/OpTrait.cpp

index e38d658..0e4ab44 100644 (file)
@@ -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<string prop> : OpTrait {
   string trait = prop;
 }
 
-// Specify a trait to control op definition generator internals.
-class OpGenInternalTrait<string prop> : 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<string prop> : OpTrait {
   string trait = prop;
 }
 
-// Specify a trait by way of a predicate on the operation.
-class PredOpTrait<string d, Pred p> : OpTrait {
-  string desc = d;
-  Pred pred = p;
+// PredOpTrait is an op trait implemented by way of a predicate on the op.
+class PredOpTrait<string descr, Pred pred> : 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
index 2c82153..2e39061 100644 (file)
@@ -32,7 +32,7 @@ mlir::tblgen::OpTrait mlir::tblgen::OpTrait::create(const llvm::Init *init) {
   auto def = cast<llvm::DefInit>(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");
 }