Skip to content

Commit

Permalink
Run LLVM JIT before all BTree tests
Browse files Browse the repository at this point in the history
  • Loading branch information
luc-tielen committed Dec 30, 2021
1 parent 54c6db3 commit 0a4ae18
Show file tree
Hide file tree
Showing 6 changed files with 269 additions and 35 deletions.
70 changes: 65 additions & 5 deletions eclair-lang.cabal
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
cabal-version: 2.2

-- This file has been generated from package.yaml by hpack version 0.33.0.
-- This file has been generated from package.yaml by hpack version 0.34.4.
--
-- see: https://github.com/sol/hpack
--
-- hash: a25d696986ffb9e46bdca3e3dcfa762a74976733f7c26bcf2058262f5fb2d6c9
-- hash: b91e2e19bff2257859664e89b83efba2264daa4210b995d4bee5d8d3b806ab11

name: eclair-lang
version: 0.1.0.0
Expand Down Expand Up @@ -45,12 +45,32 @@ library
Paths_eclair_lang
hs-source-dirs:
lib
default-extensions: NoImplicitPrelude OverloadedStrings LambdaCase ViewPatterns RankNTypes TypeFamilies DataKinds KindSignatures TupleSections DeriveFunctor DeriveFoldable DeriveTraversable DeriveGeneric DeriveAnyClass DerivingStrategies DerivingVia FlexibleContexts FlexibleInstances ScopedTypeVariables
default-extensions:
NoImplicitPrelude
OverloadedStrings
LambdaCase
ViewPatterns
RankNTypes
TypeFamilies
DataKinds
KindSignatures
TupleSections
DeriveFunctor
DeriveFoldable
DeriveTraversable
DeriveGeneric
DeriveAnyClass
DerivingStrategies
DerivingVia
FlexibleContexts
FlexibleInstances
ScopedTypeVariables
ghc-options: -fhide-source-paths -fno-show-valid-hole-fits -fno-sort-valid-hole-fits
cxx-options: -std=c++20 -D__EMBEDDED_SOUFFLE__ -Wall
build-depends:
algebraic-graphs ==0.*
, base >=4.7 && <5
, bytestring ==0.*
, containers ==0.*
, exceptions ==0.10.*
, extra ==1.*
Expand Down Expand Up @@ -87,12 +107,32 @@ executable eclairc
Paths_eclair_lang
hs-source-dirs:
src
default-extensions: NoImplicitPrelude OverloadedStrings LambdaCase ViewPatterns RankNTypes TypeFamilies DataKinds KindSignatures TupleSections DeriveFunctor DeriveFoldable DeriveTraversable DeriveGeneric DeriveAnyClass DerivingStrategies DerivingVia FlexibleContexts FlexibleInstances ScopedTypeVariables
default-extensions:
NoImplicitPrelude
OverloadedStrings
LambdaCase
ViewPatterns
RankNTypes
TypeFamilies
DataKinds
KindSignatures
TupleSections
DeriveFunctor
DeriveFoldable
DeriveTraversable
DeriveGeneric
DeriveAnyClass
DerivingStrategies
DerivingVia
FlexibleContexts
FlexibleInstances
ScopedTypeVariables
ghc-options: -fhide-source-paths -fno-show-valid-hole-fits -fno-sort-valid-hole-fits -threaded -rtsopts -with-rtsopts=-N
cxx-options: -std=c++20 -D__EMBEDDED_SOUFFLE__
build-depends:
algebraic-graphs ==0.*
, base >=4.7 && <5
, bytestring ==0.*
, containers ==0.*
, directory ==1.*
, eclair-lang
Expand Down Expand Up @@ -134,12 +174,32 @@ test-suite eclair-test
Paths_eclair_lang
hs-source-dirs:
tests
default-extensions: NoImplicitPrelude OverloadedStrings LambdaCase ViewPatterns RankNTypes TypeFamilies DataKinds KindSignatures TupleSections DeriveFunctor DeriveFoldable DeriveTraversable DeriveGeneric DeriveAnyClass DerivingStrategies DerivingVia FlexibleContexts FlexibleInstances ScopedTypeVariables
default-extensions:
NoImplicitPrelude
OverloadedStrings
LambdaCase
ViewPatterns
RankNTypes
TypeFamilies
DataKinds
KindSignatures
TupleSections
DeriveFunctor
DeriveFoldable
DeriveTraversable
DeriveGeneric
DeriveAnyClass
DerivingStrategies
DerivingVia
FlexibleContexts
FlexibleInstances
ScopedTypeVariables
ghc-options: -fhide-source-paths -fno-show-valid-hole-fits -fno-sort-valid-hole-fits
cxx-options: -std=c++20 -D__EMBEDDED_SOUFFLE__
build-depends:
algebraic-graphs ==0.*
, base >=4.7 && <5
, bytestring ==0.*
, containers ==0.*
, eclair-lang
, exceptions ==0.10.*
Expand Down
3 changes: 2 additions & 1 deletion lib/Eclair/Lowering/RA.hs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ generateFnsForRelations indexMap typeInfo = do
-- TODO: avoid codegen collisions between relations
for (toList idxs) $ \idx -> do
let meta = mkMeta idx (fromJust $ Map.lookup r typeInfo)
(idx,) <$> BTree.codegen meta
(fns, _sizes) <- BTree.codegen meta
pure (idx, fns)

pure $ map Map.fromList results

Expand Down
13 changes: 10 additions & 3 deletions lib/Eclair/Runtime/BTree.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

module Eclair.Runtime.BTree
( Meta(..)
, Sizes(..)
, SearchIndex
, SearchType(..)
, codegen
Expand Down Expand Up @@ -69,6 +70,8 @@ data Externals
data Sizes
= Sizes
{ pointerSize :: Word64
, treeSize :: Word64
, iterSize :: Word64
, valueSize :: Word64
, nodeDataSize :: Word64
, leafNodeSize :: Word64
Expand All @@ -89,13 +92,14 @@ type IRCodegen = IRBuilderT ModuleCodegen
type ModuleCodegen = ReaderT CGState ModuleBuilder


codegen :: Meta -> ModuleBuilderT IO Functions
codegen :: Meta -> ModuleBuilderT IO (Functions, Sizes)
codegen meta = do
sizes <- computeSizes meta
hoist intoIO $ do
tys <- runReaderT (generateTypes sizes) meta
exts <- mkExternals
runReaderT generateFunctions $ CGState meta tys sizes exts
fns <- runReaderT generateFunctions $ CGState meta tys sizes exts
pure (fns, sizes)
where intoIO = pure . runIdentity

mkExternals :: ModuleBuilder Externals
Expand Down Expand Up @@ -125,7 +129,10 @@ computeSizes meta = do
innerNodeTy = wrap [nodeTy, ArrayType (numKeys' + 1) (ptr nodeTy)]
leafNodeSize <- sizeOfType ("leaf_node_t", nodeTy)
innerNodeSize <- sizeOfType ("inner_node_t", innerNodeTy)
pure $ Sizes ptrSize valueSize nodeDataSize leafNodeSize innerNodeSize
let positionTy = i16
iterSize <- sizeOfType ("btree_iterator_t", wrap [ptr nodeTy, positionTy])
treeSize <- sizeOfType ("btree_t", wrap [ptr nodeTy, ptr nodeTy])
pure $ Sizes ptrSize treeSize iterSize valueSize nodeDataSize leafNodeSize innerNodeSize
where
wrap = StructureType False

Expand Down
10 changes: 9 additions & 1 deletion lib/Eclair/Runtime/LLVM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Eclair.Runtime.LLVM
( module Eclair.Runtime.LLVM
) where

import Protolude hiding ( Type, (.), bit )
import Protolude hiding ( Type, (.), bit, moduleName )
import Control.Category
import Control.Monad.Morph
import Control.Monad.Fix
Expand All @@ -17,6 +17,7 @@ import LLVM.IRBuilder.Instruction
import qualified LLVM.AST.IntegerPredicate as IP
import qualified LLVM.AST.Constant as Constant
import LLVM.AST.Operand ( Operand(..) )
import LLVM.AST (Module, moduleName, moduleDefinitions, defaultModule)
import LLVM.AST.Type
import LLVM.AST.Name
import Eclair.Runtime.Hash
Expand All @@ -30,6 +31,7 @@ import qualified LLVM.CodeGenOpt as CG
import qualified LLVM.CodeModel as CM
import qualified LLVM.Relocation as Rel
import LLVM.Target
import Data.ByteString.Short


-- TODO: remove, import directly from llvm-hs
Expand Down Expand Up @@ -72,6 +74,12 @@ sizeOfType (n, ty) = do
defineType n n' t'
setNamedType t' ty

codegenModule :: ShortByteString -> ModuleBuilderT IO a -> IO (a, Module)
codegenModule name mod =
map mkModule <$> runModuleBuilderT emptyModuleBuilder mod
where
mkModule defs = defaultModule { moduleName = name, moduleDefinitions = defs }

-- NOTE: Orphan instance, but should give no conflicts.
instance MFunctor ModuleBuilderT where
hoist nat = ModuleBuilderT . hoist nat . unModuleBuilderT
Expand Down
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies:
- protolude == 0.3.0
- extra == 1.*
- text == 1.*
- bytestring == 0.*
- vector == 0.12.*
- containers == 0.*
- transformers == 0.*
Expand Down
Loading

0 comments on commit 0a4ae18

Please sign in to comment.