[llvm] [ObjectSizeOffsetVisitor] Bail after visiting 100 instructions (PR #67479)

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 26 14:21:25 PDT 2023


================
@@ -729,13 +742,16 @@ SizeOffsetType ObjectSizeOffsetVisitor::compute(Value *V) {
           SOT.second.getBitWidth() > 1 ? SOT.second + Offset : SOT.second};
 }
 
-SizeOffsetType ObjectSizeOffsetVisitor::computeImpl(Value *V) {
+SizeOffsetType ObjectSizeOffsetVisitor::computeValue(Value *V) {
   if (Instruction *I = dyn_cast<Instruction>(V)) {
     // If we have already seen this instruction, bail out. Cycles can happen in
     // unreachable code after constant propagation.
     auto P = SeenInsts.try_emplace(I, unknown());
     if (!P.second)
       return P.first->second;
+    ++InstructionsVisited;
+    if (InstructionsVisited > ObjectSizeOffsetVisitorMaxVisitInstructions)
----------------
aeubanks wrote:

`SeenInsts` is a cache that can carry over between calls to `ObjectSizeOffsetVisitor::compute()`, but I think we want `ObjectSizeOffsetVisitorMaxVisitInstructions` to apply per call to `ObjectSizeOffsetVisitor::compute()`. This does lead us to a weird situation where successive calls to `compute()` will return different answers since we may explore more from cached results, but I think that's better than if somebody reuses a `ObjectSizeOffsetVisitor` and later calls to it all return `unknown()` since previous calls filled up the cache to `ObjectSizeOffsetVisitorMaxVisitInstructions` size

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


More information about the llvm-commits mailing list