@@ -20,7 +20,10 @@ namespace ppc2cpp {
2020#pragma clang diagnostic push
2121#pragma clang diagnostic ignored "-Wpotentially-evaluated-expression"
2222#endif
23- bool ProgramComparator::compareVarNodes (const Function& func1, const Function& func2, const VarNodePtr& var1, const VarNodePtr& var2) {
23+ bool ProgramComparator::compareVarNodes (const Function& func1, const Function& func2, const VarNodePtr& var1, const VarNodePtr& var2, VarNodeComparisonCache& comparisonCache) {
24+ auto cacheResult = comparisonCache.check (var1, var2);
25+ if (cacheResult.has_value ()) return cacheResult.value ();
26+
2427 ppc_cpu_t dialect = ppc_750cl_dialect;
2528
2629 if (!dynamic_pointer_cast<DataFlowNode>(var1) || !dynamic_pointer_cast<DataFlowNode>(var2)) {
@@ -98,12 +101,13 @@ bool ProgramComparator::compareVarNodes(const Function& func1, const Function& f
98101 return false ;
99102 }
100103
101- if (!compareVarNodes (func1, func2, var1->inputs [inputIdx], var2->inputs [inputIdx])) {
104+ if (!compareVarNodes (func1, func2, var1->inputs [inputIdx], var2->inputs [inputIdx], comparisonCache)) {
105+ comparisonCache.set (var1, var2, false );
102106#ifndef NDEBUG
103107 std::cout << " Nonmatching child at index " << inputIdx << std::endl;
104108#endif
105109 return false ;
106- }
110+ } else comparisonCache. set (var1, var2, true );
107111 }
108112 if (var2->inputs .size () > var1->inputs .size ()) {
109113 std::cout << " Expected existence of input " << var1->inputs .size () << " in first variable" << " \n " ;
@@ -138,6 +142,7 @@ bool ProgramComparator::compareFunctionFlows(const Function& func1, const Functi
138142
139143 // TODO: More helpful non-equivalence messages, and in the "order of occurence" as much as possible.
140144 // Maybe come up with a system where the types of differences are aggregates and reported in an organized manner
145+ VarNodeComparisonCache comparisonCache;
141146
142147 // basic block equivalence checking
143148 for (int bblockIdx = 0 ; bblockIdx < cfg1.blocks .size (); bblockIdx++) {
@@ -158,7 +163,8 @@ bool ProgramComparator::compareFunctionFlows(const Function& func1, const Functi
158163 const SinkNodePtr& sink1 = sinks1[sinkIdx];
159164 const SinkNodePtr& sink2 = sinks2[sinkIdx];
160165
161- if (!compareVarNodes (func1, func2, sink1, sink2)) {
166+ if (!compareVarNodes (func1, func2, sink1, sink2, comparisonCache)) {
167+ comparisonCache.set (sink1, sink2, true );
162168 std::cout << " Sinks at index " + std::to_string (sinkIdx) + " of block " + std::to_string (bblockIdx) + " did not match" << " \n " ;
163169 return false ;
164170 }
0 commit comments