js/src/jit/TypePolicy.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 * vim: set ts=8 sts=4 et sw=4 tw=99:
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef jit_TypePolicy_h
michael@0 8 #define jit_TypePolicy_h
michael@0 9
michael@0 10 #include "jit/IonAllocPolicy.h"
michael@0 11 #include "jit/IonTypes.h"
michael@0 12
michael@0 13 namespace js {
michael@0 14 namespace jit {
michael@0 15
michael@0 16 class MInstruction;
michael@0 17 class MDefinition;
michael@0 18
michael@0 19 // A type policy directs the type analysis phases, which insert conversion,
michael@0 20 // boxing, unboxing, and type changes as necessary.
michael@0 21 class TypePolicy
michael@0 22 {
michael@0 23 public:
michael@0 24 // Analyze the inputs of the instruction and perform one of the following
michael@0 25 // actions for each input:
michael@0 26 // * Nothing; the input already type-checks.
michael@0 27 // * If untyped, optionally ask the input to try and specialize its value.
michael@0 28 // * Replace the operand with a conversion instruction.
michael@0 29 // * Insert an unconditional deoptimization (no conversion possible).
michael@0 30 virtual bool adjustInputs(TempAllocator &alloc, MInstruction *def) = 0;
michael@0 31 };
michael@0 32
michael@0 33 class BoxInputsPolicy : public TypePolicy
michael@0 34 {
michael@0 35 protected:
michael@0 36 static MDefinition *boxAt(TempAllocator &alloc, MInstruction *at, MDefinition *operand);
michael@0 37
michael@0 38 public:
michael@0 39 static MDefinition *alwaysBoxAt(TempAllocator &alloc, MInstruction *at, MDefinition *operand);
michael@0 40 virtual bool adjustInputs(TempAllocator &alloc, MInstruction *def);
michael@0 41 };
michael@0 42
michael@0 43 class ArithPolicy : public BoxInputsPolicy
michael@0 44 {
michael@0 45 protected:
michael@0 46 // Specifies three levels of specialization:
michael@0 47 // - < Value. This input is expected and required.
michael@0 48 // - == Any. Inputs are probably primitive.
michael@0 49 // - == None. This op should not be specialized.
michael@0 50 MIRType specialization_;
michael@0 51
michael@0 52 public:
michael@0 53 bool adjustInputs(TempAllocator &alloc, MInstruction *def);
michael@0 54 };
michael@0 55
michael@0 56 class BitwisePolicy : public BoxInputsPolicy
michael@0 57 {
michael@0 58 protected:
michael@0 59 // Specifies three levels of specialization:
michael@0 60 // - < Value. This input is expected and required.
michael@0 61 // - == Any. Inputs are probably primitive.
michael@0 62 // - == None. This op should not be specialized.
michael@0 63 MIRType specialization_;
michael@0 64
michael@0 65 public:
michael@0 66 bool adjustInputs(TempAllocator &alloc, MInstruction *def);
michael@0 67
michael@0 68 MIRType specialization() const {
michael@0 69 return specialization_;
michael@0 70 }
michael@0 71 };
michael@0 72
michael@0 73 class ComparePolicy : public BoxInputsPolicy
michael@0 74 {
michael@0 75 bool adjustInputs(TempAllocator &alloc, MInstruction *def);
michael@0 76 };
michael@0 77
michael@0 78 // Policy for MTest instructions.
michael@0 79 class TestPolicy : public BoxInputsPolicy
michael@0 80 {
michael@0 81 public:
michael@0 82 bool adjustInputs(TempAllocator &alloc, MInstruction *ins);
michael@0 83 };
michael@0 84
michael@0 85 class TypeBarrierPolicy : public BoxInputsPolicy
michael@0 86 {
michael@0 87 public:
michael@0 88 bool adjustInputs(TempAllocator &alloc, MInstruction *ins);
michael@0 89 };
michael@0 90
michael@0 91 class CallPolicy : public BoxInputsPolicy
michael@0 92 {
michael@0 93 public:
michael@0 94 bool adjustInputs(TempAllocator &alloc, MInstruction *def);
michael@0 95 };
michael@0 96
michael@0 97 // Policy for MPow. First operand Double; second Double or Int32.
michael@0 98 class PowPolicy : public BoxInputsPolicy
michael@0 99 {
michael@0 100 MIRType specialization_;
michael@0 101
michael@0 102 public:
michael@0 103 PowPolicy(MIRType specialization)
michael@0 104 : specialization_(specialization)
michael@0 105 { }
michael@0 106
michael@0 107 bool adjustInputs(TempAllocator &alloc, MInstruction *ins);
michael@0 108 };
michael@0 109
michael@0 110 // Expect a string for operand Op. If the input is a Value, it is unboxed.
michael@0 111 template <unsigned Op>
michael@0 112 class StringPolicy : public BoxInputsPolicy
michael@0 113 {
michael@0 114 public:
michael@0 115 static bool staticAdjustInputs(TempAllocator &alloc, MInstruction *def);
michael@0 116 bool adjustInputs(TempAllocator &alloc, MInstruction *def) {
michael@0 117 return staticAdjustInputs(alloc, def);
michael@0 118 }
michael@0 119 };
michael@0 120
michael@0 121 // Expect a string for operand Op. Else a ToString instruction is inserted.
michael@0 122 template <unsigned Op>
michael@0 123 class ConvertToStringPolicy : public BoxInputsPolicy
michael@0 124 {
michael@0 125 public:
michael@0 126 static bool staticAdjustInputs(TempAllocator &alloc, MInstruction *def);
michael@0 127 bool adjustInputs(TempAllocator &alloc, MInstruction *def) {
michael@0 128 return staticAdjustInputs(alloc, def);
michael@0 129 }
michael@0 130 };
michael@0 131
michael@0 132 // Expect an Int for operand Op. If the input is a Value, it is unboxed.
michael@0 133 template <unsigned Op>
michael@0 134 class IntPolicy : public BoxInputsPolicy
michael@0 135 {
michael@0 136 public:
michael@0 137 static bool staticAdjustInputs(TempAllocator &alloc, MInstruction *def);
michael@0 138 bool adjustInputs(TempAllocator &alloc, MInstruction *def) {
michael@0 139 return staticAdjustInputs(alloc, def);
michael@0 140 }
michael@0 141 };
michael@0 142
michael@0 143 // Expect an Int for operand Op. Else a ToInt32 instruction is inserted.
michael@0 144 template <unsigned Op>
michael@0 145 class ConvertToInt32Policy : public BoxInputsPolicy
michael@0 146 {
michael@0 147 public:
michael@0 148 static bool staticAdjustInputs(TempAllocator &alloc, MInstruction *def);
michael@0 149 bool adjustInputs(TempAllocator &alloc, MInstruction *def) {
michael@0 150 return staticAdjustInputs(alloc, def);
michael@0 151 }
michael@0 152 };
michael@0 153
michael@0 154 // Expect a double for operand Op. If the input is a Value, it is unboxed.
michael@0 155 template <unsigned Op>
michael@0 156 class DoublePolicy : public BoxInputsPolicy
michael@0 157 {
michael@0 158 public:
michael@0 159 static bool staticAdjustInputs(TempAllocator &alloc, MInstruction *def);
michael@0 160 bool adjustInputs(TempAllocator &alloc, MInstruction *def) {
michael@0 161 return staticAdjustInputs(alloc, def);
michael@0 162 }
michael@0 163 };
michael@0 164
michael@0 165 // Expect a float32 for operand Op. If the input is a Value, it is unboxed.
michael@0 166 template <unsigned Op>
michael@0 167 class Float32Policy : public BoxInputsPolicy
michael@0 168 {
michael@0 169 public:
michael@0 170 static bool staticAdjustInputs(TempAllocator &alloc, MInstruction *def);
michael@0 171 bool adjustInputs(TempAllocator &alloc, MInstruction *def) {
michael@0 172 return staticAdjustInputs(alloc, def);
michael@0 173 }
michael@0 174 };
michael@0 175
michael@0 176 // Expect a float32 OR a double for operand Op, but will prioritize Float32
michael@0 177 // if the result type is set as such. If the input is a Value, it is unboxed.
michael@0 178 template <unsigned Op>
michael@0 179 class FloatingPointPolicy : public TypePolicy
michael@0 180 {
michael@0 181 MIRType policyType_;
michael@0 182
michael@0 183 public:
michael@0 184 bool adjustInputs(TempAllocator &alloc, MInstruction *def) {
michael@0 185 if (policyType_ == MIRType_Double)
michael@0 186 return DoublePolicy<Op>::staticAdjustInputs(alloc, def);
michael@0 187 return Float32Policy<Op>::staticAdjustInputs(alloc, def);
michael@0 188 }
michael@0 189 void setPolicyType(MIRType type) {
michael@0 190 policyType_ = type;
michael@0 191 }
michael@0 192 };
michael@0 193
michael@0 194 template <unsigned Op>
michael@0 195 class NoFloatPolicy : public TypePolicy
michael@0 196 {
michael@0 197 public:
michael@0 198 static bool staticAdjustInputs(TempAllocator &alloc, MInstruction *def);
michael@0 199 bool adjustInputs(TempAllocator &alloc, MInstruction *def) {
michael@0 200 return staticAdjustInputs(alloc, def);
michael@0 201 }
michael@0 202 };
michael@0 203
michael@0 204 // Box objects or strings as an input to a ToDouble instruction.
michael@0 205 class ToDoublePolicy : public BoxInputsPolicy
michael@0 206 {
michael@0 207 public:
michael@0 208 static bool staticAdjustInputs(TempAllocator &alloc, MInstruction *def);
michael@0 209 bool adjustInputs(TempAllocator &alloc, MInstruction *def) {
michael@0 210 return staticAdjustInputs(alloc, def);
michael@0 211 }
michael@0 212 };
michael@0 213
michael@0 214 // Box objects, strings and undefined as input to a ToInt32 instruction.
michael@0 215 class ToInt32Policy : public BoxInputsPolicy
michael@0 216 {
michael@0 217 public:
michael@0 218 static bool staticAdjustInputs(TempAllocator &alloc, MInstruction *def);
michael@0 219 bool adjustInputs(TempAllocator &alloc, MInstruction *def) {
michael@0 220 return staticAdjustInputs(alloc, def);
michael@0 221 }
michael@0 222 };
michael@0 223
michael@0 224 template <unsigned Op>
michael@0 225 class ObjectPolicy : public BoxInputsPolicy
michael@0 226 {
michael@0 227 public:
michael@0 228 static bool staticAdjustInputs(TempAllocator &alloc, MInstruction *ins);
michael@0 229 bool adjustInputs(TempAllocator &alloc, MInstruction *ins) {
michael@0 230 return staticAdjustInputs(alloc, ins);
michael@0 231 }
michael@0 232 };
michael@0 233
michael@0 234 // Single-object input. If the input is a Value, it is unboxed. If it is
michael@0 235 // a primitive, we use ValueToNonNullObject.
michael@0 236 class SingleObjectPolicy : public ObjectPolicy<0>
michael@0 237 { };
michael@0 238
michael@0 239 template <unsigned Op>
michael@0 240 class BoxPolicy : public BoxInputsPolicy
michael@0 241 {
michael@0 242 public:
michael@0 243 static bool staticAdjustInputs(TempAllocator &alloc, MInstruction *ins);
michael@0 244 bool adjustInputs(TempAllocator &alloc, MInstruction *ins) {
michael@0 245 return staticAdjustInputs(alloc, ins);
michael@0 246 }
michael@0 247 };
michael@0 248
michael@0 249 // Boxes everything except inputs of type Type.
michael@0 250 template <unsigned Op, MIRType Type>
michael@0 251 class BoxExceptPolicy : public TypePolicy
michael@0 252 {
michael@0 253 public:
michael@0 254 static bool staticAdjustInputs(TempAllocator &alloc, MInstruction *ins);
michael@0 255 bool adjustInputs(TempAllocator &alloc, MInstruction *ins) {
michael@0 256 return staticAdjustInputs(alloc, ins);
michael@0 257 }
michael@0 258 };
michael@0 259
michael@0 260 // Combine multiple policies.
michael@0 261 template <class Lhs, class Rhs>
michael@0 262 class MixPolicy : public TypePolicy
michael@0 263 {
michael@0 264 public:
michael@0 265 static bool staticAdjustInputs(TempAllocator &alloc, MInstruction *ins) {
michael@0 266 return Lhs::staticAdjustInputs(alloc, ins) && Rhs::staticAdjustInputs(alloc, ins);
michael@0 267 }
michael@0 268 virtual bool adjustInputs(TempAllocator &alloc, MInstruction *ins) {
michael@0 269 return staticAdjustInputs(alloc, ins);
michael@0 270 }
michael@0 271 };
michael@0 272
michael@0 273 // Combine three policies.
michael@0 274 template <class Policy1, class Policy2, class Policy3>
michael@0 275 class Mix3Policy : public TypePolicy
michael@0 276 {
michael@0 277 public:
michael@0 278 static bool staticAdjustInputs(TempAllocator &alloc, MInstruction *ins) {
michael@0 279 return Policy1::staticAdjustInputs(alloc, ins) &&
michael@0 280 Policy2::staticAdjustInputs(alloc, ins) &&
michael@0 281 Policy3::staticAdjustInputs(alloc, ins);
michael@0 282 }
michael@0 283 virtual bool adjustInputs(TempAllocator &alloc, MInstruction *ins) {
michael@0 284 return staticAdjustInputs(alloc, ins);
michael@0 285 }
michael@0 286 };
michael@0 287
michael@0 288 class CallSetElementPolicy : public SingleObjectPolicy
michael@0 289 {
michael@0 290 public:
michael@0 291 bool adjustInputs(TempAllocator &alloc, MInstruction *def);
michael@0 292 };
michael@0 293
michael@0 294 // First operand will be boxed to a Value (except for an object)
michael@0 295 // Second operand (if specified) will forcefully be unboxed to an object
michael@0 296 class InstanceOfPolicy : public TypePolicy
michael@0 297 {
michael@0 298 public:
michael@0 299 bool adjustInputs(TempAllocator &alloc, MInstruction *def);
michael@0 300 };
michael@0 301
michael@0 302 class StoreTypedArrayPolicy : public BoxInputsPolicy
michael@0 303 {
michael@0 304 protected:
michael@0 305 bool adjustValueInput(TempAllocator &alloc, MInstruction *ins, int arrayType, MDefinition *value, int valueOperand);
michael@0 306
michael@0 307 public:
michael@0 308 bool adjustInputs(TempAllocator &alloc, MInstruction *ins);
michael@0 309 };
michael@0 310
michael@0 311 class StoreTypedArrayHolePolicy : public StoreTypedArrayPolicy
michael@0 312 {
michael@0 313 public:
michael@0 314 bool adjustInputs(TempAllocator &alloc, MInstruction *ins);
michael@0 315 };
michael@0 316
michael@0 317 class StoreTypedArrayElementStaticPolicy : public StoreTypedArrayPolicy
michael@0 318 {
michael@0 319 public:
michael@0 320 bool adjustInputs(TempAllocator &alloc, MInstruction *ins);
michael@0 321 };
michael@0 322
michael@0 323 // Accepts integers and doubles. Everything else is boxed.
michael@0 324 class ClampPolicy : public BoxInputsPolicy
michael@0 325 {
michael@0 326 public:
michael@0 327 bool adjustInputs(TempAllocator &alloc, MInstruction *ins);
michael@0 328 };
michael@0 329
michael@0 330 class FilterTypeSetPolicy : public BoxInputsPolicy
michael@0 331 {
michael@0 332 public:
michael@0 333 bool adjustInputs(TempAllocator &alloc, MInstruction *ins);
michael@0 334 };
michael@0 335
michael@0 336 static inline bool
michael@0 337 CoercesToDouble(MIRType type)
michael@0 338 {
michael@0 339 if (type == MIRType_Undefined || IsFloatingPointType(type))
michael@0 340 return true;
michael@0 341 return false;
michael@0 342 }
michael@0 343
michael@0 344
michael@0 345 } // namespace jit
michael@0 346 } // namespace js
michael@0 347
michael@0 348 #endif /* jit_TypePolicy_h */

mercurial