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

Side by Side Diff: src/IceOperand.h

Issue 1768173002: Subzero: Count lookups of each constant value in the constant pool. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Code review changes Created 4 years, 9 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
« no previous file with comments | « src/IceGlobalContext.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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;
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; }
149 bool getShouldBePooled() const { return ShouldBePooled; }
145 150
146 bool getShouldBePooled() const { return shouldBePooled; } 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; }
147 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 /// Note: If ShouldBePooled is ever removed from the base class, we will want
169 /// to completely disable LookupCount in a non-DUMP build to save space.
170 CounterType LookupCount = 0;
157 }; 171 };
158 172
159 /// ConstantPrimitive<> wraps a primitive type. 173 /// ConstantPrimitive<> wraps a primitive type.
160 template <typename T, Operand::OperandKind K> 174 template <typename T, Operand::OperandKind K>
161 class ConstantPrimitive : public Constant { 175 class ConstantPrimitive : public Constant {
162 ConstantPrimitive() = delete; 176 ConstantPrimitive() = delete;
163 ConstantPrimitive(const ConstantPrimitive &) = delete; 177 ConstantPrimitive(const ConstantPrimitive &) = delete;
164 ConstantPrimitive &operator=(const ConstantPrimitive &) = delete; 178 ConstantPrimitive &operator=(const ConstantPrimitive &) = delete;
165 179
166 public: 180 public:
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 private: 947 private:
934 const Cfg *Func; 948 const Cfg *Func;
935 MetadataKind Kind; 949 MetadataKind Kind;
936 CfgVector<VariableTracking> Metadata; 950 CfgVector<VariableTracking> Metadata;
937 const static InstDefList NoDefinitions; 951 const static InstDefList NoDefinitions;
938 }; 952 };
939 953
940 } // end of namespace Ice 954 } // end of namespace Ice
941 955
942 #endif // SUBZERO_SRC_ICEOPERAND_H 956 #endif // SUBZERO_SRC_ICEOPERAND_H
OLDNEW
« no previous file with comments | « src/IceGlobalContext.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698