google / google/mlir-hs

Invalid IR or function without blockargs

Open
#34 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
128
Forks
18
PR merge metrics
No merged PRs in 30d

Description

Self-contained'ish example showing issue with function without blockargs generating invalid IR:

```hs
{-# LANGUAGE BlockArguments #-}

import qualified Data.Map.Strict as M
import Control.Monad.Reader
import Control.Monad.Identity
import Data.Char (ord)

import Test.Hspec

import qualified MLIR.Native as MLIR
import MLIR.AST
import MLIR.AST.Builder
import MLIR.AST.Serialize
import qualified Data.ByteString as BS
import qualified MLIR.AST.Dialect.Arith as Arith
import qualified MLIR.AST.Dialect.Func as Func

pack :: String -> BS.ByteString
pack = BS.pack . fmap (fromIntegral . ord)

generate :: Operation
generate = runIdentity $ evalNameSupplyT $ buildModule $ do
let w32 = IntegerType Signless 32
val <- Arith.constant w32 (IntegerAttr w32 42)
buildFunction (pack "function") [w32] NoAttrs $ do
buildBlock $ do
-- Correct value returned if blockArgument is used, else not
-- a <- blockArgument w32
c <- Arith.constant w32 (IntegerAttr w32 43)
Func.return [c]
endOfRegion
val <- Arith.constant w32 (IntegerAttr w32 44)
return ()


verifyAndDump :: Operation -> Expectation
verifyAndDump op = MLIR.withContext \ctx -> do
MLIR.registerAllDialects ctx
nativeOp <- fromAST ctx (mempty, mempty) op
MLIR.dump nativeOp
MLIR.verifyOperation nativeOp >>= (`shouldBe` True)

main = verifyAndDump generate
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.