void printOpcodeStats(std::ostream& os, const BlockList& blocks) { uint32_t counts[kNumOpcodes]; memset(counts, 0, sizeof(counts)); for (auto block : blocks) { for (auto& inst : *block) ++counts[static_cast<size_t>(inst.op())]; } os << "\nopcode counts:\n"; for (unsigned i = 0; i < kNumOpcodes; ++i) { if (counts[i] == 0) continue; auto op = safe_cast<Opcode>(i); os << folly::format("{:>5} {}\n", counts[i], opcodeName(op)); } os << '\n'; }
void printOpcode(std::ostream& os, const IRInstruction* inst, const GuardConstraints* guards) { os << color(ANSI_COLOR_CYAN) << opcodeName(inst->op()) << color(ANSI_COLOR_END) ; auto const typeParam = inst->typeParam(); auto const hasTypeParam = !typeParam.equals(Type::None); auto const hasExtra = inst->hasExtra(); auto const isGuard = guards && !inst->isTransient() && isGuardOp(inst->op()); if (!hasTypeParam && !hasExtra && !isGuard) return; os << color(ANSI_COLOR_LIGHT_BLUE) << '<' << color(ANSI_COLOR_END); if (hasTypeParam) { os << color(ANSI_COLOR_GREEN) << typeParam.toString() << color(ANSI_COLOR_END) ; if (hasExtra || isGuard) os << punc(","); } if (inst->op() == LdConst) { os << constToString(inst->typeParam(), inst->extra<LdConst>()); } else { if (hasExtra) { os << color(ANSI_COLOR_GREEN) << showExtra(inst->op(), inst->rawExtra()) << color(ANSI_COLOR_END); if (isGuard) os << punc(","); } } if (isGuard) { auto it = guards->find(inst); os << (it == guards->end() ? "unused" : it->second.toString()); } os << color(ANSI_COLOR_LIGHT_BLUE) << '>' << color(ANSI_COLOR_END); }
/* * IRInstruction */ void printOpcode(std::ostream& os, const IRInstruction* inst, const GuardConstraints* constraints) { os << color(ANSI_COLOR_CYAN) << opcodeName(inst->op()) << color(ANSI_COLOR_END) ; auto const hasTypeParam = inst->hasTypeParam(); auto const hasExtra = inst->hasExtra(); auto const isGuard = constraints && !inst->isTransient() && isGuardOp(inst->op()); if (!hasTypeParam && !hasExtra && !isGuard) return; os << color(ANSI_COLOR_LIGHT_BLUE) << '<' << color(ANSI_COLOR_END); if (hasTypeParam) { os << color(ANSI_COLOR_GREEN) << inst->typeParam().toString() << color(ANSI_COLOR_END) ; if (hasExtra || isGuard) os << punc(","); } if (hasExtra) { os << color(ANSI_COLOR_GREEN) << showExtra(inst->op(), inst->rawExtra()) << color(ANSI_COLOR_END); if (isGuard) os << punc(","); } if (isGuard) { auto it = constraints->guards.find(inst); os << (it == constraints->guards.end() ? "unused" : it->second.toString()); } os << color(ANSI_COLOR_LIGHT_BLUE) << '>' << color(ANSI_COLOR_END); }