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