Handles writing blocks. block-bytecode =: numArgs[varint] argTypeIndex[varint]* // Type indices for each block argument. numOps[varint] instruction* // Bytecode for each operation in the block.
| 1442 | /// numOps[varint] |
| 1443 | /// instruction* // Bytecode for each operation in the block. |
| 1444 | LogicalResult writeBlock(Block &block, EncodingWriter &writer) { |
| 1445 | // Record the current nextValueIndex. This will be restored after processing |
| 1446 | // the block, effectively rolling back the indices used within this block. |
| 1447 | uint64_t originalNextValueIndex = nextValueIndex; |
| 1448 | |
| 1449 | // Process block arguments. |
| 1450 | writer.writeVarInt(block.getNumArguments()); |
| 1451 | for (BlockArgument arg : block.getArguments()) { |
| 1452 | if (failed(typeMgr.writeTypeIndex(arg.getType(), writer))) |
| 1453 | return failure(); |
| 1454 | // Assign a new index to the block argument. |
| 1455 | // Block arguments are always new values in this scope. |
| 1456 | assert(!valueIndexMap.count(arg) && |
| 1457 | "block argument encountered that is already in valueIndexMap for " |
| 1458 | "this scope"); |
| 1459 | valueIndexMap[arg] = nextValueIndex++; |
| 1460 | } |
| 1461 | |
| 1462 | // Write number of operations in the block. |
| 1463 | writer.writeVarInt(block.getOperations().size()); |
| 1464 | // Process operations in the block. |
| 1465 | for (Operation &op : block) |
| 1466 | if (failed(writeOperation(&op, writer))) |
| 1467 | return failure(); |
| 1468 | |
| 1469 | // Remove all of the entries added during parsing of this block. |
| 1470 | for (uint64_t i = 0, e = nextValueIndex - originalNextValueIndex; i < e; |
| 1471 | ++i) |
| 1472 | valueIndexMap.pop_back(); |
| 1473 | |
| 1474 | // Restore nextValueIndex to what it was before this block. |
| 1475 | nextValueIndex = originalNextValueIndex; |
| 1476 | return success(); |
| 1477 | } |
| 1478 | |
| 1479 | private: |
| 1480 | llvm::MapVector<Value, uint64_t> valueIndexMap; |
nothing calls this directly
no test coverage detected