Changeset 3954 in CLRX


Ignore:
Timestamp:
Mar 31, 2018, 4:10:21 PM (8 months ago)
Author:
matszpk
Message:

CLRadeonExtender: AsmRegAlloc?: Tentative apply BlockIndex? as block index type (for recursion support).

File:
1 edited

Legend:

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

    r3953 r3954  
    556556};
    557557
     558
     559//  BlockIndex
     560
     561struct CLRX_INTERNAL BlockIndex
     562{
     563    size_t index;
     564    size_t pass;
     565   
     566    BlockIndex(size_t _index = 0, size_t _pass = 0)
     567            : index(_index), pass(_pass)
     568    { }
     569   
     570    bool operator==(const BlockIndex& v) const
     571    { return index==v.index && pass==v.pass; }
     572    bool operator!=(const BlockIndex& v) const
     573    { return index!=v.index || pass!=v.pass; }
     574   
     575    BlockIndex operator+(size_t p) const
     576    { return BlockIndex(index+p, pass); }
     577};
     578
     579std::ostream& operator<<(std::ostream& os, const BlockIndex& v)
     580{
     581    if (v.pass==0)
     582        return os << v.index;
     583    else
     584        return os << v.index << "#" << v.pass;
     585}
     586
     587namespace std
     588{
     589
     590/// std::hash specialization for CLRX CString
     591template<>
     592struct hash<BlockIndex>
     593{
     594    typedef BlockIndex argument_type;    ///< argument type
     595    typedef std::size_t result_type;    ///< result type
     596   
     597    /// a calling operator
     598    size_t operator()(const BlockIndex& r1) const
     599    {
     600        std::hash<size_t> h1;
     601        return h1(r1.index) ^ h1(r1.pass);
     602    }
     603};
     604
     605}
     606
    558607/** Simple cache **/
    559608
     
    586635
    587636typedef LastSSAIdMap RBWSSAIdMap;
    588 typedef std::unordered_map<size_t, VectorSet<size_t> > SubrLoopsMap;
     637typedef std::unordered_map<BlockIndex, VectorSet<BlockIndex> > SubrLoopsMap;
    589638
    590639struct CLRX_INTERNAL RetSSAEntry
    591640{
    592     std::vector<size_t> routines;
     641    std::vector<BlockIndex> routines;
    593642    VectorSet<size_t> ssaIds;
    594643    size_t prevSSAId; // for curSSAId
     
    610659    LastSSAIdMap lastSSAIdMap;
    611660    // key - loop block, value - last ssaId map for loop end
    612     std::unordered_map<size_t, LoopSSAIdMap> loopEnds;
     661    std::unordered_map<BlockIndex, LoopSSAIdMap> loopEnds;
    613662    bool notFirstReturn;
    614663    size_t weight_;
     
    629678
    630679struct CLRX_INTERNAL FlowStackEntry
     680{
     681    BlockIndex blockIndex;
     682    size_t nextIndex;
     683    bool isCall;
     684    RetSSAIdMap prevRetSSAIdSets;
     685};
     686
     687struct CLRX_INTERNAL FlowStackEntry2
     688{
     689    BlockIndex blockIndex;
     690    size_t nextIndex;
     691};
     692
     693struct CLRX_INTERNAL FlowStackEntry3
    631694{
    632695    size_t blockIndex;
     
    636699};
    637700
    638 struct CLRX_INTERNAL FlowStackEntry2
    639 {
    640     size_t blockIndex;
    641     size_t nextIndex;
    642 };
    643 
    644701
    645702struct CLRX_INTERNAL CallStackEntry
    646703{
    647     size_t callBlock; // index
     704    BlockIndex callBlock; // index
    648705    size_t callNextIndex; // index of call next
    649     size_t routineBlock;    // routine block
     706    BlockIndex routineBlock;    // routine block
    650707};
    651708
     
    689746static void handleSSAEntryWhileResolving(SSAReplacesMap* replacesMap,
    690747            const LastSSAIdMap* stackVarMap,
    691             std::unordered_map<AsmSingleVReg, size_t>& alreadyReadMap,
     748            std::unordered_map<AsmSingleVReg, BlockIndex>& alreadyReadMap,
    692749            FlowStackEntry2& entry, const SSAEntry& sentry,
    693750            RBWSSAIdMap* cacheSecPoints)
     
    743800}
    744801
    745 typedef std::unordered_map<size_t, std::pair<size_t, size_t> > PrevWaysIndexMap;
     802typedef std::unordered_map<BlockIndex, std::pair<BlockIndex, size_t> > PrevWaysIndexMap;
    746803
    747804// use res second point cache entry to resolve conflict with SSAIds.
     
    749806static void useResSecPointCache(SSAReplacesMap* replacesMap,
    750807        const LastSSAIdMap* stackVarMap,
    751         const std::unordered_map<AsmSingleVReg, size_t>& alreadyReadMap,
    752         const RBWSSAIdMap* resSecondPoints, size_t nextBlock,
     808        const std::unordered_map<AsmSingleVReg, BlockIndex>& alreadyReadMap,
     809        const RBWSSAIdMap* resSecondPoints, BlockIndex nextBlock,
    753810        RBWSSAIdMap* destCacheSecPoints)
    754811{
     
    804861
    805862// add new res second cache entry with readBeforeWrite for all encountered regvars
    806 static void addResSecCacheEntry(const std::unordered_map<size_t, RoutineData>& routineMap,
     863static void addResSecCacheEntry(
     864                const std::unordered_map<BlockIndex, RoutineData>& routineMap,
    807865                const std::vector<CodeBlock>& codeBlocks,
    808                 SimpleCache<size_t, RBWSSAIdMap>& resSecondPointsCache,
    809                 size_t nextBlock)
     866                SimpleCache<BlockIndex, RBWSSAIdMap>& resSecondPointsCache,
     867                BlockIndex nextBlock)
    810868{
    811869    std::cout << "addResSecCacheEntry: " << nextBlock << std::endl;
     
    816874    std::vector<bool> visited(codeBlocks.size(), false);
    817875   
    818     std::unordered_map<AsmSingleVReg, size_t> alreadyReadMap;
     876    std::unordered_map<AsmSingleVReg, BlockIndex> alreadyReadMap;
    819877   
    820878    RBWSSAIdMap cacheSecPoints;
     
    823881    {
    824882        FlowStackEntry2& entry = flowStack.back();
    825         const CodeBlock& cblock = codeBlocks[entry.blockIndex];
     883        const CodeBlock& cblock = codeBlocks[entry.blockIndex.index];
    826884       
    827885        if (entry.nextIndex == 0)
    828886        {
    829887            // process current block
    830             if (!visited[entry.blockIndex])
    831             {
    832                 visited[entry.blockIndex] = true;
     888            if (!visited[entry.blockIndex.index])
     889            {
     890                visited[entry.blockIndex.index] = true;
    833891                std::cout << "  resolv (cache): " << entry.blockIndex << std::endl;
    834892               
     
    921979// apply calls (changes from these calls) from code blocks to stack var map
    922980static void applyCallToStackVarMap(const CodeBlock& cblock,
    923         const std::unordered_map<size_t, RoutineData>& routineMap,
    924         LastSSAIdMap& stackVarMap, size_t blockIndex, size_t nextIndex)
     981        const std::unordered_map<BlockIndex, RoutineData>& routineMap,
     982        LastSSAIdMap& stackVarMap, BlockIndex blockIndex, size_t nextIndex)
    925983{
    926984    for (const NextBlock& next: cblock.nexts)
     
    9501008// it emits SSA replaces from these conflicts
    9511009static void resolveSSAConflicts(const std::deque<FlowStackEntry2>& prevFlowStack,
    952         const std::unordered_map<size_t, RoutineData>& routineMap,
     1010        const std::unordered_map<BlockIndex, RoutineData>& routineMap,
    9531011        const std::vector<CodeBlock>& codeBlocks,
    9541012        const PrevWaysIndexMap& prevWaysIndexMap,
    9551013        const std::vector<bool>& waysToCache, ResSecondPointsToCache& cblocksToCache,
    956         SimpleCache<size_t, LastSSAIdMap>& resFirstPointsCache,
    957         SimpleCache<size_t, RBWSSAIdMap>& resSecondPointsCache,
     1014        SimpleCache<BlockIndex, LastSSAIdMap>& resFirstPointsCache,
     1015        SimpleCache<BlockIndex, RBWSSAIdMap>& resSecondPointsCache,
    9581016        SSAReplacesMap& replacesMap)
    9591017{
    960     size_t nextBlock = prevFlowStack.back().blockIndex;
     1018    BlockIndex nextBlock = prevFlowStack.back().blockIndex;
    9611019    auto pfEnd = prevFlowStack.end();
    9621020    --pfEnd;
     
    9801038               
    9811039                // apply missing calls at end of the cached
    982                 const CodeBlock& cblock = codeBlocks[it->second.first];
     1040                const CodeBlock& cblock = codeBlocks[it->second.first.index];
    9831041               
    9841042                const FlowStackEntry2& entry = *(prevFlowStack.begin()+pfStartIndex-1);
     
    9931051        const FlowStackEntry2& entry = *pfit;
    9941052        std::cout << "  apply: " << entry.blockIndex << std::endl;
    995         const CodeBlock& cblock = codeBlocks[entry.blockIndex];
     1053        const CodeBlock& cblock = codeBlocks[entry.blockIndex.index];
    9961054        for (const auto& sentry: cblock.ssaInfoMap)
    9971055        {
     
    10051063       
    10061064        // put to first point cache
    1007         if (waysToCache[pfit->blockIndex] && !resFirstPointsCache.hasKey(pfit->blockIndex))
     1065        if (waysToCache[pfit->blockIndex.index] &&
     1066            !resFirstPointsCache.hasKey(pfit->blockIndex))
    10081067        {
    10091068            std::cout << "put pfcache " << pfit->blockIndex << std::endl;
     
    10141073    RBWSSAIdMap cacheSecPoints;
    10151074    const bool toCache = (!resSecondPointsCache.hasKey(nextBlock)) &&
    1016                 cblocksToCache.count(nextBlock)>=2;
     1075                cblocksToCache.count(nextBlock.index)>=2;
    10171076   
    10181077    //std::stack<CallStackEntry> callStack = prevCallStack;
     
    10241083    // already read in current path
    10251084    // key - vreg, value - source block where vreg of conflict found
    1026     std::unordered_map<AsmSingleVReg, size_t> alreadyReadMap;
     1085    std::unordered_map<AsmSingleVReg, BlockIndex> alreadyReadMap;
    10271086   
    10281087    while (!flowStack.empty())
    10291088    {
    10301089        FlowStackEntry2& entry = flowStack.back();
    1031         const CodeBlock& cblock = codeBlocks[entry.blockIndex];
     1090        const CodeBlock& cblock = codeBlocks[entry.blockIndex.index];
    10321091       
    10331092        if (entry.nextIndex == 0)
    10341093        {
    10351094            // process current block
    1036             if (!visited[entry.blockIndex])
    1037             {
    1038                 visited[entry.blockIndex] = true;
     1095            if (!visited[entry.blockIndex.index])
     1096            {
     1097                visited[entry.blockIndex.index] = true;
    10391098                std::cout << "  resolv: " << entry.blockIndex << std::endl;
    10401099               
     
    10571116            else
    10581117            {
    1059                 cblocksToCache.increase(entry.blockIndex);
     1118                cblocksToCache.increase(entry.blockIndex.index);
    10601119                std::cout << "cblockToCache: " << entry.blockIndex << "=" <<
    1061                             cblocksToCache.count(entry.blockIndex) << std::endl;
     1120                            cblocksToCache.count(entry.blockIndex.index) << std::endl;
    10621121                // back, already visited
    10631122                std::cout << "resolv already: " << entry.blockIndex << std::endl;
     
    11231182            std::cout << "  popresolv" << std::endl;
    11241183           
    1125             if (cblocksToCache.count(entry.blockIndex)==2 &&
     1184            if (cblocksToCache.count(entry.blockIndex.index)==2 &&
    11261185                !resSecondPointsCache.hasKey(entry.blockIndex))
    11271186                // add to cache
     
    12781337static void reduceSSAIdsForCalls(FlowStackEntry& entry,
    12791338            const std::vector<CodeBlock>& codeBlocks,
    1280             RetSSAIdMap& retSSAIdMap, std::unordered_map<size_t, RoutineData>& routineMap,
     1339            RetSSAIdMap& retSSAIdMap,
     1340            std::unordered_map<BlockIndex, RoutineData>& routineMap,
    12811341            SSAReplacesMap& ssaReplacesMap)
    12821342{
     
    12861346    std::unordered_set<AsmSingleVReg> reduced;
    12871347    std::unordered_set<AsmSingleVReg> changed;
    1288     const CodeBlock& cblock = codeBlocks[entry.blockIndex];
     1348    const CodeBlock& cblock = codeBlocks[entry.blockIndex.index];
    12891349    // collect rbw SSAIds
    12901350    for (const NextBlock next: cblock.nexts)
     
    13311391            }
    13321392           
    1333             for (size_t rblock: rentry.second.routines)
     1393            for (BlockIndex rblock: rentry.second.routines)
    13341394                routineMap.find(rblock)->second.lastSSAIdMap[rentry.first] =
    13351395                            VectorSet<size_t>({ minSSAId });
     
    13601420// and emits SSA replaces for these ssaids
    13611421static bool reduceSSAIds(std::unordered_map<AsmSingleVReg, size_t>& curSSAIdMap,
    1362             RetSSAIdMap& retSSAIdMap, std::unordered_map<size_t, RoutineData>& routineMap,
     1422            RetSSAIdMap& retSSAIdMap,
     1423            std::unordered_map<BlockIndex, RoutineData>& routineMap,
    13631424            SSAReplacesMap& ssaReplacesMap, FlowStackEntry& entry, SSAEntry& ssaEntry)
    13641425{
     
    13881449        // replace smallest ssaId in routineMap lastSSAId entry
    13891450        // reduce SSAIds replaces
    1390         for (size_t rblock: ssaIdsIt->second.routines)
     1451        for (BlockIndex rblock: ssaIdsIt->second.routines)
    13911452            routineMap.find(rblock)->second.lastSSAIdMap[ssaEntry.first] =
    13921453                            VectorSet<size_t>({ ssaId-1 });
     
    15491610}
    15501611
    1551 static bool tryAddLoopEnd(const FlowStackEntry& entry, size_t routineBlock,
     1612static bool tryAddLoopEnd(const FlowStackEntry& entry, BlockIndex routineBlock,
    15521613                RoutineData& rdata, bool isLoop, bool noMainLoop)
    15531614{
     
    15741635static void createRoutineData(const std::vector<CodeBlock>& codeBlocks,
    15751636        std::unordered_map<AsmSingleVReg, size_t>& curSSAIdMap,
    1576         const std::unordered_set<size_t>& loopBlocks,
     1637        const std::unordered_set<BlockIndex>& loopBlocks,
    15771638        const ResSecondPointsToCache& subroutToCache,
    1578         SimpleCache<size_t, RoutineData>& subroutinesCache,
    1579         const std::unordered_map<size_t, RoutineData>& routineMap, RoutineData& rdata,
    1580         size_t routineBlock, bool noMainLoop = false,
     1639        SimpleCache<BlockIndex, RoutineData>& subroutinesCache,
     1640        const std::unordered_map<BlockIndex, RoutineData>& routineMap, RoutineData& rdata,
     1641        BlockIndex routineBlock, bool noMainLoop = false,
    15811642        const std::vector<bool>& prevFlowStackBlocks = {})
    15821643{
     
    15841645    std::vector<bool> visited(codeBlocks.size(), false);
    15851646   
    1586     VectorSet<size_t> activeLoops;
     1647    VectorSet<BlockIndex> activeLoops;
    15871648    SubrLoopsMap subrLoopsMap;
    15881649    SubrLoopsMap loopSubrsMap;
    1589     std::unordered_map<size_t, RoutineData> subrDataForLoopMap;
     1650    std::unordered_map<BlockIndex, RoutineData> subrDataForLoopMap;
    15901651    std::deque<FlowStackEntry> flowStack;
    15911652    std::vector<bool> flowStackBlocks(codeBlocks.size(), false);
     
    15951656    RetSSAIdMap retSSAIdMap;
    15961657    flowStack.push_back({ routineBlock, 0 });
    1597     flowStackBlocks[routineBlock] = true;
     1658    flowStackBlocks[routineBlock.index] = true;
    15981659   
    15991660    while (!flowStack.empty())
    16001661    {
    16011662        FlowStackEntry& entry = flowStack.back();
    1602         const CodeBlock& cblock = codeBlocks[entry.blockIndex];
     1663        const CodeBlock& cblock = codeBlocks[entry.blockIndex.index];
    16031664       
    16041665        auto addSubroutine = [&](
    1605             std::unordered_map<size_t, LoopSSAIdMap>::const_iterator loopsit2,
     1666            std::unordered_map<BlockIndex, LoopSSAIdMap>::const_iterator loopsit2,
    16061667            bool applyToMainRoutine)
    16071668        {
     
    16211682           
    16221683            RoutineData subrData;
    1623             const bool oldFB = flowStackBlocks[entry.blockIndex];
    1624             flowStackBlocks[entry.blockIndex] = !oldFB;
     1684            const bool oldFB = flowStackBlocks[entry.blockIndex.index];
     1685            flowStackBlocks[entry.blockIndex.index] = !oldFB;
    16251686            createRoutineData(codeBlocks, curSSAIdMap, loopBlocks, subroutToCache,
    16261687                subroutinesCache, routineMap, subrData, entry.blockIndex, true,
    16271688                flowStackBlocks);
    16281689            RoutineData subrDataCopy;
    1629             flowStackBlocks[entry.blockIndex] = oldFB;
     1690            flowStackBlocks[entry.blockIndex.index] = oldFB;
    16301691           
    16311692            if (loopBlocks.find(entry.blockIndex) != loopBlocks.end())
     
    16521713            {
    16531714                std::cout << "    found loopsubrsmap: " << entry.blockIndex << ":";
    1654                 for (size_t subr: it->second)
     1715                for (BlockIndex subr: it->second)
    16551716                {
    16561717                    std::cout << " " << subr;
     
    16751736                for (auto lit2 = it2->second.rbegin(); lit2 != it2->second.rend(); ++lit2)
    16761737                {
    1677                     size_t loop = *lit2;
     1738                    BlockIndex loop = *lit2;
    16781739                    auto loopsit3 = rdata.loopEnds.find(loop);
    16791740                    if (loopsit3 == rdata.loopEnds.end() ||
     
    16971758            bool isLoop = loopBlocks.find(entry.blockIndex) != loopBlocks.end();
    16981759           
    1699             if (!prevFlowStackBlocks.empty() && prevFlowStackBlocks[entry.blockIndex])
     1760            if (!prevFlowStackBlocks.empty() && prevFlowStackBlocks[entry.blockIndex.index])
    17001761            {
    17011762                tryAddLoopEnd(entry, routineBlock, rdata, isLoop, noMainLoop);
    17021763               
    1703                 flowStackBlocks[entry.blockIndex] = !flowStackBlocks[entry.blockIndex];
     1764                flowStackBlocks[entry.blockIndex.index] =
     1765                        !flowStackBlocks[entry.blockIndex.index];
    17041766                flowStack.pop_back();
    17051767                continue;
     
    17211783                        cachedRdata = &rit->second;
    17221784                }
    1723                 if (!isLoop && visited[entry.blockIndex] && cachedRdata == nullptr &&
    1724                     subroutToCache.count(entry.blockIndex)!=0)
     1785                if (!isLoop && visited[entry.blockIndex.index] && cachedRdata == nullptr &&
     1786                    subroutToCache.count(entry.blockIndex.index)!=0)
    17251787                {
    17261788                    auto loopsit2 = rdata.loopEnds.find(entry.blockIndex);
     
    17571819                for (const auto& loopEnd: cachedRdata->loopEnds)
    17581820                {
    1759                     auto res = rdata.loopEnds.insert({ loopEnd.first, LoopSSAIdMap() });
     1821                    auto res = rdata.loopEnds.insert({ loopEnd.first, LoopSSAIdMap{} });
    17601822                    // true - do not add cached rdata loopend, because it was added
    17611823                    joinLastSSAIdMapInt(res.first->second.ssaIdMap, rdata.curSSAIdMap,
     
    17631825                }
    17641826                std::cout << "procretend2" << std::endl;
    1765                 flowStackBlocks[entry.blockIndex] = !flowStackBlocks[entry.blockIndex];
     1827                flowStackBlocks[entry.blockIndex.index] =
     1828                            !flowStackBlocks[entry.blockIndex.index];
    17661829                flowStack.pop_back();
    17671830                continue;
    17681831            }
    1769             else if (!visited[entry.blockIndex])
     1832            else if (!visited[entry.blockIndex.index])
    17701833            {
    17711834                // set up loops for which subroutine is present
    1772                 if (subroutToCache.count(entry.blockIndex)!=0 && !activeLoops.empty())
     1835                if (subroutToCache.count(entry.blockIndex.index)!=0 && !activeLoops.empty())
    17731836                {
    17741837                    subrLoopsMap.insert({ entry.blockIndex, activeLoops });
    1775                     for (size_t loop: activeLoops)
     1838                    for (BlockIndex loop: activeLoops)
    17761839                    {
    17771840                        auto res = loopSubrsMap.insert({ loop, { entry.blockIndex } });
     
    17841847                    activeLoops.insertValue(entry.blockIndex);
    17851848                std::cout << "proc: " << entry.blockIndex << std::endl;
    1786                 visited[entry.blockIndex] = true;
     1849                visited[entry.blockIndex.index] = true;
    17871850               
    17881851                for (const auto& ssaEntry: cblock.ssaInfoMap)
     
    17991862            {
    18001863                tryAddLoopEnd(entry, routineBlock, rdata, isLoop, noMainLoop);
    1801                 flowStackBlocks[entry.blockIndex] = !flowStackBlocks[entry.blockIndex];
     1864                flowStackBlocks[entry.blockIndex.index] =
     1865                        !flowStackBlocks[entry.blockIndex.index];
    18021866                flowStack.pop_back();
    18031867                continue;
     
    18361900                    }
    18371901            }
    1838             const size_t nextBlock = entry.blockIndex+1;
     1902            const BlockIndex nextBlock = entry.blockIndex+1;
    18391903            flowStack.push_back({ nextBlock, 0 });
    18401904            // negate - if true (already in flowstack, then popping keep this state)
    1841             flowStackBlocks[nextBlock] = !flowStackBlocks[nextBlock];
     1905            flowStackBlocks[nextBlock.index] = !flowStackBlocks[nextBlock.index];
    18421906            entry.nextIndex++;
    18431907        }
     
    18911955           
    18921956            if ((!noMainLoop || flowStack.size() > 1) &&
    1893                 subroutToCache.count(entry.blockIndex)!=0)
     1957                subroutToCache.count(entry.blockIndex.index)!=0)
    18941958            { //put to cache
    18951959                std::cout << "-- subrcache for " << entry.blockIndex << std::endl;
     
    18971961            }
    18981962           
    1899             flowStackBlocks[entry.blockIndex] = false;
     1963            flowStackBlocks[entry.blockIndex.index] = false;
    19001964            std::cout << "pop: " << entry.blockIndex << std::endl;
    19011965            flowStack.pop_back();
     
    19742038    size_t wrCount = 0;
    19752039   
    1976     SimpleCache<size_t, RoutineData> subroutinesCache(codeBlocks.size()<<3);
     2040    SimpleCache<BlockIndex, RoutineData> subroutinesCache(codeBlocks.size()<<3);
    19772041   
    19782042    std::deque<CallStackEntry> callStack;
     
    19852049    std::unordered_map<AsmSingleVReg, size_t> curSSAIdMap;
    19862050    // routine map - routine datas map, value - last SSA ids map
    1987     std::unordered_map<size_t, RoutineData> routineMap;
     2051    std::unordered_map<BlockIndex, RoutineData> routineMap;
    19882052    // key - current res first key, value - previous first key and its flowStack pos
    19892053    PrevWaysIndexMap prevWaysIndexMap;
    19902054    // to track ways last block indices pair: block index, flowStackPos)
    1991     std::pair<size_t, size_t> lastCommonCacheWayPoint{ SIZE_MAX, SIZE_MAX };
     2055    std::pair<BlockIndex, size_t> lastCommonCacheWayPoint{ SIZE_MAX, SIZE_MAX };
    19922056    std::vector<bool> isRoutineGen(codeBlocks.size(), false);
    19932057   
     
    19992063    flowStack.push_back({ 0, 0 });
    20002064    flowStackBlocks[0] = true;
    2001     std::unordered_set<size_t> callBlocks;
    2002     std::unordered_set<size_t> loopBlocks;
     2065    std::unordered_set<BlockIndex> callBlocks;
     2066    std::unordered_set<BlockIndex> loopBlocks;
    20032067    std::unordered_set<size_t> recurseBlocks;
    20042068   
     
    20062070    {
    20072071        FlowStackEntry& entry = flowStack.back();
    2008         CodeBlock& cblock = codeBlocks[entry.blockIndex];
     2072        CodeBlock& cblock = codeBlocks[entry.blockIndex.index];
    20092073       
    20102074        if (entry.nextIndex == 0)
    20112075        {
    20122076            // process current block
    2013             if (!visited[entry.blockIndex])
     2077            if (!visited[entry.blockIndex.index])
    20142078            {
    20152079                std::cout << "proc: " << entry.blockIndex << std::endl;
    2016                 visited[entry.blockIndex] = true;
     2080                visited[entry.blockIndex.index] = true;
    20172081               
    20182082                for (auto& ssaEntry: cblock.ssaInfoMap)
     
    20592123            {
    20602124                // handle caching for res second point
    2061                 cblocksToCache.increase(entry.blockIndex);
     2125                cblocksToCache.increase(entry.blockIndex.index);
    20622126                std::cout << "cblockToCache: " << entry.blockIndex << "=" <<
    2063                             cblocksToCache.count(entry.blockIndex) << std::endl;
     2127                            cblocksToCache.count(entry.blockIndex.index) << std::endl;
    20642128                // back, already visited
    2065                 flowStackBlocks[entry.blockIndex] = !flowStackBlocks[entry.blockIndex];
     2129                flowStackBlocks[entry.blockIndex.index] =
     2130                        !flowStackBlocks[entry.blockIndex.index];
    20662131                flowStack.pop_back();
    20672132               
    2068                 size_t curWayBIndex = flowStack.back().blockIndex;
     2133                BlockIndex curWayBIndex = flowStack.back().blockIndex;
    20692134                if (lastCommonCacheWayPoint.first != SIZE_MAX)
    20702135                {
    20712136                    // mark point of way to cache (res first point)
    2072                     waysToCache[lastCommonCacheWayPoint.first] = true;
     2137                    waysToCache[lastCommonCacheWayPoint.first.index] = true;
    20732138                    std::cout << "mark to pfcache " <<
    20742139                            lastCommonCacheWayPoint.first << ", " <<
     
    20872152        {
    20882153            std::cout << " ret: " << entry.blockIndex << std::endl;
    2089             const size_t routineBlock = callStack.back().routineBlock;
     2154            const BlockIndex routineBlock = callStack.back().routineBlock;
    20902155            RoutineData& prevRdata = routineMap.find(routineBlock)->second;
    2091             if (!isRoutineGen[routineBlock])
     2156            if (!isRoutineGen[routineBlock.index])
    20922157            {
    20932158                createRoutineData(codeBlocks, curSSAIdMap, loopBlocks,
     
    20952160                            routineBlock);
    20962161                //prevRdata.compare(myRoutineData);
    2097                 isRoutineGen[routineBlock] = true;
     2162                isRoutineGen[routineBlock.index] = true;
    20982163            }
    20992164           
     
    21532218            }
    21542219            flowStack.push_back({ entry.blockIndex+1, 0, false });
    2155             if (flowStackBlocks[entry.blockIndex+1])
     2220            if (flowStackBlocks[(entry.blockIndex+1).index])
    21562221            {
    21572222                loopBlocks.insert(entry.blockIndex+1);
    21582223                 // keep to inserted in popping
    2159                 flowStackBlocks[entry.blockIndex+1] = false;
     2224                flowStackBlocks[(entry.blockIndex+1).index] = false;
    21602225            }
    21612226            else
    2162                 flowStackBlocks[entry.blockIndex+1] = true;
     2227                flowStackBlocks[(entry.blockIndex+1).index] = true;
    21632228            entry.nextIndex++;
    21642229        }
     
    21882253           
    21892254            std::cout << "pop: " << entry.blockIndex << std::endl;
    2190             flowStackBlocks[entry.blockIndex] = false;
     2255            flowStackBlocks[entry.blockIndex.index] = false;
    21912256            flowStack.pop_back();
    21922257            if (!flowStack.empty() && lastCommonCacheWayPoint.first != SIZE_MAX &&
     
    22102275    flowStack2.push_back({ 0, 0 });
    22112276   
    2212     SimpleCache<size_t, LastSSAIdMap> resFirstPointsCache(wrCount<<1);
    2213     SimpleCache<size_t, RBWSSAIdMap> resSecondPointsCache(rbwCount<<1);
     2277    SimpleCache<BlockIndex, LastSSAIdMap> resFirstPointsCache(wrCount<<1);
     2278    SimpleCache<BlockIndex, RBWSSAIdMap> resSecondPointsCache(rbwCount<<1);
    22142279   
    22152280    while (!flowStack2.empty())
    22162281    {
    22172282        FlowStackEntry2& entry = flowStack2.back();
    2218         CodeBlock& cblock = codeBlocks[entry.blockIndex];
     2283        CodeBlock& cblock = codeBlocks[entry.blockIndex.index];
    22192284       
    22202285        if (entry.nextIndex == 0)
    22212286        {
    22222287            // process current block
    2223             if (!visited[entry.blockIndex])
    2224                 visited[entry.blockIndex] = true;
     2288            if (!visited[entry.blockIndex.index])
     2289                visited[entry.blockIndex.index] = true;
    22252290            else
    22262291            {
     
    22502315        else // back
    22512316        {
    2252             if (cblocksToCache.count(entry.blockIndex)==2 &&
     2317            if (cblocksToCache.count(entry.blockIndex.index)==2 &&
    22532318                !resSecondPointsCache.hasKey(entry.blockIndex))
    22542319                // add to cache
     
    25172582}
    25182583
    2519 typedef std::deque<FlowStackEntry>::const_iterator FlowStackCIter;
     2584typedef std::deque<FlowStackEntry3>::const_iterator FlowStackCIter;
    25202585
    25212586struct CLRX_INTERNAL VRegLastPos
     
    25322597typedef std::unordered_map<AsmSingleVReg, VRegLastPos> LastVRegMap;
    25332598
    2534 static void putCrossBlockLivenesses(const std::deque<FlowStackEntry>& flowStack,
     2599static void putCrossBlockLivenesses(const std::deque<FlowStackEntry3>& flowStack,
    25352600        const std::vector<CodeBlock>& codeBlocks,
    25362601        const Array<size_t>& codeBlockLiveTimes, const LastVRegMap& lastVRegMap,
     
    25692634}
    25702635
    2571 static void putCrossBlockForLoop(const std::deque<FlowStackEntry>& flowStack,
     2636static void putCrossBlockForLoop(const std::deque<FlowStackEntry3>& flowStack,
    25722637        const std::vector<CodeBlock>& codeBlocks,
    25732638        const Array<size_t>& codeBlockLiveTimes,
     
    28262891   
    28272892    // construct vreg liveness
    2828     std::deque<FlowStackEntry> flowStack;
     2893    std::deque<FlowStackEntry3> flowStack;
    28292894    std::vector<bool> visited(codeBlocks.size(), false);
    28302895    // hold last vreg ssaId and position
     
    28432908    while (!flowStack.empty())
    28442909    {
    2845         FlowStackEntry& entry = flowStack.back();
     2910        FlowStackEntry3& entry = flowStack.back();
    28462911        CodeBlock& cblock = codeBlocks[entry.blockIndex];
    28472912       
Note: See TracChangeset for help on using the changeset viewer.