21#include <llvm/ADT/DenseSet.h>
22#include <llvm/ADT/STLExtras.h>
25#define GEN_PASS_DEF_EXPOSECHILDMEMBERSPASS
36class ChildStorageVisitor {
38 SymbolTableCollection tables;
44 llvm::DenseSet<Operation *> visited;
46 SmallVector<StructDefOp> children;
48 llvm::DenseSet<Operation *> rolledMembers;
52 : storageRoot(root), specializations(module) {}
56 if (failed(visitStruct(storageRoot))) {
59 for (
auto child : children) {
60 for (
auto member : child.getMemberDefs()) {
61 member.setPublicAttr();
64 for (Operation *member : rolledMembers) {
74 return definition.emitError(
"llzk-expose-child-members requires monomorphized struct types");
82 for (
auto member :
definition.getMemberDefs()) {
83 if (failed(visitType(member.getType(), member))) {
92 if (rolled == storageRoot) {
96 if (
auto declaration = rolled.
getMemberDef(member.getSymNameAttr())) {
97 rolledMembers.insert(declaration);
104 LogicalResult visitFamily(
StructType structure, Operation *site) {
107 return site->emitError(
108 "missing concrete struct family element for llzk-expose-child-members"
111 auto records = dyn_cast<ArrayAttr>(metadata);
113 return site->emitError(
"invalid poly.family metadata for llzk-expose-child-members");
116 if (failed(rolled)) {
119 if (!*rolled || rolled->viaInclude()) {
120 return site->emitError(
121 "cannot resolve child-member visibility family source; inline includes first"
124 llvm::DenseSet<int64_t> seenIds;
125 for (Attribute record : records) {
126 auto dict = dyn_cast<DictionaryAttr>(record);
128 if (!type || !isa<StructType>(type.getValue())) {
129 return site->emitError(
"invalid poly.family entry for llzk-expose-child-members");
131 if (type.getValue() != structure) {
135 if (!
id || !
id.getValue().isSignedIntN(64) ||
id.getInt() < 0) {
136 return site->emitError(
"invalid poly.family entry for llzk-expose-child-members");
138 if (!seenIds.insert(
id.getInt()).second) {
142 tables, structure,
id.getInt(), site,
"llzk-expose-child-members"
147 collectRolledMembers(rolled->get(), *
definition);
149 if (seenIds.empty()) {
150 return site->emitError(
151 "missing concrete struct family element for llzk-expose-child-members"
158 LogicalResult visitType(Type type, Operation *site) {
159 if (!walkContains<StructType>(type)) {
162 if (
auto array = dyn_cast<array::ArrayType>(type)) {
163 if (!array.hasStaticShape()) {
164 return site->emitError(
"llzk-expose-child-members requires concrete array dimensions");
166 if (llvm::is_contained(array.getShape(), 0)) {
169 return visitType(array.getElementType(), site);
171 if (
auto pod = dyn_cast<pod::PodType>(type)) {
172 for (
auto record : pod.getRecords()) {
173 if (failed(visitType(record.getType(), site))) {
179 auto structure = cast<StructType>(type);
180 if (
auto params = structure.
getParams(); params && !params.empty()) {
181 return visitFamily(structure, site);
188 return site->emitError(
"cannot resolve child struct storage; inline includes first");
196 using Base = ExposeChildMembersPassBase<PassImpl>;
199 void runOnOperation()
override {
200 SymbolTableCollection tables;
207 getOperation().emitError(
208 "llzk-expose-child-members requires llzk.main or an explicit root-struct"
213 if (root->viaInclude()) {
214 getOperation().emitError(
215 "llzk-expose-child-members requires a local root struct; inline includes first"
228 auto module = getTopRootModule(root);
229 if (failed(module)) {
232 return ChildStorageVisitor(*module, root).run();
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation and configuration files Object form shall mean any form resulting from mechanical transformation or translation of a Source including but not limited to compiled object generated and conversions to other media types Work shall mean the work of whether in Source or Object made available under the as indicated by a copyright notice that is included in or attached to the whether in Source or Object that is based or other modifications as a an original work of authorship For the purposes of this Derivative Works shall not include works that remain separable or merely the Work and Derivative Works thereof Contribution shall mean any work of including the original version of the Work and any modifications or additions to that Work or Derivative Works that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner For the purposes of this definition
::std::vector< MemberDefOp > getMemberDefs()
Get all MemberDefOp in this structure.
MemberDefOp getMemberDef(::mlir::StringAttr memberName)
Gets the MemberDefOp that defines the member in this structure with the given name,...
::mlir::FailureOr< SymbolLookupResult< StructDefOp > > getDefinition(::mlir::SymbolTableCollection &symbolTable, ::mlir::Operation *op, bool reportMissing=true) const
Gets the struct op that defines this struct.
::mlir::ArrayAttr getParams() const
Resolve concrete struct specializations referenced by poly.family metadata.
mlir::LogicalResult exposeChildMembers(StructDefOp root)
Make reachable concrete child members and matching rolled family declarations public while preserving...
constexpr llvm::StringLiteral FAMILY_ATTR
constexpr llvm::StringLiteral FAMILY_SPECIALIZATION_KEY
bool isInTemplate(Operation *op)
constexpr llvm::StringLiteral FAMILY_TYPE_KEY
The original affine-parameterized struct family, paired with element indices and a concrete specializ...
FailureOr< SymbolLookupResult< StructDefOp > > getRootStructDef(SymbolTableCollection &tables, Operation *lookupFrom, StringRef symbolPath)