Changed current relation from BasicBlock to BasicBlockImpl, and Function
[jitcs.git] / src / jitcs_int_cfg_analysis.h
blobf4d92cce2ed3aecc5b91b791ee4f5c41e672fe31
1 //===-- evm/bblock.h - a single basic block --*- C++ -*-===//
2 //
3 // A basic block contains a list of instructions.
4 //
5 //===----------------------------------------------------------------------===//
7 #ifndef _JITCS_INT_CFGANALYSIS_H_
8 #define _JITCS_INT_CFGANALYSIS_H_
10 #include "jitcs_base.h"
11 #include "jitcs_int_adt_bitmap.h"
12 #include "jitcs_adt_range.h"
13 #include "jitcs_adt_slice.h"
14 #include "jitcs_int_bblock_impl.h"
16 namespace jitcs {
17 class FunctionImpl;
18 class IDumper;
20 class CFGAnalysis {
21 public:
22 enum AMode {
23 SIMPLE,
24 DEPTH_ANALYSIS
26 public:
27 CFGAnalysis();
28 CFGAnalysis(const CFGAnalysis &) = delete;
29 CFGAnalysis& operator=(const CFGAnalysis &) = delete;
31 public:
32 void init(FunctionImpl& f, AMode);
33 void clear();
34 void dump(IDumper&) const;
36 bool checkIntegrity() const;
38 public:
40 size_t getMaxBBlockDepth() const { return _maxDepth; }
41 size_t getBlockCount() const { return _order.size(); }
42 Ref<BasicBlockImpl> getOrderedBlock(size_t pos) const { return _order[pos]; }
43 Ref<const BasicBlockImpl> cgetOrderedBlock(size_t pos) const { return _order[pos]; }
44 size_t getDepth(Ref<BasicBlockImpl> bb) const { return _bblocks[bb->id()].depth; }
45 // size_t getOrder(BBlock* bb) const { return _bblocks[bb->id().id].order; }
47 private:
48 struct BBlockInfo {
49 BasicBlockImpl* bb;
50 size_t depth;
52 private:
53 size_t _calcDepth(size_t depth, size_t headbb,
54 BitSlice handled, BitSlice candidates,
55 Slice<size_t> worklist, BitSlice inworklist);
57 private:
58 Slice<BasicBlockImpl*> _order;
59 Slice<BBlockInfo> _bblocks;
60 size_t _maxDepth;
63 } // end of namespace jitcs
65 #endif
66 // _JITCS_INT_CFGANALYSIS_H_