// // inlines the function called by 'call' at that call site // static void inlineCall(FnSymbol* fn, CallExpr* call, Vec<FnSymbol*>& canRemoveRefTempSet) { INT_ASSERT(call->isResolved() == fn); SET_LINENO(call); Expr* stmt = call->getStmtExpr(); // // calculate a map from actual symbols to formal symbols // SymbolMap map; for_formals_actuals(formal, actual, call) { SymExpr* se = toSymExpr(actual); INT_ASSERT(se); if ((formal->intent & INTENT_REF) && canRemoveRefTempSet.set_in(fn)) { if (se->var->hasFlag(FLAG_REF_TEMP)) { if (CallExpr* move = findRefTempInit(se)) { SymExpr* origSym = NULL; if (CallExpr* addrOf = toCallExpr(move->get(2))) { INT_ASSERT(addrOf->isPrimitive(PRIM_ADDR_OF)); origSym = toSymExpr(addrOf->get(1)); } else { origSym = toSymExpr(move->get(2)); } INT_ASSERT(origSym); map.put(formal, origSym->var); se->var->defPoint->remove(); move->remove(); continue; } } } map.put(formal, se->var); }
SymbolMap::const_iterator findCursorInfo(const SymbolMap &map, const Location &location, const String &context, const SymbolMap *errors, bool *foundInErrors) { if (foundInErrors) *foundInErrors = false; if (map.isEmpty() && !errors) return map.end(); if (errors) { SymbolMap::const_iterator ret = findCursorInfo(map, location, context, false); if (ret != map.end()) { return ret; } ret = findCursorInfo(*errors, location, context, false); if (ret != errors->end()) { if (foundInErrors) *foundInErrors = true; return ret; } // ret = findCursorInfo(*errors, location, context, true); // if (ret != errors->end()) { // if (foundInErrors) // *foundInErrors = true; // return ret; // } // ret = findCursorInfo(map, location, context, true); // if (ret != map.end()) { // return ret; // } return map.end(); } else { const SymbolMap::const_iterator ret = findCursorInfo(map, location, context, true); return ret; } }
void trial( SymbolList & testSet, SymbolList & notCirc, SymbolMap & symbolMap ) { bool bDone = false; while (!bDone) { bDone = true; SymbolList::iterator item = testSet.begin(); SymbolList::iterator last = testSet.end(); while (item != last) { SymbolList::iterator thisItem = item++; const Symbol sym = *thisItem; bool bIsReferedTo = symbolMap.isReferredTo( sym ); bool bRefersTo = symbolMap.refersTo ( sym ); if (!( bIsReferedTo && bRefersTo) ) { bDone = false; symbolMap.remove( sym ); testSet.remove( sym ); notCirc.push_back( sym ); } } } }
void ObjIeeeAscii::PutSymbol(SymbolMap &map, int index, ObjSymbol *sym) { if (map.size() <= index) { map.resize(index > 100 ? index*2 : 200); } map[index] = sym; }
std::string getSymbol( const std::string &varName ) { SymbolMap::iterator sbmItr = _symbolMap.find( varName ); if ( sbmItr == _symbolMap.end() ) { SpecialSymbolMap::iterator ssmItr = _specialSymbolMap.find( varName ); return ssmItr == _specialSymbolMap.end() ? varName : ssmItr->second; } return sbmItr->second.back(); }
SymbolMap CursorInfo::virtuals(const Location &loc, const SymbolMap &map) const { SymbolMap ret; ret[loc] = copy(); const SymbolMap s = (kind == CXCursor_CXXMethod ? allReferences(loc, map) : targetInfos(map)); for (auto it = s.begin(); it != s.end(); ++it) { if (it->second->kind == kind) ret[it->first] = it->second; } return ret; }
SymbolMap CursorInfo::virtuals(const Location &loc, const SymbolMap &map, const SymbolMap *errors) const { SymbolMap ret; ret[loc] = *this; const SymbolMap s = (kind == CXCursor_CXXMethod ? allReferences(loc, map, errors) : targetInfos(map, errors)); for (SymbolMap::const_iterator it = s.begin(); it != s.end(); ++it) { if (it->second.kind == kind) ret[it->first] = it->second; } return ret; }
void dirtySymbols(SymbolMap &map, const Set<uint32_t> &dirty) { SymbolMap::iterator it = map.begin(); while (it != map.end()) { if (dirty.contains(it->first.fileId())) { map.erase(it++); } else { it->second->dirty(dirty); ++it; } } }
//================================== // Update CodeTree //================================== void SpineDecoder::expand_wavefront(vector<int> sym_spine){ /* 变量的定义和初始化是按照变量的用途分类的 */ int edge_metric = 0; int distance = 0; RNG rng; SymbolMap mapper; uint8_t node_symbol = 0; vector<CodeTreeNode> wavefront = this->wavefront; vector<CodeTreeNode> new_wavefront; /* 数组 wavefront 中的每一个元素对应 spine_t 的一个节点 */ vector<CodeTreeNode>::iterator iwave = wavefront.begin(); /* 创建树的过程是一层一层的创建,使用 vector 添加或删除节点时,实现起来比较方便 */ while(iwave != wavefront.end()){ for(int edge=0; edge!=(1<<(this->k)); ++edge){//edge 也就是 mt,这个循环用来遍历可能出现的 k-bit m. CodeTreeNode new_node; /* 1. update spine_value */ new_node.spine_value = hash_func(iwave->spine_value, edge); rng = RNG(new_node.spine_value); for(int i=0; i!=this->L; ++i){ node_symbol = mapper.map_func(rng.next()); distance = sym_spine[i] - node_symbol; edge_metric = distance * distance; }//end for /* 2.update path_metric */ new_node.path_metric = iwave->path_metric + edge_metric; /* 3.update path */ new_node.path = iwave->path; new_node.path.push_back(edge); /* Finaly, update wavefront */ new_wavefront.push_back(new_node); }//end for ++iwave; }//end while this->wavefront = new_wavefront; if(!wavefront.empty()) wavefront.clear(); if(!new_wavefront.empty()) new_wavefront.clear(); }
static inline void joinCursors(SymbolMap &symbols, const Set<Location> &locations) { for (Set<Location>::const_iterator it = locations.begin(); it != locations.end(); ++it) { SymbolMap::iterator c = symbols.find(*it); if (c != symbols.end()) { CursorInfo &cursorInfo = c->second; for (Set<Location>::const_iterator innerIt = locations.begin(); innerIt != locations.end(); ++innerIt) { if (innerIt != it) cursorInfo.targets.insert(*innerIt); } // ### this is filthy, we could likely think of something better } } }
// Mark the variables listed in 'with' clauses, if any, with tiMark markers. // Same as markOuterVarsWithIntents() in implementForallIntents.cpp, // except uses byrefVars instead of forallIntents. static void markOuterVarsWithIntents(CallExpr* byrefVars, SymbolMap& uses) { if (!byrefVars) return; Symbol* marker = NULL; // Keep in sync with setupForallIntents() - the actuals alternate: // (tiMark arg | reduce opExpr), task-intent variable [, repeat] for_actuals(actual, byrefVars) { SymExpr* se = toSymExpr(actual); INT_ASSERT(se); // comes as an UnresolvedSymExpr from the parser, // should have been resolved in ScopeResolve // or it is a SymExpr over a tiMark ArgSymbol // or over chpl__reduceGlob Symbol* var = se->symbol(); if (marker) { SymbolMapElem* elem = uses.get_record(var); if (elem) { elem->value = marker; } else { if (isVarSymbol(marker)) { // this is a globalOp created in setupOneReduceIntent() INT_ASSERT(!strcmp(marker->name, "chpl__reduceGlob")); USR_WARN(byrefVars, "the variable '%s' is given a reduce intent and not mentioned in the loop body - it will have the unit value after the loop", var->name); } } marker = NULL; } else { marker = var; INT_ASSERT(marker); // otherwise the alternation logic will not work } }
virtual void addPair(const Symbol & symbol, const Symbol & ref) { testSet.addUniq( symbol ); symbolMap.addPair( symbol, ref ); }
void PProfService::symbol( ::google::protobuf::RpcController* controller_base, const ::brpc::ProfileRequest* /*request*/, ::brpc::ProfileResponse* /*response*/, ::google::protobuf::Closure* done) { ClosureGuard done_guard(done); Controller* cntl = static_cast<Controller*>(controller_base); cntl->http_response().set_content_type("text/plain"); // Load /proc/self/maps pthread_once(&s_load_symbolmap_once, LoadSymbols); if (cntl->http_request().method() != HTTP_METHOD_POST) { char buf[64]; snprintf(buf, sizeof(buf), "num_symbols: %lu\n", symbol_map.size()); cntl->response_attachment().append(buf); } else { // addr_str is addressed separated by + std::string addr_str = cntl->request_attachment().to_string(); // May be quoted const char* addr_cstr = addr_str.c_str(); if (*addr_cstr == '\'' || *addr_cstr == '"') { ++addr_cstr; } std::vector<uintptr_t> addr_list; addr_list.reserve(32); butil::StringSplitter sp(addr_cstr, '+'); for ( ; sp != NULL; ++sp) { char* endptr; uintptr_t addr = strtoull(sp.field(), &endptr, 16); addr_list.push_back(addr); } FindSymbols(&cntl->response_attachment(), addr_list); } }
// // inlines the function called by 'call' at that call site // static void inlineCall(FnSymbol* fn, CallExpr* call) { INT_ASSERT(call->isResolved() == fn); SET_LINENO(call); Expr* stmt = call->getStmtExpr(); // // calculate a map from actual symbols to formal symbols // SymbolMap map; for_formals_actuals(formal, actual, call) { SymExpr* se = toSymExpr(actual); INT_ASSERT(se); map.put(formal, se->var); }
static inline void writeErrorSymbols(const SymbolMap &symbols, ErrorSymbolMap &errorSymbols, const Map<uint32_t, int> &errors) { for (Map<uint32_t, int>::const_iterator it = errors.begin(); it != errors.end(); ++it) { if (it->second) { SymbolMap &symbolsForFile = errorSymbols[it->first]; if (symbolsForFile.isEmpty()) { const Location loc(it->first, 0); SymbolMap::const_iterator sit = symbols.lower_bound(loc); while (sit != symbols.end() && sit->first.fileId() == it->first) { symbolsForFile[sit->first] = sit->second; ++sit; } } } else { errorSymbols.remove(it->first); } } }
SymbolMap CursorInfo::callers(const Location &loc, const SymbolMap &map, const SymbolMap *errors) const { SymbolMap ret; const SymbolMap cursors = virtuals(loc, map, errors); for (SymbolMap::const_iterator c = cursors.begin(); c != cursors.end(); ++c) { for (Set<Location>::const_iterator it = c->second.references.begin(); it != c->second.references.end(); ++it) { const SymbolMap::const_iterator found = RTags::findCursorInfo(map, *it, String(), errors); if (found == map.end()) continue; if (RTags::isReference(found->second.kind)) { // is this always right? ret[*it] = found->second; } else if (kind == CXCursor_Constructor && (found->second.kind == CXCursor_VarDecl || found->second.kind == CXCursor_FieldDecl)) { ret[*it] = found->second; } } } return ret; }
static void addDefAndMap(Expr* aInit, SymbolMap& map, ShadowVarSymbol* svar, VarSymbol* currVar) { if (currVar->type == dtNothing) { INT_ASSERT(currVar->firstSymExpr() == NULL); return; } aInit->insertBefore(new DefExpr(currVar)); map.put(svar, currVar); }
SymbolMap CursorInfo::referenceInfos(const SymbolMap &map) const { SymbolMap ret; for (auto it = references.begin(); it != references.end(); ++it) { auto found = RTags::findCursorInfo(map, *it, String()); if (found != map.end()) { ret[*it] = found->second; } } return ret; }
SymbolMap CursorInfo::referenceInfos(const SymbolMap &map, const SymbolMap *errors) const { SymbolMap ret; for (Set<Location>::const_iterator it = references.begin(); it != references.end(); ++it) { SymbolMap::const_iterator found = RTags::findCursorInfo(map, *it, String(), errors); if (found != map.end()) { ret[*it] = found->second; } } return ret; }
CursorInfo CursorInfo::bestTarget(const SymbolMap &map, const SymbolMap *errors, Location *loc) const { const SymbolMap targets = targetInfos(map, errors); SymbolMap::const_iterator best = targets.end(); int bestRank = -1; for (SymbolMap::const_iterator it = targets.begin(); it != targets.end(); ++it) { const CursorInfo &ci = it->second; const int r = targetRank(ci); if (r > bestRank || (r == bestRank && ci.isDefinition())) { bestRank = r; best = it; } } if (best != targets.end()) { if (loc) *loc = best->first; return best->second; } return CursorInfo(); }
std::shared_ptr<CursorInfo> CursorInfo::bestTarget(const SymbolMap &map, Location *loc) const { const SymbolMap targets = targetInfos(map); auto best = targets.end(); int bestRank = -1; for (auto it = targets.begin(); it != targets.end(); ++it) { const std::shared_ptr<CursorInfo> &ci = it->second; const int r = targetRank(ci); if (r > bestRank || (r == bestRank && ci->isDefinition())) { bestRank = r; best = it; } } if (best != targets.end()) { if (loc) *loc = best->first; return best->second; } return std::shared_ptr<CursorInfo>(); }
/** * Search for the symbol named name within the object named OBJ within * the target process proc. If the symbol is found the address of the * symbol is stored in addr. */ ps_err_e ps_pglobal_lookup(ps_prochandle* proc, const char* obj, const char* name, psaddr_t* addr) { assert(addr); *addr = 0; try { SymbolEnum e; SymbolMap* symbols = proc ? proc->symbols() : NULL; if (!symbols) { return PS_ERR; // symbols not loaded } symbols->enum_symbols(name, &e, (SymbolTable::LKUP_DYNAMIC | SymbolTable::LKUP_ISMANGLED)); if (e.size()) { // hack: cache the symbol table where the name was // found -- it is very likely the other thread_db-related // symbols are in the same table if (!proc->symtab_) { ZObjectScope scope; proc->symtab_ = e.front()->table(&scope); } assert(addr); // return the first match *addr = psaddr_t(e.front()->addr()); return PS_OK; } } catch (const exception& e) { cerr << __func__ << ": " << e.what() << endl; } return PS_ERR; }
SymbolMap CursorInfo::targetInfos(const SymbolMap &map) const { SymbolMap ret; for (Set<Location>::const_iterator it = targets.begin(); it != targets.end(); ++it) { SymbolMap::const_iterator found = RTags::findCursorInfo(map, *it); if (found != map.end()) { ret[*it] = found->second; } else { ret[*it] = CursorInfo(); // we need this one for inclusion directives which target a // non-existing CursorInfo } } return ret; }
static void FindSymbols(butil::IOBuf* out, std::vector<uintptr_t>& addr_list) { char buf[32]; for (size_t i = 0; i < addr_list.size(); ++i) { int len = snprintf(buf, sizeof(buf), "0x%08lx\t", addr_list[i]); out->append(buf, len); SymbolMap::const_iterator it = symbol_map.lower_bound(addr_list[i]); if (it == symbol_map.end() || it->first != addr_list[i]) { if (it != symbol_map.begin()) { --it; } else { len = snprintf(buf, sizeof(buf), "0x%08lx\n", addr_list[i]); out->append(buf, len); continue; } } if (it->second.empty()) { len = snprintf(buf, sizeof(buf), "0x%08lx\n", addr_list[i]); out->append(buf, len); } else { out->append(it->second); out->push_back('\n'); } } }
SymbolMap CursorInfo::targetInfos(const SymbolMap &map, const SymbolMap *errors) const { SymbolMap ret; for (Set<Location>::const_iterator it = targets.begin(); it != targets.end(); ++it) { SymbolMap::const_iterator found = RTags::findCursorInfo(map, *it, String(), errors); // ### could/should I pass symbolName as context here? if (found != map.end()) { ret[*it] = found->second; } else { ret[*it] = CursorInfo(); // we need this one for inclusion directives which target a // non-existing CursorInfo } } return ret; }
SymbolMap CursorInfo::targetInfos(const SymbolMap &map) const { SymbolMap ret; for (auto it = targets.begin(); it != targets.end(); ++it) { auto found = RTags::findCursorInfo(map, *it, String()); // ### could/should I pass symbolName as context here? if (found != map.end()) { ret[*it] = found->second; } else { ret[*it] = std::make_shared<CursorInfo>(); // we need this one for inclusion directives which target a // non-existing CursorInfo } } return ret; }
static void findOuterVars(FnSymbol* fn, SymbolMap& uses) { std::vector<BaseAST*> asts; collect_asts(fn, asts); for_vector(BaseAST, ast, asts) { if (SymExpr* symExpr = toSymExpr(ast)) { Symbol* sym = symExpr->symbol(); if (isLcnSymbol(sym)) { if (!isCorrespCoforallIndex(fn, sym) && isOuterVar(sym, fn)) uses.put(sym, markUnspecified); } } } }
static inline void allImpl(const SymbolMap &map, const Location &loc, const CursorInfo &info, SymbolMap &out, Mode mode, CXCursorKind kind) { if (out.contains(loc)) return; out[loc] = info; typedef SymbolMap (CursorInfo::*Function)(const SymbolMap &map) const; const SymbolMap targets = info.targetInfos(map); for (SymbolMap::const_iterator t = targets.begin(); t != targets.end(); ++t) { bool ok = false; switch (mode) { case VirtualRefs: case NormalRefs: ok = (t->second.kind == kind); break; case ClassRefs: ok = (t->second.isClass() || t->second.kind == CXCursor_Destructor || t->second.kind == CXCursor_Constructor); break; } if (ok) allImpl(map, t->first, t->second, out, mode, kind); } const SymbolMap refs = info.referenceInfos(map); for (SymbolMap::const_iterator r = refs.begin(); r != refs.end(); ++r) { switch (mode) { case NormalRefs: out[r->first] = r->second; break; case VirtualRefs: if (r->second.kind == kind) { allImpl(map, r->first, r->second, out, mode, kind); } else { out[r->first] = r->second; } break; case ClassRefs: if (info.isClass()) // for class/struct we want the references inserted directly regardless and also recursed out[r->first] = r->second; if (r->second.isClass() || r->second.kind == CXCursor_Destructor || r->second.kind == CXCursor_Constructor) { // if is a constructor/destructor/class reference we want to recurse it allImpl(map, r->first, r->second, out, mode, kind); } } } }
static inline void allImpl(const SymbolMap &map, const Location &loc, const std::shared_ptr<CursorInfo> &info, SymbolMap &out, Mode mode, unsigned kind) { if (out.contains(loc)) return; out[loc] = info; const SymbolMap targets = info->targetInfos(map); for (auto t = targets.begin(); t != targets.end(); ++t) { bool ok = false; switch (mode) { case VirtualRefs: case NormalRefs: ok = (t->second->kind == kind); break; case ClassRefs: ok = (t->second->isClass() || t->second->kind == CXCursor_Destructor || t->second->kind == CXCursor_Constructor); break; } if (ok) allImpl(map, t->first, t->second, out, mode, kind); } const SymbolMap refs = info->referenceInfos(map); for (auto r = refs.begin(); r != refs.end(); ++r) { switch (mode) { case NormalRefs: out[r->first] = r->second; break; case VirtualRefs: if (r->second->kind == kind) { allImpl(map, r->first, r->second, out, mode, kind); } else { out[r->first] = r->second; } break; case ClassRefs: if (info->isClass()) // for class/struct we want the references inserted directly regardless and also recursed out[r->first] = r->second; if (r->second->isClass() || r->second->kind == CXCursor_Destructor || r->second->kind == CXCursor_Constructor) { // if is a constructor/destructor/class reference we want to recurse it allImpl(map, r->first, r->second, out, mode, kind); } } } }
SymbolMap::const_iterator findCursorInfo(const SymbolMap &map, const Location &location) { if (map.isEmpty()) return map.end(); SymbolMap::const_iterator it = map.find(location); if (it != map.end()) return it; it = map.lower_bound(location); if (it == map.end()) { --it; } else { const int cmp = it->first.compare(location); if (!cmp) return it; --it; } if (location.fileId() != it->first.fileId()) return map.end(); const int off = location.offset() - it->first.offset(); if (it->second.symbolLength > off) return it; return map.end(); }