1 //===-- evm/bblock.h - a single basic block --*- C++ -*-===//
3 // A basic block contains a list of instructions.
5 //===----------------------------------------------------------------------===//
7 #ifndef _JITCS_INT_FUNCTION_IMPL_H_
8 #define _JITCS_INT_FUNCTION_IMPL_H_
10 #include "jitcs_adt_range.h"
11 #include "jitcs_adt_ref.h"
12 #include "jitcs_adt_refcounter.h"
13 #include "jitcs_base.h"
14 #include "jitcs_ids.h"
15 #include "jitcs_int_adt_tmpvector.h"
16 #include "jitcs_memmgr.h"
20 class CallingConvention
;
24 struct VirtualRegister
;
25 //struct XFragmentList;
26 //class BBlockClusterMap;
30 typedef TmpVector
<BasicBlockImpl
*, 16> BasicBlockList
;
31 typedef TmpVector
<VirtualRegister
*, 16> VirtualRegisterList
;
33 typedef BasicBlockList::iterator bb_iterator
;
34 typedef BasicBlockList::const_iterator const_bb_iterator
;
35 typedef Range
<bb_iterator
> bb_range
;
36 typedef ConstRange
<const_bb_iterator
> const_bb_range
;
38 // typedef std::vector<VReg*>::iterator vreg_iterator;
39 // typedef std::vector<VReg*>::const_iterator const_vreg_iterator;
40 // typedef Range<vreg_iterator> vreg_range;
41 // typedef ConstRange<const_vreg_iterator> const_vreg_range;
44 FunctionImpl(RefCounter
<TempAllocator
>& ins
, const std::shared_ptr
<const CallingConvention
>& cc
);
47 size_t bbs_size() const { return _bblocks
.size(); }
48 bb_iterator
bbs_begin() { return _bblocks
.begin(); }
49 bb_iterator
bbs_end() { return _bblocks
.end(); }
50 const_bb_iterator
bbs_begin() const { return bbs_cbegin(); }
51 const_bb_iterator
bbs_end() const { return bbs_cend(); }
52 const_bb_iterator
bbs_cbegin() const { return _bblocks
.begin(); }
53 const_bb_iterator
bbs_cend() const { return _bblocks
.end(); }
55 bb_range
bbs_range() { return bb_range(bbs_begin(), bbs_end()); }
56 const_bb_range
bbs_range() const { return bbs_crange(); }
57 const_bb_range
bbs_crange() const { return const_bb_range(bbs_cbegin(), bbs_cend()); }
59 // size_t vregs_size() const { return _vregs.size(); }
60 // vreg_iterator vregs_begin() { return _vregs.begin(); }
61 // vreg_iterator vregs_end() { return _vregs.end(); }
62 // const_vreg_iterator vregs_begin() const { return vregs_cbegin(); }
63 // const_vreg_iterator vregs_end() const { return vregs_cend(); }
64 // const_vreg_iterator vregs_cbegin() const { return _vregs.begin(); }
65 // const_vreg_iterator vregs_cend() const { return _vregs.end(); }
67 // vreg_range vregs_range() { return vreg_range(vregs_begin(), vregs_end()); }
68 // const_vreg_range vregs_range() const { return vregs_crange(); }
69 // const_vreg_range vregs_crange() const { return const_vreg_range(vregs_cbegin(), vregs_cend()); }
75 void dump(MachineDumper
&) const;
76 std::shared_ptr
<const CallingConvention
> getCallingConvention() const { return _cc
; }
78 Ref
<VirtualRegister
> getArgumentRegister(uint n
, RegClassId
);
79 Ref
<VirtualRegister
> getResultRegister(uint n
, RegClassId
);
80 Ref
<VirtualRegister
> createRegister(RegClassId
, int logSz
= 0);
82 //VMMemory::CodeDataArea generate(VMMemory&, bool dump);
84 //void allocateFragmentClusters(BBlockClusterMap const&);
85 //void allocateVRegMemRefs();
86 //void runPassPreDefUse();
87 //void runPassDefUseAnalysis();
88 //void runPassRegAlloc1P();
89 //VMMemory::CodeDataArea runPassCodeGen(VMMemory&);
91 //bool needsPossiblyFramePointer() const;
92 //bool needsDefinitelyFramePointer() const;
95 TempAllocator
& getAllocator() const { return *_allocator
._ptr
; }
98 Ref
<BasicBlockImpl
> getStartBlock();
99 Ref
<BasicBlockImpl
> createBasicBlock();
101 //VRegRef getFrameReg(uint fr) const { assert(fr < _frameInfoCnt); return _frameInfo[fr].reg; }
102 //int getFrameOffset(uint fr) const { assert(fr < _frameInfoCnt); return _frameInfo[fr].ofs; }
103 //void setFrame(uint fr, VRegRef vr, int o) {
104 // assert(fr < _frameInfoCnt);
105 // _frameInfo[fr].reg = vr;
106 // _frameInfo[fr].ofs = o;
109 // u8* getEstimatedOrFinalAddress(BBId);
110 //bool isValidVReg(RegId id) const { return id.id >= R_HardwareLimit && id.id - R_HardwareLimit < _vregs.size(); }
111 // RegId allocVReg(uint regclass, uint valuesize);
112 // RegId addVReg(u32 ofs);
114 //InsPtr createIns(BBlock* bb, u32 sz);
115 //InsRef createFreeIns(u32 sz);
116 //core::CopyInsPtr createCopyIns(BBlock* bb, size_t cnt);
117 //InsRef createFreeCopyIns(size_t cnt);
118 // core::KillInsPtr createKillIns(BBlock* bb, u32 cnt);
120 //void fixCtrlFlow();
123 // u8* ofs2ptr(u32 ofs) const { assert(ofs > 0); return _allocator.getPtr(ofs); }
124 // VReg* getVReg(RegId id) { assert(isValidVReg(id)); return _vregs[id.id-R_HardwareLimit]; }
125 // VReg const * getVReg(RegId id) const { assert(isValidVReg(id)); return _vregs[id.id-R_HardwareLimit]; }
126 //VReg * createVReg(RegClassId regclass, int sz = 0);
127 //VReg const* arg(uint n) const { assert(n >= 0 && n < _cc.getParamCount()); return _vregs[_cc.getResultCount()+n]; }
128 //VReg const* result(uint n) const { assert(n >= 0 && n < _cc.getResultCount()); return _vregs[n]; }
130 //VReg *getVRegRW(ResId r) { return _vregs[r.id - evm::platform::GetResCount()]; }
131 //VReg *getVRegRW(RegId r) { return _vregs[r.id - R_HardwareLimit]; }
132 //CallConv const& getCallConv() const { return _cc; }
134 //VReg const * allocCompatibleTemporaryVReg(VRegRef id);
135 //void deallocTemporaryVReg(VRegRef id);
136 //u32 getRegMask(VRegRef r) const { return r.toVReg()->mask; }
139 //u8* allocBlock(size_t sz) { return _allocator.alloc(sz); }
140 // u32 alloc(size_t sz) { return _allocator.alloc(sz); }
141 // void align(size_t sz) { return _allocator.align(sz); }
144 //void _setCode0(u8* x) { _zero = x; }
147 //void _tryToAllocateXFragmentCluster(XFragmentList const&);
148 void _prepareArgumentAndResultRegisterSpace();
151 RefCounter
<TempAllocator
> _allocator
;
152 std::shared_ptr
<const CallingConvention
> _cc
;
153 RefCounter
<IMachineInfo
> _mi
;
154 BasicBlockList _bblocks
;
155 VirtualRegisterList _parregs
, _vregs
;
156 //std::vector< std::vector<VReg const*> > _tempvregs;
161 //FrameInfo _frameInfo[MMODE_FPCount];
162 //uint _frameInfoCnt;
166 } // End jitcs namespace
169 // _JITCS_INT_FUNCTION_IMPL_H_