Swap the type and attribute parameter in ConstantOp::build()

This is to keep consistent with other TableGen generated builders
so that we can also use this builder in TableGen rules.

PiperOrigin-RevId: 229244630
This commit is contained in:
Lei Zhang 2019-01-14 13:36:02 -08:00 committed by jpienaar
parent ed26dd0421
commit 61ec6c0992
6 changed files with 17 additions and 17 deletions

View File

@ -273,8 +273,8 @@ class ConstantOp : public Op<ConstantOp, OpTrait::ZeroOperands,
OpTrait::OneResult, OpTrait::HasNoSideEffect> {
public:
/// Builds a constant op with the specified attribute value and result type.
static void build(Builder *builder, OperationState *result, Attribute value,
Type type);
static void build(Builder *builder, OperationState *result, Type type,
Attribute value);
Attribute getValue() const { return getAttr("value"); }

View File

@ -445,8 +445,8 @@ void CondBranchOp::eraseFalseOperand(unsigned index) {
//===----------------------------------------------------------------------===//
/// Builds a constant op with the specified attribute value and result type.
void ConstantOp::build(Builder *builder, OperationState *result,
Attribute value, Type type) {
void ConstantOp::build(Builder *builder, OperationState *result, Type type,
Attribute value) {
result->addAttribute("value", value);
result->types.push_back(type);
}
@ -541,7 +541,7 @@ Attribute ConstantOp::constantFold(ArrayRef<Attribute> operands,
void ConstantFloatOp::build(Builder *builder, OperationState *result,
const APFloat &value, FloatType type) {
ConstantOp::build(builder, result, builder->getFloatAttr(type, value), type);
ConstantOp::build(builder, result, type, builder->getFloatAttr(type, value));
}
bool ConstantFloatOp::isClassFor(const OperationInst *op) {
@ -558,8 +558,8 @@ bool ConstantIntOp::isClassFor(const OperationInst *op) {
void ConstantIntOp::build(Builder *builder, OperationState *result,
int64_t value, unsigned width) {
Type type = builder->getIntegerType(width);
ConstantOp::build(builder, result, builder->getIntegerAttr(type, value),
type);
ConstantOp::build(builder, result, type,
builder->getIntegerAttr(type, value));
}
/// Build a constant int op producing an integer with the specified type,
@ -567,8 +567,8 @@ void ConstantIntOp::build(Builder *builder, OperationState *result,
void ConstantIntOp::build(Builder *builder, OperationState *result,
int64_t value, Type type) {
assert(type.isa<IntegerType>() && "ConstantIntOp can only have integer type");
ConstantOp::build(builder, result, builder->getIntegerAttr(type, value),
type);
ConstantOp::build(builder, result, type,
builder->getIntegerAttr(type, value));
}
/// ConstantIndexOp only matches values whose result type is Index.
@ -579,8 +579,8 @@ bool ConstantIndexOp::isClassFor(const OperationInst *op) {
void ConstantIndexOp::build(Builder *builder, OperationState *result,
int64_t value) {
Type type = builder->getIndexType();
ConstantOp::build(builder, result, builder->getIntegerAttr(type, value),
type);
ConstantOp::build(builder, result, type,
builder->getIntegerAttr(type, value));
}
//===----------------------------------------------------------------------===//

View File

@ -1197,7 +1197,7 @@ struct SimplifyMulX0 : public RewritePattern {
void rewrite(OperationInst *op, PatternRewriter &rewriter) const override {
auto type = op->getOperand(0)->getType();
auto zeroAttr = rewriter.getZeroAttr(type);
rewriter.replaceOpWithNewOp<ConstantOp>(op, zeroAttr, type);
rewriter.replaceOpWithNewOp<ConstantOp>(op, type, zeroAttr);
}
};

View File

@ -87,8 +87,8 @@ void ConstantFold::visitOperationInst(OperationInst *op) {
if (res->use_empty()) // ignore dead uses.
continue;
auto cst = builder.create<ConstantOp>(op->getLoc(), resultConstants[i],
res->getType());
auto cst = builder.create<ConstantOp>(op->getLoc(), res->getType(),
resultConstants[i]);
existingConstants.push_back(cst);
res->replaceAllUsesWith(cst);
}

View File

@ -187,7 +187,7 @@ public:
auto valueAttr =
builder.getIntegerAttr(builder.getIndexType(), expr.getValue());
auto op =
builder.create<ConstantOp>(loc, valueAttr, builder.getIndexType());
builder.create<ConstantOp>(loc, builder.getIndexType(), valueAttr);
return op->getResult();
}

View File

@ -213,8 +213,8 @@ void GreedyPatternRewriteDriver::simplifyFunction() {
if (it != uniquedConstants.end())
cstValue = it->second->getResult(0);
else
cstValue = create<ConstantOp>(op->getLoc(), resultConstants[i],
res->getType());
cstValue = create<ConstantOp>(op->getLoc(), res->getType(),
resultConstants[i]);
// Add all the users of the result to the worklist so we make sure to
// revisit them.