Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: src/IceSwitchLowering.cpp

Issue 1257283004: Iasm and obj lowering for advanced switch lowering. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 //===- subzero/src/IceSwitchLowering.cpp - Switch lowering -----------------==// 1 //===- subzero/src/IceSwitchLowering.cpp - Switch lowering -----------------==//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 /// 9 ///
10 /// \file 10 /// \file
11 /// This file implements platform independent analysis of switch cases to 11 /// This file implements platform independent analysis of switch cases to
12 /// improve the generated code. 12 /// improve the generated code.
13 /// 13 ///
14 //===----------------------------------------------------------------------===// 14 //===----------------------------------------------------------------------===//
15 #include "IceSwitchLowering.h" 15 #include "IceSwitchLowering.h"
16 16
17 #include "IceCfgNode.h"
17 #include "IceTargetLowering.h" 18 #include "IceTargetLowering.h"
18 19
19 #include <algorithm> 20 #include <algorithm>
20 21
21 namespace Ice { 22 namespace Ice {
22 23
23 CaseClusterArray CaseCluster::clusterizeSwitch(Cfg *Func, 24 CaseClusterArray CaseCluster::clusterizeSwitch(Cfg *Func,
24 const InstSwitch *Inst) { 25 const InstSwitch *Inst) {
25 CaseClusterArray CaseClusters; 26 CaseClusterArray CaseClusters;
26 27
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 return CaseClusters; 73 return CaseClusters;
73 ++TotalRange; 74 ++TotalRange;
74 75
75 // Replace everything with a jump table 76 // Replace everything with a jump table
76 InstJumpTable *JumpTable = 77 InstJumpTable *JumpTable =
77 InstJumpTable::create(Func, TotalRange, Inst->getLabelDefault()); 78 InstJumpTable::create(Func, TotalRange, Inst->getLabelDefault());
78 for (const CaseCluster &Case : CaseClusters) { 79 for (const CaseCluster &Case : CaseClusters) {
79 // Case.High could be UINT64_MAX which makes the loop awkward. Unwrap the 80 // Case.High could be UINT64_MAX which makes the loop awkward. Unwrap the
80 // last iteration to avoid wrap around problems. 81 // last iteration to avoid wrap around problems.
81 for (uint64_t I = Case.Low; I < Case.High; ++I) 82 for (uint64_t I = Case.Low; I < Case.High; ++I)
82 JumpTable->addTarget(I - MinValue, Case.Label); 83 JumpTable->addTarget(I - MinValue, Case.Target);
83 JumpTable->addTarget(Case.High - MinValue, Case.Label); 84 JumpTable->addTarget(Case.High - MinValue, Case.Target);
85 Case.Target->setNeedsAlignment();
84 } 86 }
87 Func->addJumpTable(JumpTable);
85 88
86 CaseClusters.clear(); 89 CaseClusters.clear();
87 CaseClusters.emplace_back(MinValue, MaxValue, JumpTable); 90 CaseClusters.emplace_back(MinValue, MaxValue, JumpTable);
88 91
89 return CaseClusters; 92 return CaseClusters;
90 } 93 }
91 94
92 bool CaseCluster::tryAppend(const CaseCluster &New) { 95 bool CaseCluster::tryAppend(const CaseCluster &New) {
93 // Can only append ranges with the same target and are adjacent 96 // Can only append ranges with the same target and are adjacent
94 bool CanAppend = this->Label == New.Label && this->High + 1 == New.Low; 97 bool CanAppend = this->Target == New.Target && this->High + 1 == New.Low;
95 if (CanAppend) 98 if (CanAppend)
96 this->High = New.High; 99 this->High = New.High;
97 return CanAppend; 100 return CanAppend;
98 } 101 }
99 102
100 } // end of namespace Ice 103 } // end of namespace Ice
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698