2 module SPARC.CodeGen.Base (
31 --------------------------------------------------------------------------------
32 -- | 'InstrBlock's are the insn sequences generated by the insn selectors.
33 -- They are really trees of insns to facilitate fast appending, where a
34 -- left-to-right traversal yields the insns in the correct order.
40 -- | Condition codes passed up the tree.
43 = CondCode Bool Cond InstrBlock
46 -- | a.k.a "Register64"
47 -- Reg is the lower 32-bit temporary which contains the result.
48 -- Use getHiVRegFromLo to find the other VRegUnique.
50 -- Rules of this simplified insn selection game are therefore that
51 -- the returned Reg may be modified
59 -- | Holds code that references a memory address.
62 -- the AddrMode we can use in the instruction
63 -- that does the real load\/store.
66 -- other setup code we have to run first before we can use the
72 --------------------------------------------------------------------------------
73 -- | Code to produce a result into a register.
74 -- If the result must go in a specific register, it comes out as Fixed.
75 -- Otherwise, the parent can decide which register to put it in.
78 = Fixed Size Reg InstrBlock
79 | Any Size (Reg -> InstrBlock)
82 -- | Change the size field in a Register.
84 :: Register -> Size -> Register
86 setSizeOfRegister reg size
88 Fixed _ reg code -> Fixed size reg code
89 Any _ codefn -> Any size codefn
92 --------------------------------------------------------------------------------
93 -- | Grab the Reg for a CmmReg
94 getRegisterReg :: CmmReg -> Reg
96 getRegisterReg (CmmLocal (LocalReg u pk))
97 = RegVirtual $ mkVirtualReg u (cmmTypeSize pk)
99 getRegisterReg (CmmGlobal mid)
100 = case globalRegMaybe mid of
101 Just reg -> RegReal reg
103 "SPARC.CodeGen.Base.getRegisterReg: global is in memory"
104 (ppr $ CmmGlobal mid)
107 -- Expand CmmRegOff. ToDo: should we do it this way around, or convert
108 -- CmmExprs into CmmRegOff?
109 mangleIndexTree :: CmmExpr -> CmmExpr
111 mangleIndexTree (CmmRegOff reg off)
112 = CmmMachOp (MO_Add width) [CmmReg reg, CmmLit (CmmInt (fromIntegral off) width)]
113 where width = typeWidth (cmmRegType reg)
116 = panic "SPARC.CodeGen.Base.mangleIndexTree: no match"