[PATCH] D60295: [CodeGen] Change the jump table size unit from entry to target

Evandro Menezes via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 6 17:24:01 PDT 2019


evandro marked 4 inline comments as done.
evandro added inline comments.


================
Comment at: llvm/lib/CodeGen/SwitchLoweringUtils.cpp:156
       NumCases = getJumpTableNumCases(TotalCases, i, j);
+      NumTargets = getJumpTableNumTargets(Clusters, i, j);
+      MaxTargets = NumTargets + (HasReachableDefault && Range > NumCases);
----------------
hans wrote:
> Hmm, this is problematic. getJumpTableNumTargets has linear time complexity in the number of clusters, so I think this is essentially adding another factor O(n) to the overall time complexity, which is unfortunate.
> 
> One way to solve this within the original O(n^2) complexity of the current code, would be to build an auxiliary data structure in the outer for-loop, e.g. TotalNumTargets[], where TotalNumTargets[x] is the total number of targets in clusters i..x (i being defined in the outer loop).
> 
> That would be built in O(n) time, and the inner loop would then query TotalNumTargets[j] (in constant time).
> 
> 
If I understood you correctly, pre calculating  the number of targets in clusters i..x, where x will be j, is the same as performing this calculation inside the inner loop.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60295/new/

https://reviews.llvm.org/D60295





More information about the llvm-commits mailing list