| 1 |
/*========================== begin_copyright_notice ============================ |
| 2 |
|
| 3 |
Copyright (C) 2021 Intel Corporation |
| 4 |
|
| 5 |
SPDX-License-Identifier: MIT |
| 6 |
|
| 7 |
============================= end_copyright_notice ===========================*/ |
| 8 |
|
| 9 |
#include "FormatterJSON.hpp" |
| 10 |
#include "../IR/Messages.hpp" |
| 11 |
#include "IRToString.hpp" |
| 12 |
|
| 13 |
#include <unordered_map> |
| 14 |
|
| 15 |
using namespace iga; |
| 16 |
|
| 17 |
class JSONFormatterV1 : public BasicFormatter { |
| 18 |
protected: |
| 19 |
const Model &model; |
| 20 |
const FormatOpts &opts; |
| 21 |
const uint8_t *bits; |
| 22 |
int currIndent = 2; |
| 23 |
|
| 24 |
// map instruction ID to all def/use pairs |
| 25 |
using DUMap = std::unordered_map<int, std::vector<const Dep *>>; |
| 26 |
DUMap depDefs; |
| 27 |
DUMap depUses; |
| 28 |
|
| 29 |
const RegSet EMPTY_SET; |
| 30 |
|
| 31 |
public: |
| 32 |
JSONFormatterV1(std::ostream &o, const FormatOpts &os, const void *bs) |
| 33 |
: BasicFormatter(false, o), model(os.model), opts(os), |
| 34 |
bits((const uint8_t *)bs), EMPTY_SET(os.model) { |
| 35 |
o << std::boolalpha; |
| 36 |
if (opts.liveAnalysis) { |
| 37 |
for (const Dep &d : opts.liveAnalysis->deps) { |
| 38 |
if (d.def != nullptr) { |
| 39 |
depDefs[d.def->getID()].emplace_back(&d); |
| 40 |
} |
| 41 |
if (d.use != nullptr) { |
| 42 |
depUses[d.use->getID()].emplace_back(&d); |
| 43 |
} |
| 44 |
} |
| 45 |
} |
| 46 |
} |
| 47 |
Platform platform() const { return model.platform; } |
| 48 |
|
| 49 |
// emits an error value that'll blow up on JSON load |
| 50 |
void emitIrError(const char *what) { emit("IR.Error(\"", what, "\")"); } |
| 51 |
|
| 52 |
void emitEscaped(const std::string &s) { |
| 53 |
for (size_t i = 0; i < s.size(); i++) { |
| 54 |
switch (s[i]) { |
| 55 |
case '\n': |
| 56 |
emit("\\n"); |
| 57 |
break; |
| 58 |
case '\t': |
| 59 |
emit("\\t"); |
| 60 |
break; |
| 61 |
case '\v': |
| 62 |
emit("\\v"); |
| 63 |
break; |
| 64 |
case '\f': |
| 65 |
emit("\\f"); |
| 66 |
break; |
| 67 |
case '\a': |
| 68 |
emit("\\a"); |
| 69 |
break; |
| 70 |
case '\"': |
| 71 |
emit("\\\""); |
| 72 |
break; |
| 73 |
case '\\': |
| 74 |
emit("\\\\"); |
| 75 |
break; |
| 76 |
default: |
| 77 |
emit(s[i]); |
| 78 |
break; |
| 79 |
} |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
void emitIndent() { |
| 84 |
for (int i = 0; i < currIndent; i++) |
| 85 |
emit(' '); |
| 86 |
} |
| 87 |
void withIndent(const std::function<void()> &f) { |
| 88 |
currIndent += 2; |
| 89 |
f(); |
| 90 |
currIndent -= 2; |
| 91 |
} |
| 92 |
|
| 93 |
void emitLabel(int32_t pc) { |
| 94 |
bool printed = false; |
| 95 |
if (opts.labeler) { |
| 96 |
const char *usrL = opts.labeler(pc, opts.labelerContext); |
| 97 |
if (usrL) { |
| 98 |
printed = true; |
| 99 |
emit(usrL); |
| 100 |
} |
| 101 |
} |
| 102 |
if (!printed) { |
| 103 |
std::stringstream ss; |
| 104 |
ss << std::setw(4) << std::dec << std::setfill('0') << pc; |
| 105 |
emit("L", ss.str()); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
void emitKernel(const Kernel &k) { |
| 110 |
emit("{\n"); |
| 111 |
emit(" \"version\":\"1.0\","); |
| 112 |
emit(" \"platform\":\"", model.names[0].str(), "\","); |
| 113 |
emit(" \"insts\":[\n"); |
| 114 |
currIndent += 2; |
| 115 |
|
| 116 |
for (const Block *b : k.getBlockList()) { |
| 117 |
emitIndent(); |
| 118 |
emit("{\"kind\":\"L\""); |
| 119 |
emit(",\"value\":\""); |
| 120 |
emitLabel(b->getPC()); |
| 121 |
emit("\""); |
| 122 |
if (opts.printInstPc) { |
| 123 |
emit(",\"pc\":", b->getPC()); |
| 124 |
} |
| 125 |
emit("}"); |
| 126 |
if (b != k.getBlockList().back() || !b->getInstList().empty()) |
| 127 |
emit(","); |
| 128 |
emit("\n"); |
| 129 |
|
| 130 |
for (const Instruction *iP : b->getInstList()) { |
| 131 |
emitInst(*iP); |
| 132 |
if (iP != b->getInstList().back() || b != k.getBlockList().back()) |
| 133 |
emit(","); |
| 134 |
emit("\n"); |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
emit(" ]\n"); |
| 139 |
currIndent -= 2; |
| 140 |
emit("}\n"); |
| 141 |
emit("\n"); |
| 142 |
} |
| 143 |
|
| 144 |
std::vector<std::string> comments; |
| 145 |
|
| 146 |
void emitInst(const Instruction &i) { |
| 147 |
comments.clear(); |
| 148 |
|
| 149 |
// const bool isSend = i.getOpSpec().isAnySendFormat(); |
| 150 |
emitIndent(); |
| 151 |
emit("{"); |
| 152 |
emit("\"kind\":\"I\""); |
| 153 |
emit(", \"id\":", i.getID()); |
| 154 |
if (opts.printInstPc) { |
| 155 |
emit(", \"pc\":", i.getPC()); |
| 156 |
} |
| 157 |
|
| 158 |
if (opts.printLdSt) { |
| 159 |
if (!emitLdStInst(i)) { |
| 160 |
emitNormalInst(i); |
| 161 |
} |
| 162 |
} else { |
| 163 |
emitNormalInst(i); |
| 164 |
} |
| 165 |
|
| 166 |
if (platform() >= Platform::XE) { |
| 167 |
emitRegDist(i.getSWSB()); |
| 168 |
emitSbid(i.getSWSB()); |
| 169 |
} else { |
| 170 |
emit(", \"regDist\":null, \"sbid\":null"); |
| 171 |
} |
| 172 |
emitInstOpts(i); |
| 173 |
|
| 174 |
bool printBits = opts.printInstBits && bits != nullptr; |
| 175 |
if (printBits) { |
| 176 |
emit(", \"encoding\":"); |
| 177 |
const uint32_t *instBits = (const uint32_t *)(bits + i.getPC()); |
| 178 |
emit('\"'); |
| 179 |
if (!i.hasInstOpt(InstOpt::COMPACTED)) { |
| 180 |
emitHex(instBits[3], 8); |
| 181 |
emit('`'); |
| 182 |
emitHex(instBits[2], 8); |
| 183 |
emit('`'); |
| 184 |
} |
| 185 |
emitHex(instBits[1], 8); |
| 186 |
emit('`'); |
| 187 |
emitHex(instBits[0], 8); |
| 188 |
emit('\"'); |
| 189 |
} |
| 190 |
|
| 191 |
if (opts.printInstDefs && opts.liveAnalysis && |
| 192 |
!opts.liveAnalysis->sums.empty()) { |
| 193 |
emit(", \"liveTotals\":{"); |
| 194 |
const auto &totals = opts.liveAnalysis->sums[i.getID()]; |
| 195 |
emit("\"r\":", totals.grfBytes, ","); |
| 196 |
emit("\"acc\":", totals.accBytes, ","); |
| 197 |
emit("\"s\":", totals.scalarBytes, ","); |
| 198 |
emit("\"f\":", totals.flagBytes, ","); |
| 199 |
emit("\"a\":", totals.indexBytes); |
| 200 |
emit("}"); |
| 201 |
} |
| 202 |
|
| 203 |
emit(", \"comment\":"); |
| 204 |
if (comments.empty()) { |
| 205 |
emit("null"); |
| 206 |
} else { |
| 207 |
emit("\""); |
| 208 |
for (size_t i = 0; i < comments.size(); i++) { |
| 209 |
if (i > 0) |
| 210 |
emit("; "); |
| 211 |
emitEscaped(comments[i]); |
| 212 |
} |
| 213 |
emit("\""); |
| 214 |
} |
| 215 |
emit("}"); |
| 216 |
} |
| 217 |
|
| 218 |
void emitNormalInst(const Instruction &i) { |
| 219 |
std::string subfunc; |
| 220 |
switch (i.getOpSpec().op) { |
| 221 |
case Op::MATH: |
| 222 |
subfunc = ToSyntax(i.getSubfunction().math); |
| 223 |
break; |
| 224 |
case Op::SEND: |
| 225 |
subfunc = ToSyntax(i.getSubfunction().send); |
| 226 |
break; |
| 227 |
case Op::SENDC: |
| 228 |
subfunc = ToSyntax(i.getSubfunction().send); |
| 229 |
break; |
| 230 |
case Op::SYNC: |
| 231 |
subfunc = ToSyntax(i.getSubfunction().sync); |
| 232 |
break; |
| 233 |
case Op::BFN: |
| 234 |
if (opts.syntaxBfnSymbolicFunctions) { |
| 235 |
// decode binary function names to symbolic |
| 236 |
// bfn.(s0&s1|~s2) |
| 237 |
subfunc += "("; |
| 238 |
subfunc += i.getBfnFc().c_str(); |
| 239 |
subfunc += ")"; |
| 240 |
} else { |
| 241 |
// use a raw value |
| 242 |
// emit<uint32_t>(i.getBfnFc().value); |
| 243 |
subfunc = fmtHex((int)i.getBfnFc().value, 2); |
| 244 |
} |
| 245 |
break; |
| 246 |
case Op::DPASW: |
| 247 |
case Op::DPAS: |
| 248 |
case Op::BDPAS: |
| 249 |
subfunc = ToSyntax(i.getDpasFc()); |
| 250 |
break; |
| 251 |
default: |
| 252 |
break; |
| 253 |
} |
| 254 |
|
| 255 |
emitPredOpSubfuncExecInfoFlagReg(i, i.getOpSpec().mnemonic.str(), subfunc); |
| 256 |
// implicit accumulator def/uses |
| 257 |
emit(", \"other\":"); |
| 258 |
if (opts.liveAnalysis) { |
| 259 |
emit("{"); |
| 260 |
RegSet accIn(model); |
| 261 |
accIn.addSourceImplicit(i); |
| 262 |
emitDepInputs(i, accIn); |
| 263 |
// RegSet accOu(model); |
| 264 |
// accOu.addDestinationImplicitAccumulator(i); |
| 265 |
// emit(", "); emitDepOutputs(i, accOu); |
| 266 |
emit("}"); |
| 267 |
} else { |
| 268 |
emit("null"); |
| 269 |
} |
| 270 |
|
| 271 |
emit(",\n"); |
| 272 |
|
| 273 |
withIndent([&] { |
| 274 |
emitIndent(); |
| 275 |
emit("\"dst\":"); |
| 276 |
emitDst(i); |
| 277 |
emit(",\n"); |
| 278 |
emitIndent(); |
| 279 |
emit("\"srcs\":[\n"); |
| 280 |
withIndent([&] { |
| 281 |
for (unsigned srcIx = 0; srcIx < i.getSourceCount(); srcIx++) { |
| 282 |
emitIndent(); |
| 283 |
emitSrc(i, srcIx); |
| 284 |
if (srcIx != i.getSourceCount() - 1) |
| 285 |
emit(",\n"); |
| 286 |
} |
| 287 |
// if it's a send, create fake extra send parameters |
| 288 |
if (i.getOpSpec().isAnySendFormat()) { |
| 289 |
auto emitDesc = [&](SendDesc sd) { |
| 290 |
emit(",\n"); |
| 291 |
emitIndent(); |
| 292 |
emit("{"); |
| 293 |
RegSet rs(model); |
| 294 |
if (sd.type == SendDesc::Kind::REG32A) { |
| 295 |
emitKindField(Operand::Kind::DIRECT); |
| 296 |
emit(", \"reg\":"); |
| 297 |
emitReg(RegName::ARF_A, sd.reg); |
| 298 |
rs.setSrcRegion(RegName::ARF_A, sd.reg, Region::SRC010, 1, 4); |
| 299 |
} else { |
| 300 |
emitKindField(Operand::Kind::IMMEDIATE); |
| 301 |
emit(", \"value\":\""); |
| 302 |
emitHex(sd.imm); |
| 303 |
emit("\""); |
| 304 |
} |
| 305 |
emit(", \"rgn\":null"); |
| 306 |
emit(", \"type\":null"); |
| 307 |
emit(", "); |
| 308 |
emitDepInputs(i, rs); |
| 309 |
emit("}"); |
| 310 |
}; |
| 311 |
emitDesc(i.getExtMsgDescriptor()); |
| 312 |
emitDesc(i.getMsgDescriptor()); |
| 313 |
} |
| 314 |
}); |
| 315 |
emit("\n"); |
| 316 |
emitIndent(); |
| 317 |
emit("]"); |
| 318 |
}); |
| 319 |
} |
| 320 |
|
| 321 |
///////////////////////////////////////////////////////////////////////// |
| 322 |
bool emitLdStInst(const Instruction &i) { |
| 323 |
const auto desc = i.getMsgDescriptor(); |
| 324 |
if (desc.isReg()) { |
| 325 |
// given a register descriptor, we've no hope of decoding the op |
| 326 |
// TODO: once we have dataflow values maybe we can... |
| 327 |
return false; |
| 328 |
} |
| 329 |
const auto exDesc = i.getExtMsgDescriptor(); |
| 330 |
const auto sfid = i.getSendFc(); |
| 331 |
const auto di = tryDecode(platform(), sfid, i.getExecSize(), |
| 332 |
i.getExtImmOffDescriptor(), |
| 333 |
exDesc, desc, nullptr); |
| 334 |
if (!di) { |
| 335 |
// if message decode failed fallback to the canonical send syntax |
| 336 |
return false; |
| 337 |
} else if (!sendOpSupportsSyntax(platform(), di.info.op, sfid)) { |
| 338 |
// if decode succeeded but the syntax isn't supported, then bail |
| 339 |
return false; |
| 340 |
} |
| 341 |
|
| 342 |
emitPredOpSubfuncExecInfoFlagReg(i, di.syntax.mnemonic, di.syntax.controls); |
| 343 |
|
| 344 |
emit(",\n"); |
| 345 |
withIndent([&] { |
| 346 |
emitIndent(); |
| 347 |
if (!di.syntax.isStore()) { |
| 348 |
// there is an explicit destination |
| 349 |
const Operand &dst = i.getDestination(); |
| 350 |
emit("\"dst\":{"); |
| 351 |
emitSendDataRegDst(i, dst.getDirRegName(), dst.getDirRegRef().regNum, |
| 352 |
i.getDstLength()); |
| 353 |
emit("}"); |
| 354 |
|
| 355 |
} else { |
| 356 |
emit("\"dst\":null"); |
| 357 |
} |
| 358 |
emit(",\n"); |
| 359 |
|
| 360 |
///////////////////////////////////////////// |
| 361 |
// sources |
| 362 |
emitIndent(); |
| 363 |
emit("\"srcs\":[\n"); |
| 364 |
withIndent([&] { |
| 365 |
// everyone has src0 as an address |
| 366 |
emitIndent(); |
| 367 |
emit("{\"kind\":\"AD\""); |
| 368 |
// |
| 369 |
emit(", \"surf\":"); |
| 370 |
emitAddrSurfInfo(i, di.info); |
| 371 |
// |
| 372 |
emit(", \"scale\":1"); |
| 373 |
emit(", \"addr\":"); |
| 374 |
emitSendPayloadSrc(i, 0); |
| 375 |
|
| 376 |
emit(", \"offset\":"); |
| 377 |
emit(di.info.immediateOffset); |
| 378 |
emit("},\n"); |
| 379 |
|
| 380 |
////////////////////////////////////// |
| 381 |
// src1 (if not the old unary send) |
| 382 |
if (i.getSourceCount() > 1) { |
| 383 |
emitIndent(); |
| 384 |
emitSendPayloadSrc(i, 1, "DA"); |
| 385 |
emit("\n"); |
| 386 |
} |
| 387 |
}); |
| 388 |
|
| 389 |
emitIndent(); |
| 390 |
emit("]"); // end of srcs:[..] |
| 391 |
}); |
| 392 |
|
| 393 |
return true; |
| 394 |
} |
| 395 |
|
| 396 |
///////////////////////////////////////////////////////////////////////// |
| 397 |
// op+subfunc+exec size and exec offset |
| 398 |
void emitPredOpSubfuncExecInfoFlagReg(const Instruction &i, |
| 399 |
const std::string& mnemonic, |
| 400 |
const std::string& subop) { |
| 401 |
emitPred(i); |
| 402 |
|
| 403 |
emit(", \"op\":\"", mnemonic, "\""); |
| 404 |
if (subop.empty()) { |
| 405 |
emit(", \"subop\":null"); |
| 406 |
} else { |
| 407 |
const auto& sf = subop[0] == '.' ? subop.substr(1) : subop; |
| 408 |
emit(", \"subop\":\"", sf, "\""); |
| 409 |
} |
| 410 |
|
| 411 |
emitExecInfo(i); |
| 412 |
|
| 413 |
if (i.hasFlagModifier()) { |
| 414 |
emit(", \"fm\":{\"cond\":\"", ToSyntax(i.getFlagModifier()), "\""); |
| 415 |
// emit(", "); |
| 416 |
// RegSet rs(model); |
| 417 |
// rs.addFlagModifierOutputs(i); |
| 418 |
// emitDepOutputs(i, rs); |
| 419 |
emit("}"); |
| 420 |
} else { |
| 421 |
emit(", \"fm\":null"); |
| 422 |
} |
| 423 |
|
| 424 |
emitFlagReg(i); |
| 425 |
} |
| 426 |
|
| 427 |
void emitExecInfo(const Instruction &i) { |
| 428 |
emit(", \"es\":", ToSyntax(i.getExecSize())); |
| 429 |
emit(", \"eo\":", 4 * (int)(i.getChannelOffset())); |
| 430 |
} |
| 431 |
|
| 432 |
// pred:{func:[null|""|".any"|".all"|...],inv:[true|false]"",wren:[true|false]} |
| 433 |
void emitPred(const Instruction &i) { |
| 434 |
Predication p = i.getPredication(); |
| 435 |
emit(", \"pred\":"); |
| 436 |
if (i.hasPredication()) { |
| 437 |
emit("{"); |
| 438 |
emit("\"inv\":", p.inverse); |
| 439 |
emit(", \"func\":\"", ToSyntax(p.function), "\""); |
| 440 |
emit(", "); |
| 441 |
RegSet rs(model); |
| 442 |
rs.addPredicationInputs(i); |
| 443 |
emitDepInputs(i, rs); |
| 444 |
emit("}"); |
| 445 |
// TODO: handle SEL |
| 446 |
} else { |
| 447 |
emit("null"); |
| 448 |
} |
| 449 |
// |
| 450 |
emit(", \"wren\":", i.getMaskCtrl() == MaskCtrl::NOMASK); |
| 451 |
} |
| 452 |
|
| 453 |
// {flag:{reg:...}} |
| 454 |
void emitFlagReg(const Instruction &i) { |
| 455 |
emit(", \"freg\":"); |
| 456 |
if (i.hasPredication() || (i.hasFlagModifier() && !i.is(Op::SEL))) { |
| 457 |
emitReg(RegName::ARF_F, i.getFlagReg()); |
| 458 |
} else { |
| 459 |
emit("null"); |
| 460 |
} |
| 461 |
} |
| 462 |
|
| 463 |
// dst:{kind=..., REST, sat:T|F, defs:..., uses:...} |
| 464 |
// REST: if kind == R (direct) |
| 465 |
// reg:IR.Regs.r13 or Regs.r(r13,4) |
| 466 |
// rgn:IR.Rgns.DST1 |
| 467 |
// type:IR.Types.D |
| 468 |
void emitDst(const Instruction &i) { |
| 469 |
const OpSpec &os = i.getOpSpec(); |
| 470 |
if (os.isAnySendFormat()) { |
| 471 |
emitSendDst(i); |
| 472 |
return; |
| 473 |
} |
| 474 |
const Operand &dst = i.getDestination(); |
| 475 |
if (!i.getOpSpec().supportsDestination()) { |
| 476 |
emit("null"); |
| 477 |
return; |
| 478 |
} |
| 479 |
|
| 480 |
emit("{"); |
| 481 |
emitKindField(dst.getKind()); |
| 482 |
switch (dst.getKind()) { |
| 483 |
case Operand::Kind::DIRECT: |
| 484 |
emit(", \"reg\":"); |
| 485 |
emitReg(dst.getDirRegName(), dst.getDirRegRef()); |
| 486 |
break; |
| 487 |
case Operand::Kind::MACRO: |
| 488 |
emit(", \"reg\":"); |
| 489 |
emitReg(dst.getDirRegName(), dst.getDirRegRef()); |
| 490 |
emit(", "); |
| 491 |
emitMathMacroExtField(dst.getMathMacroExt()); |
| 492 |
break; |
| 493 |
case Operand::Kind::INDIRECT: |
| 494 |
emit(", \"areg\":"); |
| 495 |
emitReg(RegName::ARF_A, dst.getIndAddrReg()); |
| 496 |
emit(", \"aoff\":", dst.getIndImmAddr()); |
| 497 |
break; |
| 498 |
default: |
| 499 |
break; |
| 500 |
} |
| 501 |
emit(", \"sat\":", dst.getDstModifier() == DstModifier::SAT); |
| 502 |
emit(", \"rgn\":"); |
| 503 |
if (os.hasImplicitDstRegion(i.isMacro())) { |
| 504 |
emit("null"); |
| 505 |
} else { |
| 506 |
emitRgn(i, dst.getRegion(), true); |
| 507 |
} |
| 508 |
emit(", \"type\":"); |
| 509 |
emitType(dst.getType()); |
| 510 |
|
| 511 |
// def/uses |
| 512 |
emit(","); |
| 513 |
RegSet rs(model); |
| 514 |
rs.addDestinationInputs(i); |
| 515 |
emitDepInputs(i, rs); |
| 516 |
emit("}"); |
| 517 |
} |
| 518 |
|
| 519 |
void emitMathMacroExtField(MathMacroExt mme) { |
| 520 |
emit("\"mme\":\"", ToSyntax(mme).substr(1), "\""); |
| 521 |
} |
| 522 |
|
| 523 |
void emitSrc(const Instruction &i, int srcIx) { |
| 524 |
const OpSpec &os = i.getOpSpec(); |
| 525 |
if (os.isAnySendFormat()) { |
| 526 |
emitSendSrc(i, srcIx); |
| 527 |
return; |
| 528 |
} |
| 529 |
const Operand &src = i.getSource(srcIx); |
| 530 |
emit("{"); |
| 531 |
emitKindField(src.getKind()); |
| 532 |
bool immOrLbl = false; |
| 533 |
switch (src.getKind()) { |
| 534 |
case Operand::Kind::DIRECT: |
| 535 |
emitSrcModifierField(src.getSrcModifier()); |
| 536 |
emit(", \"reg\":"); |
| 537 |
emitReg(src.getDirRegName(), src.getDirRegRef()); |
| 538 |
emit(", \"rgn\":"); |
| 539 |
emitSrcRgn(i, srcIx); |
| 540 |
break; |
| 541 |
case Operand::Kind::MACRO: |
| 542 |
emitSrcModifierField(src.getSrcModifier()); |
| 543 |
emit(", \"reg\":"); |
| 544 |
emitReg(src.getDirRegName(), src.getDirRegRef()); |
| 545 |
emit(", "); |
| 546 |
emitMathMacroExtField(src.getMathMacroExt()); |
| 547 |
emit(", \"rgn\":"); |
| 548 |
emitSrcRgn(i, srcIx); |
| 549 |
break; |
| 550 |
case Operand::Kind::INDIRECT: |
| 551 |
emitSrcModifierField(src.getSrcModifier()); |
| 552 |
emit(", \"areg\":"); |
| 553 |
emitReg(RegName::ARF_A, src.getIndAddrReg()); |
| 554 |
emit(", \"aoff\":", src.getIndImmAddr()); |
| 555 |
break; |
| 556 |
case Operand::Kind::IMMEDIATE: { |
| 557 |
emit(", \"value\":\""); |
| 558 |
auto imm = src.getImmediateValue(); |
| 559 |
switch (src.getType()) { |
| 560 |
case Type::UB: |
| 561 |
emitHex(imm.u8); |
| 562 |
break; |
| 563 |
case Type::UW: |
| 564 |
emitHex(imm.u16); |
| 565 |
break; |
| 566 |
case Type::UD: |
| 567 |
emitHex(imm.u32); |
| 568 |
break; |
| 569 |
case Type::UQ: |
| 570 |
emitHex(imm.u64); |
| 571 |
break; |
| 572 |
case Type::B: |
| 573 |
emitDecimal(imm.s8); |
| 574 |
break; |
| 575 |
case Type::W: |
| 576 |
emitDecimal(imm.s16); |
| 577 |
break; |
| 578 |
case Type::D: |
| 579 |
emitDecimal(imm.s32); |
| 580 |
break; |
| 581 |
case Type::Q: |
| 582 |
emitDecimal(imm.s64); |
| 583 |
break; |
| 584 |
case Type::BF: |
| 585 |
emitHex(imm.u16); |
| 586 |
break; |
| 587 |
case Type::HF: |
| 588 |
if (opts.hexFloats) { |
| 589 |
emitHex(imm.u16); |
| 590 |
} else { |
| 591 |
FormatFloat(o, imm.u16); |
| 592 |
} |
| 593 |
break; |
| 594 |
case Type::F: |
| 595 |
case Type::TF32: |
| 596 |
if (opts.hexFloats) { |
| 597 |
emitHex(imm.u32); |
| 598 |
} else { |
| 599 |
emitFloat(imm.f32); |
| 600 |
} |
| 601 |
break; |
| 602 |
case Type::DF: |
| 603 |
if (opts.hexFloats) { |
| 604 |
emitHex(imm.u64); |
| 605 |
} else { |
| 606 |
emitFloat(imm.f64); |
| 607 |
} |
| 608 |
break; |
| 609 |
case Type::BF8: |
| 610 |
case Type::HF8: |
| 611 |
emitHex(imm.u8); |
| 612 |
break; |
| 613 |
case Type::V: |
| 614 |
emitHex(imm.u32); |
| 615 |
break; |
| 616 |
case Type::UV: |
| 617 |
emitHex(imm.u32); |
| 618 |
break; |
| 619 |
case Type::VF: |
| 620 |
emitHex(imm.u32); |
| 621 |
break; |
| 622 |
default: |
| 623 |
emitIrError("invalid type for imm"); |
| 624 |
} |
| 625 |
emit("\""); |
| 626 |
immOrLbl = true; |
| 627 |
break; |
| 628 |
} |
| 629 |
case Operand::Kind::LABEL: { |
| 630 |
const Block *b = src.getTargetBlock(); |
| 631 |
emit(", \"target\":\""); |
| 632 |
emitLabel(b ? b->getPC() : src.getImmediateValue().s32); |
| 633 |
emit("\""); |
| 634 |
immOrLbl = true; |
| 635 |
break; |
| 636 |
} |
| 637 |
default: |
| 638 |
break; |
| 639 |
} |
| 640 |
|
| 641 |
emit(", \"type\":"); |
| 642 |
if (os.hasImplicitSrcType(srcIx, immOrLbl)) { |
| 643 |
emit("null"); |
| 644 |
} else { |
| 645 |
emitType(src.getType()); |
| 646 |
} |
| 647 |
|
| 648 |
// even immediate fields will have this; it'll just be empty |
| 649 |
emit(", "); |
| 650 |
RegSet rs(model); |
| 651 |
rs.addSourceOperandInput(i, srcIx); |
| 652 |
emitDepInputs(i, rs); |
| 653 |
|
| 654 |
emit("}"); |
| 655 |
} |
| 656 |
|
| 657 |
void emitSendDst(const Instruction &i) { |
| 658 |
const Operand &dst = i.getDestination(); |
| 659 |
emit("{"); |
| 660 |
if (i.getDstLength() >= 0) { |
| 661 |
// new style send (r13:4) (take bits from desc) |
| 662 |
emitSendDataRegDst(i, dst.getDirRegName(), dst.getDirRegRef().regNum, |
| 663 |
i.getDstLength()); |
| 664 |
} else { |
| 665 |
emit("\"kind\":\"RD\""); |
| 666 |
emit(", \"reg\":"); |
| 667 |
emitReg(dst.getDirRegName(), dst.getDirRegRef()); |
| 668 |
} |
| 669 |
emit("}"); |
| 670 |
} |
| 671 |
|
| 672 |
void emitSrcModifierField(SrcModifier sm) { |
| 673 |
emit(", \"mods\":", sm == SrcModifier::NEG ? "\"n\"" |
| 674 |
: sm == SrcModifier::ABS ? "\"a\"" |
| 675 |
: sm == SrcModifier::NEG_ABS ? "\"na\"" |
| 676 |
: "\"\""); |
| 677 |
} |
| 678 |
|
| 679 |
void emitKindField(Operand::Kind k) { |
| 680 |
emit("\"kind\":"); |
| 681 |
switch (k) { |
| 682 |
case Operand::Kind::DIRECT: |
| 683 |
emit("\"RD\""); |
| 684 |
break; |
| 685 |
case Operand::Kind::MACRO: |
| 686 |
emit("\"RM\""); |
| 687 |
break; |
| 688 |
case Operand::Kind::INDIRECT: |
| 689 |
emit("\"RI\""); |
| 690 |
break; |
| 691 |
case Operand::Kind::LABEL: |
| 692 |
emit("\"LB\""); |
| 693 |
break; |
| 694 |
case Operand::Kind::IMMEDIATE: |
| 695 |
emit("\"IM\""); |
| 696 |
break; |
| 697 |
default: |
| 698 |
emitIrError("bad operand kind"); |
| 699 |
} |
| 700 |
} |
| 701 |
|
| 702 |
void emitSrcRgn(const Instruction &i, int srcIx) { |
| 703 |
const Operand &src = i.getSource(srcIx); |
| 704 |
if (i.getOpSpec().hasImplicitSrcRegion(srcIx, i.getExecSize(), |
| 705 |
i.isMacro())) { |
| 706 |
emit("null"); |
| 707 |
} else { |
| 708 |
emitRgn(i, src.getRegion(), false); |
| 709 |
} |
| 710 |
} |
| 711 |
|
| 712 |
void emitSendSrc(const Instruction &i, int srcIx) { |
| 713 |
const Operand &src = i.getSource(srcIx); |
| 714 |
|
| 715 |
if (srcIx == 0 && i.getSrc0Length() >= 0) { |
| 716 |
emit("{"); |
| 717 |
const auto di = tryDecode(i, nullptr); |
| 718 |
emit("\"kind\":\"AD\""); |
| 719 |
emit(", \"surf\":"); |
| 720 |
if (di) { |
| 721 |
comments.push_back(di.info.description); |
| 722 |
emitAddrSurfInfo(i, di.info); |
| 723 |
} else { |
| 724 |
emit("null"); |
| 725 |
} |
| 726 |
emit(", \"scale\":1"); |
| 727 |
emit(", \"addr\":"); |
| 728 |
emitSendPayloadSrc(i, 0); |
| 729 |
if (di) { |
| 730 |
// e.g. legacy scratch |
| 731 |
emit(", \"offset\":", di.info.immediateOffset); |
| 732 |
} else { |
| 733 |
// shouldn't be a reg, but we emit something |
| 734 |
emit(", \"offset\":0"); |
| 735 |
} |
| 736 |
emit("}"); |
| 737 |
} else if (srcIx == 1 && i.getSrc1Length() >= 0) { |
| 738 |
emitSendPayloadSrc(i, 1, "DA"); |
| 739 |
} else { |
| 740 |
// old send operand (treat as raw direct register access) |
| 741 |
emit("\"kind\":\"RD\""); |
| 742 |
emit(", \"reg\":"); |
| 743 |
emitReg(src.getDirRegName(), src.getDirRegRef()); |
| 744 |
emit(", \"rgn\":null"); |
| 745 |
emit(", \"type\":null"); |
| 746 |
// the best we can do is guess it's 1 without decoding the message |
| 747 |
RegSet rs(model); |
| 748 |
rs.addSourceOperandInput(i, srcIx); |
| 749 |
emitSendPayloadDeps(i, rs, src.getDirRegName(), src.getDirRegRef().regNum, |
| 750 |
1, true); |
| 751 |
} |
| 752 |
} |
| 753 |
|
| 754 |
void emitAddrSurfInfo(const Instruction &i, const MessageInfo &mi) { |
| 755 |
emit("{\"type\":"); |
| 756 |
switch (mi.addrType) { |
| 757 |
case AddrType::INVALID: |
| 758 |
emit("\"invalid\""); |
| 759 |
break; |
| 760 |
case AddrType::FLAT: |
| 761 |
emit("\"flat\""); |
| 762 |
break; |
| 763 |
case AddrType::BTI: |
| 764 |
emit("\"bti\""); |
| 765 |
break; |
| 766 |
case AddrType::BSS: |
| 767 |
emit("\"bss\""); |
| 768 |
break; |
| 769 |
case AddrType::SS: |
| 770 |
emit("\"ss\""); |
| 771 |
break; |
| 772 |
case AddrType::SURF: |
| 773 |
emit("\"surf\""); |
| 774 |
break; |
| 775 |
default: |
| 776 |
emitIrError("invalid surface type"); |
| 777 |
} |
| 778 |
|
| 779 |
emit(", \"offset\":"); |
| 780 |
RegSet surfOffDeps(model); |
| 781 |
if (mi.surfaceId.isReg()) { |
| 782 |
surfOffDeps.setSrcRegion(RegName::ARF_A, mi.surfaceId.reg, Region::SRC010, |
| 783 |
1, 4); |
| 784 |
emitReg(RegName::ARF_A, mi.surfaceId.reg); |
| 785 |
} else { |
| 786 |
emitDecimal(mi.surfaceId.imm); |
| 787 |
} |
| 788 |
emit(", "); |
| 789 |
emitDepInputs(i, surfOffDeps); |
| 790 |
emit("}"); // end of surf:{...} |
| 791 |
} |
| 792 |
|
| 793 |
void emitSendPayloadSrc(const Instruction &i, int srcIx, |
| 794 |
const char *kind = nullptr) { |
| 795 |
const Operand &src = i.getSource(srcIx); |
| 796 |
RegName regName = src.getDirRegName(); |
| 797 |
int regStart = src.getDirRegRef().regNum; |
| 798 |
int regCount = srcIx == 0 ? i.getSrc0Length() : i.getSrc1Length(); |
| 799 |
emit("{"); |
| 800 |
if (kind) { |
| 801 |
emit("\"kind\":\"", kind, "\", "); |
| 802 |
} |
| 803 |
emit("\"reg\":"); |
| 804 |
emitReg(regName, regStart); |
| 805 |
emit(", \"len\":", regCount); |
| 806 |
RegSet rs(model); |
| 807 |
rs.addSourceOperandInput(i, srcIx); |
| 808 |
emitSendPayloadDeps(i, rs, regName, regCount, regCount, true); |
| 809 |
emit("}"); |
| 810 |
} |
| 811 |
|
| 812 |
void emitSendDataRegDst(const Instruction &i, RegName dataReg, int regNum, |
| 813 |
int regLen) { |
| 814 |
emit("\"kind\":\"DA\""); |
| 815 |
emitSendPayloadFields(dataReg, regNum, regLen); |
| 816 |
emitSendPayloadDeps(i, EMPTY_SET, dataReg, regNum, regLen, false); |
| 817 |
} |
| 818 |
|
| 819 |
void emitSendPayloadFields(RegName reg, int regNum, int numRegs) { |
| 820 |
emit(", \"reg\":"); |
| 821 |
emitReg(reg, regNum); |
| 822 |
emit(", \"len\":", numRegs); |
| 823 |
} |
| 824 |
void emitSendPayloadDeps(const Instruction &i, const RegSet ®Stats, |
| 825 |
RegName reg, int regNum, int numRegs, bool isRead) { |
| 826 |
if (isRead) { |
| 827 |
emit(", "); |
| 828 |
emitDepInputs(i, regStats); |
| 829 |
} else { |
| 830 |
// emit(", "); |
| 831 |
// emitDepOutputs(i, rs); |
| 832 |
} |
| 833 |
} |
| 834 |
|
| 835 |
void emitRgn(const Instruction &i, Region r, bool dst = false) { |
| 836 |
if (!dst) { |
| 837 |
// fix ternary regions |
| 838 |
if (r.getVt() == Region::Vert::VT_INVALID && |
| 839 |
r.getWi() == Region::Width::WI_INVALID) { |
| 840 |
// ternary src2 |
| 841 |
// officially it was: w = 0 if h is 0 or E; v = w * h |
| 842 |
// use normalized regions here to simplify |
| 843 |
// <0> ==> <0;1,0> |
| 844 |
// <K> ==> <K;1,0> |
| 845 |
auto hz = r.getHz(); |
| 846 |
// auto es = i.getExecSize(); |
| 847 |
if (hz == Region::Horz::HZ_0) { |
| 848 |
r = Region::SRC010; |
| 849 |
} else { |
| 850 |
r = Region::SRC110; |
| 851 |
r.set(Region::Vert(hz)); |
| 852 |
} |
| 853 |
} else if (r.getWi() == Region::Width::WI_INVALID) { |
| 854 |
// ternary src0/src1 |
| 855 |
// w = 1 when v & h are 0 |
| 856 |
// = v when h = 0 |
| 857 |
// = v/h otherwise |
| 858 |
auto vt = r.getVt(); |
| 859 |
auto hz = r.getHz(); |
| 860 |
if (vt == Region::Vert::VT_0 && hz == Region::Horz::HZ_0) { |
| 861 |
r.set(Region::Width::WI_1); |
| 862 |
} else if (hz == Region::Horz::HZ_0) { |
| 863 |
r.set(Region::Width(int(vt))); |
| 864 |
} else { |
| 865 |
r.set(Region::Width(int(vt) / int(hz))); |
| 866 |
} |
| 867 |
} |
| 868 |
} |
| 869 |
emitRgn(r, dst); |
| 870 |
} // emitRgn |
| 871 |
|
| 872 |
void emitRgn(Region r, bool dst = false) { |
| 873 |
if (dst) { |
| 874 |
#if IGA_SHORTHAND_JSON |
| 875 |
emit("IR.Rgns."); |
| 876 |
switch (r.getHz()) { |
| 877 |
case Region::Horz::HZ_1: |
| 878 |
emit("d1"); |
| 879 |
break; |
| 880 |
case Region::Horz::HZ_2: |
| 881 |
emit("d2"); |
| 882 |
break; |
| 883 |
case Region::Horz::HZ_4: |
| 884 |
emit("d4"); |
| 885 |
break; |
| 886 |
default: |
| 887 |
emit("IR.Error(\"invalid dst region\")"); |
| 888 |
} |
| 889 |
#else |
| 890 |
emit("{\"Hz\":", int(r.getHz()), "}"); |
| 891 |
#endif |
| 892 |
} else { |
| 893 |
#if IGA_SHORTHAND_JSON |
| 894 |
emit("IR.Rgns."); |
| 895 |
if (r == Region::SRC010) { |
| 896 |
emit("s0_1_0"); |
| 897 |
} else if (r == Region::SRC110) { |
| 898 |
emit("s1_1_0"); |
| 899 |
} else if (r == Region::SRC210) { |
| 900 |
emit("s2_1_0"); |
| 901 |
} else if (r == Region::SRC410) { |
| 902 |
emit("s4_1_0"); |
| 903 |
} else if (r.getVt() == Region::Vert::VT_VxH) { |
| 904 |
// <w,h> region for indrect access |
| 905 |
// let the JS library sort it out |
| 906 |
emit("sVxH(", int(r.getWi()), ",", int(r.getHz()), ")"); |
| 907 |
} else { |
| 908 |
emit("sVWH(", int(r.getVt()), ",", int(r.getWi()), ",", int(r.getHz()), |
| 909 |
")"); |
| 910 |
} |
| 911 |
#else |
| 912 |
emit("{"); |
| 913 |
if (r.getVt() == Region::Vert::VT_VxH) { |
| 914 |
emit("\"Vt\":null"); |
| 915 |
} else { |
| 916 |
emit("\"Vt\":", int(r.getVt())); |
| 917 |
} |
| 918 |
emit(",\"Wi\":", int(r.getWi()), ",\"Hz\":", int(r.getHz())); |
| 919 |
emit("}"); |
| 920 |
#endif |
| 921 |
} |
| 922 |
} |
| 923 |
|
| 924 |
void emitType(Type t) { |
| 925 |
if (t == Type::INVALID) { |
| 926 |
emit("null"); |
| 927 |
return; |
| 928 |
} |
| 929 |
#if IGA_SHORTHAND_JSON |
| 930 |
emit("IR.Types."); // e.g. IR.Types.UQ |
| 931 |
auto s = ToSyntax(t); // ":uq" |
| 932 |
for (size_t i = 1; i < s.size(); i++) |
| 933 |
emit((char)toupper(s[i])); |
| 934 |
#else |
| 935 |
emit("\"", ToSyntax(t).substr(1), "\""); // Type::UQ => "uq" |
| 936 |
#endif |
| 937 |
} |
| 938 |
|
| 939 |
void emitRegDist(const SWSB &di) { |
| 940 |
emit(", \"regDist\":"); |
| 941 |
auto emitPipeDist = [&](const char *pfx) { |
| 942 |
emit("\"", pfx, "@", (int)di.minDist, "\""); |
| 943 |
}; |
| 944 |
switch (di.distType) { |
| 945 |
case SWSB::DistType::REG_DIST: |
| 946 |
emitPipeDist(""); |
| 947 |
break; |
| 948 |
case SWSB::DistType::REG_DIST_ALL: |
| 949 |
emitPipeDist("A"); |
| 950 |
break; |
| 951 |
case SWSB::DistType::REG_DIST_FLOAT: |
| 952 |
emitPipeDist("F"); |
| 953 |
break; |
| 954 |
case SWSB::DistType::REG_DIST_INT: |
| 955 |
emitPipeDist("I"); |
| 956 |
break; |
| 957 |
case SWSB::DistType::REG_DIST_LONG: |
| 958 |
emitPipeDist("L"); |
| 959 |
break; |
| 960 |
case SWSB::DistType::REG_DIST_MATH: |
| 961 |
emitPipeDist("M"); |
| 962 |
break; |
| 963 |
case SWSB::DistType::REG_DIST_SCALAR: |
| 964 |
emitPipeDist("S"); |
| 965 |
break; |
| 966 |
default: |
| 967 |
emit("null"); |
| 968 |
break; |
| 969 |
} |
| 970 |
} |
| 971 |
|
| 972 |
void emitSbid(const SWSB &di) { |
| 973 |
emit(", \"sbid\":"); |
| 974 |
auto emitSwsbEvent = [&](const char *sfx) { |
| 975 |
emit("\"$", (int)di.sbid, sfx, "\""); |
| 976 |
}; |
| 977 |
switch (di.tokenType) { |
| 978 |
case SWSB::TokenType::DST: |
| 979 |
emitSwsbEvent(".dst"); |
| 980 |
break; |
| 981 |
case SWSB::TokenType::SRC: |
| 982 |
emitSwsbEvent(".src"); |
| 983 |
break; |
| 984 |
case SWSB::TokenType::SET: |
| 985 |
emitSwsbEvent(""); |
| 986 |
break; |
| 987 |
default: |
| 988 |
emit("null"); |
| 989 |
break; |
| 990 |
} |
| 991 |
} |
| 992 |
|
| 993 |
void emitInstOpts(const Instruction &i) { |
| 994 |
static const InstOpt ALL_INST_OPTS[]{ |
| 995 |
InstOpt::ACCWREN, InstOpt::ATOMIC, InstOpt::BREAKPOINT, |
| 996 |
InstOpt::COMPACTED, InstOpt::EOT, InstOpt::NOCOMPACT, |
| 997 |
InstOpt::NODDCHK, InstOpt::NODDCLR, InstOpt::NOPREEMPT, |
| 998 |
InstOpt::NOSRCDEPSET, InstOpt::SWITCH, InstOpt::SERIALIZE, |
| 999 |
InstOpt::EXBSO, InstOpt::CPS, |
| 1000 |
}; |
| 1001 |
|
| 1002 |
InstOptSet ios = i.getInstOpts(); |
| 1003 |
emit(", \"opts\":["); |
| 1004 |
bool first = true; |
| 1005 |
auto emitSeparator = [&]() { |
| 1006 |
if (first) |
| 1007 |
first = false; |
| 1008 |
else |
| 1009 |
emit(","); |
| 1010 |
}; |
| 1011 |
for (size_t i = 0; |
| 1012 |
i < sizeof(ALL_INST_OPTS) / sizeof(ALL_INST_OPTS[0]) && !ios.empty(); |
| 1013 |
i++) { |
| 1014 |
if (ios.contains(ALL_INST_OPTS[i])) { |
| 1015 |
emitSeparator(); |
| 1016 |
ios.remove(ALL_INST_OPTS[i]); |
| 1017 |
emit("\"", ToSyntax(ALL_INST_OPTS[i]), "\""); |
| 1018 |
} |
| 1019 |
} |
| 1020 |
|
| 1021 |
const auto &di = i.getSWSB(); |
| 1022 |
// special token and dist/token won't co-exist in the same swsb |
| 1023 |
// no need to insert "," after this since there must not be |
| 1024 |
// dist/token swsb |
| 1025 |
if (di.hasSpecialToken()) { |
| 1026 |
IGA_ASSERT(!di.hasDist() && !di.hasToken(), "malformed SWSB IR"); |
| 1027 |
if (di.spToken == SWSB::SpecialToken::NOACCSBSET) { |
| 1028 |
emitSeparator(); |
| 1029 |
emit("NoAccSBSet"); |
| 1030 |
} |
| 1031 |
} |
| 1032 |
emit("]"); |
| 1033 |
} |
| 1034 |
|
| 1035 |
void emitReg(RegName rn, RegRef rr) { |
| 1036 |
#if IGA_SHORTHAND_JSON |
| 1037 |
bool hasShortName = rn == RegName::GRF_R || rn == RegName::ARF_A || |
| 1038 |
rn == RegName::ARF_ACC || rn == RegName::ARF_NULL; |
| 1039 |
if (rr.subRegNum == 0 && hasShortName) { |
| 1040 |
// IR.Regs.r13 is a direct reference |
| 1041 |
const RegInfo *ri = model.lookupRegInfoByRegName(rn); |
| 1042 |
if (ri == nullptr) { |
| 1043 |
emitIrError("unsupported RegName"); |
| 1044 |
} else if (ri->hasRegNum()) { |
| 1045 |
emit("IR.Regs.", ToSyntax(rn), rr.regNum); |
| 1046 |
} else if (rn == RegName::ARF_NULL) { |
| 1047 |
emit("IR.Regs.null_0"); // since "null" is a keyword |
| 1048 |
} else { |
| 1049 |
emit("IR.Regs.", ToSyntax(rn)); |
| 1050 |
} |
| 1051 |
} else if (rn == RegName::ARF_F) { |
| 1052 |
emit("IR.Regs.f", rr.regNum, "_", rr.subRegNum); |
| 1053 |
} else { |
| 1054 |
// IR.Regs.reg("r",13,4) creates a new object to r13.4 |
| 1055 |
emit("IR.Regs.reg(\"", ToSyntax(rn), "\",", rr.regNum, ",", rr.subRegNum, |
| 1056 |
")"); |
| 1057 |
} |
| 1058 |
#else |
| 1059 |
// use full JSON syntax (no shortcuts) |
| 1060 |
emit("{" |
| 1061 |
"\"rn\":\"", |
| 1062 |
ToSyntax(rn), |
| 1063 |
"\"," |
| 1064 |
"\"r\":", |
| 1065 |
rr.regNum, ",", "\"sr\":", rr.subRegNum, "}"); |
| 1066 |
#endif |
| 1067 |
} |
| 1068 |
void emitReg(RegName rn, int regNum, int sr = 0) { |
| 1069 |
emitReg(rn, RegRef((int16_t)regNum, (int16_t)sr)); |
| 1070 |
} |
| 1071 |
|
| 1072 |
/* |
| 1073 |
///////////////////////////////////////////////////////////////////////// |
| 1074 |
// call this for operands that are instruction outputs |
| 1075 |
void emitDepOutputs(const Instruction &i, const RegSet &rs) { |
| 1076 |
// 'i' is writing 'rs' emit all pairs where this is the |
| 1077 |
// def and report them as uess |
| 1078 |
emit("\"uses\":["); |
| 1079 |
if (opts.liveAnalysis) { |
| 1080 |
emit("]"); |
| 1081 |
return; |
| 1082 |
} |
| 1083 |
// the users of 'rs' are all those that use this set |
| 1084 |
bool first = true; |
| 1085 |
for (const Dep *d : depDefs[i.getID()]) { |
| 1086 |
if (d->use != nullptr && rs.intersects(d->values)) { |
| 1087 |
if (first) |
| 1088 |
first = false; |
| 1089 |
else |
| 1090 |
emit(","); |
| 1091 |
emit(d->use->getID()); |
| 1092 |
} |
| 1093 |
} |
| 1094 |
emit("]"); |
| 1095 |
} |
| 1096 |
*/ |
| 1097 |
|
| 1098 |
// call this for operands that are instruction inputs |
| 1099 |
void emitDepInputs(const Instruction &i, const RegSet &rs) { |
| 1100 |
// 'i' is writing 'rs' emit all pairs where this is the |
| 1101 |
// def and report them as uess |
| 1102 |
emit("\"defs\":["); |
| 1103 |
if (opts.liveAnalysis == nullptr) { |
| 1104 |
emit("]"); |
| 1105 |
return; |
| 1106 |
} |
| 1107 |
// the users of 'rs' are all those that use this set |
| 1108 |
bool first = true; |
| 1109 |
auto c = depUses[i.getID()]; |
| 1110 |
for (const Dep *d : c) { |
| 1111 |
if (d->def != nullptr && rs.intersects(d->values)) { |
| 1112 |
if (first) |
| 1113 |
first = false; |
| 1114 |
else |
| 1115 |
emit(","); |
| 1116 |
emit(d->def->getID()); |
| 1117 |
} |
| 1118 |
} |
| 1119 |
emit("]"); |
| 1120 |
} |
| 1121 |
}; // JSONFormatterV1 |
| 1122 |
|
| 1123 |
namespace iga { |
| 1124 |
void FormatJSON2(std::ostream &o, const FormatOpts &opts, const Kernel &k, |
| 1125 |
const void *bits); |
| 1126 |
} |
| 1127 |
|
| 1128 |
void iga::FormatJSON(std::ostream &o, const FormatOpts &opts, const Kernel &k, |
| 1129 |
const void *bits) { |
| 1130 |
if (opts.printJsonVersion > 1) |
| 1131 |
iga::FormatJSON2(o, opts, k, bits); |
| 1132 |
else |
| 1133 |
JSONFormatterV1(o, opts, bits).emitKernel(k); |
| 1134 |
} |
| 1135 |
|
| 1136 |
void iga::FormatInstructionJSON1(std::ostream &o, const FormatOpts &opts, |
| 1137 |
const Instruction &i, const void *bits) { |
| 1138 |
JSONFormatterV1(o, opts, bits).emitInst(i); |
| 1139 |
} |