@@ -321,6 +321,8 @@ struct ScheduleTreeAndDomain {
321321 * recursively descending over the Stmt.
322322 * "s" is the current position in the recursive descent.
323323 * "set" describes the bounds on the outer loop iterators.
324+ * "outer" contains the names of the outer loop iterators
325+ * from outermost to innermost.
324326 * Return the schedule tree corresponding to the subtree at "s",
325327 * along with a separated out domain.
326328 *
@@ -329,14 +331,18 @@ struct ScheduleTreeAndDomain {
329331 * (for the writes) to the corresponding tag in the access relations.
330332 * "statements" collects the mapping from instance set tuple identifiers
331333 * to the corresponding Provide node.
334+ * "iterators" collects the mapping from instance set tuple identifiers
335+ * to the corresponding outer loop iterator names, from outermost to innermost.
332336 */
333337ScheduleTreeAndDomain makeScheduleTreeHelper (
334338 const Stmt& s,
335339 isl::set set,
340+ std::vector<std::string>& outer,
336341 isl::union_map* reads,
337342 isl::union_map* writes,
338343 AccessMap* accesses,
339- StatementMap* statements) {
344+ StatementMap* statements,
345+ IteratorMap* iterators) {
340346 ScheduleTreeAndDomain result;
341347 if (auto op = s.as <For>()) {
342348 // Add one additional dimension to our set of loop variables
@@ -372,8 +378,17 @@ ScheduleTreeAndDomain makeScheduleTreeHelper(
372378 }
373379
374380 // Recursively descend.
381+ auto outerNext = outer;
382+ outerNext.push_back (op->name );
375383 auto body = makeScheduleTreeHelper (
376- op->body , set, reads, writes, accesses, statements);
384+ op->body ,
385+ set,
386+ outerNext,
387+ reads,
388+ writes,
389+ accesses,
390+ statements,
391+ iterators);
377392
378393 // Create an affine function that defines an ordering for all
379394 // the statements in the body of this loop over the values of
@@ -419,8 +434,8 @@ ScheduleTreeAndDomain makeScheduleTreeHelper(
419434 // children.
420435 std::vector<ScheduleTreeUPtr> trees;
421436 for (Stmt s : stmts) {
422- auto mem =
423- makeScheduleTreeHelper ( s, set, reads, writes, accesses, statements);
437+ auto mem = makeScheduleTreeHelper (
438+ s, set, outer, reads, writes, accesses, statements, iterators );
424439 ScheduleTreeUPtr filter;
425440 if (mem.tree ) {
426441 // No statement instances are shared between the blocks, so we
@@ -452,6 +467,7 @@ ScheduleTreeAndDomain makeScheduleTreeHelper(
452467 size_t stmtIndex = statements->size ();
453468 isl::id id (set.get_ctx (), kStatementLabel + std::to_string (stmtIndex));
454469 statements->emplace (id, op);
470+ iterators->emplace (id, outer);
455471 isl::set domain = set.set_tuple_id (id);
456472 result.domain = domain;
457473
@@ -474,13 +490,16 @@ ScheduleTreeAndAccesses makeScheduleTree(isl::space paramSpace, const Stmt& s) {
474490 result.writes = result.reads = isl::union_map::empty (paramSpace);
475491
476492 // Walk the IR building a schedule tree
493+ std::vector<std::string> outer;
477494 auto treeAndDomain = makeScheduleTreeHelper (
478495 s,
479496 isl::set::universe (paramSpace),
497+ outer,
480498 &result.reads ,
481499 &result.writes ,
482500 &result.accesses ,
483- &result.statements );
501+ &result.statements ,
502+ &result.iterators );
484503
485504 // TODO: This fails if the stmt is just a Provide node, I'm not sure
486505 // what the schedule tree should look like in that case.
0 commit comments