Skip to content

Commit 3572f99

Browse files
committed
more fixes based on review
1 parent fd21254 commit 3572f99

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

lib/Conversion/SCFToCalyx/SCFToCalyx.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,33 +1050,32 @@ static LogicalResult buildAllocOp(ComponentLoweringState &componentState,
10501050
llvm::json::Array result;
10511051
result.reserve(std::max(static_cast<int>(shape.size()), 1));
10521052

1053-
bool isSignlessOrUnsigned = memtype.getElementType().isSignlessInteger() ||
1054-
memtype.getElementType().isUnsignedInteger();
1053+
Type elemType = memtype.getElementType();
1054+
bool isSigned =
1055+
!elemType.isSignlessInteger() && !elemType.isUnsignedInteger();
10551056
for (uint64_t bitValue : flattenedVals) {
10561057
llvm::json::Value value = 0;
10571058
if (isFloat) {
1058-
// we cast to `double` and let downstream calyx to deal with the actual
1059-
// value's precision handling
1059+
// We cast to `double` and let downstream calyx to deal with the actual
1060+
// value's precision handling.
10601061
value = bit_cast<double>(bitValue);
10611062
} else {
1062-
APInt apInt(/*numBits=*/elmTyBitWidth, bitValue,
1063-
/*isSigned=*/!isSignlessOrUnsigned);
1064-
if (!isSignlessOrUnsigned) {
1065-
// need to explicitly assign it to an int variable before storing to a
1066-
// json Value, otherwise it will interpret the raw data
1067-
int64_t signedValue = apInt.getSExtValue();
1068-
value = signedValue;
1069-
} else
1063+
APInt apInt(/*numBits=*/elmTyBitWidth, bitValue, isSigned);
1064+
// The conditional ternary operation will cause the `value` to interpret
1065+
// the underlying data as unsigned regardless `isSigned` or not.
1066+
if (isSigned)
1067+
value = static_cast<int64_t>(apInt.getSExtValue());
1068+
else
10701069
value = apInt.getZExtValue();
10711070
}
1072-
result.push_back(value);
1071+
result.push_back(std::move(value));
10731072
}
10741073

10751074
componentState.setDataField(memoryOp.getName(), result);
10761075
std::string numType =
10771076
memtype.getElementType().isInteger() ? "bitnum" : "ieee754_float";
1078-
componentState.setFormat(memoryOp.getName(), numType,
1079-
/*isSigned=*/!isSignlessOrUnsigned, elmTyBitWidth);
1077+
componentState.setFormat(memoryOp.getName(), numType, isSigned,
1078+
elmTyBitWidth);
10801079

10811080
return success();
10821081
}

0 commit comments

Comments
 (0)