OSDN Git Service

Avoid heap allocation for binary search work stack.
authorAndrew Scull <ascull@google.com>
Thu, 23 Jul 2015 18:41:18 +0000 (11:41 -0700)
committerAndrew Scull <ascull@google.com>
Thu, 23 Jul 2015 18:41:18 +0000 (11:41 -0700)
During switch lowering a binary search tree is created. The height of this
tree is usually small so no need for heap allocation.

BUG=
R=jvoung@chromium.org, jvoung, stichnot

Review URL: https://codereview.chromium.org/1240323005.

src/IceTargetLoweringX86BaseImpl.h

index fc0a8e2..77048b0 100644 (file)
@@ -4698,8 +4698,8 @@ void TargetX86Base<Machine>::lowerSwitch(const InstSwitch *Inst) {
     SizeT Size;
     typename Traits::Insts::Label *Label;
   };
-  std::stack<SearchSpan, std::deque<SearchSpan, CfgLocalAllocator<SearchSpan>>>
-      SearchSpanStack;
+  // The stack will only grow to the height of the tree so 12 should be plenty
+  std::stack<SearchSpan, llvm::SmallVector<SearchSpan, 12>> SearchSpanStack;
   SearchSpanStack.emplace(0, CaseClusters.size(), nullptr);
   bool DoneCmp = false;