diff --git a/deps/tblgen/jl-generators.cc b/deps/tblgen/jl-generators.cc index 0d154b09..9153bccc 100644 --- a/deps/tblgen/jl-generators.cc +++ b/deps/tblgen/jl-generators.cc @@ -172,12 +172,12 @@ bool emitOpTableDefs(const llvm::RecordKeeper &recordKeeper, const char *imports; if (isExternal) { - imports = R"(import MLIR.IR: IR, NamedAttribute, Value, Location, Block, Region, Attribute, context, IndexType + imports = R"(import MLIR.IR: IR, NamedAttribute, Value, value, Location, Block, Region, Attribute, context, IndexType import MLIR.Dialects: namedattribute, operandsegmentsizes)"; } else { - imports = R"(import ...IR: IR, NamedAttribute, Value, Location, Block, Region, Attribute, context, IndexType + imports = R"(import ...IR: IR, NamedAttribute, Value, value, Location, Block, Region, Attribute, context, IndexType import ..Dialects: namedattribute, operandsegmentsizes)"; } @@ -261,23 +261,15 @@ end } operandname = sanitizeName(operandname); - std::string type = "Value"; - bool optional = named_operand.isOptional(); bool variadic = named_operand.isVariadic(); - if (variadic) - { - type = "Vector{" + type + "}"; - } - std::string separator = ", "; if (optional) { - optionals += llvm::formatv(R"(!isnothing({0}) && push!(operands, {0}{1}) + optionals += llvm::formatv(R"(!isnothing({0}) && push!(operands, value{2}({0}){1}) )", - operandname, (variadic ? "..." : "")); - type = "Union{Nothing, " + type + "}"; + operandname, (variadic ? "..." : ""), (variadic ? "." : "")); defaultvalue = "=nothing"; if (!alreadykeyword) { @@ -287,11 +279,11 @@ end } else { - operandcontainer += operandname + (variadic ? "..." : "") + ", "; + operandcontainer += llvm::formatv(R"(value{0}({1}){2}, )", (variadic ? "." : ""), operandname, (variadic ? "..." : "")); separator = (!alreadykeyword && i == op.getNumOperands() - 1) ? "; " : ", "; } - operandarguments += operandname + defaultvalue + "::" + type + separator; + operandarguments += operandname + defaultvalue + separator; } if (operandarguments == "") { operandarguments = "; "; diff --git a/src/IR/AffineExpr.jl b/src/IR/AffineExpr.jl index 7a0f4931..13a5607c 100644 --- a/src/IR/AffineExpr.jl +++ b/src/IR/AffineExpr.jl @@ -124,11 +124,11 @@ ConstantExpr(constant; context::Context=context()) = AffineExpr(API.mlirAffineConstantExprGet(context, constant)) """ - value(affineExpr) + constvalue(affineExpr) Returns the value of the given affine constant expression. """ -function value(expr::AffineExpr) +function constvalue(expr::AffineExpr) @assert isconstantexpr(expr) "The given affine expression is not a constant expression" return API.mlirAffineConstantExprGetValue(expr) end diff --git a/src/IR/Value.jl b/src/IR/Value.jl index f4d3da07..ba21a38a 100644 --- a/src/IR/Value.jl +++ b/src/IR/Value.jl @@ -11,6 +11,16 @@ Base.convert(::Core.Type{API.MlirValue}, value::Value) = value.value Base.size(value::Value) = Base.size(Type(value)) Base.ndims(value::Value) = Base.ndims(Type(value)) +abstract type ValueTrait end +struct Convertible <: ValueTrait end +struct NonConvertible <: ValueTrait end + +ValueTrait(T) = NonConvertible() +value(x::Value) = x +value(x::T) where T = value(ValueTrait(T), x) +value(::Convertible, x) = x.value +value(::NonConvertible, x::T) where T = error("Type $T does not have the Convertible ValueTrait") + """ ==(value1, value2)