Chromium Code Reviews| Index: src/IceOperand.h |
| diff --git a/src/IceOperand.h b/src/IceOperand.h |
| index 9638066ec89f157fde02511aa98edc716fc595e6..5627ef5da907277facbc07d0b6d8449bf05dc9bd 100644 |
| --- a/src/IceOperand.h |
| +++ b/src/IceOperand.h |
| @@ -8,11 +8,10 @@ |
| //===----------------------------------------------------------------------===// |
| /// |
| /// \file |
| -/// This file declares the Operand class and its target-independent |
| -/// subclasses. The main classes are Variable, which represents an |
| -/// LLVM variable that is either register- or stack-allocated, and the |
| -/// Constant hierarchy, which represents integer, floating-point, |
| -/// and/or symbolic constants. |
| +/// This file declares the Operand class and its target-independent subclasses. |
| +/// The main classes are Variable, which represents an LLVM variable that is |
| +/// either register- or stack-allocated, and the Constant hierarchy, which |
| +/// represents integer, floating-point, and/or symbolic constants. |
| /// |
| //===----------------------------------------------------------------------===// |
| @@ -32,7 +31,7 @@ class Operand { |
| Operand &operator=(const Operand &) = delete; |
| public: |
| - static const size_t MaxTargetKinds = 10; |
| + static constexpr size_t MaxTargetKinds = 10; |
| enum OperandKind { |
| kConst_Base, |
| kConstInteger32, |
| @@ -42,24 +41,24 @@ public: |
| kConstRelocatable, |
| kConstUndef, |
| kConst_Target, // leave space for target-specific constant kinds |
| - kConst_Num = kConst_Target + MaxTargetKinds, |
| + kConst_Max = kConst_Target + MaxTargetKinds, |
| kVariable, |
| kVariable_Target, // leave space for target-specific variable kinds |
| - kVariable_Num = kVariable_Target + MaxTargetKinds, |
| + kVariable_Max = kVariable_Target + MaxTargetKinds, |
| // Target-specific operand classes use kTarget as the starting |
| // point for their Kind enum space. Note that the value-spaces are shared |
| // across targets. To avoid confusion over the definition of shared |
| // values, an object specific to one target should never be passed |
| // to a different target. |
| - kTarget |
| + kTarget, |
| + kTarget_Max = kTarget + MaxTargetKinds, |
|
Jim Stichnoth
2015/09/08 22:10:32
What do you think of setting kTarget_Max = uint8_t
|
| }; |
| OperandKind getKind() const { return Kind; } |
| Type getType() const { return Ty; } |
| - /// Every Operand keeps an array of the Variables referenced in |
| - /// the operand. This is so that the liveness operations can get |
| - /// quick access to the variables of interest, without having to dig |
| - /// so far into the operand. |
| + /// Every Operand keeps an array of the Variables referenced in the operand. |
| + /// This is so that the liveness operations can get quick access to the |
| + /// variables of interest, without having to dig so far into the operand. |
| SizeT getNumVars() const { return NumVars; } |
| Variable *getVar(SizeT I) const { |
| assert(I < getNumVars()); |
| @@ -86,7 +85,10 @@ public: |
| /// @} |
| protected: |
| - Operand(OperandKind Kind, Type Ty) : Ty(Ty), Kind(Kind) {} |
| + Operand(OperandKind Kind, Type Ty) : Ty(Ty), Kind(Kind) { |
| + // It is undefined behavior to have a larger value in the enum |
| + assert(Kind <= kTarget_Max); |
| + } |
| virtual ~Operand() = default; |
| const Type Ty; |
| @@ -118,7 +120,7 @@ public: |
| static bool classof(const Operand *Operand) { |
| OperandKind Kind = Operand->getKind(); |
| - return Kind >= kConst_Base && Kind <= kConst_Num; |
| + return Kind >= kConst_Base && Kind <= kConst_Max; |
| } |
| /// Judge if this given immediate should be randomized or pooled |
| @@ -508,7 +510,7 @@ public: |
| static bool classof(const Operand *Operand) { |
| OperandKind Kind = Operand->getKind(); |
| - return Kind >= kVariable && Kind <= kVariable_Num; |
| + return Kind >= kVariable && Kind <= kVariable_Max; |
| } |
| protected: |