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

Side by Side Diff: src/IceSwitchLowering.h

Issue 1234803007: Introduction of improved switch lowering. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Formatting tweaks. Created 5 years, 5 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
(Empty)
1 //===---- subzero/src/IceSwitchLowering.h - Switch lowering ----*- C++ -*--===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// \brief The file contains helpers for switch lowering.
12 //===----------------------------------------------------------------------===//
13
14 #ifndef SUBZERO_SRC_ICESWITCHLOWERING_H
15 #define SUBZERO_SRC_ICESWITCHLOWERING_H
16
17 #include "IceCfgNode.h"
18 #include "IceInst.h"
19
20 namespace Ice {
21
22 class CaseCluster;
23
24 typedef std::vector<CaseCluster, CfgLocalAllocator<CaseCluster>>
25 CaseClusterArray;
26
27 /// A cluster of cases can be tested by a common method during switch lowering.
28 class CaseCluster {
29 CaseCluster() = delete;
Jim Stichnoth 2015/07/17 15:33:47 Also delete default copy ctor and assignment opera
ascull 2015/07/17 18:21:29 Done.
30
31 public:
32 enum CaseClusterKind {
33 Range, /// Numerically adjacent case values with same target.
34 JumpTable, /// Different targets and possibly sparse.
35 };
36
37 /// Create a cluster of a single case represented by a unitary range.
38 CaseCluster(uint64_t Value, CfgNode *Label)
39 : Kind(Range), Low(Value), High(Value), Label(Label) {}
40 /// Create a case consisting of a jump table.
41 CaseCluster(uint64_t Low, uint64_t High, InstJumpTable *JT)
42 : Kind(JumpTable), Low(Low), High(High), JT(JT) {}
43
44 CaseClusterKind getKind() const { return Kind; }
45 uint64_t getLow() const { return Low; }
46 uint64_t getHigh() const { return High; }
47 CfgNode *getLabel() const {
48 assert(Kind == Range);
49 return Label;
50 }
51 InstJumpTable *getJumpTable() const {
52 assert(Kind == JumpTable);
53 return JT;
54 }
55
56 /// Discover cases which can be clustered together and return the clusters
57 /// ordered by case value.
58 static CaseClusterArray clusterizeSwitch(Cfg *Func, const InstSwitch *Inst);
59
60 private:
61 CaseClusterKind Kind;
62 uint64_t Low;
63 uint64_t High;
64 union {
65 CfgNode *Label; /// Target for a range.
66 InstJumpTable *JT; /// Jump table targets.
67 };
68
69 /// Try and append a cluster returning whether or not it was successful.
70 bool tryAppend(const CaseCluster &x);
Jim Stichnoth 2015/07/17 15:33:47 change x to New, like the method definition
ascull 2015/07/17 18:21:29 Done.
71 };
72
73 } // end of namespace Ice
74
75 #endif // SUBZERO_SRC_ICESWITCHLOWERING_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698