@@ -71,6 +71,38 @@ already computed
71
71
72
72
namespace DXIL
73
73
{
74
+ void OutputGraph (const char *const name, const ControlFlow *graph)
75
+ {
76
+ ControlFlow::BlockArray divergentBlocks = graph->GetDivergentBlocks ();
77
+ rdcarray<ConvergentBlockData> convergentBlocks = graph->GetConvergentBlocks ();
78
+
79
+ rdcstr fname = StringFormat::Fmt (" %s.txt" , name);
80
+ FILE *f = FileIO::fopen (fname.c_str (), FileIO::WriteText);
81
+ rdcstr line = StringFormat::Fmt (" digraph %s {\n " , name);
82
+ fprintf (f, line.c_str ());
83
+ for (uint32_t from : graph->m_Blocks )
84
+ {
85
+ line = StringFormat::Fmt (" %u" , from);
86
+ if (divergentBlocks.contains (from))
87
+ line += StringFormat::Fmt (" [shape=diamond color=red]" );
88
+ line += " ;\n " ;
89
+
90
+ for (uint32_t to : graph->m_BlockOutLinks [from])
91
+ line += StringFormat::Fmt (" %u -> %u [weight=1];\n " , from, to);
92
+
93
+ fprintf (f, line.c_str ());
94
+ }
95
+ for (ConvergentBlockData data : convergentBlocks)
96
+ {
97
+ line = StringFormat::Fmt (" %u -> %u [weight=0 style=dashed color=blue constraint=false];\n " ,
98
+ data.first , data.second , data.first , data.second );
99
+
100
+ fprintf (f, line.c_str ());
101
+ }
102
+ fprintf (f, " }\n " );
103
+ FileIO::fclose (f);
104
+ }
105
+
74
106
bool ControlFlow::IsBlockConnected (const size_t pathsType, uint32_t from, uint32_t to) const
75
107
{
76
108
const rdcarray<BlockPath> &paths = m_PathSets[pathsType];
@@ -627,6 +659,7 @@ void ControlFlow::Construct(const rdcarray<rdcpair<uint32_t, uint32_t>> &links)
627
659
}
628
660
RDCLOG (" Convergent Blocks: %s" , output.c_str ());
629
661
}
662
+ // OutputGraph("dxil_cfg", this);
630
663
631
664
// Clear temporary data
632
665
m_TracedBlocks.clear ();
@@ -1813,6 +1846,8 @@ TEST_CASE("DXIL Control Flow", "[dxil][controlflow]")
1813
1846
REQUIRE (expectedCountDivergentBlocks == convergentBlocks.count ());
1814
1847
CheckDivergentBlocks (expectedConvergentBlocks, divergentBlocks);
1815
1848
CheckConvergentBlocks (expectedConvergentBlocks, convergentBlocks);
1849
+
1850
+ // OutputGraph("complex_case", &controlFlow);
1816
1851
}
1817
1852
};
1818
1853
};
0 commit comments