MCPcopy Create free account
hub / github.com/NVIDIA/cuda-tile / parseAPInt

Method parseAPInt

lib/Bytecode/Reader/BytecodeReader.cpp:1296–1350  ·  view source on GitHub ↗

Parses an APInt from the bytecode stream.

Source from the content-addressed store, hash-verified

1294
1295 /// Parses an APInt from the bytecode stream.
1296 static LogicalResult parseAPInt(EncodingReader &reader, unsigned bitWidth,
1297 APInt &apIntResult) {
1298 // Small values are encoded using a single byte.
1299 if (bitWidth <= 8) {
1300 uint8_t value;
1301 if (failed(reader.readLE(value)))
1302 return reader.emitError()
1303 << "failed to read byte for APInt (<= 8 bits).";
1304 // Validate that the value fits in the specified bit width.
1305 if (!llvm::isUIntN(bitWidth, value))
1306 return reader.emitError()
1307 << "value " << static_cast<unsigned>(value)
1308 << " does not fit in " << bitWidth << " bits.";
1309 apIntResult = APInt(bitWidth, value);
1310 return success();
1311 }
1312
1313 // Large values up to 64 bits are encoded using a single varint.
1314 if (bitWidth <= 64) {
1315 uint64_t value;
1316 if (failed(reader.readSignedVarInt(value)))
1317 return reader.emitError()
1318 << "failed to read signed varint for APInt (<= 64 bits).";
1319 // Validate that the value fits in the specified bit width.
1320 if (!llvm::isUIntN(bitWidth, value))
1321 return reader.emitError() << "value " << value << " does not fit in "
1322 << bitWidth << " bits";
1323 apIntResult = APInt(bitWidth, value);
1324 return success();
1325 }
1326
1327 // Otherwise, for really big values we encode the array of active words in
1328 // the value.
1329 uint64_t numActiveWords;
1330 if (failed(reader.readVarInt(numActiveWords)))
1331 return reader.emitError()
1332 << "failed to read numActiveWords for APInt (> 64 bits).";
1333 // Validate that numActiveWords makes sense for the given bitWidth.
1334 uint64_t expectedMaxWords = (bitWidth + 63) / 64;
1335 if (numActiveWords > expectedMaxWords)
1336 return reader.emitError()
1337 << "numActiveWords " << numActiveWords << " exceeds maximum of "
1338 << expectedMaxWords << " for " << bitWidth << " bit";
1339 if (numActiveWords == 0)
1340 return reader.emitError()
1341 << "numActiveWords cannot be zero for multi-word APInt";
1342
1343 SmallVector<uint64_t, 4> words(numActiveWords);
1344 for (uint64_t i = 0; i < numActiveWords; ++i)
1345 if (failed(reader.readSignedVarInt(words[i])))
1346 return reader.emitError()
1347 << "failed to read word " << i << " for multi-word APInt.";
1348 apIntResult = APInt(bitWidth, words);
1349 return success();
1350 }
1351
1352 /// Parses a scalar attribute that was serialized directly (inline).
1353 /// Currently supports:

Callers

nothing calls this directly

Calls 4

readLEMethod · 0.80
emitErrorMethod · 0.80
readSignedVarIntMethod · 0.80
readVarIntMethod · 0.80

Tested by

no test coverage detected