| 1 |
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 2 |
* vim: set ts=8 sts=2 et sw=2 tw=80: |
| 3 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 4 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 6 |
|
| 7 |
#include "jit/CacheIRSpewer.h" |
| 8 |
|
| 9 |
#include "mozilla/Sprintf.h" |
| 10 |
|
| 11 |
#include <algorithm> |
| 12 |
#include <stdarg.h> |
| 13 |
|
| 14 |
#include "jsapi.h" |
| 15 |
#include "jsmath.h" |
| 16 |
|
| 17 |
#include "js/ColumnNumber.h" // JS::LimitedColumnNumberOneOrigin |
| 18 |
#include "js/Printer.h" // js::GenericPrinter |
| 19 |
#include "js/ScalarType.h" // js::Scalar::Type |
| 20 |
#include "util/GetPidProvider.h" |
| 21 |
#include "util/Text.h" |
| 22 |
#include "vm/JSFunction.h" |
| 23 |
#include "vm/JSObject.h" |
| 24 |
#include "vm/JSScript.h" |
| 25 |
|
| 26 |
#include "vm/JSObject-inl.h" |
| 27 |
#include "vm/Realm-inl.h" |
| 28 |
|
| 29 |
using namespace js; |
| 30 |
using namespace js::jit; |
| 31 |
|
| 32 |
#ifdef JS_CACHEIR_SPEW |
| 33 |
|
| 34 |
// Text spewer for CacheIR ops that can be used with JitSpew. |
| 35 |
// Output looks like this: |
| 36 |
// |
| 37 |
// GuardToInt32 inputId 0, resultId 2 |
| 38 |
// GuardToInt32 inputId 1, resultId 3 |
| 39 |
// CompareInt32Result op JSOp::Lt, lhsId 2, rhsId 3 |
| 40 |
// ReturnFromIC |
| 41 |
class MOZ_RAII CacheIROpsJitSpewer { |
| 42 |
GenericPrinter& out_; |
| 43 |
|
| 44 |
// String prepended to each line. Can be used for indentation. |
| 45 |
const char* prefix_; |
| 46 |
|
| 47 |
CACHE_IR_SPEWER_GENERATED |
| 48 |
|
| 49 |
void spewOp(CacheOp op) { |
| 50 |
const char* opName = CacheIROpNames[size_t(op)]; |
| 51 |
out_.printf("%s%-30s", prefix_, opName); |
| 52 |
} |
| 53 |
void spewOpEnd() { out_.printf("\n"); } |
| 54 |
|
| 55 |
void spewArgSeparator() { out_.printf(", "); } |
| 56 |
|
| 57 |
void spewOperandId(const char* name, OperandId id) { |
| 58 |
spewRawOperandId(name, id.id()); |
| 59 |
} |
| 60 |
void spewRawOperandId(const char* name, uint32_t id) { |
| 61 |
out_.printf("%s %u", name, id); |
| 62 |
} |
| 63 |
void spewField(const char* name, uint32_t offset) { |
| 64 |
out_.printf("%s %u", name, offset); |
| 65 |
} |
| 66 |
void spewBoolImm(const char* name, bool b) { |
| 67 |
out_.printf("%s %s", name, b ? "true" : "false"); |
| 68 |
} |
| 69 |
void spewByteImm(const char* name, uint8_t val) { |
| 70 |
out_.printf("%s %u", name, val); |
| 71 |
} |
| 72 |
void spewJSOpImm(const char* name, JSOp op) { |
| 73 |
out_.printf("%s JSOp::%s", name, CodeName(op)); |
| 74 |
} |
| 75 |
void spewTypeofEqOperandImm(const char* name, TypeofEqOperand operand) { |
| 76 |
out_.printf("%s %s %s", name, JSTypeToString(operand.type()), |
| 77 |
CodeName(operand.compareOp())); |
| 78 |
} |
| 79 |
void spewStaticStringImm(const char* name, const char* str) { |
| 80 |
out_.printf("%s \"%s\"", name, str); |
| 81 |
} |
| 82 |
void spewInt32Imm(const char* name, int32_t val) { |
| 83 |
out_.printf("%s %d", name, val); |
| 84 |
} |
| 85 |
void spewUInt32Imm(const char* name, uint32_t val) { |
| 86 |
out_.printf("%s %u", name, val); |
| 87 |
} |
| 88 |
void spewCallFlagsImm(const char* name, CallFlags flags) { |
| 89 |
out_.printf( |
| 90 |
"%s (format %u%s%s%s)", name, flags.getArgFormat(), |
| 91 |
flags.isConstructing() ? ", isConstructing" : "", |
| 92 |
flags.isSameRealm() ? ", isSameRealm" : "", |
| 93 |
flags.needsUninitializedThis() ? ", needsUninitializedThis" : ""); |
| 94 |
} |
| 95 |
void spewJSWhyMagicImm(const char* name, JSWhyMagic magic) { |
| 96 |
out_.printf("%s JSWhyMagic(%u)", name, unsigned(magic)); |
| 97 |
} |
| 98 |
void spewScalarTypeImm(const char* name, Scalar::Type type) { |
| 99 |
out_.printf("%s Scalar::Type(%u)", name, unsigned(type)); |
| 100 |
} |
| 101 |
void spewUnaryMathFunctionImm(const char* name, UnaryMathFunction fun) { |
| 102 |
const char* funName = GetUnaryMathFunctionName(fun); |
| 103 |
out_.printf("%s UnaryMathFunction::%s", name, funName); |
| 104 |
} |
| 105 |
void spewValueTypeImm(const char* name, ValueType type) { |
| 106 |
out_.printf("%s ValueType(%u)", name, unsigned(type)); |
| 107 |
} |
| 108 |
void spewJSNativeImm(const char* name, JSNative native) { |
| 109 |
out_.printf("%s %p", name, native); |
| 110 |
} |
| 111 |
void spewGuardClassKindImm(const char* name, GuardClassKind kind) { |
| 112 |
out_.printf("%s GuardClassKind(%u)", name, unsigned(kind)); |
| 113 |
} |
| 114 |
void spewArrayBufferViewKindImm(const char* name, ArrayBufferViewKind kind) { |
| 115 |
out_.printf("%s ArrayBufferViewKind(%u)", name, unsigned(kind)); |
| 116 |
} |
| 117 |
void spewWasmValTypeImm(const char* name, wasm::ValType::Kind kind) { |
| 118 |
out_.printf("%s WasmValTypeKind(%u)", name, unsigned(kind)); |
| 119 |
} |
| 120 |
void spewAllocKindImm(const char* name, gc::AllocKind kind) { |
| 121 |
out_.printf("%s AllocKind(%u)", name, unsigned(kind)); |
| 122 |
} |
| 123 |
void spewCompletionKindImm(const char* name, CompletionKind kind) { |
| 124 |
out_.printf("%s CompletionKind(%u)", name, unsigned(kind)); |
| 125 |
} |
| 126 |
void spewRealmFuseIndexImm(const char* name, RealmFuses::FuseIndex index) { |
| 127 |
out_.printf("%s RealmFuseIndex(%u=%s)", name, unsigned(index), |
| 128 |
RealmFuses::getFuseName(index)); |
| 129 |
} |
| 130 |
|
| 131 |
public: |
| 132 |
CacheIROpsJitSpewer(GenericPrinter& out, const char* prefix) |
| 133 |
: out_(out), prefix_(prefix) {} |
| 134 |
|
| 135 |
void spew(CacheIRReader& reader) { |
| 136 |
do { |
| 137 |
switch (reader.readOp()) { |
| 138 |
# define SPEW_OP(op, ...) \ |
| 139 |
case CacheOp::op: \ |
| 140 |
spew##op(reader); \ |
| 141 |
break; |
| 142 |
CACHE_IR_OPS(SPEW_OP) |
| 143 |
# undef SPEW_OP |
| 144 |
|
| 145 |
default: |
| 146 |
MOZ_CRASH("Invalid op"); |
| 147 |
} |
| 148 |
} while (reader.more()); |
| 149 |
} |
| 150 |
}; |
| 151 |
|
| 152 |
void js::jit::SpewCacheIROps(GenericPrinter& out, const char* prefix, |
| 153 |
CacheIRReader& reader) { |
| 154 |
CacheIROpsJitSpewer spewer(out, prefix); |
| 155 |
spewer.spew(reader); |
| 156 |
} |
| 157 |
|
| 158 |
void js::jit::SpewCacheIROps(GenericPrinter& out, const char* prefix, |
| 159 |
const CacheIRStubInfo* info) { |
| 160 |
CacheIRReader reader(info); |
| 161 |
SpewCacheIROps(out, prefix, reader); |
| 162 |
} |
| 163 |
|
| 164 |
// JSON spewer for CacheIR ops. Output looks like this: |
| 165 |
// |
| 166 |
// ... |
| 167 |
// { |
| 168 |
// "op":"GuardToInt32", |
| 169 |
// "args":[ |
| 170 |
// { |
| 171 |
// "name":"inputId", |
| 172 |
// "type":"Id", |
| 173 |
// "value":0 |
| 174 |
// }, |
| 175 |
// { |
| 176 |
// "name":"resultId", |
| 177 |
// "type":"Id", |
| 178 |
// "value":1 |
| 179 |
// } |
| 180 |
// ] |
| 181 |
// }, |
| 182 |
// { |
| 183 |
// "op":"Int32IncResult", |
| 184 |
// "args":[ |
| 185 |
// { |
| 186 |
// "name":"inputId", |
| 187 |
// "type":"Id", |
| 188 |
// "value":1 |
| 189 |
// } |
| 190 |
// ] |
| 191 |
// } |
| 192 |
// ... |
| 193 |
class MOZ_RAII CacheIROpsJSONSpewer { |
| 194 |
JSONPrinter& j_; |
| 195 |
|
| 196 |
CACHE_IR_SPEWER_GENERATED |
| 197 |
|
| 198 |
void spewOp(CacheOp op) { |
| 199 |
const char* opName = CacheIROpNames[size_t(op)]; |
| 200 |
j_.beginObject(); |
| 201 |
j_.property("op", opName); |
| 202 |
j_.beginListProperty("args"); |
| 203 |
} |
| 204 |
void spewOpEnd() { |
| 205 |
j_.endList(); |
| 206 |
j_.endObject(); |
| 207 |
} |
| 208 |
|
| 209 |
void spewArgSeparator() {} |
| 210 |
|
| 211 |
template <typename T> |
| 212 |
void spewArgImpl(const char* name, const char* type, T value) { |
| 213 |
j_.beginObject(); |
| 214 |
j_.property("name", name); |
| 215 |
j_.property("type", type); |
| 216 |
j_.property("value", value); |
| 217 |
j_.endObject(); |
| 218 |
} |
| 219 |
|
| 220 |
void spewOperandId(const char* name, OperandId id) { |
| 221 |
spewRawOperandId(name, id.id()); |
| 222 |
} |
| 223 |
void spewRawOperandId(const char* name, uint32_t id) { |
| 224 |
spewArgImpl(name, "Id", id); |
| 225 |
} |
| 226 |
void spewField(const char* name, uint32_t offset) { |
| 227 |
spewArgImpl(name, "Field", offset); |
| 228 |
} |
| 229 |
void spewBoolImm(const char* name, bool b) { spewArgImpl(name, "Imm", b); } |
| 230 |
void spewByteImm(const char* name, uint8_t val) { |
| 231 |
spewArgImpl(name, "Imm", val); |
| 232 |
} |
| 233 |
void spewJSOpImm(const char* name, JSOp op) { |
| 234 |
spewArgImpl(name, "JSOp", CodeName(op)); |
| 235 |
} |
| 236 |
void spewTypeofEqOperandImm(const char* name, TypeofEqOperand operand) { |
| 237 |
spewArgImpl(name, "TypeofEqOperand", uint8_t(operand.rawValue())); |
| 238 |
} |
| 239 |
void spewStaticStringImm(const char* name, const char* str) { |
| 240 |
spewArgImpl(name, "String", str); |
| 241 |
} |
| 242 |
void spewInt32Imm(const char* name, int32_t val) { |
| 243 |
spewArgImpl(name, "Imm", val); |
| 244 |
} |
| 245 |
void spewUInt32Imm(const char* name, uint32_t val) { |
| 246 |
spewArgImpl(name, "Imm", val); |
| 247 |
} |
| 248 |
void spewCallFlagsImm(const char* name, CallFlags flags) { |
| 249 |
spewArgImpl(name, "Imm", flags.toByte()); |
| 250 |
} |
| 251 |
void spewJSWhyMagicImm(const char* name, JSWhyMagic magic) { |
| 252 |
spewArgImpl(name, "Imm", unsigned(magic)); |
| 253 |
} |
| 254 |
void spewScalarTypeImm(const char* name, Scalar::Type type) { |
| 255 |
spewArgImpl(name, "Imm", unsigned(type)); |
| 256 |
} |
| 257 |
void spewUnaryMathFunctionImm(const char* name, UnaryMathFunction fun) { |
| 258 |
const char* funName = GetUnaryMathFunctionName(fun); |
| 259 |
spewArgImpl(name, "MathFunction", funName); |
| 260 |
} |
| 261 |
void spewValueTypeImm(const char* name, ValueType type) { |
| 262 |
spewArgImpl(name, "Imm", unsigned(type)); |
| 263 |
} |
| 264 |
void spewJSNativeImm(const char* name, JSNative native) { |
| 265 |
spewArgImpl(name, "Word", uintptr_t(native)); |
| 266 |
} |
| 267 |
void spewGuardClassKindImm(const char* name, GuardClassKind kind) { |
| 268 |
spewArgImpl(name, "Imm", unsigned(kind)); |
| 269 |
} |
| 270 |
void spewArrayBufferViewKindImm(const char* name, ArrayBufferViewKind kind) { |
| 271 |
spewArgImpl(name, "Imm", unsigned(kind)); |
| 272 |
} |
| 273 |
void spewRealmFuseIndexImm(const char* name, RealmFuses::FuseIndex kind) { |
| 274 |
spewArgImpl(name, "Imm", unsigned(kind)); |
| 275 |
} |
| 276 |
void spewWasmValTypeImm(const char* name, wasm::ValType::Kind kind) { |
| 277 |
spewArgImpl(name, "Imm", unsigned(kind)); |
| 278 |
} |
| 279 |
void spewAllocKindImm(const char* name, gc::AllocKind kind) { |
| 280 |
spewArgImpl(name, "Imm", unsigned(kind)); |
| 281 |
} |
| 282 |
void spewCompletionKindImm(const char* name, CompletionKind kind) { |
| 283 |
spewArgImpl(name, "Imm", unsigned(kind)); |
| 284 |
} |
| 285 |
|
| 286 |
public: |
| 287 |
explicit CacheIROpsJSONSpewer(JSONPrinter& j) : j_(j) {} |
| 288 |
|
| 289 |
void spew(CacheIRReader& reader) { |
| 290 |
do { |
| 291 |
switch (reader.readOp()) { |
| 292 |
# define SPEW_OP(op, ...) \ |
| 293 |
case CacheOp::op: \ |
| 294 |
spew##op(reader); \ |
| 295 |
break; |
| 296 |
CACHE_IR_OPS(SPEW_OP) |
| 297 |
# undef SPEW_OP |
| 298 |
|
| 299 |
default: |
| 300 |
MOZ_CRASH("Invalid op"); |
| 301 |
} |
| 302 |
} while (reader.more()); |
| 303 |
} |
| 304 |
}; |
| 305 |
|
| 306 |
MOZ_RUNINIT CacheIRSpewer CacheIRSpewer::cacheIRspewer; |
| 307 |
|
| 308 |
CacheIRSpewer::CacheIRSpewer() |
| 309 |
: outputLock_(mutexid::CacheIRSpewer), guardCount_(0) { |
| 310 |
spewInterval_ = |
| 311 |
getenv("CACHEIR_LOG_FLUSH") ? atoi(getenv("CACHEIR_LOG_FLUSH")) : 10000; |
| 312 |
|
| 313 |
if (spewInterval_ < 1) { |
| 314 |
spewInterval_ = 1; |
| 315 |
} |
| 316 |
} |
| 317 |
|
| 318 |
CacheIRSpewer::~CacheIRSpewer() { |
| 319 |
if (!enabled()) { |
| 320 |
return; |
| 321 |
} |
| 322 |
|
| 323 |
json_.ref().endList(); |
| 324 |
output_.flush(); |
| 325 |
output_.finish(); |
| 326 |
} |
| 327 |
|
| 328 |
# ifndef JIT_SPEW_DIR |
| 329 |
# if defined(_WIN32) |
| 330 |
# define JIT_SPEW_DIR "." |
| 331 |
# elif defined(__ANDROID__) |
| 332 |
# define JIT_SPEW_DIR "/data/local/tmp" |
| 333 |
# else |
| 334 |
# define JIT_SPEW_DIR "/tmp" |
| 335 |
# endif |
| 336 |
# endif |
| 337 |
|
| 338 |
bool CacheIRSpewer::init(const char* filename) { |
| 339 |
if (enabled()) { |
| 340 |
return true; |
| 341 |
} |
| 342 |
|
| 343 |
char name[256]; |
| 344 |
uint32_t pid = getpid(); |
| 345 |
// Default to JIT_SPEW_DIR/cacheir${pid}.json |
| 346 |
if (filename[0] == '1') { |
| 347 |
SprintfLiteral(name, JIT_SPEW_DIR "/cacheir%" PRIu32 ".json", pid); |
| 348 |
} else { |
| 349 |
SprintfLiteral(name, "%s%" PRIu32 ".json", filename, pid); |
| 350 |
} |
| 351 |
|
| 352 |
if (!output_.init(name)) { |
| 353 |
return false; |
| 354 |
} |
| 355 |
|
| 356 |
json_.emplace(output_); |
| 357 |
json_->beginList(); |
| 358 |
return true; |
| 359 |
} |
| 360 |
|
| 361 |
void CacheIRSpewer::beginCache(const IRGenerator& gen) { |
| 362 |
MOZ_ASSERT(enabled()); |
| 363 |
JSONPrinter& j = json_.ref(); |
| 364 |
const char* filename = gen.script_->filename(); |
| 365 |
j.beginObject(); |
| 366 |
j.property("name", CacheKindNames[uint8_t(gen.cacheKind_)]); |
| 367 |
j.property("file", filename ? filename : "null"); |
| 368 |
j.property("mode", int(gen.mode_)); |
| 369 |
if (jsbytecode* pc = gen.pc_) { |
| 370 |
JS::LimitedColumnNumberOneOrigin column; |
| 371 |
j.property("line", PCToLineNumber(gen.script_, pc, &column)); |
| 372 |
j.property("column", column.oneOriginValue()); |
| 373 |
j.formatProperty("pc", "%p", pc); |
| 374 |
} |
| 375 |
} |
| 376 |
|
| 377 |
void CacheIRSpewer::valueProperty(const char* name, const Value& v) { |
| 378 |
MOZ_ASSERT(enabled()); |
| 379 |
JSONPrinter& j = json_.ref(); |
| 380 |
|
| 381 |
j.beginObjectProperty(name); |
| 382 |
|
| 383 |
const char* type = InformalValueTypeName(v); |
| 384 |
if (v.isInt32()) { |
| 385 |
type = "int32"; |
| 386 |
} |
| 387 |
j.property("type", type); |
| 388 |
|
| 389 |
if (v.isInt32()) { |
| 390 |
j.property("value", v.toInt32()); |
| 391 |
} else if (v.isDouble()) { |
| 392 |
j.floatProperty("value", v.toDouble(), 3); |
| 393 |
} else if (v.isString() || v.isSymbol()) { |
| 394 |
JSString* str = v.isString() ? v.toString() : v.toSymbol()->description(); |
| 395 |
if (str && str->isLinear()) { |
| 396 |
j.property("value", &str->asLinear()); |
| 397 |
} |
| 398 |
} else if (v.isObject()) { |
| 399 |
JSObject& object = v.toObject(); |
| 400 |
j.formatProperty("value", "%p (shape: %p)", &object, object.shape()); |
| 401 |
|
| 402 |
if (object.is<JSFunction>()) { |
| 403 |
if (JSAtom* name = object.as<JSFunction>().maybePartialDisplayAtom()) { |
| 404 |
j.property("funName", name); |
| 405 |
} |
| 406 |
} |
| 407 |
|
| 408 |
if (NativeObject* nobj = |
| 409 |
object.is<NativeObject>() ? &object.as<NativeObject>() : nullptr) { |
| 410 |
j.beginListProperty("flags"); |
| 411 |
{ |
| 412 |
if (nobj->isIndexed()) { |
| 413 |
j.value("indexed"); |
| 414 |
} |
| 415 |
if (nobj->inDictionaryMode()) { |
| 416 |
j.value("dictionaryMode"); |
| 417 |
} |
| 418 |
} |
| 419 |
j.endList(); |
| 420 |
if (nobj->isIndexed()) { |
| 421 |
j.beginObjectProperty("indexed"); |
| 422 |
{ |
| 423 |
j.property("denseInitializedLength", |
| 424 |
nobj->getDenseInitializedLength()); |
| 425 |
j.property("denseCapacity", nobj->getDenseCapacity()); |
| 426 |
j.property("denseElementsAreSealed", nobj->denseElementsAreSealed()); |
| 427 |
j.property("denseElementsAreFrozen", nobj->denseElementsAreFrozen()); |
| 428 |
} |
| 429 |
j.endObject(); |
| 430 |
} |
| 431 |
} |
| 432 |
} |
| 433 |
|
| 434 |
j.endObject(); |
| 435 |
} |
| 436 |
|
| 437 |
void CacheIRSpewer::opcodeProperty(const char* name, const JSOp op) { |
| 438 |
MOZ_ASSERT(enabled()); |
| 439 |
JSONPrinter& j = json_.ref(); |
| 440 |
|
| 441 |
j.beginStringProperty(name); |
| 442 |
output_.put(CodeName(op)); |
| 443 |
j.endStringProperty(); |
| 444 |
} |
| 445 |
|
| 446 |
void CacheIRSpewer::jstypeProperty(const char* name, const JSType type) { |
| 447 |
MOZ_ASSERT(enabled()); |
| 448 |
JSONPrinter& j = json_.ref(); |
| 449 |
|
| 450 |
j.beginStringProperty(name); |
| 451 |
output_.put(JSTypeToString(type)); |
| 452 |
j.endStringProperty(); |
| 453 |
} |
| 454 |
|
| 455 |
void CacheIRSpewer::cacheIRSequence(CacheIRReader& reader) { |
| 456 |
MOZ_ASSERT(enabled()); |
| 457 |
JSONPrinter& j = json_.ref(); |
| 458 |
|
| 459 |
j.beginListProperty("cacheIR"); |
| 460 |
|
| 461 |
CacheIROpsJSONSpewer spewer(j); |
| 462 |
spewer.spew(reader); |
| 463 |
|
| 464 |
j.endList(); |
| 465 |
} |
| 466 |
|
| 467 |
void CacheIRSpewer::attached(const char* name) { |
| 468 |
MOZ_ASSERT(enabled()); |
| 469 |
json_.ref().property("attached", name); |
| 470 |
} |
| 471 |
|
| 472 |
void CacheIRSpewer::endCache() { |
| 473 |
MOZ_ASSERT(enabled()); |
| 474 |
json_.ref().endObject(); |
| 475 |
} |
| 476 |
|
| 477 |
#endif /* JS_CACHEIR_SPEW */ |
| 478 |
|
| 479 |
#ifdef ENABLE_JS_AOT_ICS |
| 480 |
|
| 481 |
// Note: for several of the functions below that return string |
| 482 |
// representations of enums, it's important to keep the strings below |
| 483 |
// *exactly* in sync with the names of the defined constants. The string |
| 484 |
// that this function returns is used to generate the checked-in corpus |
| 485 |
// source code. |
| 486 |
|
| 487 |
static const char* JSValueTypeToString(JSValueType type) { |
| 488 |
switch (type) { |
| 489 |
case JSVAL_TYPE_DOUBLE: |
| 490 |
return "JSVAL_TYPE_DOUBLE"; |
| 491 |
case JSVAL_TYPE_INT32: |
| 492 |
return "JSVAL_TYPE_INT32"; |
| 493 |
case JSVAL_TYPE_BOOLEAN: |
| 494 |
return "JSVAL_TYPE_BOOLEAN"; |
| 495 |
case JSVAL_TYPE_UNDEFINED: |
| 496 |
return "JSVAL_TYPE_UNDEFINED"; |
| 497 |
case JSVAL_TYPE_NULL: |
| 498 |
return "JSVAL_TYPE_NULL"; |
| 499 |
case JSVAL_TYPE_MAGIC: |
| 500 |
return "JSVAL_TYPE_MAGIC"; |
| 501 |
case JSVAL_TYPE_STRING: |
| 502 |
return "JSVAL_TYPE_STRING"; |
| 503 |
case JSVAL_TYPE_SYMBOL: |
| 504 |
return "JSVAL_TYPE_SYMBOL"; |
| 505 |
case JSVAL_TYPE_PRIVATE_GCTHING: |
| 506 |
return "JSVAL_TYPE_PRIVATE_GCTHING"; |
| 507 |
case JSVAL_TYPE_BIGINT: |
| 508 |
return "JSVAL_TYPE_BIGINT"; |
| 509 |
case JSVAL_TYPE_OBJECT: |
| 510 |
return "JSVAL_TYPE_OBJECT"; |
| 511 |
case JSVAL_TYPE_UNKNOWN: |
| 512 |
return "JSVAL_TYPE_UNKNOWN"; |
| 513 |
} |
| 514 |
MOZ_CRASH("Unknown JSValueType"); |
| 515 |
} |
| 516 |
|
| 517 |
static const char* ArrayBufferViewKindName(ArrayBufferViewKind kind) { |
| 518 |
switch (kind) { |
| 519 |
case ArrayBufferViewKind::FixedLength: |
| 520 |
return "FixedLength"; |
| 521 |
case ArrayBufferViewKind::Resizable: |
| 522 |
return "Resizable"; |
| 523 |
} |
| 524 |
MOZ_CRASH("Unknown ArrayBufferViewKind"); |
| 525 |
} |
| 526 |
|
| 527 |
// Text spewer for CacheIR ops that produces output that can be included |
| 528 |
// in the AOT IC corpus. |
| 529 |
// |
| 530 |
// Output looks like this: |
| 531 |
// |
| 532 |
// OP(GuardToInt32) ID(0) ID(2) |
| 533 |
// OP(GuardToInt32) ID(1) ID(3) |
| 534 |
// OP(CompareInt32Result) JSOP(Lt) ID(2) ID(3) |
| 535 |
// OP(ReturnFromIC) |
| 536 |
// |
| 537 |
// The output is meant to be interpreted in the context of defined |
| 538 |
// preprocessor macros to reproduce the CacheIR bytecode. |
| 539 |
class MOZ_RAII CacheIROpsAotSpewer { |
| 540 |
GenericPrinter& out_; |
| 541 |
|
| 542 |
CACHE_IR_SPEWER_GENERATED |
| 543 |
|
| 544 |
void spewOp(CacheOp op) { |
| 545 |
const char* opName = CacheIROpNames[size_t(op)]; |
| 546 |
out_.printf("OP(%s) ", opName); |
| 547 |
} |
| 548 |
void spewOpEnd() { out_.printf(" "); } |
| 549 |
|
| 550 |
void spewArgSeparator() { out_.printf(" "); } |
| 551 |
|
| 552 |
void spewOperandId(const char* name, OperandId id) { |
| 553 |
spewRawOperandId(name, id.id()); |
| 554 |
} |
| 555 |
void spewRawOperandId(const char* name, uint32_t id) { |
| 556 |
(void)name; |
| 557 |
out_.printf("ID(%u)", id); |
| 558 |
} |
| 559 |
void spewField(const char* name, uint32_t offset) { |
| 560 |
(void)name; |
| 561 |
out_.printf("OFFSET(%d)", int(offset / sizeof(uintptr_t))); |
| 562 |
} |
| 563 |
void spewBoolImm(const char* name, bool b) { |
| 564 |
(void)name; |
| 565 |
out_.printf("BOOL(%d)", b ? 1 : 0); |
| 566 |
} |
| 567 |
void spewByteImm(const char* name, uint8_t val) { |
| 568 |
(void)name; |
| 569 |
out_.printf("BYTE(%u)", val); |
| 570 |
} |
| 571 |
void spewJSOpImm(const char* name, JSOp op) { |
| 572 |
(void)name; |
| 573 |
out_.printf("JSOP(%s)", CodeName(op)); |
| 574 |
} |
| 575 |
void spewTypeofEqOperandImm(const char* name, TypeofEqOperand operand) { |
| 576 |
(void)name; |
| 577 |
out_.printf(name, "TYPEOFEQOPERAND(%u)", operand.rawValue()); |
| 578 |
} |
| 579 |
void spewStaticStringImm(const char* name, const char* str) { |
| 580 |
(void)name; |
| 581 |
out_.printf("STATICSTRING(\"%s\")", str); |
| 582 |
} |
| 583 |
void spewInt32Imm(const char* name, int32_t val) { |
| 584 |
(void)name; |
| 585 |
out_.printf("INT32(%d)", val); |
| 586 |
} |
| 587 |
void spewUInt32Imm(const char* name, uint32_t val) { |
| 588 |
(void)name; |
| 589 |
out_.printf("UINT32(%u)", val); |
| 590 |
} |
| 591 |
void spewCallFlagsImm(const char* name, CallFlags flags) { |
| 592 |
(void)name; |
| 593 |
out_.printf("CALLFLAGS(%u)", flags.toByte()); |
| 594 |
} |
| 595 |
void spewJSWhyMagicImm(const char* name, JSWhyMagic magic) { |
| 596 |
(void)name; |
| 597 |
out_.printf("WHYMAGIC(%u)", unsigned(magic)); |
| 598 |
} |
| 599 |
void spewScalarTypeImm(const char* name, Scalar::Type type) { |
| 600 |
(void)name; |
| 601 |
out_.printf("SCALARTYPE(%s)", Scalar::name(type)); |
| 602 |
} |
| 603 |
void spewUnaryMathFunctionImm(const char* name, UnaryMathFunction fun) { |
| 604 |
(void)name; |
| 605 |
const char* funName = GetUnaryMathFunctionName(fun, true); |
| 606 |
out_.printf("UNARYMATHFUNC(%s)", funName); |
| 607 |
} |
| 608 |
void spewValueTypeImm(const char* name, ValueType type) { |
| 609 |
(void)name; |
| 610 |
out_.printf("VALUETYPE(%s)", |
| 611 |
JSValueTypeToString(static_cast<JSValueType>(type))); |
| 612 |
} |
| 613 |
void spewJSNativeImm(const char* name, JSNative native) { |
| 614 |
(void)name; |
| 615 |
out_.printf("NATIVEIMM(%p)", native); |
| 616 |
} |
| 617 |
void spewGuardClassKindImm(const char* name, GuardClassKind kind) { |
| 618 |
(void)name; |
| 619 |
out_.printf("GUARDCLASSKIND(%s)", GuardClassKindEnumName(kind)); |
| 620 |
} |
| 621 |
void spewArrayBufferViewKindImm(const char* name, ArrayBufferViewKind kind) { |
| 622 |
(void)name; |
| 623 |
out_.printf("ARRAYBUFFERVIEWKIND(%s)", ArrayBufferViewKindName(kind)); |
| 624 |
} |
| 625 |
void spewWasmValTypeImm(const char* name, wasm::ValType::Kind kind) { |
| 626 |
(void)name; |
| 627 |
out_.printf("WASMVALTYPE(%s)", wasm::ValTypeTraits::KindEnumName(kind)); |
| 628 |
} |
| 629 |
void spewAllocKindImm(const char* name, gc::AllocKind kind) { |
| 630 |
(void)name; |
| 631 |
out_.printf("ALLOCKIND(%s)", js::gc::AllocKindName(kind)); |
| 632 |
} |
| 633 |
void spewCompletionKindImm(const char* name, CompletionKind kind) { |
| 634 |
(void)name; |
| 635 |
out_.printf("COMPLETIONKIND(%s)", CompletionKindName(kind)); |
| 636 |
} |
| 637 |
void spewRealmFuseIndexImm(const char* name, RealmFuses::FuseIndex index) { |
| 638 |
(void)name; |
| 639 |
out_.printf("REALMFUSE(%u)", unsigned(index)); |
| 640 |
} |
| 641 |
|
| 642 |
public: |
| 643 |
CacheIROpsAotSpewer(GenericPrinter& out) : out_(out) {} |
| 644 |
|
| 645 |
void spew(CacheIRReader& reader) { |
| 646 |
do { |
| 647 |
switch (reader.readOp()) { |
| 648 |
# define SPEW_OP(op, ...) \ |
| 649 |
case CacheOp::op: \ |
| 650 |
spew##op(reader); \ |
| 651 |
break; |
| 652 |
CACHE_IR_OPS(SPEW_OP) |
| 653 |
# undef SPEW_OP |
| 654 |
|
| 655 |
default: |
| 656 |
MOZ_CRASH("Invalid op"); |
| 657 |
} |
| 658 |
} while (reader.more()); |
| 659 |
} |
| 660 |
}; |
| 661 |
|
| 662 |
void js::jit::SpewCacheIROpsAsAOT(GenericPrinter& out, CacheKind kind, |
| 663 |
const CacheIRWriter& writer) { |
| 664 |
// Fields, comma-separated: |
| 665 |
// - kind |
| 666 |
// - numOperandIds (u32) |
| 667 |
// - numInputOperands (u32) |
| 668 |
// - numInstructions (u32) |
| 669 |
// - typeData (TypeData aka JSValueType) |
| 670 |
// - stubDataSize (u32) |
| 671 |
// - stubFields (list of (StubField::Type, u64)) |
| 672 |
// - operandLastUsed (list of u32) |
| 673 |
out.printf("%s, %u, %u, %u, %s, %u, ", CacheKindNames[size_t(kind)], |
| 674 |
writer.numInputOperands(), writer.numOperandIds(), |
| 675 |
writer.numInstructions(), |
| 676 |
JSValueTypeToString(writer.typeData().type()), |
| 677 |
uint32_t(writer.stubDataSize())); |
| 678 |
|
| 679 |
for (uint32_t i = 0; i < writer.numStubFields(); i++) { |
| 680 |
auto field = writer.stubField(i); |
| 681 |
out.printf("STUBFIELD(%s) ", StubFieldTypeName(field.type())); |
| 682 |
} |
| 683 |
out.printf(", "); |
| 684 |
|
| 685 |
for (uint32_t i = 0; i < writer.numOperandIds(); i++) { |
| 686 |
out.printf("LASTUSED(%u) ", writer.operandLastUsed(i)); |
| 687 |
} |
| 688 |
out.printf(", "); |
| 689 |
|
| 690 |
CacheIRReader reader(writer.codeStart(), writer.codeEnd()); |
| 691 |
CacheIROpsAotSpewer spewer(out); |
| 692 |
spewer.spew(reader); |
| 693 |
out.printf("\n"); |
| 694 |
} |
| 695 |
|
| 696 |
#endif /* ENABLE_JS_AOT_ICS */ |