1 //===-- evm/bblock.h - a single basic block --*- C++ -*-===//
3 // A basic block contains a list of instructions.
5 //===----------------------------------------------------------------------===//
7 #ifndef _JITCS_INT_BBLOCK_IMPL_H_
8 #define _JITCS_INT_BBLOCK_IMPL_H_
10 #include "jitcs_adt_range.h"
11 #include "jitcs_int_adt_tmpvector.h"
12 #include "jitcs_base.h"
13 #include "jitcs_instruction.h"
20 class BasicBlockImpl
{
22 // TODO: use structures that use TempAllocator
23 typedef TmpVector
<BasicBlockImpl
*, 2> BasicBlockList
;
24 typedef TmpVector
<Instruction
*, 8> InstructionList
;
26 typedef BasicBlockList::iterator bb_iterator
;
27 typedef BasicBlockList::const_iterator const_bb_iterator
;
28 typedef InstructionList::iterator ins_iterator
;
29 typedef InstructionList::const_iterator const_ins_iterator
;
30 typedef Range
<bb_iterator
> bb_range
;
31 typedef Range
<ins_iterator
> ins_range
;
32 typedef ConstRange
<const_bb_iterator
> const_bb_range
;
33 typedef ConstRange
<const_ins_iterator
> const_ins_range
;
36 BasicBlockImpl(FunctionImpl
& f
, BBId id
);
37 ~BasicBlockImpl() = default;
38 BasicBlockImpl(const BasicBlockImpl
&) = delete;
39 void operator=(const BasicBlockImpl
&) = delete;
42 BBId
id() const { return _bbId
; }
43 RefOrNull
<BasicBlockImpl
> getFallThruFrom() const { return _bbFallThruFrom
; }
44 RefOrNull
<BasicBlockImpl
> getFallThruTo() const { return _bbFallThruTo
; }
46 size_t instr_size() const { return _listOfIns
.size(); }
48 bb_iterator
pred_begin() { return _predecessors
.begin(); }
49 bb_iterator
pred_end() { return _predecessors
.end(); }
50 const_bb_iterator
pred_begin() const { return pred_cbegin(); }
51 const_bb_iterator
pred_end() const { return pred_cend(); }
52 const_bb_iterator
pred_cbegin() const { return _predecessors
.begin(); }
53 const_bb_iterator
pred_cend() const { return _predecessors
.end(); }
55 bb_iterator
succ_begin() { return _successors
.begin(); }
56 bb_iterator
succ_end() { return _successors
.end(); }
57 const_bb_iterator
succ_begin() const { return succ_cbegin(); }
58 const_bb_iterator
succ_end() const { return succ_cend(); }
59 const_bb_iterator
succ_cbegin() const { return _successors
.begin(); }
60 const_bb_iterator
succ_cend() const { return _successors
.end(); }
62 ins_iterator
instr_begin() { return _listOfIns
.begin(); }
63 ins_iterator
instr_end() { return _listOfIns
.end(); }
64 const_ins_iterator
instr_begin() const { return instr_cbegin(); }
65 const_ins_iterator
instr_end() const { return instr_cend(); }
66 const_ins_iterator
instr_cbegin() const { return _listOfIns
.begin(); }
67 const_ins_iterator
instr_cend() const { return _listOfIns
.end(); }
69 bb_range
pred_range() { return bb_range(pred_begin(), pred_end()); }
70 const_bb_range
pred_range() const { return pred_crange(); }
71 const_bb_range
pred_crange() const { return const_bb_range(pred_cbegin(), pred_cend()); }
73 bb_range
succ_range() { return bb_range(succ_begin(), succ_end()); }
74 const_bb_range
succ_range() const { return succ_crange(); }
75 const_bb_range
succ_crange() const { return const_bb_range(succ_cbegin(), succ_cend()); }
77 ins_range
instr_range() { return ins_range(instr_begin(), instr_end()); }
78 const_ins_range
instr_range() const { return instr_crange(); }
79 const_ins_range
instr_crange() const { return const_ins_range(instr_cbegin(), instr_cend()); }
81 // std::vector<BBlock*> const* getPredecessors() const { return &_predecessors; }
82 // std::vector<BBlock*> const* getSuccessors() const { return &_successors; }
83 // std::vector<InsRef> const* getInstructions() const { return &_listOfIns; }
86 // methods for use when constructing basic blocks
87 // append: add a block of instructions to the basic block. the stream is broken down
88 // into individual instructions here. also, it must be ascertained, that the data pointed to by
89 // p is alive until the compilation of the function is complete. if in doubt, use append_copy
91 // append_copy: same as append, but copies data to the storage of a TempAllocator first.
92 size_t append(iptr
* p
, size_t N
);
93 size_t append_copy(iptr
const *p
, size_t N
);
95 // methods for fixing up the control flow graph
96 static void BuildEdge(BasicBlockImpl
* fromBB
, BasicBlockImpl
* toBB
, bool isFallthru
);
98 void dump(MachineDumper
&) const;
102 TempAllocator
& _alloc
;
103 InstructionList _listOfIns
;
104 BasicBlockList _successors
, _predecessors
;
106 RefOrNull
<BasicBlockImpl
> _bbFallThruFrom
, _bbFallThruTo
;
109 //inline bool evm::NextData::isRegDead(BBlock* bb, ResId res) const {
110 // return isRegDead() || (isRegDeadOrLiveOut() && !bb->getLiveOut().test(res.id));
114 } // End jitcs namespace
117 // _JITCS_INT_BBLOCK_IMPL_H_