5 #ifndef V8_COMPILER_OPERATOR_H_ 6 #define V8_COMPILER_OPERATOR_H_ 10 #include "src/base/compiler-specific.h" 11 #include "src/base/flags.h" 12 #include "src/base/functional.h" 13 #include "src/globals.h" 14 #include "src/handles.h" 15 #include "src/zone/zone.h" 33 class V8_EXPORT_PRIVATE
Operator :
public NON_EXPORTED_BASE(ZoneObject) {
35 typedef uint16_t Opcode;
41 kCommutative = 1 << 0,
42 kAssociative = 1 << 1,
49 kFoldable = kNoRead | kNoWrite,
50 kKontrol = kNoDeopt | kFoldable | kNoThrow,
51 kEliminatable = kNoDeopt | kNoWrite | kNoThrow,
52 kPure = kNoDeopt | kNoRead | kNoWrite | kNoThrow | kIdempotent
56 #define OPERATOR_PROPERTY_LIST(V) \ 58 V(Associative) V(Idempotent) V(NoRead) V(NoWrite) V(NoThrow) V(NoDeopt) 61 enum class PrintVerbosity { kVerbose, kSilent };
65 size_t value_in,
size_t effect_in,
size_t control_in,
66 size_t value_out,
size_t effect_out,
size_t control_out);
73 Opcode opcode()
const {
return opcode_; }
77 const char* mnemonic()
const {
return mnemonic_; }
82 virtual bool Equals(
const Operator* that)
const {
83 return this->opcode() == that->opcode();
92 bool HasProperty(Property property)
const {
93 return (properties() & property) == property;
96 Properties properties()
const {
return properties_; }
99 int ValueInputCount()
const {
return value_in_; }
100 int EffectInputCount()
const {
return effect_in_; }
101 int ControlInputCount()
const {
return control_in_; }
103 int ValueOutputCount()
const {
return value_out_; }
104 int EffectOutputCount()
const {
return effect_out_; }
105 int ControlOutputCount()
const {
return control_out_; }
107 static size_t ZeroIfEliminatable(
Properties properties) {
108 return (properties & kEliminatable) == kEliminatable ? 0 : 1;
111 static size_t ZeroIfNoThrow(
Properties properties) {
112 return (properties & kNoThrow) == kNoThrow ? 0 : 2;
115 static size_t ZeroIfPure(
Properties properties) {
116 return (properties & kPure) == kPure ? 0 : 1;
123 void PrintTo(std::ostream& os,
124 PrintVerbosity verbose = PrintVerbosity::kVerbose)
const {
127 return PrintToImpl(os, verbose);
130 void PrintPropsTo(std::ostream& os)
const;
133 virtual void PrintToImpl(std::ostream& os, PrintVerbosity verbose)
const;
136 const char* mnemonic_;
151 std::ostream& operator<<(std::ostream& os,
const Operator& op);
155 template <
typename T>
160 template <
typename T>
166 template <
typename T,
typename Pred = OpEqualTo<T>,
typename Hash = OpHash<T>>
170 size_t value_in,
size_t effect_in,
size_t control_in,
171 size_t value_out,
size_t effect_out,
size_t control_out,
172 T parameter, Pred
const& pred = Pred(), Hash
const& hash = Hash())
173 :
Operator(opcode, properties, mnemonic, value_in, effect_in, control_in,
174 value_out, effect_out, control_out),
175 parameter_(parameter),
179 T const& parameter()
const {
return parameter_; }
181 bool Equals(
const Operator* other)
const final {
182 if (opcode() != other->opcode())
return false;
185 return this->pred_(this->parameter(), that->parameter());
187 size_t HashCode()
const final {
188 return base::hash_combine(this->opcode(), this->hash_(this->parameter()));
196 virtual void PrintParameter(std::ostream& os, PrintVerbosity verbose)
const {
197 os <<
"[" << parameter() <<
"]";
200 void PrintToImpl(std::ostream& os, PrintVerbosity verbose)
const override {
202 PrintParameter(os, verbose);
213 template <
typename T>
214 inline T const& OpParameter(
const Operator* op) {
252 #endif // V8_COMPILER_OPERATOR_H_