本文整理汇总了C++中TransIDSet类的典型用法代码示例。如果您正苦于以下问题:C++ TransIDSet类的具体用法?C++ TransIDSet怎么用?C++ TransIDSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TransIDSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: findPredTrans
static TransIDSet findPredTrans(TransID dstID,
const ProfData* profData,
const SrcDB& srcDB,
const TcaTransIDMap& jmpToTransID) {
SrcKey dstSK = profData->transSrcKey(dstID);
const SrcRec* dstSR = srcDB.find(dstSK);
assertx(dstSR);
TransIDSet predSet;
for (auto& inBr : dstSR->incomingBranches()) {
TransID srcID = folly::get_default(jmpToTransID, inBr.toSmash(),
kInvalidTransID);
FTRACE(5, "findPredTrans: toSmash = {} srcID = {}\n",
inBr.toSmash(), srcID);
if (srcID != kInvalidTransID && profData->isKindProfile(srcID)) {
auto srcSuccOffsets = profData->transLastSrcKey(srcID).succOffsets();
if (srcSuccOffsets.count(dstSK.offset())) {
predSet.insert(srcID);
} else {
FTRACE(5, "findPredTrans: WARNING: incoming branch with impossible "
"control flow between translations: {} -> {}"
"(probably due to side exit)\n", srcID, dstID);
}
}
}
return predSet;
}
开发者ID:191919,项目名称:hhvm,代码行数:28,代码来源:trans-cfg.cpp
示例2: findPredTrans
static TransIDSet findPredTrans(TransID dstID, const ProfData* profData) {
auto const dstRec = profData->transRec(dstID);
auto const dstSK = dstRec->srcKey();
const SrcRec* dstSR = tc::findSrcRec(dstSK);
assertx(dstSR);
TransIDSet predSet;
for (auto& inBr : dstSR->incomingBranches()) {
auto const srcID = profData->jmpTransID(inBr.toSmash());
if (srcID == kInvalidTransID) continue;
auto const srcRec = profData->transRec(srcID);
if (!srcRec || !srcRec->isProfile()) continue;
FTRACE(5, "findPredTrans: toSmash = {} srcID = {}\n",
inBr.toSmash(), srcID);
auto srcSuccOffsets = srcRec->lastSrcKey().succOffsets();
if (srcSuccOffsets.count(dstSK.offset())) {
predSet.insert(srcID);
} else {
FTRACE(5, "findPredTrans: WARNING: incoming branch with impossible "
"control flow between translations: {} -> {}"
"(probably due to side exit)\n", srcID, dstID);
}
}
return predSet;
}
开发者ID:HilayPatel,项目名称:hhvm,代码行数:28,代码来源:trans-cfg.cpp
示例3: findPredTrans
static TransIDSet findPredTrans(const SrcRec* sr,
const TcaTransIDMap& jmpToTransID) {
assert(sr);
TransIDSet predSet;
for (auto& inBr : sr->incomingBranches()) {
TransID srcId = mapGet(jmpToTransID, inBr.toSmash(), InvalidID);
FTRACE(5, "findPredTrans: toSmash = {} srcId = {}\n",
inBr.toSmash(), srcId);
if (srcId != InvalidID) {
predSet.insert(srcId);
}
}
return predSet;
}
开发者ID:aakrit,项目名称:hiphop-php,代码行数:16,代码来源:trans-cfg.cpp
示例4: findPredTransIDs
/*
* Search the HHIR control-flow graph backwards starting at `b' for
* the first blocks not in `visited' that belong to a Profile
* translation other than `headerTID', and add those blocks' TransIDs
* to `set'.
*/
void findPredTransIDs(TransID headerTID, Block* b,
boost::dynamic_bitset<>& visited,
TransIDSet& set) {
if (visited[b->id()]) return;
visited[b->id()] = true;
auto bTID = b->front().marker().profTransID();
if (set.count(bTID)) return;
if (bTID != headerTID) {
if (bTID != kInvalidTransID) set.insert(bTID);
else assertx(b->id() == 0); // only the entry block may have no ProfTransID
return;
}
// Keep searching.
for (auto& predEdge : b->preds()) {
findPredTransIDs(headerTID, predEdge.from(), visited, set);
}
}
开发者ID:lpathy,项目名称:hhvm,代码行数:23,代码来源:loop-analysis.cpp
示例5: markCovered
/**
* Add to sets coveredNodes and coveredArcs the cfg arcs that are now
* covered given the new region containing the translations in
* selectedVec.
*/
static void markCovered(const TransCFG& cfg, const RegionDescPtr region,
const TransIDVec& selectedVec, const TransIDSet heads,
TransIDSet& coveredNodes,
TransCFG::ArcPtrSet& coveredArcs) {
assert(selectedVec.size() > 0);
TransID newHead = selectedVec[0];
assert(!region->empty());
assert(newHead == getTransId(region->entry()->id()));
// Mark all region's nodes as covered.
coveredNodes.insert(selectedVec.begin(), selectedVec.end());
// Mark all incoming arcs into newHead from covered nodes as covered.
for (auto arc : cfg.inArcs(newHead)) {
TransID src = arc->src();
if (coveredNodes.count(src)) {
coveredArcs.insert(arc);
}
}
// Mark all CFG arcs within the region as covered.
region->forEachArc([&](RegionDesc::BlockId src, RegionDesc::BlockId dst) {
if (!hasTransId(src) || !hasTransId(dst)) return;
TransID srcTid = getTransId(src);
TransID dstTid = getTransId(dst);
assert(cfg.hasArc(srcTid, dstTid));
bool foundArc = false;
for (auto arc : cfg.outArcs(srcTid)) {
if (arc->dst() == dstTid) {
coveredArcs.insert(arc);
foundArc = true;
}
}
always_assert(foundArc);
});
// Mark all outgoing arcs from the region to a head node as covered.
for (auto node : selectedVec) {
for (auto arc : cfg.outArcs(node)) {
if (heads.count(arc->dst())) {
coveredArcs.insert(arc);
}
}
}
}
开发者ID:AmineCherrai,项目名称:hhvm,代码行数:50,代码来源:regionize-func.cpp
示例6: selectWholeCFG
/*
* Constructs a region, beginning with triggerId, that includes as much of the
* TransCFG as possible. Excludes multiple translations of the same SrcKey.
*/
RegionDescPtr selectWholeCFG(TransID triggerId,
const ProfData* profData,
const TransCFG& cfg,
TransIDSet& selectedSet,
TransIDVec* selectedVec) {
selectedSet.clear();
if (selectedVec) selectedVec->clear();
return DFS(profData, cfg, selectedSet, selectedVec).go(triggerId);
}
开发者ID:Ruwan-Ranganath,项目名称:hhvm,代码行数:13,代码来源:region-whole-cfg.cpp
示例7: markCovered
/**
* Add to sets coveredNodes and coveredArcs the cfg arcs that are now
* covered given the new region containing the translations in
* selectedVec.
*/
static void markCovered(const TransCFG& cfg, const TransIDVec selectedVec,
const TransIDSet heads, TransIDSet& coveredNodes,
TransCFG::ArcPtrSet& coveredArcs) {
assert(selectedVec.size() > 0);
TransID newHead = selectedVec[0];
// Mark all region's nodes as covered.
coveredNodes.insert(selectedVec.begin(), selectedVec.end());
// Mark all incoming arcs into newHead from covered nodes as covered.
for (auto arc : cfg.inArcs(newHead)) {
TransID src = arc->src();
if (coveredNodes.count(src)) {
coveredArcs.insert(arc);
}
}
// Mark all arcs between consecutive region nodes as covered.
for (size_t i = 0; i < selectedVec.size() - 1; i++) {
TransID node = selectedVec[i];
TransID next = selectedVec[i + 1];
bool foundArc = false;
for (auto arc : cfg.outArcs(node)) {
if (arc->dst() == next) {
coveredArcs.insert(arc);
foundArc = true;
}
}
always_assert(foundArc);
}
// Mark all outgoing arcs from the region to a head node as covered.
for (auto node : selectedVec) {
for (auto arc : cfg.outArcs(node)) {
if (heads.count(arc->dst())) {
coveredArcs.insert(arc);
}
}
}
}
开发者ID:artursmolarek,项目名称:hhvm,代码行数:45,代码来源:regionize-func.cpp
示例8: regionizeFunc
/**
* Regionize a func, so that each node and each arc in its TransCFG is
* "covered". A node is covered if any region contains it. An arc T1->T2
* is covered if either:
*
* a) T1 and T2 are in the same region R and T2 immediately follows
* T1 in R.
* b) T2 is the head (first translation) of a region.
*
* Basic algorithm:
*
* 1) sort nodes in decreasing weight order
* 2) for each node N:
* 2.1) if N and all its incoming arcs are covered, then continue
* 2.2) select a region starting at this node and mark nodes/arcs as
* covered appropriately
*/
void regionizeFunc(const Func* func,
MCGenerator* mcg,
RegionVec& regions) {
const Timer rf_timer(Timer::regionizeFunc);
assert(RuntimeOption::EvalJitPGO);
auto const funcId = func->getFuncId();
auto const profData = mcg->tx().profData();
TransCFG cfg(funcId, profData, mcg->tx().getSrcDB(),
mcg->getJmpToTransIDMap());
if (Trace::moduleEnabled(HPHP::Trace::pgo, 5)) {
auto dotFileName = folly::to<std::string>(
"/tmp/func-cfg-", funcId, ".dot");
cfg.print(dotFileName, funcId, profData, nullptr);
FTRACE(5, "regionizeFunc: initial CFG for func {} saved to file {}\n",
funcId, dotFileName);
}
TransCFG::ArcPtrVec arcs = cfg.arcs();
std::vector<TransID> nodes = cfg.nodes();
std::sort(nodes.begin(), nodes.end(),
[&](TransID tid1, TransID tid2) -> bool {
if (RuntimeOption::EvalJitPGORegionSelector == "wholecfg") {
auto bcOff1 = profData->transStartBcOff(tid1);
auto bcOff2 = profData->transStartBcOff(tid2);
if (bcOff1 != bcOff2) return bcOff1 < bcOff2;
}
if (cfg.weight(tid1) != cfg.weight(tid2)) {
return cfg.weight(tid1) > cfg.weight(tid2);
}
// In case of ties, pick older translations first, in an
// attempt to start loops at their headers.
return tid1 < tid2;
});
TransCFG::ArcPtrSet coveredArcs;
TransIDSet coveredNodes;
TransIDSet heads;
TransIDToRegionMap headToRegion;
RegionToTransIDsMap regionToTransIds;
regions.clear();
for (auto node : nodes) {
if (!coveredNodes.count(node) ||
!allArcsCovered(cfg.inArcs(node), coveredArcs)) {
TransID newHead = node;
FTRACE(6, "regionizeFunc: selecting trace to cover node {}\n", newHead);
TransIDSet selectedSet;
TransIDVec selectedVec;
RegionDescPtr region;
if (RuntimeOption::EvalJitPGORegionSelector == "hottrace") {
region = selectHotTrace(newHead, profData, cfg,
selectedSet, &selectedVec);
} else if (RuntimeOption::EvalJitPGORegionSelector == "wholecfg") {
region = selectWholeCFG(newHead, profData, cfg, selectedSet,
&selectedVec);
} else {
always_assert(0 && "Invalid value for EvalJitPGORegionSelector");
}
FTRACE(6, "regionizeFunc: selected region to cover node {}\n{}\n",
newHead, show(*region));
profData->setOptimized(profData->transSrcKey(newHead));
assert(selectedVec.size() > 0 && selectedVec[0] == newHead);
regions.push_back(region);
heads.insert(newHead);
markCovered(cfg, region, selectedVec, heads, coveredNodes, coveredArcs);
regionToTransIds[region] = selectedVec;
headToRegion[newHead] = region;
FTRACE(6, "regionizeFunc: selected trace: {}\n",
folly::join(", ", selectedVec));
}
}
assert(coveredNodes.size() == cfg.nodes().size());
assert(coveredArcs.size() == arcs.size());
sortRegions(regions, func, cfg, profData, headToRegion, regionToTransIds);
if (debug && Trace::moduleEnabled(HPHP::Trace::pgo, 5)) {
FTRACE(5, "\n--------------------------------------------\n"
"regionizeFunc({}): computed regions:\n", funcId);
//.........这里部分代码省略.........
开发者ID:AmineCherrai,项目名称:hhvm,代码行数:101,代码来源:regionize-func.cpp
示例9: selectHotTrace
RegionDescPtr selectHotTrace(HotTransContext& ctx,
TransIDSet& selectedSet,
TransIDVec* selectedVec /* = nullptr */) {
auto region = std::make_shared<RegionDesc>();
TransID tid = ctx.tid;
TransID prevId = kInvalidTransID;
selectedSet.clear();
if (selectedVec) selectedVec->clear();
TypedLocations accumPostConds;
// Maps from BlockIds to accumulated post conditions for that block.
// Used to determine if we can add branch-over edges by checking the
// pre-conditions of the successor block.
hphp_hash_map<RegionDesc::BlockId, TypedLocations> blockPostConds;
auto numBCInstrs = ctx.maxBCInstrs;
FTRACE(1, "selectHotTrace: starting with maxBCInstrs = {}\n", numBCInstrs);
while (!selectedSet.count(tid)) {
auto rec = ctx.profData->transRec(tid);
auto blockRegion = rec->region();
if (blockRegion == nullptr) break;
// Break if region would be larger than the specified limit.
if (blockRegion->instrSize() > numBCInstrs) {
FTRACE(2, "selectHotTrace: breaking region at Translation {} because "
"size would exceed of maximum translation limit\n", tid);
break;
}
// If the debugger is attached, only allow single-block regions.
if (prevId != kInvalidTransID && isDebuggerAttachedProcess()) {
FTRACE(2, "selectHotTrace: breaking region at Translation {} "
"because of debugger is attached\n", tid);
break;
}
// Break if block is not the first and it corresponds to the main
// function body entry. This is to prevent creating multiple
// large regions containing the function body (starting at various
// DV funclets).
if (prevId != kInvalidTransID) {
auto const func = rec->func();
auto const bcOffset = rec->startBcOff();
if (func->base() == bcOffset) {
FTRACE(2, "selectHotTrace: breaking region because reached the main "
"function body entry at Translation {} (BC offset {})\n",
tid, bcOffset);
break;
}
}
if (prevId != kInvalidTransID) {
auto sk = rec->srcKey();
if (ctx.profData->optimized(sk)) {
FTRACE(2, "selectHotTrace: breaking region because next sk already "
"optimized, for Translation {}\n", tid);
break;
}
}
bool hasPredBlock = !region->empty();
RegionDesc::BlockId predBlockId = (hasPredBlock ?
region->blocks().back().get()->id() : 0);
auto const& newFirstBlock = blockRegion->entry();
auto newFirstBlockId = newFirstBlock->id();
// Add blockRegion's blocks and arcs to region.
region->append(*blockRegion);
numBCInstrs -= blockRegion->instrSize();
assertx(numBCInstrs >= 0);
if (hasPredBlock) {
region->addArc(predBlockId, newFirstBlockId);
}
selectedSet.insert(tid);
if (selectedVec) selectedVec->push_back(tid);
const auto lastSk = rec->lastSrcKey();
if (breaksRegion(lastSk)) {
FTRACE(2, "selectHotTrace: breaking region because of last instruction "
"in Translation {}: {}\n", tid, opcodeToName(lastSk.op()));
break;
}
auto outArcs = ctx.cfg->outArcs(tid);
if (outArcs.size() == 0) {
FTRACE(2, "selectHotTrace: breaking region because there's no successor "
"for Translation {}\n", tid);
break;
}
auto newLastBlock = blockRegion->blocks().back();
discardPoppedTypes(accumPostConds,
blockRegion->entry()->initialSpOffset());
mergePostConds(accumPostConds, newLastBlock->postConds());
blockPostConds[newLastBlock->id()] = accumPostConds;
TransCFG::ArcPtrVec possibleOutArcs;
//.........这里部分代码省略.........
开发者ID:BruceZu,项目名称:hhvm,代码行数:101,代码来源:region-hot-trace.cpp
示例10: selectHotTrace
RegionDescPtr selectHotTrace(TransID triggerId,
const ProfData* profData,
TransCFG& cfg,
TransIDSet& selectedSet,
TransIDVec* selectedVec) {
auto region = std::make_shared<RegionDesc>();
TransID tid = triggerId;
TransID prevId = kInvalidTransID;
selectedSet.clear();
if (selectedVec) selectedVec->clear();
PostConditions accumPostConds;
// Maps BlockIds to the set of BC offsets for its successor blocks.
// Used to prevent multiple successors with the same SrcKey for now.
// This can go away once task #4157613 is done.
hphp_hash_map<RegionDesc::BlockId, SrcKeySet> succSKSet;
// Maps from BlockIds to accumulated post conditions for that block.
// Used to determine if we can add branch-over edges by checking the
// pre-conditions of the successor block.
hphp_hash_map<RegionDesc::BlockId, PostConditions> blockPostConds;
while (!selectedSet.count(tid)) {
RegionDescPtr blockRegion = profData->transRegion(tid);
if (blockRegion == nullptr) break;
// If the debugger is attached, only allow single-block regions.
if (prevId != kInvalidTransID && isDebuggerAttachedProcess()) {
FTRACE(2, "selectHotTrace: breaking region at Translation {} "
"because of debugger is attached\n", tid);
break;
}
// Break if block is not the first and requires reffiness checks.
// Task #2589970: fix translateRegion to support mid-region reffiness checks
if (prevId != kInvalidTransID) {
auto nRefDeps = blockRegion->blocks[0]->reffinessPreds().size();
if (nRefDeps > 0) {
FTRACE(2, "selectHotTrace: breaking region because of refDeps ({}) at "
"Translation {}\n", nRefDeps, tid);
break;
}
}
// Break if block is not the first and it corresponds to the main
// function body entry. This is to prevent creating multiple
// large regions containing the function body (starting at various
// DV funclets).
if (prevId != kInvalidTransID) {
const Func* func = profData->transFunc(tid);
Offset bcOffset = profData->transStartBcOff(tid);
if (func->base() == bcOffset) {
FTRACE(2, "selectHotTrace: breaking region because reached the main "
"function body entry at Translation {} (BC offset {})\n",
tid, bcOffset);
break;
}
}
if (prevId != kInvalidTransID) {
auto sk = profData->transSrcKey(tid);
if (profData->optimized(sk)) {
FTRACE(2, "selectHotTrace: breaking region because next sk already "
"optimized, for Translation {}\n", tid);
break;
}
}
// Break trace if translation tid cannot follow the execution of
// the entire translation prevId. This can only happen if the
// execution of prevId takes a side exit that leads to the
// execution of tid.
if (prevId != kInvalidTransID) {
Op* lastInstr = profData->transLastInstr(prevId);
const Unit* unit = profData->transFunc(prevId)->unit();
OffsetSet succOffs = findSuccOffsets(lastInstr, unit);
if (!succOffs.count(profData->transSrcKey(tid).offset())) {
if (HPHP::Trace::moduleEnabled(HPHP::Trace::pgo, 2)) {
FTRACE(2, "selectHotTrace: WARNING: Breaking region @: {}\n",
show(*region));
FTRACE(2, "selectHotTrace: next translation selected: tid = {}\n{}\n",
tid, show(*blockRegion));
FTRACE(2, "\nsuccOffs = {}\n", folly::join(", ", succOffs));
}
break;
}
}
if (region->blocks.size() > 0) {
auto& newBlock = blockRegion->blocks.front();
auto newBlockId = newBlock->id();
auto predBlockId = region->blocks.back().get()->id();
if (!RuntimeOption::EvalHHIRBytecodeControlFlow) {
region->addArc(predBlockId, newBlockId);
} else {
// With bytecode control-flow, we add all forward arcs in the TransCFG
// that are induced by the blocks in the region, as a simple way
// to expose control-flow for now.
// This can go away once Task #4075822 is done.
auto newBlockSrcKey = blockRegion->blocks.front().get()->start();
//.........这里部分代码省略.........
开发者ID:Prinhotels,项目名称:hhvm,代码行数:101,代码来源:region-hot-trace.cpp
示例11: selectHotTrace
RegionDescPtr selectHotTrace(TransID triggerId,
const ProfData* profData,
TransCFG& cfg,
TransIDSet& selectedSet,
TransIDVec* selectedVec) {
auto region = std::make_shared<RegionDesc>();
TransID tid = triggerId;
TransID prevId = kInvalidTransID;
selectedSet.clear();
if (selectedVec) selectedVec->clear();
PostConditions accumPostConds;
// Maps from BlockIds to accumulated post conditions for that block.
// Used to determine if we can add branch-over edges by checking the
// pre-conditions of the successor block.
hphp_hash_map<RegionDesc::BlockId, PostConditions> blockPostConds;
uint32_t numBCInstrs = 0;
while (!selectedSet.count(tid)) {
RegionDescPtr blockRegion = profData->transRegion(tid);
if (blockRegion == nullptr) break;
// Break if region would be larger than the specified limit.
auto newInstrSize = numBCInstrs + blockRegion->instrSize();
if (newInstrSize > RuntimeOption::EvalJitMaxRegionInstrs) {
FTRACE(2, "selectHotTrace: breaking region at Translation {} because "
"size ({}) would exceed of maximum translation limit\n",
tid, newInstrSize);
break;
}
// If the debugger is attached, only allow single-block regions.
if (prevId != kInvalidTransID && isDebuggerAttachedProcess()) {
FTRACE(2, "selectHotTrace: breaking region at Translation {} "
"because of debugger is attached\n", tid);
break;
}
// Break if block is not the first and it corresponds to the main
// function body entry. This is to prevent creating multiple
// large regions containing the function body (starting at various
// DV funclets).
if (prevId != kInvalidTransID) {
const Func* func = profData->transFunc(tid);
Offset bcOffset = profData->transStartBcOff(tid);
if (func->base() == bcOffset) {
FTRACE(2, "selectHotTrace: breaking region because reached the main "
"function body entry at Translation {} (BC offset {})\n",
tid, bcOffset);
break;
}
}
if (prevId != kInvalidTransID) {
auto sk = profData->transSrcKey(tid);
if (profData->optimized(sk)) {
FTRACE(2, "selectHotTrace: breaking region because next sk already "
"optimized, for Translation {}\n", tid);
break;
}
}
bool hasPredBlock = !region->empty();
RegionDesc::BlockId predBlockId = (hasPredBlock ?
region->blocks().back().get()->id() : 0);
auto const& newFirstBlock = blockRegion->entry();
auto newFirstBlockId = newFirstBlock->id();
auto newLastBlockId = blockRegion->blocks().back()->id();
// Add blockRegion's blocks and arcs to region.
region->append(*blockRegion);
numBCInstrs += blockRegion->instrSize();
if (hasPredBlock) {
region->addArc(predBlockId, newFirstBlockId);
}
// When Eval.JitLoops is set, insert back-edges in the region if
// they exist in the TransCFG.
if (RuntimeOption::EvalJitLoops) {
assertx(hasTransId(newFirstBlockId));
auto newTransId = getTransId(newFirstBlockId);
// Don't add the arc if the last opcode in the source block ends
// the region.
if (!breaksRegion(*profData->transLastInstr(newTransId))) {
auto& blocks = region->blocks();
for (auto iOther = 0; iOther < blocks.size(); iOther++) {
auto other = blocks[iOther];
auto otherFirstBlockId = other.get()->id();
if (!hasTransId(otherFirstBlockId)) continue;
auto otherTransId = getTransId(otherFirstBlockId);
if (cfg.hasArc(newTransId, otherTransId)) {
region->addArc(newLastBlockId, otherFirstBlockId);
}
}
}
}
//.........这里部分代码省略.........
开发者ID:191919,项目名称:hhvm,代码行数:101,代码来源:region-hot-trace.cpp
示例12: regionizeFunc
/**
* Regionize a func, so that each node and each arc in its TransCFG is
* "covered". A node is covered if any region contains it. An arc T1->T2
* is covered if either:
*
* a) T1 and T2 are in the same region R and T2 immediately follows
* T1 in R.
* b) T2 is the head (first translation) of a region.
*
* Basic algorithm:
*
* 1) sort nodes in decreasing weight order
* 2) for each node N:
* 2.1) if N and all its incoming arcs are covered, then continue
* 2.2) select a region starting at this node and mark nodes/arcs as
* covered appropriately
*/
void regionizeFunc(const Func* func,
Transl::TranslatorX64* tx64,
RegionVec& regions) {
assert(RuntimeOption::EvalJitPGO);
FuncId funcId = func->getFuncId();
ProfData* profData = tx64->profData();
TransCFG cfg(funcId, profData, tx64->getSrcDB(), tx64->getJmpToTransIDMap());
if (Trace::moduleEnabled(HPHP::Trace::pgo, 5)) {
string dotFileName = folly::to<string>("/tmp/func-cfg-", funcId, ".dot");
cfg.print(dotFileName, funcId, profData, nullptr);
FTRACE(5, "regionizeFunc: initial CFG for func {} saved to file {}\n",
funcId, dotFileName);
}
TransCFG::ArcPtrVec arcs = cfg.arcs();
vector<TransID> nodes = cfg.nodes();
std::sort(nodes.begin(), nodes.end(),
[&](TransID tid1, TransID tid2) -> bool {
if (cfg.weight(tid1) != cfg.weight(tid2)) {
return cfg.weight(tid1) > cfg.weight(tid2);
}
// In case of ties, pick older translations first, in an
// attempt to start loops at their headers.
return tid1 < tid2;
});
TransCFG::ArcPtrSet coveredArcs;
TransIDSet coveredNodes;
TransIDSet heads;
TransIDToRegionMap headToRegion;
RegionToTransIDsMap regionToTransIds;
regions.clear();
for (auto node : nodes) {
if (!setContains(coveredNodes, node) ||
!allArcsCovered(cfg.inArcs(node), coveredArcs)) {
TransID newHead = node;
FTRACE(6, "regionizeFunc: selecting trace to cover node {}\n", newHead);
TransIDSet selectedSet;
TransIDVec selectedVec;
RegionDescPtr region = selectHotTrace(newHead, profData, cfg,
selectedSet, &selectedVec);
profData->setOptimized(profData->transSrcKey(newHead));
assert(selectedVec.size() > 0 && selectedVec[0] == newHead);
regions.push_back(region);
heads.insert(newHead);
markCovered(cfg, selectedVec, heads, coveredNodes, coveredArcs);
regionToTransIds[region] = selectedVec;
headToRegion[newHead] = region;
FTRACE(6, "regionizeFunc: selected trace: {}\n",
folly::join(", ", selectedVec));
}
}
assert(coveredNodes.size() == cfg.nodes().size());
assert(coveredArcs.size() == arcs.size());
sortRegion(regions, func, cfg, profData, headToRegion, regionToTransIds);
if (debug && Trace::moduleEnabled(HPHP::Trace::pgo, 5)) {
FTRACE(5, "\n--------------------------------------------\n"
"regionizeFunc({}): computed regions:\n", funcId);
for (auto region : regions) {
FTRACE(5, "{}\n\n", show(*region));
}
}
}
开发者ID:360buyliulei,项目名称:hiphop-php,代码行数:87,代码来源:regionize-func.cpp
示例13: selectHotTrace
RegionDescPtr selectHotTrace(TransID triggerId,
const ProfData* profData,
TransCFG& cfg,
TransIDSet& selectedSet,
TransIDVec* selectedVec) {
auto region = std::make_shared<RegionDesc>();
TransID tid = triggerId;
TransID prevId = InvalidID;
selectedSet.clear();
if (selectedVec) selectedVec->clear();
PostConditions accumPostConds;
while (!selectedSet.count(tid)) {
RegionDescPtr blockRegion = profData->transRegion(tid);
if (blockRegion == nullptr) break;
// If the debugger is attached, only allow single-block regions.
if (prevId != InvalidID && isDebuggerAttachedProcess()) {
FTRACE(2, "selectHotTrace: breaking region at Translation {} "
"because of debugger is attached\n", tid);
break;
}
// Break if block is not the first and requires reffiness checks.
// Task #2589970: fix translateRegion to support mid-region reffiness checks
if (prevId != InvalidID) {
auto nRefDeps = blockRegion->blocks[0]->reffinessPreds().size();
if (nRefDeps > 0) {
FTRACE(2, "selectHotTrace: breaking region because of refDeps ({}) at "
"Translation {}\n", nRefDeps, tid);
break;
}
}
// Break if block is not the first and it corresponds to the main
// function body entry. This is to prevent creating multiple
// large regions containing the function body (starting at various
// DV funclets).
if (prevId != InvalidID) {
const Func* func = profData->transFunc(tid);
Offset bcOffset = profData->transStartBcOff(tid);
if (func->base() == bcOffset) {
FTRACE(2, "selectHotTrace: breaking region because reached the main "
"function body entry at Translation {} (BC offset {})\n",
tid, bcOffset);
break;
}
}
if (prevId != InvalidID) {
auto sk = profData->transSrcKey(tid);
if (profData->optimized(sk)) {
FTRACE(2, "selectHotTrace: breaking region because next sk already "
"optimized, for Translation {}\n", tid);
break;
}
}
// Break trace if translation tid cannot follow the execution of
// the entire translation prevId. This can only happen if the
// execution of prevId takes a side exit that leads to the
// execution of tid.
if (prevId != InvalidID) {
Op* lastInstr = profData->transLastInstr(prevId);
const Unit* unit = profData->transFunc(prevId)->unit();
OffsetSet succOffs = findSuccOffsets(lastInstr, unit);
if (!succOffs.count(profData->transSrcKey(tid).offset())) {
if (HPHP::Trace::moduleEnabled(HPHP::Trace::pgo, 2)) {
FTRACE(2, "selectHotTrace: WARNING: Breaking region @: {}\n",
JIT::show(*region));
FTRACE(2, "selectHotTrace: next translation selected: tid = {}\n{}\n",
tid, JIT::show(*blockRegion));
FTRACE(2, "\nsuccOffs = {}\n", folly::join(", ", succOffs));
}
break;
}
}
region->blocks.insert(region->blocks.end(), blockRegion->blocks.begin(),
blockRegion->blocks.end());
selectedSet.insert(tid);
if (selectedVec) selectedVec->push_back(tid);
Op lastOp = *(profData->transLastInstr(tid));
if (breaksRegion(lastOp)) {
FTRACE(2, "selectHotTrace: breaking region because of last instruction "
"in Translation {}: {}\n", tid, opcodeToName(lastOp));
break;
}
auto outArcs = cfg.outArcs(tid);
if (outArcs.size() == 0) {
FTRACE(2, "selectHotTrace: breaking region because there's no successor "
"for Translation {}\n", tid);
break;
}
auto lastNewBlock = blockRegion->blocks.back();
discardPoppedTypes(accumPostConds,
//.........这里部分代码省略.........
开发者ID:DirektSPEED,项目名称:hhvm,代码行数:101,代码来源:region-hot-trace.cpp
示例14: selectHotTrace
RegionDescPtr selectHotTrace(TransID triggerId,
const ProfData* profData,
TransCFG& cfg,
TransIDSet& selectedSet,
TransIDVec* selectedVec) {
auto region = std::make_shared<RegionDesc>();
TransID tid = triggerId;
TransID prevId = kInvalidTransID;
selectedSet.clear();
if (selectedVec) selectedVec->clear();
PostConditions accumPostConds;
// Maps BlockIds to the set of BC offsets for its successor blocks.
// Used to prevent multiple successors with the same SrcKey for now.
// This can go away once task #4157613 is done.
hphp_hash_map<RegionDesc::BlockId, SrcKeySet> succSKSet;
// Maps from BlockIds to accumulated post conditions for that block.
// Used to determine if we can add branch-over edges by checking the
// pre-conditions of the successor block.
hphp_hash_map<RegionDesc::BlockId, PostConditions> blockPostConds;
while (!selectedSet.count(tid)) {
RegionDescPtr blockRegion = profData->transRegion(tid);
if (blockRegion == nullptr) break;
// If the debugger is attached, only allow single-block regions.
if (prevId != kInvalidTransID && isDebuggerAttachedProcess()) {
FTRACE(2, "selectHotTrace: breaking region at Translation {} "
"because of debugger is attached\n", tid);
break;
}
// Break if block is not the first and it corresponds to the main
// function body entry. This is to prevent creating multiple
// large regions containing the function body (starting at various
// DV funclets).
if (prevId != kInvalidTransID) {
const Func* func = profData->transFunc(tid);
Offset bcOffset = profData->transStartBcOff(tid);
if (func->base() == bcOffset) {
FTRACE(2, "selectHotTrace: breaking region because reached the main "
"function body entry at Translation {} (BC offset {})\n",
tid, bcOffset);
break;
}
}
if (prevId != kInvalidTransID) {
auto sk = profData->transSrcKey(tid);
if (profData->optimized(sk)) {
FTRACE(2, "selectHotTrace: breaking region because next sk already "
"optimized, for Translation {}\n", tid);
break;
}
}
bool hasPredBlock = !region->empty();
RegionDesc::BlockId predBlockId = (hasPredBlock ?
region->blocks().back().get()->id() : 0);
auto const& newFirstBlock = blockRegion->entry();
auto newFirstBlockId = newFirstBlock->id();
auto newFirstBlockSk = newFirstBlock->start();
auto newLastBlockId = blockRegion->blocks().back()->id();
// Make sure we don't end up with multiple successors for the same
// SrcKey. Task #4157613 will allow the following check to go away.
// This needs to be done before we insert blockRegion into region,
// to avoid creating unreachable blocks.
if (RuntimeOption::EvalHHIRBytecodeControlFlow && hasPredBlock &&
succSKSet[predBlockId].count(newFirstBlockSk)) {
break;
}
// Add blockRegion's blocks and arcs to region.
region->append(*blockRegion);
if (hasPredBlock) {
if (RuntimeOption::EvalHHIRBytecodeControlFlow) {
// This is checked above.
assert(succSKSet[predBlockId].count(newFirstBlockSk) == 0);
succSKSet[predBlockId].insert(newFirstBlockSk);
}
region->addArc(predBlockId, newFirstBlockId);
}
// With bytecode control-flow, we add all forward arcs in the TransCFG
// that are induced by the blocks in the region, as a simple way
// to expose control-flow for now.
// This can go away once Task #4075822 is done.
if (RuntimeOption::EvalHHIRBytecodeControlFlow) {
assert(hasTransId(newFirstBlockId));
auto newTransId = getTransId(newFirstBlockId);
auto& blocks = region->blocks();
for (auto iOther = 0; iOther < blocks.size(); iOther++) {
auto other = blocks[iOther];
auto otherFirstBlockId = other.get()->id();
if (!hasTransId(otherFirstBlockId)) continue;
auto otherTransId = getTransId(otherFirstBlockId);
//.........这里部分代码省略.........
开发者ID:CryQ,项目名称:hhvm,代码行数:101,代码来源:region-hot-trace.cpp
示例15: selectHotTrace
RegionDescPtr selectHotTrace(TransID triggerId,
const ProfData* profData,
TransCFG& cfg,
TransIDSet& selectedSet) {
JIT::RegionDescPtr region = smart::make_unique<JIT::RegionDesc>();
TransID tid = triggerId;
TransID prevId = InvalidID;
selectedSet.clear();
while (!setContains(selectedSet, tid)) {
RegionDesc::BlockPtr block = profData->transBlock(tid);
if (block == nullptr) break;
// If the debugger is attached, only allow single-block regions.
if (prevId != InvalidID && isDebuggerAttachedProcess()) {
FTRACE(5, "selectHotRegion: breaking region at Translation {} "
"because of debugger is attached\n", tid);
break;
}
// Break if block is not the first and requires reffiness checks.
// Task #2589970: fix translateRegion to support mid-region reffiness checks
if (prevId != InvalidID) {
auto nRefDeps = block->reffinessPreds().size();
if (nRefDeps > 0) {
FTRACE(5, "selectHotRegion: breaking region because of refDeps ({}) at "
"Translation {}\n", nRefDeps, tid);
break;
}
}
// Break trace if translation tid cannot follow the execution of
// the entire translation prevTd. This can only happen if the
// execution of prevId takes a side exit that leads to the
// execution of tid.
if (prevId != InvalidID) {
Op* lastInstr = profData->transLastInstr(prevId);
const Unit* unit = profData->transFunc(prevId)->unit();
OffsetSet succOffs = findSuccOffsets(lastInstr, unit);
if (!setContains(succOffs, profData->transSrcKey(tid).offset())) {
if (HPHP::Trace::moduleEnabled(HPHP::Trace::pgo, 5)) {
FTRACE(5, "selectHotTrace: WARNING: Breaking region @: {}\n",
JIT::show(*region));
FTRACE(5, "selectHotTrace: next translation selected: tid = {}\n{}\n",
tid, JIT::show(*block));
std::string succStr("succOffs = ");
for (auto succ : succOffs) {
succStr += lexical_cast<std::string>(succ);
}
FTRACE(5, "\n{}\n", succStr);
}
break;
}
}
region->blocks.emplace_back(block);
selectedSet.insert(tid);
Op lastOp = *(profData->transLastInstr(tid));
if (breaksRegion(lastOp)) {
FTRACE(5, "selectHotTrace: breaking region because of last instruction "
"in Translation {}: {}\n", tid, opcodeToName(lastOp));
break;
}
auto outArcs = cfg.outArcs(tid);
if (outArcs.size() == 0) {
FTRACE(5, "selectHotTrace: breaking region because there's no successor "
"for Translation {}\n", tid);
break;
}
auto maxWeight = std::numeric_limits<int64_t>::min();
TransCFG::Arc* maxArc = nullptr;
for (auto arc : outArcs) {
if (arc->weight() >= maxWeight) {
maxWeight = arc->weight();
maxArc = arc;
}
}
assert(maxArc != nullptr);
prevId = tid;
tid = maxArc->dst();
}
return region;
}
开发者ID:HendrikGrunstra,项目名称:hiphop-php,代码行数:88,代码来源:region-hot-trace.cpp
注:本文中的TransIDSet类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论