Ticket #5814: 0001-llvmGen-Use-new-fence-instruction.patch

File 0001-llvmGen-Use-new-fence-instruction.patch, 4.9 KB (added by bgamari, 4 years ago)

Preliminary patch

  • compiler/llvmGen/Llvm.hs

    From 4ecaabfd18be5275a83ef4cef26507778771d9d0 Mon Sep 17 00:00:00 2001
    From: Ben Gamari <ben@panda.(none)>
    Date: Tue, 24 Jan 2012 19:56:35 -0500
    Subject: [PATCH] llvmGen: Use new fence instruction
    
    ---
     compiler/llvmGen/Llvm.hs                |    3 +++
     compiler/llvmGen/Llvm/AbsSyn.hs         |   10 ++++++++++
     compiler/llvmGen/Llvm/PpLlvm.hs         |   12 ++++++++++++
     compiler/llvmGen/LlvmCodeGen/CodeGen.hs |   26 +++++++++++++++++---------
     4 files changed, 42 insertions(+), 9 deletions(-)
    
    diff --git a/compiler/llvmGen/Llvm.hs b/compiler/llvmGen/Llvm.hs
    index b15b6f2..32df9e3 100644
    a b module Llvm ( 
    2020        LlvmBlocks, LlvmBlock(..), LlvmBlockId,
    2121        LlvmParamAttr(..), LlvmParameter,
    2222
     23        -- * Fence synchronization
     24        LlvmSyncOrdering(..),
     25
    2326        -- * Call Handling
    2427        LlvmCallConvention(..), LlvmCallType(..), LlvmParameterListType(..),
    2528        LlvmLinkageType(..), LlvmFuncAttr(..),
  • compiler/llvmGen/Llvm/AbsSyn.hs

    diff --git a/compiler/llvmGen/Llvm/AbsSyn.hs b/compiler/llvmGen/Llvm/AbsSyn.hs
    index a28734b..c9c8d3b 100644
    a b data LlvmFunction = LlvmFunction { 
    6464
    6565type LlvmFunctions  = [LlvmFunction]
    6666
     67data LlvmSyncOrdering = SyncAcquire
     68                      | SyncRelease
     69                      | SyncAcqRel
     70                      | SyncSeqCst
     71                      deriving (Show, Eq)
    6772
    6873-- | Llvm Statements
    6974data LlvmStatement
    data LlvmStatement 
    7580  = Assignment LlvmVar LlvmExpression
    7681
    7782  {- |
     83    Memory fence operation
     84  -}
     85  | Fence Bool LlvmSyncOrdering
     86
     87  {- |
    7888    Always branch to the target label
    7989  -}
    8090  | Branch LlvmVar
  • compiler/llvmGen/Llvm/PpLlvm.hs

    diff --git a/compiler/llvmGen/Llvm/PpLlvm.hs b/compiler/llvmGen/Llvm/PpLlvm.hs
    index 2945777..bfc037e 100644
    a b ppLlvmStatement stmt = 
    211211  let ind = (text "  " <>)
    212212  in case stmt of
    213213        Assignment  dst expr      -> ind $ ppAssignment dst (ppLlvmExpression expr)
     214        Fence       st ord        -> ind $ ppFence st ord
    214215        Branch      target        -> ind $ ppBranch target
    215216        BranchIf    cond ifT ifF  -> ind $ ppBranchIf cond ifT ifF
    216217        Comment     comments      -> ind $ ppLlvmComments comments
    ppCmpOp op left right = 
    301302ppAssignment :: LlvmVar -> Doc -> Doc
    302303ppAssignment var expr = (text $ getName var) <+> equals <+> expr
    303304
     305ppFence :: Bool -> LlvmSyncOrdering -> Doc
     306ppFence st ord =
     307  let singleThread = case st of True  -> text "singlethread"
     308                                False -> empty
     309  in text "fence" <+> singleThread <+> ppSyncOrdering ord
     310
     311ppSyncOrdering :: LlvmSyncOrdering -> Doc
     312ppSyncOrdering SyncAcquire = text "acquire"
     313ppSyncOrdering SyncRelease = text "release"
     314ppSyncOrdering SyncAcqRel  = text "acq_rel"
     315ppSyncOrdering SyncSeqCst  = text "seq_cst"
    304316
    305317ppLoad :: LlvmVar -> Doc
    306318ppLoad var = text "load" <+> texts var
  • compiler/llvmGen/LlvmCodeGen/CodeGen.hs

    diff --git a/compiler/llvmGen/LlvmCodeGen/CodeGen.hs b/compiler/llvmGen/LlvmCodeGen/CodeGen.hs
    index d503782..75388d3 100644
    a b stmtToInstrs env stmt = case stmt of 
    137137        -> return (env, unitOL $ Return Nothing, [])
    138138
    139139
    140 -- | Foreign Calls
    141 genCall :: LlvmEnv -> CmmCallTarget -> [HintedCmmFormal] -> [HintedCmmActual]
    142               -> CmmReturnInfo -> UniqSM StmtData
     140barrier :: LlvmEnv -> UniqSM StmtData
     141barrier env = do
     142    let s = Fence False SyncAcqRel
     143    return (env, unitOL s, [])
    143144
    144 -- Write barrier needs to be handled specially as it is implemented as an LLVM
    145 -- intrinsic function.
    146 genCall env (CmmPrim MO_WriteBarrier) _ _ _
    147  | platformArch (getLlvmPlatform env) `elem` [ArchX86, ArchX86_64, ArchSPARC]
    148     = return (env, nilOL, [])
    149  | otherwise = do
     145oldBarrier :: LlvmEnv -> UniqSM StmtData
     146oldBarrier env = do
    150147    let fname = fsLit "llvm.memory.barrier"
    151148    let funSig = LlvmFunctionDecl fname ExternallyVisible CC_Ccc LMVoid
    152149                    FixedArgs (tysToParams [i1, i1, i1, i1, i1]) llvmFunAlign
    genCall env (CmmPrim MO_WriteBarrier) _ _ _ 
    167164        lmTrue :: LlvmVar
    168165        lmTrue  = mkIntLit i1 (-1)
    169166
     167-- | Foreign Calls
     168genCall :: LlvmEnv -> CmmCallTarget -> [HintedCmmFormal] -> [HintedCmmActual]
     169              -> CmmReturnInfo -> UniqSM StmtData
     170
     171-- Write barrier needs to be handled specially as it is implemented as an LLVM
     172-- intrinsic function.
     173genCall env (CmmPrim MO_WriteBarrier) _ _ _
     174 | platformArch (getLlvmPlatform env) `elem` [ArchX86, ArchX86_64, ArchSPARC]
     175    = return (env, nilOL, [])
     176 | otherwise = barrier env
     177
    170178-- Handle popcnt function specifically since GHC only really has i32 and i64
    171179-- types and things like Word8 are backed by an i32 and just present a logical
    172180-- i8 range. So we must handle conversions from i32 to i8 explicitly as LLVM