3 #include "jitcs_instructionstream.h"
4 #include "jitcs_dumper.h"
5 #include "jitcs_int_cfg_analysis.h"
11 static void test(UnitTest
& t
) {
12 typedef void (__cdecl
*FT0_c
)();
13 RefCounter
<IMachineInfo
> mi
= host::GetMachineInfo();
14 RefCounter
<TempAllocator
> alloc(new TempAllocator
);
16 std::unique_ptr
<Function
> fn
= mi
->createFnc
<FT0_c
>(alloc
);
17 InstructionStreamBuffer
<256> ibuf
;
19 Ref
<BasicBlock
> bb1
= fn
->getStartBlock();
20 Ref
<BasicBlock
> bb2
= fn
->createBasicBlock();
21 Ref
<BasicBlock
> bb3
= fn
->createBasicBlock();
22 Ref
<BasicBlock
> bb4
= fn
->createBasicBlock();
23 Ref
<BasicBlock
> bb5
= fn
->createBasicBlock();
24 Ref
<BasicBlock
> bb6
= fn
->createBasicBlock();
27 host::JGE_BB_FT(ibuf
, bb2
, bb3
);
35 host::JGE_BB_FT(ibuf
, bb4
, bb5
);
39 host::JMP_BB(ibuf
, bb6
);
43 host::JMP_BB(ibuf
, bb6
);
47 host::JGE_BB_FT(ibuf
, bb3
, bb2
);
51 a
.init(reinterpret_cast<FunctionImpl
&>(*fn
), CFGAnalysis::DEPTH_ANALYSIS
);
52 t
.check("V1/blocks", a
.getBlockCount() == 6);
53 t
.check("V1/order integrity", a
.checkIntegrity());
54 t
.check("V1/total depth", a
.getMaxBBlockDepth() == 1);
55 t
.check("V1/individual depth 1", a
.getDepth(reinterpret_cast<BasicBlockImpl
*>(bb1
._ptr
)) == 0);
56 t
.check("V1/individual depth 2", a
.getDepth(reinterpret_cast<BasicBlockImpl
*>(bb2
._ptr
)) == 0);
57 t
.check("V1/individual depth 3", a
.getDepth(reinterpret_cast<BasicBlockImpl
*>(bb3
._ptr
)) == 1);
58 t
.check("V1/individual depth 4", a
.getDepth(reinterpret_cast<BasicBlockImpl
*>(bb4
._ptr
)) == 1);
59 t
.check("V1/individual depth 5", a
.getDepth(reinterpret_cast<BasicBlockImpl
*>(bb5
._ptr
)) == 1);
60 t
.check("V1/individual depth 6", a
.getDepth(reinterpret_cast<BasicBlockImpl
*>(bb6
._ptr
)) == 1);
63 std::unique_ptr
<Function
> fn
= mi
->createFnc
<FT0_c
>(alloc
);
64 InstructionStreamBuffer
<256> ibuf
;
66 Ref
<BasicBlock
> bb1
= fn
->getStartBlock();
67 Ref
<BasicBlock
> bb2
= fn
->createBasicBlock();
68 Ref
<BasicBlock
> bb3
= fn
->createBasicBlock();
69 Ref
<BasicBlock
> bb4
= fn
->createBasicBlock();
70 Ref
<BasicBlock
> bb5
= fn
->createBasicBlock();
71 Ref
<BasicBlock
> bb6
= fn
->createBasicBlock();
74 host::JGE_BB_FT(ibuf
, bb2
, bb3
);
78 host::JMP_BB(ibuf
, bb3
);
82 host::JGE_BB_FT(ibuf
, bb4
, bb6
);
86 host::JMP_BB(ibuf
, bb5
);
90 host::JL_BB_FT(ibuf
, bb2
, bb6
);
98 a
.init(reinterpret_cast<FunctionImpl
&>(*fn
), CFGAnalysis::DEPTH_ANALYSIS
);
99 t
.check("V2/blocks", a
.getBlockCount() == 6);
100 t
.check("V2/order integrity", a
.checkIntegrity());
101 t
.check("V2/total depth", a
.getMaxBBlockDepth() == 1);
102 t
.check("V2/individual depth 1", a
.getDepth(reinterpret_cast<BasicBlockImpl
*>(bb1
._ptr
)) == 0);
103 t
.check("V2/individual depth 2", a
.getDepth(reinterpret_cast<BasicBlockImpl
*>(bb2
._ptr
)) == 1);
104 t
.check("V2/individual depth 3", a
.getDepth(reinterpret_cast<BasicBlockImpl
*>(bb3
._ptr
)) == 1);
105 t
.check("V2/individual depth 4", a
.getDepth(reinterpret_cast<BasicBlockImpl
*>(bb4
._ptr
)) == 1);
106 t
.check("V2/individual depth 5", a
.getDepth(reinterpret_cast<BasicBlockImpl
*>(bb5
._ptr
)) == 1);
107 t
.check("V2/individual depth 6", a
.getDepth(reinterpret_cast<BasicBlockImpl
*>(bb6
._ptr
)) == 0);
111 static UnitTestRun
_("CFG Analysis", test
);