Skip to content

Commit

Permalink
Work on getting rewriter + IR playing nice together. (#314)
Browse files Browse the repository at this point in the history
* Work on getting rewriter + IR playing nice together.

There are a few different changes here, with the goal of improving the interaction between the "rewriter" code generation approach and the new IR and type legalization code.

The main changes are:

- Add a new pass that occurs before the AST legalization pass, which walks the (used) AST declarations and tries to discover (1) which declarations need to be specialized/lowered via the IR, and (2) which declarations need to be included in the resulting AST module.

- AST-based legalization now uses the generated list when in "rewriter" mode, so that we should be working around issues that users were seeing with types not getting emitted.
  - TODO: we still need an equivalent fixup in the case of non-"rewriter" emit, so this may still be a problem for `.slang` files.

- IR type legalization now precedes AST legalization, so that we can record information on how any IR global values got legalized (e.g., if they got split). Then AST legalization includes logic to reconstruct suitable tuple expressions to reference a split global.

- When emitting using IR + AST, we walk all of the declarations that we decided belonged to the IR, but which were subsequently referenced in the AST, to make sure they get output (this would include `struct` types that are declared in a file compiled via IR, but never used in IR-based code).

The rewriter+IR use case still doesn't *quite* work, but the logic for walking the AST in a pre-pass ends up being needed/useful to fix some pure rewriter bugs, so I'm getting this checked in sooner rather than later.

* Fixup: walk arguments to generic declaration reference

The gotcha here is that the code for walking the AST would walk a line of code like:

    SomeType a;

and know to traverse the declaration of `SomeType`, but if it saw a line of code like:

    ParameterBlock<SomeType> b;

it would traverse the declaration of `ParameterBlock`, but fail to visit that of `SomeType`.
  • Loading branch information
Tim Foley authored Dec 18, 2017
1 parent 46b68ed commit 393e25f
Show file tree
Hide file tree
Showing 14 changed files with 973 additions and 162 deletions.
2 changes: 1 addition & 1 deletion source/core/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ namespace Slang

void Reverse()
{
for (int i = 0; i < (_count >> 1); i++)
for (UInt i = 0; i < (_count >> 1); i++)
{
Swap(buffer, i, _count - i - 1);
}
Expand Down
Loading

0 comments on commit 393e25f

Please sign in to comment.