[llvm] Introduce CounterExpressionBuilder::replace(C, Map) (PR #112698)

NAKAMURA Takumi via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 18 02:11:01 PDT 2024


================
@@ -135,6 +135,38 @@ Counter CounterExpressionBuilder::subtract(Counter LHS, Counter RHS,
   return Simplify ? simplify(Cnt) : Cnt;
 }
 
+Counter CounterExpressionBuilder::replace(Counter C, const ReplaceMap &Map) {
+  auto I = Map.find(C);
+
+  // Replace C with the Map even if C is Expression.
+  if (I != Map.end())
+    return I->second;
+
+  // Traverse only Expression.
+  if (!C.isExpression())
+    return C;
+
+  auto CE = Expressions[C.getExpressionID()];
+  auto NewLHS = replace(CE.LHS, Map);
----------------
chapuni wrote:

I suppose at most the number of terms, unless the expression is made buggy with loops. (Then, other CounterExpression stuff would hang or crash, I guess) Would we really check if the expr would not be buggy?

If we should introduce such a check, it may be not depth limit but the set of `Seen`.

https://github.com/llvm/llvm-project/pull/112698


More information about the llvm-commits mailing list