Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions deps/tblgen/jl-generators.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)";
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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 = "; ";
Expand Down
4 changes: 2 additions & 2 deletions src/IR/AffineExpr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/IR/Value.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down