"profiler/vscode:/vscode.git/clone" did not exist on "87fd11526f32b09baa1c72735d1ee4c4fb412dc0"
Commit 6106ed16 authored by Paul's avatar Paul
Browse files

Create a type attribute

parent 8e50db0f
...@@ -132,6 +132,23 @@ struct mlir_program ...@@ -132,6 +132,23 @@ struct mlir_program
return mlirRankedTensorTypeGet(lens.size(), lens.data(), make_type(s.type())); return mlirRankedTensorTypeGet(lens.size(), lens.data(), make_type(s.type()));
} }
template<class Range>
std::vector<MlirType> make_tensors(const Range& r)
{
std::vector<MlirType> result;
std::transform(r.begin(), r.end(), std::back_inserter(result), [&](const auto& s) {
return make_tensor(s);
});
return result;
}
MlirType make_function_type(const std::vector<shape>& inputs, const std::vector<shape>& outputs)
{
auto in = make_tensors(inputs);
auto out = make_tensors(outputs);
return mlirFunctionTypeGet(ctx.get(), in.size(), in.data(), out.size(), out.data());
}
MlirIdentifier id(const std::string_view& s) const MlirIdentifier id(const std::string_view& s) const
{ {
return mlirIdentifierGet(ctx.get(), make_mlir_string_ref(s)); return mlirIdentifierGet(ctx.get(), make_mlir_string_ref(s));
...@@ -180,10 +197,7 @@ struct mlir_program ...@@ -180,10 +197,7 @@ struct mlir_program
std::vector<MlirNamedAttribute> attributes; std::vector<MlirNamedAttribute> attributes;
attributes.reserve(v.size()); attributes.reserve(v.size());
std::transform(v.begin(), v.end(), std::back_inserter(attributes), [&](auto&& x) { std::transform(v.begin(), v.end(), std::back_inserter(attributes), [&](auto&& x) {
MlirNamedAttribute attr; return name_attribute(x.get_key(), x.without_key());
attr.name = id(x.get_key());
attr.attribute = attribute(x.without_key());
return attr;
}); });
return mlirDictionaryAttrGet(ctx.get(), attributes.size(), attributes.data()); return mlirDictionaryAttrGet(ctx.get(), attributes.size(), attributes.data());
} }
...@@ -198,6 +212,21 @@ struct mlir_program ...@@ -198,6 +212,21 @@ struct mlir_program
} }
} }
MlirAttribute attribute(MlirType t) const
{
return mlirTypeAttrGet(t);
}
template<class T>
MlirNamedAttribute name_attribute(const std::string_view& key, const T& x) const
{
MlirNamedAttribute attr;
attr.name = id(key);
attr.attribute = attribute(x);
return attr;
}
mlir_context ctx; mlir_context ctx;
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment