30 using Base = LLZKDialectBytecodeInterface<global::GlobalDialect>;
35 LogicalResult upgradeFromVersion(
36 Operation *root,
const LLZKDialectVersion & ,
const LLZKDialectVersion &requested
38 auto res = root->walk([](global::GlobalDefOp global) -> WalkResult {
40 auto errFn = [context = initialValue.getContext()] {
43 FailureOr<global::NormalizedGlobalInitializer> normalized =
45 if (failed(normalized)) {
46 return global.emitError(
47 "contains a legacy initializer that is incompatible with its declared type"
51 global.
setTypeAttr(TypeAttr::get(normalized->type));
53 return WalkResult::advance();
55 if (res.wasInterrupted()) {
62 if (requested.majorVersion < 3) {
63 SymbolTableCollection tables;
64 res = root->walk([&tables](global::GlobalReadOp read) -> WalkResult {
65 auto globalRef = llvm::cast<global::GlobalRefOpInterface>(read.getOperation());
66 FailureOr<SymbolLookupResult<global::GlobalDefOp>> target =
67 globalRef.getGlobalDefOp(tables);
68 if (succeeded(target) && target->get().isConstant()) {
71 return WalkResult::advance();
74 return failure(res.wasInterrupted());
80auto global::GlobalDialect::initialize() ->
void {
87 addInterfaces<GlobalDialectBytecodeInterface>();
static InFlightDiagnosticWrapper createSilent(mlir::MLIRContext *ctx)
Construct a silent diagnostic that does nothing when appended to or reported.
void setInitialValueAttr(::mlir::Attribute attr)
void setTypeAttr(::mlir::TypeAttr attr)
::mlir::Attribute getInitialValueAttr()
void setConstant(bool attrValue)
mlir::FailureOr< NormalizedGlobalInitializer > normalizeGlobalInitializer(mlir::Type type, mlir::Attribute value, EmitErrorFn emitError)
Normalize unambiguous initializer representations and their declared type.
This implements the bytecode interface for the LLZK dialect.