[llvm-commits] SwitchLowering refactoring patch for review

Chris Lattner clattner at apple.com
Sat Mar 24 17:16:40 PDT 2007


On Mar 20, 2007, at 9:29 AM, Anton Korobeynikov wrote:
> This is the first patch targeting switch lowering refactoring as
> indicated in PR926.

oooh!

> Currently it implements "worklist" strategy, where we're deciding  
> either
> emit JT or split the case range or each step (not only in the early
> beginning). Also, I've included some heuristic to calculate pivot:
> maximise sum of densities of RHS & LHS. This lead to unbalanced tree,
> but really increase chances of JT emission in the future.
>
> E.g. we split switch (0-5, 120-126, 1024) into 2 JT's and 1 specific
> comparison + some "glue" code to discriminate cases.
>
> Tested with:
>
> 1. llvm-gcc bootstrap
> 2. Building mozilla & qt with bootstrapped compiler.

+  struct JumpTableHeader
+  {
+    JumpTableHeader(uint64_t F, uint64_t L, Value* SV,  
MachineBasicBlock* H,
+                    bool E = false):

Nitpick: the { should go on the same line as the struct.


+void SelectionDAGLowering::visitJumpTableHeader 
(SelectionDAGISel::JumpTable &JT,
+                                          
SelectionDAGISel::JumpTableHeader &JTH) {

Please add a comment block before this method, describing what it does.

+      unsigned LSize = 1;
+      unsigned RSize = Size-1;
+      for (CaseItr I = CR.Range.first, J=I+1, E = CR.Range.second;
+           J!=E; ++I, ++J, ++LSize, --RSize) {
+        uint64_t LEnd = cast<ConstantInt>(I->first)->getSExtValue();
+        uint64_t RBegin = cast<ConstantInt>(J->first)->getSExtValue();
+        double LDensity = (double)LSize / (double)((LEnd - First) +  
1ULL);
+        double RDensity = (double)RSize / (double)((Last - RBegin) +  
1ULL);
+        if (Density < (LDensity + RDensity)) {
+          Pivot = J;
+          Density = LDensity + RDensity;
+        }
+      }

Please add some comments explaining how this works.


I have to say, you did an *excellent* job.  Nice work,

-Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20070324/bd760465/attachment.html>


More information about the llvm-commits mailing list