Changeset 4062 in CLRX


Ignore:
Timestamp:
May 2, 2018, 10:05:12 PM (3 weeks ago)
Author:
matszpk
Message:

CLRadeonExtender: AsmRegAlloc?: Add SVRegMap and SVRegBlockMap and apply to AsmRegAllocSSAData code.
Prepping to joinRegVarLivenesses like resolvingSSAConflicts (with caching).

Location:
CLRadeonExtender/trunk/amdasm
Files:
3 edited

Legend:

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

    r4061 r4062  
    10861086    std::unordered_set<size_t> blockInWay;
    10871087   
     1088    // key - current res first key, value - previous first key and its flowStack pos
     1089    PrevWaysIndexMap prevWaysIndexMap;
     1090    // to track ways last block indices pair: block index, flowStackPos)
     1091    std::pair<size_t, size_t> lastCommonCacheWayPoint{ SIZE_MAX, SIZE_MAX };
     1092    std::vector<bool> waysToCache(codeBlocks.size(), false);
     1093    ResSecondPointsToCache cblocksToCache(codeBlocks.size());
     1094   
     1095    size_t rbwCount = 0;
     1096    size_t wrCount = 0;
     1097   
    10881098    std::vector<Liveness> livenesses[MAX_REGTYPES_NUM];
    10891099   
     
    11261136                        // update last
    11271137                        res.first->second.push_back(flowStack.size()-1);
     1138                   
     1139                    // count read before writes (for cache weight)
     1140                    if (sentry.second.readBeforeWrite)
     1141                        rbwCount++;
     1142                    if (sentry.second.ssaIdChange!=0)
     1143                        wrCount++;
    11281144                }
    11291145               
     
    12111227            else
    12121228            {
     1229                cblocksToCache.increase(entry.blockIndex);
     1230                ARDOut << "cblockToCache: " << entry.blockIndex << "=" <<
     1231                            cblocksToCache.count(entry.blockIndex) << "\n";
     1232               
    12131233                // back, already visited
    12141234                flowStack.pop_back();
     1235               
     1236                size_t curWayBIndex = flowStack.back().blockIndex;
     1237                if (lastCommonCacheWayPoint.first != SIZE_MAX)
     1238                {
     1239                    // mark point of way to cache (res first point)
     1240                    waysToCache[lastCommonCacheWayPoint.first] = true;
     1241                    ARDOut << "mark to pfcache " <<
     1242                            lastCommonCacheWayPoint.first << ", " <<
     1243                            curWayBIndex << "\n";
     1244                    prevWaysIndexMap[curWayBIndex] = lastCommonCacheWayPoint;
     1245                }
     1246                lastCommonCacheWayPoint = { curWayBIndex, flowStack.size()-1 };
     1247                ARDOut << "lastCcwP: " << curWayBIndex << "\n";
    12151248                continue;
    12161249            }
     
    12431276                    }
    12441277                }
     1278           
     1279           
     1280            if (!flowStack.empty() && lastCommonCacheWayPoint.first != SIZE_MAX &&
     1281                    lastCommonCacheWayPoint.second >= flowStack.size())
     1282            {
     1283                lastCommonCacheWayPoint =
     1284                        { flowStack.back().blockIndex, flowStack.size()-1 };
     1285                ARDOut << "POPlastCcwP: " << lastCommonCacheWayPoint.first << "\n";
     1286            }
    12451287        }
    12461288    }
    12471289   
    12481290    // after, that resolve joins (join with already visited code)
     1291    SimpleCache<size_t, SVRegMap> resFirstPointsCache(wrCount<<1);
     1292    SimpleCache<size_t, SVRegMap> resSecondPointsCache(rbwCount<<1);
     1293   
    12491294    flowStack.clear();
    12501295    std::fill(visited.begin(), visited.end(), false);
     
    12861331        }
    12871332        else // back
     1333        {
     1334            /*if (cblocksToCache.count(entry.blockIndex)==2 &&
     1335                !resSecondPointsCache.hasKey(entry.blockIndex))
     1336                // add to cache
     1337                addResSecCacheEntry(routineMap, codeBlocks, resSecondPointsCache,
     1338                            entry.blockIndex);*/
    12881339            flowStack.pop_back();
     1340        }
    12891341    }
    12901342   
  • CLRadeonExtender/trunk/amdasm/AsmRegAlloc.h

    r4049 r4062  
    136136};
    137137
     138typedef std::unordered_map<AsmSingleVReg, BlockIndex> SVRegBlockMap;
     139typedef std::unordered_map<AsmSingleVReg, size_t> SVRegMap;
    138140typedef LastSSAIdMap RBWSSAIdMap;
    139141typedef std::unordered_map<BlockIndex, VectorSet<BlockIndex> > SubrLoopsMap;
  • CLRadeonExtender/trunk/amdasm/AsmRegAllocSSAData.cpp

    r4050 r4062  
    5454
    5555static void handleSSAEntryWhileResolving(SSAReplacesMap* replacesMap,
    56             const LastSSAIdMap* stackVarMap,
    57             std::unordered_map<AsmSingleVReg, BlockIndex>& alreadyReadMap,
     56            const LastSSAIdMap* stackVarMap, SVRegBlockMap& alreadyReadMap,
    5857            FlowStackEntry2& entry, const SSAEntry& sentry,
    5958            RBWSSAIdMap* cacheSecPoints)
     
    9897// it emits SSA replaces from these conflicts
    9998static void useResSecPointCache(SSAReplacesMap* replacesMap,
    100         const LastSSAIdMap* stackVarMap,
    101         const std::unordered_map<AsmSingleVReg, BlockIndex>& alreadyReadMap,
     99        const LastSSAIdMap* stackVarMap, const SVRegBlockMap& alreadyReadMap,
    102100        const RBWSSAIdMap* resSecondPoints, BlockIndex nextBlock,
    103101        RBWSSAIdMap* destCacheSecPoints)
     
    151149    CBlockBitPool visited(codeBlocks.size(), false);
    152150   
    153     std::unordered_map<AsmSingleVReg, BlockIndex> alreadyReadMap;
     151    SVRegBlockMap alreadyReadMap;
    154152   
    155153    RBWSSAIdMap cacheSecPoints;
     
    358356    // already read in current path
    359357    // key - vreg, value - source block where vreg of conflict found
    360     std::unordered_map<AsmSingleVReg, BlockIndex> alreadyReadMap;
     358    SVRegBlockMap alreadyReadMap;
    361359   
    362360    while (!flowStack.empty())
     
    575573// (just join child call from parent)
    576574static void joinRoutineData(RoutineData& dest, const RoutineData& src,
    577             const std::unordered_map<AsmSingleVReg, size_t>& curSSAIdMap,
    578             bool notFirstReturn)
     575            const SVRegMap& curSSAIdMap, bool notFirstReturn)
    579576{
    580577    // insert readBeforeWrite only if doesnt exists in destination
     
    697694}
    698695
    699 static void reduceSSAIds2(std::unordered_map<AsmSingleVReg, size_t>& curSSAIdMap,
    700             RetSSAIdMap& retSSAIdMap, FlowStackEntry& entry, const SSAEntry& ssaEntry)
     696static void reduceSSAIds2(SVRegMap& curSSAIdMap, RetSSAIdMap& retSSAIdMap,
     697                FlowStackEntry& entry, const SSAEntry& ssaEntry)
    701698{
    702699    const SSAInfo& sinfo = ssaEntry.second;
     
    722719// reduce retSSAIds (last SSAIds for regvar) while passing by code block
    723720// and emits SSA replaces for these ssaids
    724 static void reduceSSAIds(std::unordered_map<AsmSingleVReg, size_t>& curSSAIdMap,
    725             RetSSAIdMap& retSSAIdMap, RoutineMap& routineMap,
    726             SSAReplacesMap& ssaReplacesMap, FlowStackEntry& entry, SSAEntry& ssaEntry)
     721static void reduceSSAIds(SVRegMap& curSSAIdMap, RetSSAIdMap& retSSAIdMap,
     722            RoutineMap& routineMap, SSAReplacesMap& ssaReplacesMap, FlowStackEntry& entry,
     723            SSAEntry& ssaEntry)
    727724{
    728725    SSAInfo& sinfo = ssaEntry.second;
     
    852849}
    853850
    854 static void initializePrevRetSSAIds(
    855             const std::unordered_map<AsmSingleVReg, size_t>& curSSAIdMap,
     851static void initializePrevRetSSAIds(const SVRegMap& curSSAIdMap,
    856852            const RetSSAIdMap& retSSAIdMap, const RoutineData& rdata,
    857853            FlowStackEntry& entry)
     
    872868
    873869// revert retSSAIdMap while leaving from code block
    874 static void revertRetSSAIdMap(std::unordered_map<AsmSingleVReg, size_t>& curSSAIdMap,
    875             RetSSAIdMap& retSSAIdMap, FlowStackEntry& entry, RoutineData* rdata)
     870static void revertRetSSAIdMap(SVRegMap& curSSAIdMap, RetSSAIdMap& retSSAIdMap,
     871            FlowStackEntry& entry, RoutineData* rdata)
    876872{
    877873    // revert retSSAIdMap
     
    969965
    970966static void createRoutineData(const std::vector<CodeBlock>& codeBlocks,
    971         std::unordered_map<AsmSingleVReg, size_t>& curSSAIdMap,
    972         const std::unordered_set<BlockIndex>& loopBlocks,
     967        SVRegMap& curSSAIdMap, const std::unordered_set<BlockIndex>& loopBlocks,
    973968        const std::unordered_set<BlockIndex>& callBlocks,
    974969        const ResSecondPointsToCache& subroutToCache,
     
    12491244                    // for next recursion pass call - choose origRvwSSAIdMap
    12501245                    // otherwise - standard rbwSsaIdMap
    1251                     const std::unordered_map<AsmSingleVReg, size_t>& srcRbwSSAIdMap =
     1246                    const SVRegMap& srcRbwSSAIdMap =
    12521247                        (entry.blockIndex.pass == 0 && rblock.pass!=0) ?
    12531248                        srcRdata.origRbwSSAIdMap : srcRdata.rbwSSAIdMap;
     
    14801475    std::deque<FlowStackEntry> flowStack;
    14811476    // total SSA count
    1482     std::unordered_map<AsmSingleVReg, size_t> totalSSACountMap;
     1477    SVRegMap totalSSACountMap;
    14831478    // last SSA ids map from returns
    14841479    RetSSAIdMap retSSAIdMap;
    14851480    // last SSA ids in current way in code flow
    1486     std::unordered_map<AsmSingleVReg, size_t> curSSAIdMap;
     1481    SVRegMap curSSAIdMap;
    14871482    // routine map - routine datas map, value - last SSA ids map
    14881483    RoutineMap routineMap;
     
    15101505     * this stuff has been deleted */
    15111506   
    1512     std::unordered_map<size_t, std::unordered_map<AsmSingleVReg, size_t> >
    1513             curSSAIdMapStateMap;
     1507    std::unordered_map<size_t, SVRegMap > curSSAIdMapStateMap;
    15141508   
    15151509    /*
Note: See TracChangeset for help on using the changeset viewer.