KMfilterCenters KMlocal::execute() // execute the algorithm { reset(); // resets everything while(!isDone()) { // while not done beginRun(); // start a new run do { // do while run is not done beginStage(); // start of stage processing KMalg method = selectMethod(); // select a method switch(method) { // apply one stage case LLOYD: // Lloyd's algorithm curr.lloyd1Stage(); break; case SWAP: // swap heuristic curr.swap1Stage(); break; case RANDOM: // get random centers curr.genRandom(); break; default: // shouldn't come here assert(false); break; } endStage(); // end of stage processing } while(!isRunDone()); // while run is not done endRun(); // end of run processing tryAcceptance(); // accept if appropriate } return best; // return best solution }
RegionDescPtr selectRegion(const RegionContext& context, TransKind kind) { auto const mode = regionMode(); FTRACE(1, "Select region: mode={} context:\n{}", static_cast<int>(mode), show(context) ); auto region = [&]{ try { switch (mode) { case RegionMode::None: return RegionDescPtr{nullptr}; case RegionMode::Method: return selectMethod(context); case RegionMode::Tracelet: return selectTracelet(context, kind == TransKind::Profile); } not_reached(); } catch (const std::exception& e) { FTRACE(1, "region selector threw: {}\n", e.what()); return RegionDescPtr{nullptr}; } }(); if (region) { FTRACE(3, "{}", show(*region)); always_assert(region->instrSize() <= RuntimeOption::EvalJitMaxRegionInstrs); } else { FTRACE(1, "no region selectable; using tracelet compiler\n"); } return region; }
RegionDescPtr selectRegion(const RegionContext& context, const Transl::Tracelet* t) { auto const mode = regionMode(); FTRACE(1, "Select region: mode={} context:\n{}", static_cast<int>(mode), show(context) ); auto region = [&] { try { switch (mode) { case RegionMode::None: return RegionDescPtr{nullptr}; case RegionMode::OneBC: return selectOneBC(context); case RegionMode::Method: return selectMethod(context); case RegionMode::Tracelet: return selectTracelet(context, 0); case RegionMode::Legacy: always_assert(t); return selectTraceletLegacy(*t); case RegionMode::HotBlock: case RegionMode::HotTrace: always_assert(0 && "unsupported region mode"); } not_reached(); } catch (const std::exception& e) { FTRACE(1, "region selector threw: {}\n", e.what()); return RegionDescPtr{nullptr}; } }(); if (region) { FTRACE(3, "{}", show(*region)); } else { FTRACE(1, "no region selectable; using tracelet compiler\n"); } return region; }