本文整理汇总了C++中TransCFG::weight方法的典型用法代码示例。如果您正苦于以下问题:C++ TransCFG::weight方法的具体用法?C++ TransCFG::weight怎么用?C++ TransCFG::weight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TransCFG
的用法示例。
在下文中一共展示了TransCFG::weight方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sortRegions
/**
* Sorts the regions vector in a linear order to be used for
* translation. The goal is to obtain an order that improves locality
* when the function is executed. Each region is translated separately.
*/
static void sortRegions(RegionVec& regions,
const Func* func,
const TransCFG& cfg,
const ProfData* profData,
const TransIDToRegionMap& headToRegion,
const RegionToTransIDsMap& regionToTransIds) {
RegionVec sorted;
RegionSet selected;
if (regions.empty()) return;
// First, pick the region starting at the lowest bytecode offset.
// This will normally correspond to the main function entry (for
// normal, regular bytecode), but it may not be for irregular
// functions written in hhas (like array_map and array_filter). If
// there multiple regions starting at the lowest bytecode offset,
// pick the one with the largest profile weight.
RegionDescPtr entryRegion = nullptr;
int64_t maxEntryWeight = -1;
Offset lowestOffset = kInvalidOffset;
for (const auto& pair : regionToTransIds) {
auto r = pair.first;
auto& tids = pair.second;
TransID firstTid = tids[0];
Offset firstOffset = profData->transSrcKey(firstTid).offset();
int64_t weight = cfg.weight(firstTid);
if (lowestOffset == kInvalidOffset || firstOffset < lowestOffset ||
(firstOffset == lowestOffset && weight > maxEntryWeight)) {
entryRegion = r;
maxEntryWeight = weight;
lowestOffset = firstOffset;
}
}
assert(entryRegion);
sorted.push_back(entryRegion);
selected.insert(entryRegion);
RegionDescPtr region = entryRegion;
// Select the remaining regions, iteratively picking the most likely
// region to execute next.
for (auto i = 1; i < regions.size(); i++) {
int64_t maxWeight = -1;
int64_t maxHeadWeight = -1;
RegionDescPtr bestNext = nullptr;
auto regionTransIds = getRegionTransIDVec(regionToTransIds, region);
for (auto next : regions) {
if (selected.count(next)) continue;
auto nextTransIds = getRegionTransIDVec(regionToTransIds, next);
int64_t weight = interRegionWeight(regionTransIds, nextTransIds[0], cfg);
int64_t headWeight = cfg.weight(nextTransIds[0]);
if ((weight > maxWeight) ||
(weight == maxWeight && headWeight > maxHeadWeight)) {
maxWeight = weight;
maxHeadWeight = headWeight;
bestNext = next;
}
}
assert(bestNext);
sorted.push_back(bestNext);
selected.insert(bestNext);
region = bestNext;
}
assert(sorted.size() == regions.size());
regions = sorted;
if (debug && Trace::moduleEnabled(HPHP::Trace::pgo, 5)) {
for (size_t i = 0; i < regions.size(); i++) {
auto r = regions[i];
auto tids = getRegionTransIDVec(regionToTransIds, r);
std::string transIds = folly::join(", ", tids);
FTRACE(6, "sortRegions: region[{}]: {}\n", i, transIds);
}
}
}
示例2: sortRegion
/**
* Sorts the regions vector in a linear order to be used for
* translation. The goal is to obtain an order that improves locality
* when the function is executed.
*/
static void sortRegion(RegionVec& regions,
const Func* func,
const TransCFG& cfg,
const ProfData* profData,
const TransIDToRegionMap& headToRegion,
const RegionToTransIDsMap& regionToTransIds) {
RegionVec sorted;
RegionSet selected;
// First, pick the region for the function body entry. There may be
// multiple translations of the function body, so pick the one with
// largest profile weight.
RegionDescPtr entryRegion = nullptr;
int64_t maxEntryWeight = -1;
for (const auto& pair : regionToTransIds) {
auto r = pair.first;
auto& tids = pair.second;
for (auto tid : tids) {
if (profData->transSrcKey(tid).offset() == func->base()) {
int64_t weight = cfg.weight(tid);
if (weight > maxEntryWeight) {
entryRegion = r;
maxEntryWeight = weight;
}
}
}
}
assert(entryRegion);
sorted.push_back(entryRegion);
selected.insert(entryRegion);
RegionDescPtr region = entryRegion;
// Select the remaining regions, iteratively picking the most likely
// region to execute next.
for (auto i = 1; i < regions.size(); i++) {
int64_t maxWeight = -1;
int64_t maxHeadWeight = -1;
RegionDescPtr bestNext = nullptr;
auto regionTransIds = getRegionTransIDVec(regionToTransIds, region);
for (auto next : regions) {
if (setContains(selected, next)) continue;
auto nextTransIds = getRegionTransIDVec(regionToTransIds, next);
int64_t weight = interRegionWeight(regionTransIds, nextTransIds[0], cfg);
int64_t headWeight = cfg.weight(nextTransIds[0]);
if ((weight > maxWeight) ||
(weight == maxWeight && headWeight > maxHeadWeight)) {
maxWeight = weight;
maxHeadWeight = headWeight;
bestNext = next;
}
}
assert(bestNext);
sorted.push_back(bestNext);
selected.insert(bestNext);
region = bestNext;
}
assert(sorted.size() == regions.size());
regions = sorted;
if (debug && Trace::moduleEnabled(HPHP::Trace::pgo, 5)) {
for (size_t i = 0; i < regions.size(); i++) {
auto r = regions[i];
auto tids = getRegionTransIDVec(regionToTransIds, r);
std::string transIds = folly::join(", ", tids);
FTRACE(6, "sortRegion: region[{}]: {}\n", i, transIds);
}
}
}