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

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: 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;
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.
jvoung (off chromium) 2015/07/15 18:32:01 At first I was surprised this was unitary, while t
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 private:
jvoung (off chromium) 2015/07/15 18:32:01 nit: I tend to prefer just having all the public:
ascull 2015/07/16 19:38:45 Done.
45 CaseClusterKind Kind;
46 uint64_t Low;
47 uint64_t High;
48 union {
49 CfgNode *Label; /// Target for a range.
50 InstJumpTable *JT; /// Jump table targets.
51 };
52
53 public:
54 CaseClusterKind getKind() const { return Kind; }
55 uint64_t getLow() const { return Low; }
56 uint64_t getHigh() const { return High; }
57 CfgNode *getLabel() const {
58 assert(Kind == Range);
59 return Label;
60 }
61 InstJumpTable *getJumpTable() const {
62 assert(Kind == JumpTable);
63 return JT;
64 }
65
66 /// Discover cases which can be clustered together and return the clusters
67 /// ordered by case value.
68 static CaseClusterArray clusterizeSwitch(Cfg *Func, const InstSwitch *Inst);
69
70 private:
71 /// Try and append a cluster returning whether or not it was successful.
72 bool tryAppend(const CaseCluster& x);
jvoung (off chromium) 2015/07/15 18:32:01 I think LLVM style puts the & next to the x? Did c
ascull 2015/07/16 19:38:45 Done.
73 };
74
75 } // end of namespace Ice
76
77 #endif // SUBZERO_SRC_ICESWITCHLOWERING_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698