2 module SPARC.CodeGen.Base (
29 --------------------------------------------------------------------------------
30 -- | 'InstrBlock's are the insn sequences generated by the insn selectors.
31 -- They are really trees of insns to facilitate fast appending, where a
32 -- left-to-right traversal yields the insns in the correct order.
38 -- | Condition codes passed up the tree.
41 = CondCode Bool Cond InstrBlock
44 -- | a.k.a "Register64"
45 -- Reg is the lower 32-bit temporary which contains the result.
46 -- Use getHiVRegFromLo to find the other VRegUnique.
48 -- Rules of this simplified insn selection game are therefore that
49 -- the returned Reg may be modified
57 -- | Holds code that references a memory address.
60 -- the AddrMode we can use in the instruction
61 -- that does the real load\/store.
64 -- other setup code we have to run first before we can use the
70 --------------------------------------------------------------------------------
71 -- | Code to produce a result into a register.
72 -- If the result must go in a specific register, it comes out as Fixed.
73 -- Otherwise, the parent can decide which register to put it in.
76 = Fixed Size Reg InstrBlock
77 | Any Size (Reg -> InstrBlock)
80 -- | Change the size field in a Register.
82 :: Register -> Size -> Register
84 setSizeOfRegister reg size
86 Fixed _ reg code -> Fixed size reg code
87 Any _ codefn -> Any size codefn
90 --------------------------------------------------------------------------------
91 -- | Grab the Reg for a CmmReg
92 getRegisterReg :: CmmReg -> Reg
94 getRegisterReg (CmmLocal (LocalReg u pk))
95 = RegVirtual $ mkVirtualReg u (cmmTypeSize pk)
97 getRegisterReg (CmmGlobal mid)
98 = case get_GlobalReg_reg_or_addr mid of
101 _ -> pprPanic "SPARC.CodeGen.Base.getRegisterReg: global is in memory"
102 (ppr $ CmmGlobal mid)
105 -- Expand CmmRegOff. ToDo: should we do it this way around, or convert
106 -- CmmExprs into CmmRegOff?
107 mangleIndexTree :: CmmExpr -> CmmExpr
109 mangleIndexTree (CmmRegOff reg off)
110 = CmmMachOp (MO_Add width) [CmmReg reg, CmmLit (CmmInt (fromIntegral off) width)]
111 where width = typeWidth (cmmRegType reg)
114 = panic "SPARC.CodeGen.Base.mangleIndexTree: no match"