1 //===-- jitcs_vregref.h - Class to represent a single basic block --*- C++ -*-===//
3 // A basicblock contains nodes, and must end in a terminal instruction node.
4 // Nodes can be instructions, constants. Each node may produce more than one
7 //===----------------------------------------------------------------------===//
10 #define _JITCS_VREG_H_
12 #include "jitcs_ids.h"
13 //#include "jitcs_fragment.h"
19 struct VRegPlacement
{
22 bool isPlaced() const { return modeNOffset
!= 0; }
23 bool isMem() const { return isPlaced(); }
26 modeNOffset
= (0 << MMODE_Bits
) | MMODE_None
;
28 void place(uint fpmode
, int ofs
) {
29 assert(fpmode
>= MMODE_SPRel
&& fpmode
< MMODE_SPRel
+ MMODE_FPCount
);
30 assert((ofs
<< MMODE_Bits
) >> MMODE_Bits
== ofs
);
31 modeNOffset
= (ofs
<< 4) | (fpmode
);
33 int getFP() { assert(isPlaced()); return (modeNOffset
& 15) - MMODE_SPRel
; }
34 int getOffset() { assert(isPlaced()); return modeNOffset
>> 4; }
35 static VRegPlacement
MakeEmpty() { VRegPlacement p
; p
.unplace(); return p
; }
36 static VRegPlacement
MakeMem(uint fp
, int ofs
) { VRegPlacement p
; p
.place(fp
, ofs
); return p
; }
38 void dump(IDumper
& o
) const;
48 VRegPlacement spillplacement
;
50 u32 spillCount
, reloadCount
;
51 // XFragmentList fragments;
53 void dump(IDumper
&) const;
55 void setupDynamic(size_t vregno
, RegClassId rc
, u32 mask
= 0, u8 sz
= 0);
56 static VReg
CreateStatic(RegId hwr
, ResId
, RegClassId
, ResClassId
, u8 sz
);
58 bool getsSpilled() const { return spillCount
> 0; }
59 bool getsReloaded() const { return reloadCount
> 0; }
65 void operator =(VReg
const* v
) { _ptr
= v
; }
67 void clear() { _ptr
= jitcs_nullptr
; }
68 VReg
const* toVReg() const { return _ptr
; }
69 operator VReg
const*() const { return toVReg(); }
71 VReg
* toMutableVReg() {
72 VReg
const* v
= toVReg();
73 assert(v
->isMutable());
74 return const_cast<VReg
*>(v
);
77 RegId
getId() const { return toVReg()->id
; }
78 ResId
getRes() const { return toVReg()->res
; }
79 RegClassId
getRegClass() const { return toVReg()->regclass
; }
80 ResClassId
getResClass() const { return toVReg()->resclass
; }
82 bool isHWReg() const { return getId() < R_HardwareLimit
; }
83 bool isEmpty() const { return _ptr
== jitcs_nullptr
; }
84 bool isValid() const { return !isEmpty(); }
86 static VRegRef
Make(VReg
const* r
) { VRegRef v
; v
._ptr
; return v
; }
88 inline bool operator ==(VRegRef r1
, VRegRef r2
) { return r1
._ptr
== r2
._ptr
; }
89 inline bool operator !=(VRegRef r1
, VRegRef r2
) { return r1
._ptr
!= r2
._ptr
; }
91 } // End EVM namespace