| OLD | NEW |
| (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 CaseCluster(const CaseCluster &) = default; |
| 38 CaseCluster &operator=(const CaseCluster &) = default; |
| 39 |
| 40 /// Create a cluster of a single case represented by a unitary range. |
| 41 CaseCluster(uint64_t Value, CfgNode *Label) |
| 42 : Kind(Range), Low(Value), High(Value), Label(Label) {} |
| 43 /// Create a case consisting of a jump table. |
| 44 CaseCluster(uint64_t Low, uint64_t High, InstJumpTable *JT) |
| 45 : Kind(JumpTable), Low(Low), High(High), JT(JT) {} |
| 46 |
| 47 CaseClusterKind getKind() const { return Kind; } |
| 48 uint64_t getLow() const { return Low; } |
| 49 uint64_t getHigh() const { return High; } |
| 50 CfgNode *getLabel() const { |
| 51 assert(Kind == Range); |
| 52 return Label; |
| 53 } |
| 54 InstJumpTable *getJumpTable() const { |
| 55 assert(Kind == JumpTable); |
| 56 return JT; |
| 57 } |
| 58 |
| 59 /// Discover cases which can be clustered together and return the clusters |
| 60 /// ordered by case value. |
| 61 static CaseClusterArray clusterizeSwitch(Cfg *Func, const InstSwitch *Inst); |
| 62 |
| 63 private: |
| 64 CaseClusterKind Kind; |
| 65 uint64_t Low; |
| 66 uint64_t High; |
| 67 union { |
| 68 CfgNode *Label; /// Target for a range. |
| 69 InstJumpTable *JT; /// Jump table targets. |
| 70 }; |
| 71 |
| 72 /// Try and append a cluster returning whether or not it was successful. |
| 73 bool tryAppend(const CaseCluster &New); |
| 74 }; |
| 75 |
| 76 } // end of namespace Ice |
| 77 |
| 78 #endif // SUBZERO_SRC_ICESWITCHLOWERING_H |
| OLD | NEW |