Skip to content

Commit 070305f

Browse files
committed
Remove mutex around LLVM calls from booster
Previously the LLVM backend was not thread-safe so the simplification calls had to be sequentialised for concurrent RPC requests. Since thread-local storage is now used, the calls can be executed concurrently/in parallel using multiple cores. This PR removes the mutex that sequentialised the calls before.
1 parent f6e0f33 commit 070305f

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

booster/library/Booster/LLVM/Internal.hs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ module Booster.LLVM.Internal (
1919
LlvmError (..),
2020
) where
2121

22-
import Control.Concurrent.MVar (MVar, newMVar, withMVar)
2322
import Control.Exception (IOException)
2423
import Control.Monad (foldM, forM_, void, (>=>))
2524
import Control.Monad.Catch (MonadCatch, MonadMask, MonadThrow, catch)
@@ -104,21 +103,19 @@ data API = API
104103
, simplifyBool :: KorePatternPtr -> IO (Either LlvmError Bool)
105104
, simplify :: KorePatternPtr -> KoreSortPtr -> IO (Either LlvmError ByteString)
106105
, collect :: IO ()
107-
, mutex :: MVar ()
108106
}
109107

110108
newtype LLVM a = LLVM (ReaderT API IO a)
111109
deriving newtype (Functor, Applicative, Monad, MonadIO, MonadThrow, MonadCatch, MonadMask)
112110

113-
{- | Uses dlopen to load a .so/.dylib C library at runtime. For doucmentation of flags such as `RTL_LAZY`, consult e.g.
111+
{- | Uses dlopen to load a .so/.dylib C library at runtime. For documentation of flags such as `RTL_LAZY`, consult e.g.
114112
https://man7.org/linux/man-pages/man3/dlopen.3.html
115113
-}
116114
withDLib :: FilePath -> (Linker.DL -> IO a) -> IO a
117115
withDLib dlib = Linker.withDL dlib [Linker.RTLD_LAZY]
118116

119117
runLLVM :: API -> LLVM a -> IO a
120-
runLLVM api (LLVM m) =
121-
withMVar api.mutex $ const $ runReaderT m api
118+
runLLVM api (LLVM m) = runReaderT m api
122119

123120
mkAPI :: Linker.DL -> IO API
124121
mkAPI dlib = flip runReaderT dlib $ do
@@ -282,8 +279,7 @@ mkAPI dlib = flip runReaderT dlib $ do
282279
stderr
283280
"[Warn] Using an LLVM backend compiled with --llvm-mutable-bytes (unsound byte array semantics)"
284281

285-
mutex <- liftIO $ newMVar ()
286-
pure API{patt, symbol, sort, simplifyBool, simplify, collect, mutex}
282+
pure API{patt, symbol, sort, simplifyBool, simplify, collect}
287283

288284
ask :: LLVM API
289285
ask = LLVM Reader.ask

0 commit comments

Comments
 (0)