[Git][ghc/ghc][wip/supersven/riscv-ncg] Fix register allocation bug

Sven Tennie (@supersven) gitlab at gitlab.haskell.org
Mon Apr 24 19:10:06 UTC 2023



Sven Tennie pushed to branch wip/supersven/riscv-ncg at Glasgow Haskell Compiler / GHC


Commits:
f3d1472c by Sven Tennie at 2023-04-24T19:09:14+00:00
Fix register allocation bug

- - - - -


3 changed files:

- compiler/GHC/CmmToAsm/RISCV64/Ppr.hs
- compiler/GHC/CmmToAsm/RISCV64/Regs.hs
- compiler/GHC/CmmToAsm/Reg/Linear/RISCV64.hs


Changes:

=====================================
compiler/GHC/CmmToAsm/RISCV64/Ppr.hs
=====================================
@@ -139,8 +139,12 @@ pprInstr platform instr = case instr of
   -- see Note [dualLine and dualDoc] in GHC.Utils.Outputable
   NEWBLOCK _ -> error "pprInstr: NEWBLOCK"
   LDATA _ _ -> error "pprInstr: LDATA"
+  PUSH_STACK_FRAME -> error "pprInstr: PUSH_STACK_FRAME"
+  POP_STACK_FRAME -> error "pprInstr: POP_STACK_FRAME"
   J label -> line $ pprJ label
   LI reg immediate -> line $ pprLI reg immediate
+  LA reg label -> error $ "pprInstr: LA " ++ show reg ++ " " ++ show label
+  MV dst src -> error $ "pprInstr: MV " ++ show dst ++ " " ++ show src
   where
     pprLI :: IsLine doc => Reg -> Integer -> doc
     pprLI reg immediate = text "\tli" <+> pprReg reg <> char ',' <+> (text.show) immediate


=====================================
compiler/GHC/CmmToAsm/RISCV64/Regs.hs
=====================================
@@ -8,7 +8,7 @@ import GHC.Platform
 import GHC.Platform.Regs
 
 allMachRegNos   :: [RegNo]
-allMachRegNos   = [1..31] ++ [32..63]
+allMachRegNos   = [0..31] ++ [32..63]
 
 -- argRegs is the set of regs which are read for an n-argument call to C.
 allGpArgRegs :: [Reg]


=====================================
compiler/GHC/CmmToAsm/Reg/Linear/RISCV64.hs
=====================================
@@ -52,7 +52,7 @@ getFreeRegs cls (FreeRegs g f)
   -- TODO: how to handle small floats?
   | RcFloat   <- cls = [] -- For now we only support double and integer registers, floats will need to be promoted.
   | RcDouble  <- cls = go 32 f 31
-  | RcInteger <- cls = go 1 g 30
+  | RcInteger <- cls = go 0 g 30
     where
         go _   _ i | i < 0 = []
         go off x i | testBit x i = RealRegSingle (off + i) : (go off x $! i - 1)



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f3d1472c5e71d6b669fea8854f5ea3d420f3bdae

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f3d1472c5e71d6b669fea8854f5ea3d420f3bdae
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230424/f94442ec/attachment-0001.html>


More information about the ghc-commits mailing list