Add constant build() method not requiring result type

Instead, we deduce the result type from the given attribute.

This is in preparation for generating constant ops with TableGen.

PiperOrigin-RevId: 232723467
This commit is contained in:
Lei Zhang 2019-02-06 12:27:30 -08:00 committed by jpienaar
parent c78d708487
commit 888b9fa8a6
2 changed files with 11 additions and 0 deletions

View File

@ -225,6 +225,11 @@ public:
static void build(Builder *builder, OperationState *result, Type type,
Attribute value);
/// Builds a constant op with the specified attribute value and the
/// attribute's type.
static void build(Builder *builder, OperationState *result,
NumericAttr value);
Attribute getValue() const { return getAttr("value"); }
static StringRef getOperationName() { return "constant"; }

View File

@ -250,6 +250,12 @@ void ConstantOp::build(Builder *builder, OperationState *result, Type type,
result->types.push_back(type);
}
void ConstantOp::build(Builder *builder, OperationState *result,
NumericAttr value) {
result->addAttribute("value", value);
result->types.push_back(value.getType());
}
void ConstantOp::print(OpAsmPrinter *p) const {
*p << "constant ";
p->printOptionalAttrDict(getAttrs(), /*elidedAttrs=*/"value");