Changeset 4064 in CLRX


Ignore:
Timestamp:
May 3, 2018, 1:05:15 PM (3 months ago)
Author:
matszpk
Message:

CLRadeonExtender: AsmRegAlloc?: Prepping to better joinRegVars (createLivenesses).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • CLRadeonExtender/trunk/amdasm/AsmRegAlloc.cpp

    r4063 r4064  
    723723}
    724724
     725static Liveness& getLiveness2(const AsmSingleVReg& svreg,
     726        size_t ssaId, std::vector<Liveness>* livenesses,
     727        const VarIndexMap* vregIndexMaps, size_t regTypesNum, const cxuint* regRanges)
     728{
     729    cxuint regType = getRegType(regTypesNum, regRanges, svreg); // regtype
     730    const VarIndexMap& vregIndexMap = vregIndexMaps[regType];
     731    const std::vector<size_t>& ssaIdIndices = vregIndexMap.find(svreg)->second;
     732    ARDOut << "lvn[" << regType << "][" << ssaIdIndices[ssaId] << "]. ssaId: " <<
     733            ssaId << ". svreg: " << svreg.regVar << ":" << svreg.index << "\n";
     734    return livenesses[regType][ssaIdIndices[ssaId]];
     735}
     736
    725737/* TODO: add handling calls
    726738 * handle many start points in this code (for example many kernel's in same code)
     
    777789}
    778790
    779 static void joinSVregWithVisited(const SVRegMap* stackVarMap, const SSAEntry& sentry,
    780             const std::deque<FlowStackEntry3>& prevFlowStack,
     791static void joinSVregWithVisited(const SVRegMap* stackVarMap, const AsmSingleVReg& vreg,
     792            size_t ssaIdNextBefore, const std::deque<FlowStackEntry3>& prevFlowStack,
    781793            const std::vector<CodeBlock>& codeBlocks, const VarIndexMap* vregIndexMaps,
    782794            std::vector<Liveness>* livenesses, size_t regTypesNum, const cxuint* regRanges)
     
    784796    auto pfEnd = prevFlowStack.end();
    785797    --pfEnd;
    786     const SSAInfo& sinfo = sentry.second;
    787798   
    788799    // join liveness for this variable ssaId>.
    789800    // only if in previous block previous SSAID is
    790801    // read before all writes
    791     auto it = stackVarMap->find(sentry.first);
     802    auto it = stackVarMap->find(vreg);
    792803   
    793804    const size_t pfStart = (it != stackVarMap->end() ? it->second : 0);
     
    795806        //continue;
    796807    // fill up previous part
    797     Liveness& lv = getLiveness(sentry.first, 0, sinfo,
     808    Liveness& lv = getLiveness2(vreg, ssaIdNextBefore,
    798809            livenesses, vregIndexMaps, regTypesNum, regRanges);
    799810    auto flit = prevFlowStack.begin() + pfStart;
     
    801812        // fill up liveness for first code block
    802813        const CodeBlock& cblock = codeBlocks[flit->blockIndex];
    803         auto ssaInfoIt = cblock.ssaInfoMap.find(sentry.first);
     814        auto ssaInfoIt = cblock.ssaInfoMap.find(vreg);
    804815        size_t prevLastPos = (ssaInfoIt != cblock.ssaInfoMap.end()) ?
    805816                ssaInfoIt->second.lastPos+1 : cblock.start;
     
    816827static void handleSSAEntryWhileJoining(const SVRegMap* stackVarMap,
    817828            SVRegMap& alreadyReadMap, FlowStackEntry3& entry, const SSAEntry& sentry,
    818             const std::deque<FlowStackEntry3>& prevFlowStack,
     829            SVRegMap* cacheSecPoints, const std::deque<FlowStackEntry3>& prevFlowStack,
    819830            const std::vector<CodeBlock>& codeBlocks, const VarIndexMap* vregIndexMaps,
    820831            std::vector<Liveness>* livenesses, size_t regTypesNum, const cxuint* regRanges)
     
    828839    if (res.second && sinfo.readBeforeWrite)
    829840    {
    830         /*if (cacheSecPoints != nullptr)
    831         {
    832             auto res = cacheSecPoints->insert({ sentry.first, { sinfo.ssaIdBefore } });
     841        if (cacheSecPoints != nullptr)
     842        {
     843            auto res = cacheSecPoints->insert({ sentry.first, sinfo.ssaIdBefore });
    833844            if (!res.second)
    834                 res.first->second.insertValue(sinfo.ssaIdBefore);
    835         }*/
     845                res.first->second = sinfo.ssaIdBefore;
     846        }
    836847       
    837848        if (stackVarMap != nullptr)
    838             joinSVregWithVisited(stackVarMap, sentry, prevFlowStack,
     849            joinSVregWithVisited(stackVarMap, sentry.first,
     850                    sentry.second.ssaIdBefore, prevFlowStack,
    839851                    codeBlocks, vregIndexMaps, livenesses, regTypesNum, regRanges);
    840852    }
     
    851863    ARDOut << "use joinSecPointCache for " << nextBlock <<
    852864            ", alreadyRMapSize: " << alreadyReadMap.size() << "\n";
    853     for (const auto& sentry: *resSecondPoints)
    854     {
    855         const bool alreadyRead = alreadyReadMap.find(sentry.first) != alreadyReadMap.end();
     865    for (const auto& rsentry: *resSecondPoints)
     866    {
     867        const bool alreadyRead = alreadyReadMap.find(rsentry.first) != alreadyReadMap.end();
    856868        if (destCacheSecPoints != nullptr && !alreadyRead)
    857869        {
    858             auto res = destCacheSecPoints->insert(sentry);
     870            auto res = destCacheSecPoints->insert(rsentry);
    859871            if (!res.second)
    860                 res.first->second = sentry.second;
     872                res.first->second = rsentry.second;
    861873        }
    862874       
     
    864876        {
    865877            if (!alreadyRead)
    866                 joinSVregWithVisited(stackVarMap, sentry, prevFlowStack,
    867                     codeBlocks, vregIndexMaps, livenesses, regTypesNum, regRanges);
    868         }
    869     }
     878                joinSVregWithVisited(stackVarMap, rsentry.first, rsentry.second,
     879                    prevFlowStack, codeBlocks, vregIndexMaps, livenesses, regTypesNum,
     880                    regRanges);
     881        }
     882    }
     883}
     884
     885// add new join second cache entry with readBeforeWrite for all encountered regvars
     886static void addJoinSecCacheEntry(const RoutineMap& routineMap,
     887                const std::vector<CodeBlock>& codeBlocks,
     888                SimpleCache<size_t, SVRegMap>& resSecondPointsCache,
     889                size_t nextBlock)
     890{
     891    ARDOut << "addJoinSecCacheEntry: " << nextBlock << "\n";
     892    //std::stack<CallStackEntry> callStack = prevCallStack;
     893    // traverse by graph from next block
     894    std::deque<FlowStackEntry3> flowStack;
     895    flowStack.push_back({ nextBlock, 0 });
     896    CBlockBitPool visited(codeBlocks.size(), false);
     897   
     898    SVRegBlockMap alreadyReadMap;
     899    SVRegMap cacheSecPoints;
     900   
     901    while (!flowStack.empty())
     902    {
     903        FlowStackEntry3& entry = flowStack.back();
     904        const CodeBlock& cblock = codeBlocks[entry.blockIndex];
     905       
     906        if (entry.nextIndex == 0)
     907        {
     908            // process current block
     909            if (!visited[entry.blockIndex])
     910            {
     911                visited[entry.blockIndex] = true;
     912                ARDOut << "  resolv (cache): " << entry.blockIndex << "\n";
     913               
     914                const SVRegMap* resSecondPoints =
     915                            resSecondPointsCache.use(entry.blockIndex);
     916                if (resSecondPoints == nullptr)
     917                {
     918                    for (auto& sentry: cblock.ssaInfoMap)
     919                        /*handleSSAEntryWhileResolving(nullptr, nullptr,
     920                                alreadyReadMap, entry, sentry,
     921                                &cacheSecPoints)*/;
     922                }
     923                else // to use cache
     924                {
     925                    /*useResSecPointCache(nullptr, nullptr, alreadyReadMap,
     926                            resSecondPoints, entry.blockIndex, &cacheSecPoints);*/
     927                    flowStack.pop_back();
     928                    continue;
     929                }
     930            }
     931            else
     932            {
     933                // back, already visited
     934                ARDOut << "join already (cache): " << entry.blockIndex << "\n";
     935                flowStack.pop_back();
     936                continue;
     937            }
     938        }
     939       
     940        if (entry.nextIndex < cblock.nexts.size())
     941        {
     942            flowStack.push_back({ cblock.nexts[entry.nextIndex].block, 0 });
     943            entry.nextIndex++;
     944        }
     945        else if (((entry.nextIndex==0 && cblock.nexts.empty()) ||
     946                // if have any call then go to next block
     947                (cblock.haveCalls && entry.nextIndex==cblock.nexts.size())) &&
     948                 !cblock.haveReturn && !cblock.haveEnd)
     949        {
     950            // add toResolveMap ssaIds inside called routines
     951            for (const auto& next: cblock.nexts)
     952                if (next.isCall)
     953                {
     954                    const RoutineData& rdata = routineMap.find(next.block)->second;
     955                    for (const auto& v: rdata.rbwSSAIdMap)
     956                        alreadyReadMap.insert({v.first, entry.blockIndex });
     957                    for (const auto& v: rdata.lastSSAIdMap)
     958                        alreadyReadMap.insert({v.first, entry.blockIndex });
     959                }
     960           
     961            flowStack.push_back({ entry.blockIndex+1, 0 });
     962            entry.nextIndex++;
     963        }
     964        else // back
     965        {
     966            // remove old to resolve in leaved way to allow collecting next ssaId
     967            // before write (can be different due to earlier visit)
     968            for (const auto& next: cblock.nexts)
     969                if (next.isCall)
     970                {
     971                    const RoutineData& rdata = routineMap.find(next.block)->second;
     972                    for (const auto& v: rdata.rbwSSAIdMap)
     973                    {
     974                        auto it = alreadyReadMap.find(v.first);
     975                        if (it != alreadyReadMap.end() && it->second == entry.blockIndex)
     976                            alreadyReadMap.erase(it);
     977                    }
     978                    for (const auto& v: rdata.lastSSAIdMap)
     979                    {
     980                        auto it = alreadyReadMap.find(v.first);
     981                        if (it != alreadyReadMap.end() && it->second == entry.blockIndex)
     982                            alreadyReadMap.erase(it);
     983                    }
     984                }
     985           
     986            for (const auto& sentry: cblock.ssaInfoMap)
     987            {
     988                auto it = alreadyReadMap.find(sentry.first);
     989                if (it != alreadyReadMap.end() && it->second == entry.blockIndex)
     990                    // remove old to resolve in leaved way to allow collecting next ssaId
     991                    // before write (can be different due to earlier visit)
     992                    alreadyReadMap.erase(it);
     993            }
     994            ARDOut << "  popjoin (cache)\n";
     995            flowStack.pop_back();
     996        }
     997    }
     998   
     999    //resSecondPointsCache.put(nextBlock, cacheSecPoints);
    8701000}
    8711001
     
    9121042                for (const auto& sentry: cblock.ssaInfoMap)
    9131043                    handleSSAEntryWhileJoining(&stackVarMap, alreadyReadMap, entry, sentry,
    914                                 //toCache ? &cacheSecPoints : nullptr)
     1044                                nullptr,
    9151045                                prevFlowStack, codeBlocks, vregIndexMaps, livenesses,
    9161046                                regTypesNum, regRanges);
     
    13261456   
    13271457    // after, that resolve joins (join with already visited code)
     1458    // SVRegMap in this cache: key - vreg, value - last flowStack entry position
    13281459    SimpleCache<size_t, SVRegMap> resFirstPointsCache(wrCount<<1);
     1460    // SVRegMap in this cache: key - vreg, value - first readBefore in second part
    13291461    SimpleCache<size_t, SVRegMap> resSecondPointsCache(rbwCount<<1);
    13301462   
Note: See TracChangeset for help on using the changeset viewer.