Changeset 2526 in CLRX


Ignore:
Timestamp:
Nov 3, 2016, 10:40:31 PM (4 years ago)
Author:
matszpk
Message:

CLRadeonExtender: Delegate writeLabelsTo... to public API. fix dontPrintLabelsAfterCode.
ROCm: Print labels between data regions and config.

Location:
CLRadeonExtender/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • CLRadeonExtender/trunk/CLRX/amdasm/Disassembler.h

    r2525 r2526  
    6969private:
    7070    friend struct GCNDisasmUtils; // INTERNAL LOGIC
     71public:
     72    typedef std::vector<size_t>::const_iterator LabelIter;  ///< label iterator
     73   
     74    /// named label iterator
     75    typedef std::vector<std::pair<size_t, CString> >::const_iterator NamedLabelIter;
    7176protected:
    7277    /// internal relocation structure
     
    7883    };
    7984   
    80     typedef std::vector<size_t>::const_iterator LabelIter;  ///< label iterator
    81    
    8285    /// relocation iterator
    8386    typedef std::vector<std::pair<size_t, Relocation> >::const_iterator RelocIter;
    8487   
    85     /// named label iterator
    86     typedef std::vector<std::pair<size_t, CString> >::const_iterator NamedLabelIter;
    87    
    8888    Disassembler& disassembler; ///< disassembler instance
    8989    size_t startOffset; ///< start offset
     90    size_t labelStartOffset; /// < start offset of labels
    9091    size_t inputSize;   ///< size of input
    9192    const cxbyte* input;    ///< input code
     
    100101    explicit ISADisassembler(Disassembler& disassembler, cxuint outBufSize = 500);
    101102   
     103    /// write location in the code
     104    void writeLocation(size_t pos);
     105    /// write relocation to current place in instruction
     106    bool writeRelocation(size_t pos, RelocIter& relocIter);
     107   
     108public:
     109    virtual ~ISADisassembler();
     110   
    102111    /// write all labels before specified position
    103112    void writeLabelsToPosition(size_t pos, LabelIter& labelIter,
     
    105114    /// write all labels to end
    106115    void writeLabelsToEnd(size_t start, LabelIter labelIter, NamedLabelIter namedLabelIter);
    107     /// write location in the code
    108     void writeLocation(size_t pos);
    109     /// write relocation to current place in instruction
    110     bool writeRelocation(size_t pos, RelocIter& relocIter);
    111    
    112 public:
    113     virtual ~ISADisassembler();
    114116   
    115117    /// set input code
    116     void setInput(size_t inputSize, const cxbyte* input, size_t startOffset = 0)
     118    void setInput(size_t inputSize, const cxbyte* input, size_t startOffset = 0,
     119        size_t labelStartOffset = 0)
    117120    {
    118121        this->inputSize = inputSize;
    119122        this->input = input;
    120123        this->startOffset = startOffset;
     124        this->labelStartOffset = labelStartOffset;
    121125    }
    122126   
     
    159163        relocations.clear();
    160164    }
     165   
     166    const std::vector<size_t>& getLabels() const
     167    { return labels; }
     168    const std::vector<std::pair<size_t, CString> >& getNamedLabels() const
     169    { return namedLabels; }
     170   
     171    void flushOutput()
     172    { return output.flush(); }
    161173};
    162174
  • CLRadeonExtender/trunk/amdasm/DisasmROCm.cpp

    r2524 r2526  
    433433        const cxbyte* code = rocmInput->code;
    434434        output.write(".text\n", 6);
     435        // clear labels
     436        isaDisassembler->clearNumberedLabels();
     437       
     438        /// analyze code with collecting labels
    435439        for (size_t i = 0; i < regionsNum; i++)
    436440        {
    437441            const ROCmDisasmRegionInput& region = rocmInput->regions[sorted[i].second];
    438             output.write(region.regionName.c_str(), region.regionName.size());
    439             output.write(":\n", 2);
     442            if (region.isKernel && doDumpCode)
     443            {
     444                isaDisassembler->setInput(region.size-256, code + region.offset+256,
     445                                    region.offset+256);
     446                isaDisassembler->analyzeBeforeDisassemble();
     447            }
     448            isaDisassembler->addNamedLabel(region.offset, region.regionName);
     449        }
     450        isaDisassembler->prepareLabelsAndRelocations();
     451       
     452        ISADisassembler::LabelIter curLabel;
     453        ISADisassembler::NamedLabelIter curNamedLabel;
     454        const auto& labels = isaDisassembler->getLabels();
     455        const auto& namedLabels = isaDisassembler->getNamedLabels();
     456        // real disassemble
     457        size_t prevRegionEnd = 0;
     458        bool prevIsKernel = false;
     459        for (size_t i = 0; i < regionsNum; i++)
     460        {
     461            const ROCmDisasmRegionInput& region = rocmInput->regions[sorted[i].second];
     462           
     463            if (prevIsKernel)
     464                prevRegionEnd++;
     465            isaDisassembler->setInput(prevRegionEnd, code + region.offset,
     466                                    region.offset, prevRegionEnd);
     467            curLabel = std::lower_bound(labels.begin(), labels.end(), prevRegionEnd);
     468            curNamedLabel = std::lower_bound(namedLabels.begin(), namedLabels.end(),
     469                std::make_pair(prevRegionEnd, CString()),
     470                  [](const std::pair<size_t,CString>& a,
     471                                 const std::pair<size_t, CString>& b)
     472                  { return a.first < b.first; });
     473            isaDisassembler->writeLabelsToPosition(0, curLabel, curNamedLabel);
     474            isaDisassembler->flushOutput();
     475           
    440476            if (region.isKernel)
    441477            {
     
    447483                        output.write(".skip 256\n", 10);
    448484                }
     485               
    449486                if (doDumpCode)
    450487                {
    451488                    isaDisassembler->setInput(region.size-256, code + region.offset+256,
    452                                     region.offset+256);
     489                                    region.offset+256, region.offset+1);
    453490                    isaDisassembler->setDontPrintLabels(i+1<regionsNum);
    454                     isaDisassembler->beforeDisassemble();
    455491                    isaDisassembler->disassemble();
    456492                }
     
    463499                printDisasmData(region.size, code + region.offset, output, true);
    464500            }
     501            prevRegionEnd = region.offset + region.size;
     502            prevIsKernel = region.isKernel;
    465503        }
    466504    }
  • CLRadeonExtender/trunk/amdasm/Disassembler.cpp

    r2525 r2526  
    3737
    3838ISADisassembler::ISADisassembler(Disassembler& _disassembler, cxuint outBufSize)
    39         : disassembler(_disassembler), startOffset(0),
    40           dontPrintLabelsAfterCode(true), output(outBufSize, _disassembler.getOutput())
     39        : disassembler(_disassembler), startOffset(0), labelStartOffset(0),
     40          dontPrintLabelsAfterCode(false), output(outBufSize, _disassembler.getOutput())
    4141{ }
    4242
  • CLRadeonExtender/trunk/amdasm/GCNDisasm.cpp

    r2525 r2526  
    24292429void GCNDisassembler::disassemble()
    24302430{
    2431     LabelIter curLabel = std::lower_bound(labels.begin(), labels.end(), startOffset);
     2431    LabelIter curLabel = std::lower_bound(labels.begin(), labels.end(), labelStartOffset);
    24322432    RelocIter curReloc = std::lower_bound(relocations.begin(), relocations.end(),
    24332433        std::make_pair(startOffset, Relocation()),
     
    24352435          { return a.first < b.first; });
    24362436    NamedLabelIter curNamedLabel = std::lower_bound(namedLabels.begin(), namedLabels.end(),
    2437         std::make_pair(startOffset, CString()),
     2437        std::make_pair(labelStartOffset, CString()),
    24382438          [](const std::pair<size_t,CString>& a, const std::pair<size_t, CString>& b)
    24392439          { return a.first < b.first; });
     
    27792779        output.put('\n');
    27802780    }
    2781     if (dontPrintLabelsAfterCode)
    2782     {
     2781    if (!dontPrintLabelsAfterCode)
    27832782        writeLabelsToEnd(codeWordsNum<<2, curLabel, curNamedLabel);
    2784         output.flush();
    2785     }
     2783    output.flush();
    27862784    disassembler.getOutput().flush();
    2787     labels.clear(); // free labels
    2788 }
     2785}
Note: See TracChangeset for help on using the changeset viewer.