diff options
author | Edward Z. Yang <ezyang@mit.edu> | 2011-04-04 12:56:57 +0100 |
---|---|---|
committer | Edward Z. Yang <ezyang@mit.edu> | 2011-04-05 18:01:50 +0100 |
commit | d70fc3c10316422c71a0b7d895ed5c50242d27b0 (patch) | |
tree | 487cf4a8719fa7d134dd59250638b309377897a8 | |
parent | 12929a219671cd7794b5a533cebdfef11d2f8ff4 (diff) | |
download | haskell-d70fc3c10316422c71a0b7d895ed5c50242d27b0.tar.gz |
CmmOpt cannot assume single assignment for hand-written or new codegen Cmm.
This change may constitute a substantial performance hit, due to the new
creation of a set for every instruction we emit.
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
-rw-r--r-- | compiler/cmm/CmmOpt.hs | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/compiler/cmm/CmmOpt.hs b/compiler/cmm/CmmOpt.hs index 0dec26da6f..c71f188ba7 100644 --- a/compiler/cmm/CmmOpt.hs +++ b/compiler/cmm/CmmOpt.hs @@ -115,12 +115,15 @@ cmmMiniInlineStmts uses (stmt@(CmmAssign (CmmLocal (LocalReg u _)) expr) : stmts cmmMiniInlineStmts uses (stmt:stmts) = stmt : cmmMiniInlineStmts uses stmts -lookForInline u expr (stmt : rest) +lookForInline u expr stmts = lookForInline' u expr regset stmts + where regset = foldRegsUsed extendRegSet emptyRegSet expr + +lookForInline' u expr regset (stmt : rest) | Just 1 <- lookupUFM (countUses stmt) u, ok_to_inline = Just (inlineStmt u expr stmt : rest) | ok_to_skip - = case lookForInline u expr rest of + = case lookForInline' u expr regset rest of Nothing -> Nothing Just stmts -> Just (stmt:stmts) @@ -137,13 +140,18 @@ lookForInline u expr (stmt : rest) CmmCall{} -> hasNoGlobalRegs expr _ -> True - -- We can skip over assignments to other tempoararies, because we - -- know that expressions aren't side-effecting and temporaries are - -- single-assignment. + -- Expressions aren't side-effecting. Temporaries may or may not + -- be single-assignment depending on the source (the old code + -- generator creates single-assignment code, but hand-written Cmm + -- and Cmm from the new code generator is not single-assignment.) + -- So we do an extra check to make sure that the register being + -- changed is not one we were relying on. I don't know how much of a + -- performance hit this is (we have to create a regset for every + -- instruction.) -- EZY ok_to_skip = case stmt of CmmNop -> True CmmComment{} -> True - CmmAssign (CmmLocal (LocalReg u' _)) rhs | u' /= u -> True + CmmAssign (CmmLocal r@(LocalReg u' _)) rhs | u' /= u && not (r `elemRegSet` regset) -> True CmmAssign g@(CmmGlobal _) rhs -> not (g `regUsedIn` expr) _other -> False |