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

Function createGlobal

lib/Bytecode/Reader/BytecodeReader.cpp:2353–2408  ·  view source on GitHub ↗

Creates a global (cuda_tile::GlobalOp) based on the parsed GlobalInfo.

Source from the content-addressed store, hash-verified

2351
2352/// Creates a global (cuda_tile::GlobalOp) based on the parsed GlobalInfo.
2353static LogicalResult
2354createGlobal(const GlobalInfo &globalInfo, OpBuilder &builder,
2355 const EncodingReader &reader, LazyTypeTable &types,
2356 ArrayRef<ArrayRef<uint8_t>> constants,
2357 DenseElementsAttrCache &constCache, DebugInfoReader &debuginfo,
2358 MLIRContext &context) {
2359 if (globalInfo.constantValueIndex >= constants.size())
2360 return reader.emitError() << "global value constant index out of bounds";
2361
2362 StringRef symNameStr;
2363 if (failed(reader.getString(globalInfo.symbolNameIndex, symNameStr, context)))
2364 return reader.emitError()
2365 << "failed to get global symbol name string for index "
2366 << globalInfo.symbolNameIndex;
2367 if (symNameStr.empty())
2368 return reader.emitError() << "global symbol name at index "
2369 << globalInfo.symbolNameIndex << " is empty";
2370
2371 FailureOr<Attribute> valueAttr =
2372 constCache.getOrCreate(types.getType(globalInfo.valueTypeIndex),
2373 constants[globalInfo.constantValueIndex], context);
2374 if (failed(valueAttr))
2375 return failure();
2376
2377 auto denseValueAttr = dyn_cast<DenseTypedElementsAttr>(*valueAttr);
2378 if (!denseValueAttr)
2379 return reader.emitError()
2380 << "parsed global constant attribute is not the expected type "
2381 "derived from DenseTypedElementsAttr";
2382
2383 // Global variables must not have DILocAttr location type because CudaTile
2384 // supports only local scope. Therefore, global variables must have UnknownLoc
2385 // location type - the only other legal location type.
2386 //
2387 // Convert symbolVisibility from serialized integer to enum, then to
2388 // attribute.
2389 auto symbolVisibility =
2390 symbolizeSymbolVisibility(globalInfo.symbolVisibility);
2391 if (!symbolVisibility.has_value())
2392 return reader.emitError() << "invalid symbol visibility value: "
2393 << globalInfo.symbolVisibility;
2394
2395 auto symbolVisibilityAttr =
2396 cuda_tile::SymbolVisibilityAttr::get(&context, symbolVisibility.value());
2397
2398 // Convert constant from uint64_t (0=not present, !=0=present) to UnitAttr.
2399 // UnitAttr is present (non-null) when constant!=0, otherwise nullptr.
2400 auto constantAttr =
2401 (globalInfo.constant != 0) ? mlir::UnitAttr::get(&context) : nullptr;
2402
2403 cuda_tile::GlobalOp::create(builder, UnknownLoc::get(&context),
2404 builder.getStringAttr(symNameStr), denseValueAttr,
2405 builder.getI64IntegerAttr(globalInfo.alignment),
2406 constantAttr, symbolVisibilityAttr);
2407 return success();
2408}
2409
2410//===----------------------------------------------------------------------===//

Callers 1

readBytecodeMethod · 0.85

Calls 5

sizeMethod · 0.80
emitErrorMethod · 0.80
getStringMethod · 0.80
getOrCreateMethod · 0.80
getTypeMethod · 0.80

Tested by

no test coverage detected