# ir: new pass iteration strategy · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/0ea50b3157f00ab56b2752dfa8c70edb4bce2af7)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 0ea50b3157f00ab56b2752dfa8c70edb4bce2af7

Requested commit: 0ea50b3157f00ab56b2752dfa8c70edb4bce2af7

Commit: 0ea50b3157f00ab56b2752dfa8c70edb4bce2af7

Tree: f93d27fecd278dec741d35d5f0f6099d9d136d07

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
ir: new pass iteration strategy

Before:
 * IR basic blocks are in arbitrary order
 * when doing an IR pass, when a block is encountered, code
   must look at all the instructions in the old basic block,
   determine what blocks are referenced, and queue up those
   old basic blocks first.
 * This had a bug (See #667)

Now:
 * IR basic blocks are required to be in an order that guarantees
   they will be referenced by a branch, before any instructions
   within are referenced.
   ir pass1 is updated to meet this constraint.
 * When doing an IR pass, we iterate over old basic blocks
   in the order they appear. Blocks which have not been
   referenced are discarded.
 * After the pass is complete, we must iterate again to look
   for old basic blocks which now point to incomplete new
   basic blocks, due to comptime code generation.
 * This last part can probably be optimized - most of the time
   we don't need to iterate over the basic block again.

closes #667

```

## Parents

- [aafb83228890c07eb3f0a203010d044aaceb8f85](https://git.cafe/gitcafe/zig/commit/aafb83228890c07eb3f0a203010d044aaceb8f85?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/0ea50b3157f00ab56b2752dfa8c70edb4bce2af7?format=markdown)
