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

Function parseGlobalSection

lib/Bytecode/Reader/BytecodeReader.cpp:2249–2323  ·  view source on GitHub ↗

Parses the global section and creates metadata for each global variable.

Source from the content-addressed store, hash-verified

2247
2248/// Parses the global section and creates metadata for each global variable.
2249static LogicalResult
2250parseGlobalSection(ArrayRef<uint8_t> payload, const EncodingReader &mainReader,
2251 std::vector<GlobalInfo> &globalInfoList,
2252 MLIRContext &context,
2253 const BytecodeVersion &bytecodeVersion) {
2254 EncodingReader sectionReader(payload, context);
2255 sectionReader.inheritStringTableFrom(mainReader);
2256
2257 uint64_t numGlobals;
2258 if (failed(sectionReader.readVarInt(numGlobals)))
2259 return sectionReader.emitError() << "failed to read number of global.";
2260
2261 // Determine minimum size based on bytecode version.
2262 // Version 13.1: 4 varints (symbolNameIndex, valueTypeIndex,
2263 // constantValueIndex, alignment) Version 13.3+: 6 varints (added
2264 // symbolVisibility and constant)
2265 auto version_13_3 = BytecodeVersion::fromVersion(13, 3, 0);
2266 size_t kMinGlobalInfoSize = (bytecodeVersion >= *version_13_3) ? 6 : 4;
2267
2268 if (numGlobals >
2269 (payload.size() - sectionReader.currentOffset()) / kMinGlobalInfoSize) {
2270 return sectionReader.emitError()
2271 << "number of globals (" << numGlobals << ") exceeds the maximum of "
2272 << (payload.size() - sectionReader.currentOffset()) /
2273 kMinGlobalInfoSize
2274 << " that can fit in the remaining payload of "
2275 << (payload.size() - sectionReader.currentOffset()) << " bytes.";
2276 }
2277
2278 globalInfoList.reserve(numGlobals);
2279
2280 for (uint64_t i = 0; i < numGlobals; ++i) {
2281 GlobalInfo globalInfo;
2282 // 1. Read symbol name index.
2283 if (failed(sectionReader.readVarInt(globalInfo.symbolNameIndex)))
2284 return sectionReader.emitError()
2285 << "failed to read global symbol name string.";
2286
2287 // 2. Read type index of the value.
2288 if (failed(sectionReader.readVarInt(globalInfo.valueTypeIndex)))
2289 return sectionReader.emitError() << "failed to read global value type";
2290
2291 // 3. Read constant index for the value.
2292 if (failed(sectionReader.readVarInt(globalInfo.constantValueIndex)))
2293 return sectionReader.emitError()
2294 << "failed to read global value constant index";
2295
2296 // 4. Read alignment.
2297 if (failed(sectionReader.readVarInt(globalInfo.alignment)))
2298 return sectionReader.emitError() << "failed to read global alignment";
2299
2300 // 5. Read symbol_visibility (added in version 13.3).
2301 if (bytecodeVersion >= *version_13_3) {
2302 if (failed(sectionReader.readVarInt(globalInfo.symbolVisibility)))
2303 return sectionReader.emitError()
2304 << "failed to read global symbol visibility";
2305 } else {
2306 // For older bytecode versions (< 13.3), use default value (Public = 0).

Callers 1

readBytecodeMethod · 0.85

Calls 5

readVarIntMethod · 0.80
emitErrorMethod · 0.80
sizeMethod · 0.80
currentOffsetMethod · 0.80

Tested by

no test coverage detected