OLD | NEW |
---|---|
1 //===- subzero/src/IceOperand.h - High-level operands -----------*- C++ -*-===// | 1 //===- subzero/src/IceOperand.h - High-level operands -----------*- C++ -*-===// |
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 /// \brief Declares the Operand class and its target-independent subclasses. | 11 /// \brief Declares the Operand class and its target-independent subclasses. |
12 /// | 12 /// |
13 /// The main classes are Variable, which represents an LLVM variable that is | 13 /// The main classes are Variable, which represents an LLVM variable that is |
14 /// either register- or stack-allocated, and the Constant hierarchy, which | 14 /// either register- or stack-allocated, and the Constant hierarchy, which |
15 /// represents integer, floating-point, and/or symbolic constants. | 15 /// represents integer, floating-point, and/or symbolic constants. |
16 /// | 16 /// |
17 //===----------------------------------------------------------------------===// | 17 //===----------------------------------------------------------------------===// |
18 | 18 |
19 #ifndef SUBZERO_SRC_ICEOPERAND_H | 19 #ifndef SUBZERO_SRC_ICEOPERAND_H |
20 #define SUBZERO_SRC_ICEOPERAND_H | 20 #define SUBZERO_SRC_ICEOPERAND_H |
21 | 21 |
22 #include "IceDefs.h" | 22 #include "IceDefs.h" |
23 #include "IceCfg.h" | 23 #include "IceCfg.h" |
24 #include "IceGlobalContext.h" | 24 #include "IceGlobalContext.h" |
25 #include "IceTypes.h" | 25 #include "IceTypes.h" |
26 | 26 |
27 #include "llvm/Support/Format.h" | 27 #include "llvm/Support/Format.h" |
28 | 28 |
29 #include <limits> | 29 #include <limits> |
30 #include <type_traits> | |
30 | 31 |
31 namespace Ice { | 32 namespace Ice { |
32 | 33 |
33 class Operand { | 34 class Operand { |
34 Operand() = delete; | 35 Operand() = delete; |
35 Operand(const Operand &) = delete; | 36 Operand(const Operand &) = delete; |
36 Operand &operator=(const Operand &) = delete; | 37 Operand &operator=(const Operand &) = delete; |
37 | 38 |
38 public: | 39 public: |
39 static constexpr size_t MaxTargetKinds = 10; | 40 static constexpr size_t MaxTargetKinds = 10; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 Constant() = delete; | 119 Constant() = delete; |
119 Constant(const Constant &) = delete; | 120 Constant(const Constant &) = delete; |
120 Constant &operator=(const Constant &) = delete; | 121 Constant &operator=(const Constant &) = delete; |
121 | 122 |
122 public: | 123 public: |
123 virtual void emitPoolLabel(Ostream &Str, const GlobalContext *Ctx) const { | 124 virtual void emitPoolLabel(Ostream &Str, const GlobalContext *Ctx) const { |
124 (void)Str; | 125 (void)Str; |
125 (void)Ctx; | 126 (void)Ctx; |
126 llvm::report_fatal_error("emitPoolLabel not defined for type"); | 127 llvm::report_fatal_error("emitPoolLabel not defined for type"); |
127 }; | 128 }; |
129 // Declare the lookup counter to take minimal space in a non-DUMP build. | |
130 using CounterType = | |
131 std::conditional<BuildDefs::dump(), uint64_t, uint8_t>::type; | |
John
2016/03/07 15:50:26
What about void instead? Then you could use enable
Jim Stichnoth
2016/03/07 16:11:10
You also need to conditionally declare the field a
| |
128 void emit(const Cfg *Func) const override { emit(Func->getTarget()); } | 132 void emit(const Cfg *Func) const override { emit(Func->getTarget()); } |
129 virtual void emit(TargetLowering *Target) const = 0; | 133 virtual void emit(TargetLowering *Target) const = 0; |
130 | 134 |
131 static bool classof(const Operand *Operand) { | 135 static bool classof(const Operand *Operand) { |
132 OperandKind Kind = Operand->getKind(); | 136 OperandKind Kind = Operand->getKind(); |
133 return Kind >= kConst_Base && Kind <= kConst_Max; | 137 return Kind >= kConst_Base && Kind <= kConst_Max; |
134 } | 138 } |
135 | 139 |
136 /// Judge if this given immediate should be randomized or pooled By default | 140 /// Judge if this given immediate should be randomized or pooled By default |
137 /// should return false, only constant integers should truly go through this | 141 /// should return false, only constant integers should truly go through this |
138 /// method. | 142 /// method. |
139 virtual bool shouldBeRandomizedOrPooled(const GlobalContext *Ctx) { | 143 virtual bool shouldBeRandomizedOrPooled(const GlobalContext *Ctx) { |
140 (void)Ctx; | 144 (void)Ctx; |
141 return false; | 145 return false; |
142 } | 146 } |
143 | 147 |
144 void setShouldBePooled(bool R) { shouldBePooled = R; } | 148 void setShouldBePooled(bool R) { shouldBePooled = R; } |
145 | |
146 bool getShouldBePooled() const { return shouldBePooled; } | 149 bool getShouldBePooled() const { return shouldBePooled; } |
147 | 150 |
151 // This should be thread-safe because the constant pool lock is acquired | |
152 // before the method is invoked. | |
153 void updateLookupCount() { | |
154 if (!BuildDefs::dump()) | |
155 return; | |
156 ++LookupCount; | |
157 } | |
158 CounterType getLookupCount() const { return LookupCount; } | |
159 | |
148 protected: | 160 protected: |
149 Constant(OperandKind Kind, Type Ty) | 161 Constant(OperandKind Kind, Type Ty) : Operand(Kind, Ty) { |
150 : Operand(Kind, Ty), shouldBePooled(false) { | |
151 Vars = nullptr; | 162 Vars = nullptr; |
152 NumVars = 0; | 163 NumVars = 0; |
153 } | 164 } |
154 /// Whether we should pool this constant. Usually Float/Double and pooled | 165 /// Whether we should pool this constant. Usually Float/Double and pooled |
155 /// Integers should be flagged true. | 166 /// Integers should be flagged true. |
156 bool shouldBePooled; | 167 bool shouldBePooled = false; |
168 CounterType LookupCount = 0; | |
157 }; | 169 }; |
158 | 170 |
159 /// ConstantPrimitive<> wraps a primitive type. | 171 /// ConstantPrimitive<> wraps a primitive type. |
160 template <typename T, Operand::OperandKind K> | 172 template <typename T, Operand::OperandKind K> |
161 class ConstantPrimitive : public Constant { | 173 class ConstantPrimitive : public Constant { |
162 ConstantPrimitive() = delete; | 174 ConstantPrimitive() = delete; |
163 ConstantPrimitive(const ConstantPrimitive &) = delete; | 175 ConstantPrimitive(const ConstantPrimitive &) = delete; |
164 ConstantPrimitive &operator=(const ConstantPrimitive &) = delete; | 176 ConstantPrimitive &operator=(const ConstantPrimitive &) = delete; |
165 | 177 |
166 public: | 178 public: |
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
933 private: | 945 private: |
934 const Cfg *Func; | 946 const Cfg *Func; |
935 MetadataKind Kind; | 947 MetadataKind Kind; |
936 CfgVector<VariableTracking> Metadata; | 948 CfgVector<VariableTracking> Metadata; |
937 const static InstDefList NoDefinitions; | 949 const static InstDefList NoDefinitions; |
938 }; | 950 }; |
939 | 951 |
940 } // end of namespace Ice | 952 } // end of namespace Ice |
941 | 953 |
942 #endif // SUBZERO_SRC_ICEOPERAND_H | 954 #endif // SUBZERO_SRC_ICEOPERAND_H |
OLD | NEW |