_XResourceInfo *_XResourceManager::loadResource(const char * name,_XResourceType type,_XResourcePosition resoursePosition) //载入指定资源 { if(name == NULL) return NULL; _XResourceInfo * temp = isLoad(name); if(temp != NULL && temp->m_type == type) {//已经载入,并且资源是匹配的 ++ temp->m_counter; //增加一层引用 printf("%d:%s\n",temp->m_counter,temp->m_name); return temp; }else {//尚未载入 temp = createMem<_XResourceInfo>(); if(temp == NULL) return NULL; temp->m_name = createArrayMem<char>(MAX_FILE_NAME_LENGTH); if(temp->m_name == NULL) return NULL; strcpy(temp->m_name,name); temp->m_type = type; if(temp->load(resoursePosition) != 0) { m_resourceBuff.push_back(temp); ++ m_resourceSum; ++ temp->m_counter; return temp; //资源载入成功 }else {//资源载入失败 XDELETE_ARRAY(temp->m_name); XDELETE(temp); return NULL; } } }
void MemoryValue::dumpMeta(CommaPrinter& comma, PrintStream& out) const { if (m_offset) out.print(comma, "offset = ", m_offset); if ((isLoad() && effects().reads != range()) || (isStore() && effects().writes != range())) out.print(comma, "range = ", range()); }
static bool propagateValueToSuccessors(analysis::DataflowGraph& dfg, BlockSet& blocks, InstructionVector::iterator instruction) { if(!isOutputConstant(instruction)) { return false; } auto ptx = static_cast<ir::PTXInstruction*>(instruction->i); if(ptx->isLoad()) { return false; } // TODO support instructions with multiple destinations if(instruction->d.size() != 1) { return false; } report(" checking " << instruction->i->toString()); // get the value ir::PTXOperand value; bool success = computeValue(value, *ptx); if(!success) { report(" could not determine the resulting value."); return false; } // send it to successors auto registerId = *instruction->d.back().pointer; auto block = instruction->block; BlockSet visited; updateUses(block, registerId, value, visited); return true; }
void HoistParameterLoadsPass::runOnKernel(ir::IRKernel& k) { typedef std::pair<ir::ControlFlowGraph::iterator, ir::PTXInstruction*> Load; typedef std::vector<Load> LoadVector; auto aliasAnalysis = static_cast<analysis::SimpleAliasAnalysis*>( getAnalysis(Analysis::SimpleAliasAnalysis)); LoadVector candidateLoads; report("Hoisting loads in kernel '" << k.name << "'"); report(" Identifying candidate loads"); for(auto block = k.cfg()->begin(); block != k.cfg()->end(); ++block) { for(auto instruction = block->instructions.begin(); instruction != block->instructions.end(); ++instruction) { auto ptx = static_cast<ir::PTXInstruction*>(*instruction); if(ptx->isLoad() && aliasAnalysis->cannotAliasAnyStore(*instruction) && hasNoRegisterDependencies(*ptx)) { report(" " << ptx->toString()); candidateLoads.push_back(std::make_pair(block, ptx)); } } } report(" Attempting to hoist loads"); for(auto load = candidateLoads.begin(); load != candidateLoads.end(); ++load) { _tryHoistingLoad(load->first, load->second, k); } invalidateAnalysis(analysis::Analysis::DataflowGraphAnalysis); invalidateAnalysis(analysis::Analysis::SimpleAliasAnalysis ); }
void DynamicLibrary::load(const char *fileName, OpenFlags flags) { if (isLoad()) { lastErrorMessage_.clear(); errorCode_ = LoaderError::LIBRARY_ALREADY_LOADED; return; } if (! static_cast<bool>(flags & OpenFlags::LAZY_BINDING)) { flags |= OpenFlags::ONLOAD_BINDING; } void* handler = DynamicLibrary::dlopen(fileName, flags); if (handler != nullptr) { libraryHandle_ = LibraryHandle(handler, &dlclose); } else { lastErrorMessage_ = DynamicLibrary::dlerror(); errorCode_ = LoaderError::LIBRARY_LOAD_FAILED; } }
void Components::Unload() { if (isLoad()) { DllDetailIterator ddiIterator = DDV.begin(); do { _FreeComponent pFreeComponent = (_FreeComponent) GetProcAddress(ddiIterator->hModule, "FreeComponent"); if (pFreeComponent) pFreeComponent(); else delete ddiIterator->pComponent; FreeLibrary(ddiIterator->hModule); ddiIterator++; } while (ddiIterator != DDV.end()); } }
void MemMap::optimizeMemoryAccesses(Trace* trace) { StoreList tracking; for (IRInstruction* inst : trace->getInstructionList()) { // initialize each instruction as live inst->setId(LIVE); int offset = -1; Opcode op = inst->getOpcode(); if (isLoad(op)) { if (op == LdProp) { offset = inst->getSrc(1)->getConstValAsInt(); } optimizeLoad(inst, offset); } else if (isStore(op)) { if (op == StProp || op == StPropNT) { offset = inst->getSrc(1)->getConstValAsInt(); } // if we see a store, first check if its last available access is a store // if it is, then the last access is a dead store IRInstruction* access = getLastAccess(inst->getSrc(0), offset); if (access != NULL && isStore(access->getOpcode())) { // if a dead St* is followed by a St*NT, then the second store needs to // now write in the type because the first store will be removed if (access->getOpcode() == StProp && op == StPropNT) { inst->setOpcode(StProp); } else if (access->getOpcode() == StLoc && op == StLocNT) { inst->setOpcode(StLoc); } else if (access->getOpcode() == StRef && op == StRefNT) { inst->setOpcode(StRef); } access->setId(DEAD); } // start tracking the current store tracking.push_back(std::make_pair(inst, std::vector<IRInstruction*>())); } else if (inst->mayRaiseError()) { // if the function has an exit edge that we don't know anything about // (raising an error), then all stores we're currently tracking need to // be erased. all stores already declared dead are untouched StoreList::iterator it, end; for (it = tracking.begin(), end = tracking.end(); it != end; ) { StoreList::iterator copy = it; ++it; if (copy->first->getId() != DEAD) { // XXX: t1779667 tracking.erase(copy); } } } // if the current instruction is guarded, make sure all of our stores that // are not yet dead know about it if (inst->getLabel() != NULL) { for (auto& entry : tracking) { if (entry.first->getId() != DEAD) { entry.second.push_back(inst); } } } Simplifier::copyProp(inst); processInstruction(inst); } sinkStores(tracking); // kill the dead stores removeDeadInstructions(trace); }
void MemMap::optimizeMemoryAccesses(Trace* trace) { if (hasInternalFlow(trace)) { // This algorithm only works with linear traces. // TODO t2066994: reset state after each block, at least. return; } StoreList tracking; const Func* curFunc = nullptr; for (Block* block : trace->getBlocks()) { for (IRInstruction& inst : *block) { if (inst.getOpcode() == Marker) { curFunc = inst.getExtra<Marker>()->func; } // initialize each instruction as live setLive(inst, true); int offset = -1; Opcode op = inst.getOpcode(); if (isLoad(op)) { if (op == LdProp) { offset = inst.getSrc(1)->getValInt(); } // initialize each instruction as live setLive(inst, true); optimizeLoad(&inst, offset); } else if (isStore(op)) { if (op == StProp || op == StPropNT) { offset = inst.getSrc(1)->getValInt(); } // if we see a store, first check if its last available access is a store // if it is, then the last access is a dead store auto access = inst.getOpcode() == StLoc || inst.getOpcode() == StLocNT ? lastLocalAccess(inst.getExtra<LocalId>()->locId) : getLastAccess(inst.getSrc(0), offset); if (access && isStore(access->getOpcode())) { // if a dead St* is followed by a St*NT, then the second store needs to // now write in the type because the first store will be removed if (access->getOpcode() == StProp && op == StPropNT) { inst.setOpcode(StProp); } else if (access->getOpcode() == StLoc && op == StLocNT) { inst.setOpcode(StLoc); } else if (access->getOpcode() == StRef && op == StRefNT) { inst.setOpcode(StRef); } setLive(*access, false); } // start tracking the current store tracking.push_back(std::make_pair(&inst, std::vector<IRInstruction*>())); } else if (inst.mayRaiseError()) { // if the function has an exit edge that we don't know anything about // (raising an error), then all stores we're currently tracking need to // be erased. all stores already declared dead are untouched StoreList::iterator it, end; for (it = tracking.begin(), end = tracking.end(); it != end; ) { StoreList::iterator copy = it; ++it; if (isLive(copy->first)) { // XXX: t1779667 tracking.erase(copy); } } } // if the current instruction is guarded, make sure all of our stores that // are not yet dead know about it if (inst.getTaken()) { for (auto& entry : tracking) { if (isLive(entry.first)) { entry.second.push_back(&inst); } } } Simplifier::copyProp(&inst); processInstruction(&inst, curFunc && curFunc->isPseudoMain()); } } sinkStores(tracking); // kill the dead stores removeDeadInstructions(trace, m_liveInsts); }
bool Instruction::isMemop(){ return (isLoad() || isStore()); }
bool Instruction::accessesMemory() const { return isLoad() || isStore(); }