CodeNodePtr findMultiplyReferenced( CodeNodePtr node, const ReferenceMap& refs ) { assert(node); ReferenceMap::const_iterator it = refs.find(node); if (REN_DYNAMIC_CAST_PTR(p, CallCodeNode, node)) { if (it != refs.end() && it->second.size() > 1) { return p; } } else if (REN_DYNAMIC_CAST_PTR(p, IfCodeNode, node)) { if (it != refs.end() && it->second.size() > 1) { return p; } } else if (REN_DYNAMIC_CAST_PTR(p, NameCodeNode, node)) { // Do nothing. } else { assert(!"Unknown code node type"); } CodeNodeList args = node->getChildren(); for (size_t i = 0; i < args.size(); ++i) { CodeNodePtr c = findMultiplyReferenced(args[i], refs); if (c) { return c; } } return CodeNodePtr(); }
int Linker :: fillImportTable(ImageInfo& info) { int count = 0; ReferenceMap::Iterator it = info.image->getExternalIt(); while (!it.Eof()) { ident_t external = it.key(); ident_t function = external + external.findLast('.') + 1; IdentifierString dll(external + getlength(DLL_NAMESPACE) + 1, function - (external + getlength(DLL_NAMESPACE)) - 2); if (dll.ident().compare(RTDLL_FORWARD)) { dll.copy(info.project->resolvePrimitive(RTDLL_FORWARD)); } ReferenceMap* functions = info.importTable.get(dll); if (functions==NULL) { functions = new ReferenceMap(0); info.importTable.add(dll, functions); } functions->add(function, *it); it++; count++; } return count; }
void HexagonExpandCondsets::addRefToMap(RegisterRef RR, ReferenceMap &Map, unsigned Exec) { unsigned Mask = getMaskForSub(RR.Sub) | Exec; ReferenceMap::iterator F = Map.find(RR.Reg); if (F == Map.end()) Map.insert(std::make_pair(RR.Reg, Mask)); else F->second |= Mask; }
bool HexagonExpandCondsets::isRefInMap(RegisterRef RR, ReferenceMap &Map, unsigned Exec) { ReferenceMap::iterator F = Map.find(RR.Reg); if (F == Map.end()) return false; unsigned Mask = getMaskForSub(RR.Sub) | Exec; if (Mask & F->second) return true; return false; }
static inline void writeReferences(const ReferenceMap &references, SymbolMap &symbols) { const ReferenceMap::const_iterator end = references.end(); for (ReferenceMap::const_iterator it = references.begin(); it != end; ++it) { const Set<Location> &refs = it->second; for (Set<Location>::const_iterator rit = refs.begin(); rit != refs.end(); ++rit) { CursorInfo &ci = symbols[*rit]; ci.references.insert(it->first); } } }
void GLSLShader::share() { ReferenceMap rm; countReferences(main, rm); // std::cout << "++++\n"; // output(std::cout); // Conversion to StatementPtr overload is ambiguous otherwise. StatementPtr main_stmt(main); while (CodeNodePtr p = findMultiplyReferenced(main_stmt, rm)) { ReferenceList rl = rm[p]; ReferencePath prefix(getCommonPrefix(rl)); assert(prefix[0] == main); string name = newRegisterName(); CodeNodePtr nameReference( new NameCodeNode( name, p->getType(), p->getFrequency(), NullValue, ValueNode::BUILTIN)); // suitable substitute for local replace(main_stmt, p, nameReference); AssignmentPtr ns(new Assignment); ns->define = true; ns->lhs = name; ns->rhs = p; assert(!prefix.empty()); StatementPtr lastInCommonPrefix(prefix[prefix.size() - 1]); // Make a new block. BlockPtr newBlock(new Block); newBlock->statements.push_back(ns); newBlock->statements.push_back(lastInCommonPrefix); if (main_stmt == lastInCommonPrefix) { main = newBlock; main_stmt = main; } else { replace(main_stmt, lastInCommonPrefix, newBlock); } rm.clear(); countReferences(main, rm); // std::cout << "++++\n"; // output(std::cout); } }
RememberedSet::ReferenceMap* RememberedSet::ReferenceMap::forwardMap() const { ReferenceMap* newRefMap = new ReferenceMap(); for (const_iterator it = mRefs.begin(); it != mRefs.end(); it++) { GCObject* newReferent = it->second->getPtr(); Object** newReference = reinterpret_cast<Object**>(reinterpret_cast<byte*>(newReferent) + (reinterpret_cast<byte*>(it->first) - reinterpret_cast<byte*>(it->second))); newRefMap->addReference(newReference, newReferent); } return newRefMap; }