Changeset 2582 in CLRX


Ignore:
Timestamp:
Nov 21, 2016, 3:26:23 PM (3 years ago)
Author:
matszpk
Message:

CLRadeonExtender: Comment typo in AsmGalliumFormat?. Code for AsmROCmFormat.
ROCmBinGen: Add addEmptyKernel to ROCmInput.

Location:
CLRadeonExtender/trunk
Files:
7 edited

Legend:

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

    r2581 r2582  
    6565   
    6666    ROCM_COMMENT = LAST_COMMON+1,        ///< ROCm comment section
     67    ROCM_CONFIG_CTRL_DIRECTIVE,
    6768   
    6869    EXTRA_FIRST = 0xfc,
  • CLRadeonExtender/trunk/CLRX/amdasm/Assembler.h

    r2490 r2582  
    666666    friend class AsmAmdCL2Handler;
    667667    friend class AsmGalliumHandler;
     668    friend class AsmROCmHandler;
    668669    friend class ISAAssembler;
    669670   
  • CLRadeonExtender/trunk/CLRX/amdbin/ROCmBinaries.h

    r2576 r2582  
    174174    std::vector<BinSection> extraSections;  ///< extra sections
    175175    std::vector<BinSymbol> extraSymbols;    ///< extra symbols
     176   
     177    void addEmptyKernel(const char* kernelName);
    176178};
    177179
  • CLRadeonExtender/trunk/amdasm/AsmGalliumFormat.cpp

    r2377 r2582  
    132132        section.type = AsmSectionType::EXTRA_SECTION;
    133133        section.elfBinSectId = extraSectionCount++;
    134         /// referfence entry is available and unchangeable by whole lifecycle of section map
     134        /// reference entry is available and unchangeable by whole lifecycle of section map
    135135        section.name = out.first->first.c_str();
    136136    }
  • CLRadeonExtender/trunk/amdasm/AsmROCmFormat.cpp

    r2581 r2582  
    2929
    3030using namespace CLRX;
     31
     32/*
     33 * ROCm format handler
     34 */
     35
     36AsmROCmHandler::AsmROCmHandler(Assembler& assembler): AsmFormatHandler(assembler),
     37             output{}, codeSection(0), commentSection(ASMSECT_NONE),
     38             extraSectionCount(0)
     39{
     40    assembler.currentKernel = ASMKERN_GLOBAL;
     41    assembler.currentSection = 0;
     42    sections.push_back({ ASMKERN_GLOBAL, AsmSectionType::CODE,
     43                ELFSECTID_TEXT, ".text" });
     44    currentKcodeKernel = ASMKERN_GLOBAL;
     45    savedSection = 0;
     46}
     47
     48cxuint AsmROCmHandler::addKernel(const char* kernelName)
     49{
     50    cxuint thisKernel = output.symbols.size();
     51    cxuint thisSection = sections.size();
     52    output.addEmptyKernel(kernelName);
     53    /// add kernel config section
     54    sections.push_back({ thisKernel, AsmSectionType::CONFIG, ELFSECTID_UNDEF, nullptr });
     55    kernelStates.push_back({ thisSection, false, 0 });
     56   
     57    if (assembler.currentKernel == ASMKERN_GLOBAL)
     58        savedSection = assembler.currentSection;
     59   
     60    assembler.currentKernel = thisKernel;
     61    assembler.currentSection = thisSection;
     62    return thisKernel;
     63}
     64
     65cxuint AsmROCmHandler::addSection(const char* sectionName, cxuint kernelId)
     66{
     67    const cxuint thisSection = sections.size();
     68    Section section;
     69    section.kernelId = ASMKERN_GLOBAL;  // we ignore input kernelId, we go to main
     70   
     71    if (::strcmp(sectionName, ".text") == 0) // code
     72    {
     73        if (codeSection!=ASMSECT_NONE)
     74            throw AsmFormatException("Only one section '.text' can be in binary");
     75        codeSection = thisSection;
     76        section.type = AsmSectionType::CODE;
     77        section.elfBinSectId = ELFSECTID_TEXT;
     78        section.name = ".text"; // set static name (available by whole lifecycle)
     79    }
     80    else if (::strcmp(sectionName, ".comment") == 0) // comment
     81    {
     82        if (commentSection!=ASMSECT_NONE)
     83            throw AsmFormatException("Only one section '.comment' can be in binary");
     84        commentSection = thisSection;
     85        section.type = AsmSectionType::GALLIUM_COMMENT;
     86        section.elfBinSectId = ELFSECTID_COMMENT;
     87        section.name = ".comment"; // set static name (available by whole lifecycle)
     88    }
     89    else
     90    {
     91        auto out = extraSectionMap.insert(std::make_pair(CString(sectionName),
     92                    thisSection));
     93        if (!out.second)
     94            throw AsmFormatException("Section already exists");
     95        section.type = AsmSectionType::EXTRA_SECTION;
     96        section.elfBinSectId = extraSectionCount++;
     97        /// reference entry is available and unchangeable by whole lifecycle of section map
     98        section.name = out.first->first.c_str();
     99    }
     100    sections.push_back(section);
     101   
     102    assembler.currentKernel = ASMKERN_GLOBAL;
     103    assembler.currentSection = thisSection;
     104    return thisSection;
     105}
     106
     107cxuint AsmROCmHandler::getSectionId(const char* sectionName) const
     108{
     109    if (::strcmp(sectionName, ".text") == 0) // code
     110        return codeSection;
     111    else if (::strcmp(sectionName, ".comment") == 0) // comment
     112        return commentSection;
     113    else
     114    {
     115        SectionMap::const_iterator it = extraSectionMap.find(sectionName);
     116        if (it != extraSectionMap.end())
     117            return it->second;
     118    }
     119    return ASMSECT_NONE;
     120}
     121
     122void AsmROCmHandler::setCurrentKernel(cxuint kernel)
     123{
     124    if (kernel != ASMKERN_GLOBAL && kernel >= kernelStates.size())
     125        throw AsmFormatException("KernelId out of range");
     126   
     127    if (assembler.currentKernel == ASMKERN_GLOBAL)
     128        savedSection = assembler.currentSection;
     129   
     130    assembler.currentKernel = kernel;
     131    if (kernel != ASMKERN_GLOBAL)
     132        assembler.currentSection = kernelStates[kernel].defaultSection;
     133    else // default main section
     134        assembler.currentSection = savedSection;
     135}
     136
     137void AsmROCmHandler::setCurrentSection(cxuint sectionId)
     138{
     139    if (sectionId >= sections.size())
     140        throw AsmFormatException("SectionId out of range");
     141   
     142    if (assembler.currentKernel == ASMKERN_GLOBAL)
     143        savedSection = assembler.currentSection;
     144   
     145    assembler.currentSection = sectionId;
     146    assembler.currentKernel = sections[sectionId].kernelId;
     147}
     148
     149
     150AsmFormatHandler::SectionInfo AsmROCmHandler::getSectionInfo(cxuint sectionId) const
     151{
     152    if (sectionId >= sections.size())
     153        throw AsmFormatException("Section doesn't exists");
     154   
     155    AsmFormatHandler::SectionInfo info;
     156    info.type = sections[sectionId].type;
     157    info.flags = 0;
     158    if (info.type == AsmSectionType::CODE)
     159        info.flags = ASMSECT_ADDRESSABLE | ASMSECT_WRITEABLE;
     160    else if (info.type != AsmSectionType::CONFIG)
     161        info.flags = ASMSECT_ADDRESSABLE | ASMSECT_WRITEABLE | ASMSECT_ABS_ADDRESSABLE;
     162   
     163    info.name = sections[sectionId].name;
     164    return info;
     165}
     166
     167bool AsmROCmHandler::parsePseudoOp(const CString& firstName,
     168       const char* stmtPlace, const char* linePtr)
     169{
     170    return false;
     171}
     172
     173void AsmROCmHandler::restoreKcodeCurrentAllocRegs()
     174{
     175    if (currentKcodeKernel != ASMKERN_GLOBAL)
     176    {
     177        Kernel& newKernel = kernelStates[currentKcodeKernel];
     178        assembler.isaAssembler->setAllocatedRegisters(newKernel.allocRegs,
     179                            newKernel.allocRegFlags);
     180    }
     181}
     182
     183void AsmROCmHandler::saveKcodeCurrentAllocRegs()
     184{
     185    if (currentKcodeKernel != ASMKERN_GLOBAL)
     186    {   // save other state
     187        size_t regTypesNum;
     188        Kernel& oldKernel = kernelStates[currentKcodeKernel];
     189        const cxuint* regs = assembler.isaAssembler->getAllocatedRegisters(
     190                            regTypesNum, oldKernel.allocRegFlags);
     191        std::copy(regs, regs+2, oldKernel.allocRegs);
     192    }
     193}
     194
     195
     196void AsmROCmHandler::handleLabel(const CString& label)
     197{
     198    if (assembler.sections[assembler.currentSection].type != AsmSectionType::CODE)
     199        return;
     200    auto kit = assembler.kernelMap.find(label);
     201    if (kit == assembler.kernelMap.end())
     202        return;
     203    if (!kcodeSelection.empty())
     204        return; // do not change if inside kcode
     205    // save other state
     206    saveKcodeCurrentAllocRegs();
     207    // restore this state
     208    currentKcodeKernel = kit->second;
     209    restoreKcodeCurrentAllocRegs();
     210}
     211
     212
     213bool AsmROCmHandler::prepareBinary()
     214{
     215    return false;
     216}
     217
     218void AsmROCmHandler::writeBinary(std::ostream& os) const
     219{
     220}
     221
     222void AsmROCmHandler::writeBinary(Array<cxbyte>& array) const
     223{
     224}
  • CLRadeonExtender/trunk/amdasm/Assembler.cpp

    r2581 r2582  
    17991799            break;
    18001800        case BinaryFormat::ROCM:
    1801             //formatHandler = new AsmROCmHandler(*this);
     1801            formatHandler = new AsmROCmHandler(*this);
    18021802            break;
    18031803        default:
  • CLRadeonExtender/trunk/amdbin/ROCmBinaries.cpp

    r2579 r2582  
    139139}
    140140
     141
     142void ROCmInput::addEmptyKernel(const char* kernelName)
     143{
     144    symbols.push_back({ kernelName, 0, 0, true });
     145}
    141146/*
    142147 * ROCm Binary Generator
Note: See TracChangeset for help on using the changeset viewer.