@@ -1334,8 +1334,9 @@ static void emitAttrGetterWithReturnType(FmtContext &fctx,
13341334 PrintFatalError (" DefaultValuedAttr of type " + attr.getAttrDefName () +
13351335 " must have a constBuilder" );
13361336 }
1337- std::string defaultValue = std::string (
1338- tgfmt (attr.getConstBuilderTemplate (), &fctx, attr.getDefaultValue ()));
1337+ std::string defaultValue =
1338+ std::string (tgfmt (attr.getConstBuilderTemplate (), &fctx,
1339+ tgfmt (attr.getDefaultValue (), &fctx)));
13391340 body << " if (!attr)\n return "
13401341 << tgfmt (attr.getConvertFromStorageCall (),
13411342 &fctx.withSelf (defaultValue))
@@ -1467,6 +1468,7 @@ void OpEmitter::genPropertiesSupport() {
14671468 os << " if (!attr) attr = dict.get(\" result_segment_sizes\" );" ;
14681469 }
14691470
1471+ fctx.withBuilder (odsBuilder);
14701472 setPropMethod << " {\n "
14711473 << formatv (propFromAttrFmt,
14721474 tgfmt (prop.getConvertFromAttributeCall (),
@@ -1479,7 +1481,7 @@ void OpEmitter::genPropertiesSupport() {
14791481 prop.getStorageTypeValueOverride ());
14801482 } else if (prop.hasDefaultValue ()) {
14811483 setPropMethod << formatv (attrGetDefaultFmt, name,
1482- prop.getDefaultValue ());
1484+ tgfmt ( prop.getDefaultValue (), &fctx ));
14831485 } else {
14841486 setPropMethod << formatv (attrGetNoDefaultFmt, name);
14851487 }
@@ -2919,6 +2921,9 @@ getBuilderSignature(const Builder &builder) {
29192921 arguments.emplace_back (" ::mlir::OpBuilder &" , odsBuilder);
29202922 arguments.emplace_back (" ::mlir::OperationState &" , builderOpState);
29212923
2924+ FmtContext fctx;
2925+ fctx.withBuilder (odsBuilder);
2926+
29222927 for (unsigned i = 0 , e = params.size (); i < e; ++i) {
29232928 // If no name is provided, generate one.
29242929 std::optional<StringRef> paramName = params[i].getName ();
@@ -2931,7 +2936,7 @@ getBuilderSignature(const Builder &builder) {
29312936 defaultValue = *defaultParamValue;
29322937
29332938 arguments.emplace_back (params[i].getCppType (), std::move (name),
2934- defaultValue);
2939+ tgfmt ( defaultValue, &fctx) );
29352940 }
29362941
29372942 return arguments;
@@ -3189,6 +3194,9 @@ void OpEmitter::buildParamList(SmallVectorImpl<MethodParameter> ¶mList,
31893194 }
31903195 }
31913196
3197+ FmtContext fctx;
3198+ fctx.withBuilder (odsBuilder);
3199+
31923200 for (int i = 0 , e = op.getNumArgs (), numOperands = 0 ; i < e; ++i) {
31933201 Argument arg = op.getArg (i);
31943202 if (const auto *operand =
@@ -3210,7 +3218,7 @@ void OpEmitter::buildParamList(SmallVectorImpl<MethodParameter> ¶mList,
32103218 StringRef type = prop.getInterfaceType ();
32113219 std::string defaultValue;
32123220 if (prop.hasDefaultValue () && i >= defaultValuedAttrLikeStartIndex) {
3213- defaultValue = prop.getDefaultValue ();
3221+ defaultValue = tgfmt ( prop.getDefaultValue (), &fctx );
32143222 }
32153223 bool isOptional = prop.hasDefaultValue ();
32163224 paramList.emplace_back (type, propArg->name , StringRef (defaultValue),
@@ -3242,7 +3250,7 @@ void OpEmitter::buildParamList(SmallVectorImpl<MethodParameter> ¶mList,
32423250 if (i >= defaultValuedAttrStartIndex) {
32433251 if (attrParamKind == AttrParamKind::UnwrappedValue &&
32443252 canUseUnwrappedRawValue (attr))
3245- defaultValue += attr.getDefaultValue ();
3253+ defaultValue += tgfmt ( attr.getDefaultValue (), &fctx );
32463254 else
32473255 defaultValue += " nullptr" ;
32483256 }
@@ -4172,6 +4180,9 @@ OpOperandAdaptorEmitter::OpOperandAdaptorEmitter(
41724180 staticVerifierEmitter(staticVerifierEmitter),
41734181 emitHelper(op, /* emitForOp=*/ false ) {
41744182
4183+ FmtContext fctx;
4184+ fctx.withBuilder (odsBuilder);
4185+
41754186 genericAdaptorBase.declare <VisibilityDeclaration>(Visibility::Public);
41764187 bool useProperties = emitHelper.hasProperties ();
41774188 if (useProperties) {
@@ -4212,7 +4223,7 @@ OpOperandAdaptorEmitter::OpOperandAdaptorEmitter(
42124223 if (prop.hasStorageTypeValueOverride ())
42134224 os << " = " << prop.getStorageTypeValueOverride ();
42144225 else if (prop.hasDefaultValue ())
4215- os << " = " << prop.getDefaultValue ();
4226+ os << " = " << tgfmt ( prop.getDefaultValue (), &fctx );
42164227 comparatorOs << " rhs." << name << " == this->" << name
42174228 << " &&\n " ;
42184229 // Emit accessors using the interface type.
@@ -4454,7 +4465,6 @@ OpOperandAdaptorEmitter::OpOperandAdaptorEmitter(
44544465 if (auto *m = genericAdaptor.addMethod (" RangeT" , " getOperands" ))
44554466 m->body () << " return odsOperands;" ;
44564467
4457- FmtContext fctx;
44584468 fctx.withBuilder (" ::mlir::Builder(odsAttrs.getContext())" );
44594469
44604470 // Generate named accessor with Attribute return type.
@@ -4481,8 +4491,9 @@ OpOperandAdaptorEmitter::OpOperandAdaptorEmitter(
44814491 // Use the default value if attribute is not set.
44824492 // TODO: this is inefficient, we are recreating the attribute for every
44834493 // call. This should be set instead.
4484- std::string defaultValue = std::string (
4485- tgfmt (attr.getConstBuilderTemplate (), &fctx, attr.getDefaultValue ()));
4494+ std::string defaultValue =
4495+ std::string (tgfmt (attr.getConstBuilderTemplate (), &fctx,
4496+ tgfmt (attr.getDefaultValue (), &fctx)));
44864497 body << " if (!attr)\n attr = " << defaultValue << " ;\n " ;
44874498 }
44884499 body << " return attr;\n " ;
0 commit comments