Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

luc-tielen
Copy link
Contributor

Same as #367. But for the llvm-12 branch.

Previously, the latest terminator instruction was always used (`br`,
`condBr`, `ret`, ...). This limited composability when creating
combinators based on the IR builder.

Now, we keep track of the first terminator which is more in line with
how LLVM semantics work (terminators that appear later in a basic block
are dead code).

With this change, we can now create control flow combinators that work
like we expect them to:

```haskell
-- A combinator for a "one sided if statement"
if' condition asm = mdo
  condBr condition begin end
  begin <- block `named` "if.begin"
  asm
  br end
  end <- block `named` "if.end"
  return ()

example = do
  function "f" [(AST.i1, "a"), (AST.i1, "b")] AST.i1 $ \[a, b] -> mdo

    entry <- block `named` "entry"; do
      if' a $ do
        if' b $ do
          -- Previously, this ret instruction would not be emitted!
          ret (bit 0)

      ret (bit 1)
```
Copy link
Member

@andrew-wja andrew-wja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! Looks good to me.

@andrew-wja andrew-wja merged commit 9db6578 into llvm-hs:llvm-12 Oct 15, 2021
@luc-tielen luc-tielen deleted the llvm-12 branch October 15, 2021 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.