Changeset 4107 in CLRX


Ignore:
Timestamp:
May 7, 2018, 11:07:14 PM (3 weeks ago)
Author:
matszpk
Message:

CLRadeonExtender: AsmRegAlloc?: Add special livetime for calls to join used svregs in call time and svregs used inisde routines.
Small fix in joinVRegRecur.

File:
1 edited

Legend:

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

    r4106 r4107  
    735735}
    736736
     737
     738static void applyToLiveCallTime(size_t block, Liveness& lv,
     739            const std::vector<CodeBlock>& codeBlocks,
     740            const std::unordered_map<size_t, size_t>& callLiveTimesMap)
     741{
     742    auto cit = callLiveTimesMap.find(block);
     743    if (cit != callLiveTimesMap.end())
     744    {
     745        size_t callLiveTime = cit->second;
     746        const CodeBlock& cblock = codeBlocks[block];
     747        for (const NextBlock& next: cblock.nexts)
     748            if (next.isCall)
     749            {
     750                lv.insert(callLiveTime, callLiveTime+1);
     751                callLiveTime--;
     752            }
     753    }
     754}
     755
    737756static void fillUpInsideRoutine(std::vector<bool>& visited,
    738             const std::vector<CodeBlock>& codeBlocks, size_t startBlock,
    739             const AsmSingleVReg& svreg, Liveness& lv)
     757            const std::vector<CodeBlock>& codeBlocks,
     758            const std::unordered_map<size_t, size_t>& callLiveTimesMap,
     759            size_t startBlock, const AsmSingleVReg& svreg, Liveness& lv)
    740760{
    741761    std::deque<FlowStackEntry3> flowStack;
     
    766786                // just insert
    767787                lv.insert(cbStart, cblock.end);
     788               
     789                applyToLiveCallTime(entry.blockIndex, lv, codeBlocks, callLiveTimesMap);
    768790            }
    769791            else
     
    794816static void joinVRegRecur(const std::deque<FlowStackEntry3>& flowStack,
    795817            const std::vector<CodeBlock>& codeBlocks, const RoutineLvMap& routineMap,
     818            const std::unordered_map<size_t, size_t>& callLiveTimesMap,
    796819            LastVRegStackPos flowStkStart, const AsmSingleVReg& svreg, size_t ssaId,
    797820            const VarIndexMap* vregIndexMaps, std::vector<Liveness>* livenesses,
     
    869892            size_t blockStart = entry.blockIndex;
    870893            if (!entry.inSubroutines)
    871                 fillUpInsideRoutine(visited, codeBlocks, blockStart, svreg, lv);
     894                fillUpInsideRoutine(visited, codeBlocks, callLiveTimesMap,
     895                            blockStart, svreg, lv);
    872896            else
    873             {
    874897                // fill up next block in path (do not fill start block)
    875                 const CodeBlock& cbstart = codeBlocks[blockStart];
    876                 for (size_t k = 0; k < cbstart.nexts.size(); k++)
    877                     if (!cbstart.nexts[k].isCall)
    878                         fillUpInsideRoutine(visited, codeBlocks,
    879                                 cbstart.nexts[k].block, svreg, lv);
    880             }
     898                fillUpInsideRoutine(visited, codeBlocks, callLiveTimesMap,
     899                        blockStart+1, svreg, lv);
    881900            rjStack.pop();
    882901        }
     
    885904    auto flit = flowStack.begin() + flowStkStart.stackPos + (flowStkStart.inSubroutines);
    886905    const CodeBlock& lastBlk = codeBlocks[flit->blockIndex];
     906   
     907    applyToLiveCallTime(flit->blockIndex, lv, codeBlocks, callLiveTimesMap);
    887908   
    888909    auto sinfoIt = lastBlk.ssaInfoMap.find(svreg);
     
    899920    {
    900921        const CodeBlock& cblock = codeBlocks[flit->blockIndex];
     922        applyToLiveCallTime(flit->blockIndex, lv, codeBlocks, callLiveTimesMap);
    901923        lv.insert(cblock.start, cblock.end);
    902924    }
    903925}
    904926
    905 /* TODO: add handling calls
    906  * handle many start points in this code (for example many kernel's in same code)
     927/* handle many start points in this code (for example many kernel's in same code)
    907928 * replace sets by vector, and sort and remove same values on demand
    908929 */
     
    911932static void putCrossBlockLivenesses(const std::deque<FlowStackEntry3>& flowStack,
    912933        const std::vector<CodeBlock>& codeBlocks, const RoutineLvMap& routineMap,
     934        const std::unordered_map<size_t, size_t>& callLiveTimesMap,
    913935        const LastVRegMap& lastVRegMap, std::vector<Liveness>* livenesses,
    914936        const VarIndexMap* vregIndexMaps, size_t regTypesNum, const cxuint* regRanges)
     
    924946                lvrit->second.back() : LastVRegStackPos{ 0, false };
    925947           
    926             joinVRegRecur(flowStack, codeBlocks, routineMap, flowStackStart,
    927                     entry.first, entry.second.ssaIdBefore, vregIndexMaps, livenesses,
    928                     regTypesNum, regRanges, true);
     948            joinVRegRecur(flowStack, codeBlocks, routineMap, callLiveTimesMap,
     949                    flowStackStart, entry.first, entry.second.ssaIdBefore,
     950                    vregIndexMaps, livenesses, regTypesNum, regRanges, true);
    929951        }
    930952}
     
    10771099static void joinRegVarLivenesses(const std::deque<FlowStackEntry3>& prevFlowStack,
    10781100        const std::vector<CodeBlock>& codeBlocks, const RoutineLvMap& routineMap,
     1101        const std::unordered_map<size_t, size_t>& callLiveTimesMap,
    10791102        const PrevWaysIndexMap& prevWaysIndexMap,
    10801103        const std::vector<bool>& waysToCache, ResSecondPointsToCache& cblocksToCache,
     
    11821205                                        it->second : LastVRegStackPos{ 0, false });
    11831206                           
    1184                             joinVRegRecur(prevFlowStack, codeBlocks, routineMap, stackPos,
     1207                            joinVRegRecur(prevFlowStack, codeBlocks, routineMap,
     1208                                callLiveTimesMap, stackPos,
    11851209                                sentry.first, sentry.second.ssaIdBefore, vregIndexMaps,
    11861210                                livenesses, regTypesNum, regRanges, true);
     
    12051229                                        it->second : LastVRegStackPos{ 0, false });
    12061230                           
    1207                             joinVRegRecur(prevFlowStack, codeBlocks, routineMap, stackPos,
     1231                            joinVRegRecur(prevFlowStack, codeBlocks, routineMap,
     1232                                callLiveTimesMap, stackPos,
    12081233                                rsentry.first, rsentry.second, vregIndexMaps,
    12091234                                livenesses, regTypesNum, regRanges, true);
     
    16211646    RoutineLvMap routineMap;
    16221647    std::vector<Liveness> livenesses[MAX_REGTYPES_NUM];
     1648    std::unordered_map<size_t, size_t> callLiveTimesMap;
    16231649   
    16241650    for (size_t i = 0; i < regTypesNum; i++)
    16251651        livenesses[i].resize(graphVregsCounts[i]);
    16261652   
     1653    // callLiveTime - call live time where routine will be called
     1654    // reverse counted, begin from SIZE_MAX, used for joining svreg from routines
     1655    // and svreg used in this time
     1656    size_t callLiveTime = SIZE_MAX-1;
    16271657    size_t curLiveTime = 0;
    16281658    flowStack.push_back({ 0, 0 });
     
    16421672                ARDOut << "joinpush: " << entry.blockIndex << "\n";
    16431673                if (flowStack.size() > 1)
    1644                     putCrossBlockLivenesses(flowStack, codeBlocks, routineMap, lastVRegMap,
     1674                    putCrossBlockLivenesses(flowStack, codeBlocks, routineMap,
     1675                            callLiveTimesMap, lastVRegMap,
    16451676                            livenesses, vregIndexMaps, regTypesNum, regRanges);
    16461677                // update last vreg position
     
    17851816                            lvrit->second.back() : LastVRegStackPos{ 0, false };
    17861817                   
    1787                     joinVRegRecur(flowStack, codeBlocks, routineMap, flowStackStart,
     1818                    joinVRegRecur(flowStack, codeBlocks, routineMap,
     1819                            callLiveTimesMap, flowStackStart,
    17881820                            entry.first, entry.second, vregIndexMaps,
    17891821                            livenesses, regTypesNum, regRanges, false);
     
    18131845            if (entry.nextIndex!=0) // if back from calls (just return from calls)
    18141846            {
     1847                callLiveTimesMap.insert({ entry.blockIndex, callLiveTime });
     1848               
    18151849                std::unordered_set<AsmSingleVReg> regSVRegs;
    18161850                // just add last access of svreg from call routines to lastVRegMap
     1851                // and join svregs from routine with svreg used at this time
    18171852                for (const NextBlock& next: cblock.nexts)
    18181853                    if (next.isCall)
     
    18291864                                                { flowStack.size()-1, true });
    18301865                            }
     1866                       
     1867                        for (cxuint r = 0; r < regTypesNum; r++)
     1868                            for(size_t lvIndex: rdata.allSSAs[r])
     1869                                livenesses[r][lvIndex].insert(callLiveTime, callLiveTime+1);
     1870                        callLiveTime--;
    18311871                    }
    18321872            }
     
    18871927            else
    18881928            {
    1889                 joinRegVarLivenesses(flowStack, codeBlocks, routineMap,
     1929                joinRegVarLivenesses(flowStack, codeBlocks, routineMap, callLiveTimesMap,
    18901930                        prevWaysIndexMap, waysToCache, cblocksToCache,
    18911931                        joinFirstPointsCache, joinSecondPointsCache,
Note: See TracChangeset for help on using the changeset viewer.