Skip to content

Commit 96c69a8

Browse files
committed
Update calls to APInt constructor.
This was needed when llvm/llvm-project@3494ee9 landed. Similar changes were made upstream here: https://github.com/llvm/llvm-project/pull/80309/files. Basically, we now expect the width and value arguments to the APInt constructor to be consistent. There is some implicit extension or truncation depending on the signedness of the value, and now a flag to opt into it. With this change I've simply opted into the flag where necessary, rather than thinking hard about how to compute the correct width given the value. In places where the `isSigned` flag took the default value of false, I kept that when I had to explicitly set that flag. There was exactly one place (CalyxHelpers.cpp), where I actually flipped the value of `isSigned`. The comment in the code made me think this erroneously thought the flag was "isUnsigned".
1 parent 3b25689 commit 96c69a8

File tree

8 files changed

+18
-11
lines changed

8 files changed

+18
-11
lines changed

lib/Conversion/DCToHW/DCToHW.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ struct RTLBuilder {
237237
}
238238

239239
Value constant(unsigned width, int64_t value, StringRef name = {}) {
240-
return constant(APInt(width, value));
240+
return constant(
241+
APInt(width, value, /*isSigned=*/false, /*implicitTrunc=*/true));
241242
}
242243
std::pair<Value, Value> wrap(Value data, Value valid, StringRef name = {}) {
243244
auto wrapOp = b.create<esi::WrapValidReadyOp>(loc, data, valid);

lib/Conversion/HandshakeToHW/HandshakeToHW.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,8 @@ struct RTLBuilder {
484484

485485
Value constant(unsigned width, int64_t value,
486486
std::optional<StringRef> name = {}) {
487-
return constant(APInt(width, value));
487+
return constant(
488+
APInt(width, value, /*isSigned=*/false, /*implicitTrunc=*/true));
488489
}
489490
std::pair<Value, Value> wrap(Value data, Value valid,
490491
std::optional<StringRef> name = {}) {

lib/Dialect/Arc/Transforms/ArcCanonicalizer.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,8 @@ ICMPCanonicalizer::matchAndRewrite(comb::ICmpOp op,
446446
}
447447
rewriter.replaceOpWithNewOp<comb::ICmpOp>(
448448
op, op.getPredicate(), andOp,
449-
getConstant(APInt(*optionalWidth, rhs.getZExtValue())),
449+
getConstant(APInt(*optionalWidth, rhs.getZExtValue(),
450+
/*isSigned=*/false, /*implicitTrunc=*/true)),
450451
op.getTwoState());
451452
return success();
452453
}
@@ -464,7 +465,8 @@ ICMPCanonicalizer::matchAndRewrite(comb::ICmpOp op,
464465
}
465466
rewriter.replaceOpWithNewOp<comb::ICmpOp>(
466467
op, op.getPredicate(), orOp,
467-
getConstant(APInt(*optionalWidth, rhs.getZExtValue())),
468+
getConstant(APInt(*optionalWidth, rhs.getZExtValue(),
469+
/*isSigned=*/false, /*implicitTrunc=*/true)),
468470
op.getTwoState());
469471
return success();
470472
}

lib/Dialect/Calyx/Transforms/CalyxHelpers.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ hw::ConstantOp createConstant(Location loc, OpBuilder &builder,
3232
size_t value) {
3333
OpBuilder::InsertionGuard g(builder);
3434
builder.setInsertionPointToStart(component.getBodyBlock());
35-
return builder.create<hw::ConstantOp>(loc,
36-
APInt(width, value, /*unsigned=*/true));
35+
return builder.create<hw::ConstantOp>(
36+
loc, APInt(width, value, /*isSigned=*/false));
3737
}
3838

3939
calyx::InstanceOp createInstance(Location loc, OpBuilder &builder,

lib/Dialect/Calyx/Transforms/RemoveCombGroups.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ struct RemoveCombGroupsPattern : public OpRewritePattern<calyx::CombGroupOp> {
140140

141141
rewriter.setInsertionPointToStart(group.getBodyBlock());
142142
auto oneConstant = rewriter.create<hw::ConstantOp>(
143-
group.getLoc(), APInt(1, 1, /*isSigned=*/true));
143+
group.getLoc(), APInt(1, 1, /*isSigned=*/true, /*implicitTrunc=*/true));
144144

145145
// Maintain the set of cell results which have already been assigned to
146146
// its register within this group.

lib/Dialect/FIRRTL/FIRRTLUtils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ IntegerAttr circt::firrtl::getIntZerosAttr(Type type) {
188188
/// type. This handles both the known width and unknown width case.
189189
IntegerAttr circt::firrtl::getIntOnesAttr(Type type) {
190190
int32_t width = abs(type_cast<IntType>(type).getWidthOrSentinel());
191-
return getIntAttr(type, APInt(width, -1));
191+
return getIntAttr(
192+
type, APInt(width, -1, /*isSigned=*/false, /*implicitTrunc=*/true));
192193
}
193194

194195
/// Return the single assignment to a Property value. It is assumed that the

lib/Dialect/HW/HWOps.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,9 @@ void ConstantOp::build(OpBuilder &builder, OperationState &result,
309309
void ConstantOp::build(OpBuilder &builder, OperationState &result, Type type,
310310
int64_t value) {
311311
auto numBits = cast<IntegerType>(type).getWidth();
312-
build(builder, result, APInt(numBits, (uint64_t)value, /*isSigned=*/true));
312+
build(builder, result,
313+
APInt(numBits, (uint64_t)value, /*isSigned=*/true,
314+
/*implicitTrunc=*/true));
313315
}
314316

315317
void ConstantOp::getAsmResultNames(

tools/handshake-runner/Simulation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ Any readValueWithType(mlir::Type type, std::stringstream &arg) {
8989
int64_t x;
9090
arg >> x;
9191
int64_t width = INDEX_WIDTH;
92-
APInt aparg(width, x);
92+
APInt aparg(width, x, /*isSigned=*/false, /*implicitTrunc=*/true);
9393
return aparg;
9494
} else if (isa<mlir::IntegerType>(type)) {
9595
int64_t x;
9696
arg >> x;
9797
int64_t width = type.getIntOrFloatBitWidth();
98-
APInt aparg(width, x);
98+
APInt aparg(width, x, /*isSigned=*/false, /*implicitTrunc=*/true);
9999
return aparg;
100100
} else if (type.isF32()) {
101101
float x;

0 commit comments

Comments
 (0)