Changeset 3272 in CLRX


Ignore:
Timestamp:
Aug 31, 2017, 8:01:36 PM (5 months ago)
Author:
matszpk
Message:

CLRadeonExtender: GalliumDisasm?: Add correct (first version) disassembly for binaries compiled by LLVM 4.0 or later.
clrxdisasm: add option '--llvmVersion'.

Location:
CLRadeonExtender/trunk
Files:
8 edited

Legend:

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

    r3259 r3272  
    324324    bool isLLVM390;     ///< if >=LLVM3.9
    325325    bool isMesa170;     ///< if >=Mesa3D 17.0
     326    bool isHSACO;       ///< if HSACO (LLVM 4.0)
    326327    size_t globalDataSize;  ///< global (constants for kernels) data size
    327328    const cxbyte* globalData;   ///< global (constants for kernels) data
     
    430431     * \param output output stream
    431432     * \param flags flags for disassembler
     433     * \param llvmVersion LLVM version
    432434     */
    433435    Disassembler(GPUDeviceType deviceType, const GalliumBinary& binary,
    434                  std::ostream& output, Flags flags = 0);
     436                 std::ostream& output, Flags flags = 0, cxuint llvmVersion = 0);
    435437   
    436438    /// constructor for Gallium disassembler input
  • CLRadeonExtender/trunk/amdasm/DisasmGallium.cpp

    r3270 r3272  
    1919
    2020#include <CLRX/Config.h>
     21#include <algorithm>
    2122#include <cstdint>
    2223#include <cstdio>
     
    8081
    8182GalliumDisasmInput* CLRX::getGalliumDisasmInputFromBinary(GPUDeviceType deviceType,
    82            const GalliumBinary& binary)
     83           const GalliumBinary& binary, cxuint llvmVersion)
    8384{
    8485    std::unique_ptr<GalliumDisasmInput> input(new GalliumDisasmInput);
    8586    input->deviceType = deviceType;
     87    input->isHSACO = (llvmVersion >= 40000);
    8688    if (!binary.is64BitElfBinary())
    8789    {
     
    286288            }
    287289            else
     290            {
    288291                dumpKernelConfig(output, maxSgprsNum, arch, kinput.progInfo,
    289292                    galliumInput->isLLVM390);
    290         }
    291         isaDisassembler->addNamedLabel(kinput.offset, kinput.kernelName);
     293                if (galliumInput->isHSACO)
     294                    dumpHSACOConfig(output, maxSgprsNum, arch,
     295                        *reinterpret_cast<const ROCmKernelConfig*>(
     296                             galliumInput->code + kinput.offset));
     297            }
     298        }
     299        if (!galliumInput->isHSACO)
     300            isaDisassembler->addNamedLabel(kinput.offset, kinput.kernelName);
    292301    }
    293302    if (doDumpCode && galliumInput->code != nullptr && galliumInput->codeSize != 0)
    294303    {   // print text
    295         output.write(".text\n", 6);
    296         isaDisassembler->setInput(galliumInput->codeSize, galliumInput->code);
    297         isaDisassembler->beforeDisassemble();
    298         isaDisassembler->disassemble();
     304        if (!galliumInput->isHSACO)
     305        {
     306            output.write(".text\n", 6);
     307            isaDisassembler->setInput(galliumInput->codeSize, galliumInput->code);
     308            isaDisassembler->beforeDisassemble();
     309            isaDisassembler->disassemble();
     310        }
     311        else
     312        {   // LLVM 4.0 - HSACO code
     313            std::vector<ROCmDisasmRegionInput> regions(galliumInput->kernels.size());
     314            for (size_t i = 0; i < galliumInput->kernels.size(); i++)
     315            {
     316                const GalliumDisasmKernelInput& kernel = galliumInput->kernels[i];
     317                ROCmDisasmRegionInput& region = regions[i];
     318                region.regionName = kernel.kernelName;
     319                region.offset = kernel.offset;
     320                const size_t end = (i+1 < galliumInput->kernels.size()) ?
     321                        galliumInput->kernels[i+1].offset : galliumInput->codeSize;
     322                region.size = end - kernel.offset;
     323                region.type = ROCmRegionType::KERNEL;
     324            }
     325           
     326            disassembleHSACOCode(output, regions, galliumInput->codeSize,
     327                            galliumInput->code, isaDisassembler, flags);
     328        }
    299329    }
    300330}
  • CLRadeonExtender/trunk/amdasm/DisasmInternals.h

    r3271 r3272  
    8585
    8686extern CLRX_INTERNAL GalliumDisasmInput* getGalliumDisasmInputFromBinary(
    87             GPUDeviceType deviceType, const GalliumBinary& binary);
     87            GPUDeviceType deviceType, const GalliumBinary& binary, cxuint llvmVersion);
    8888
    8989extern CLRX_INTERNAL const std::pair<const char*, KernelArgType> disasmArgTypeNameMap[74];
  • CLRadeonExtender/trunk/amdasm/Disassembler.cpp

    r3270 r3272  
    331331
    332332Disassembler::Disassembler(GPUDeviceType deviceType, const GalliumBinary& binary,
    333            std::ostream& _output, Flags _flags) :
     333           std::ostream& _output, Flags _flags, cxuint llvmVersion) :
    334334           fromBinary(true), binaryFormat(BinaryFormat::GALLIUM),
    335335           galliumInput(nullptr), output(_output), flags(_flags), sectionCount(0)
    336336{
    337337    isaDisassembler.reset(new GCNDisassembler(*this));
    338     galliumInput = getGalliumDisasmInputFromBinary(deviceType, binary);
     338    galliumInput = getGalliumDisasmInputFromBinary(deviceType, binary, llvmVersion);
    339339}
    340340
  • CLRadeonExtender/trunk/doc/ClrxDisasm.md

    r3139 r3272  
    1616clrxdisasm [-mdcCfhar?] [-g GPUDEVICE] [-a ARCH] [-t VERSION] [--metadata] [--data]
    1717[--calNotes] [--config] [--floats] [--hexcode] [--all] [--raw] [--gpuType=GPUDEVICE]
    18 [--arch=ARCH] [--driverVersion=VERSION] [--buggyFPLit] [--help] [--usage] [--version]
    19 [file...]
     18[--arch=ARCH] [--driverVersion=VERSION] [--llvmVersion=VERSION] [--buggyFPLit]
     19[--help] [--usage] [--version] [file...]
    2020
    2121### Program Options
     
    8383Used for AMD OpenCL 2.0 binaries.
    8484
     85* **--llvmVersion=VERSION**
     86
     87    Choose LLVM version that generates binaries.
     88Version is number in that form: MajorVersion*100 + MinorVersion.
     89
     90
    8591* **--buggyFPLit**
    8692
  • CLRadeonExtender/trunk/programs/clrxdisasm.cpp

    r3259 r3272  
    5050    { "driverVersion", 't', CLIArgType::UINT, false, false,
    5151        "set driver version (for AmdCL2)", nullptr },
     52    { "llvmVersion", 0, CLIArgType::UINT, false, false,
     53        "set LLVM version (for Gallium)", nullptr },
    5254    { "buggyFPLit", 0, CLIArgType::NONE, false, false,
    5355        "use old and buggy fplit rules", nullptr },
     
    9496    if (cli.hasShortOption('t'))
    9597        driverVersion = cli.getShortOptArg<cxuint>('t');
     98    cxuint llvmVersion = 0;
     99    if (cli.hasLongOption("llvmVersion"))
     100        llvmVersion = cli.getLongOptArg<cxuint>("llvmVersion");
    96101   
    97102    int ret = 0;
     
    171176                {
    172177                    GalliumBinary galliumBin(binaryData.size(),binaryData.data(), 0);
    173                     Disassembler disasm(gpuDeviceType, galliumBin, std::cout, disasmFlags);
     178                    Disassembler disasm(gpuDeviceType, galliumBin, std::cout,
     179                            disasmFlags, llvmVersion);
    174180                    disasm.disassemble();
    175181                }
  • CLRadeonExtender/trunk/programs/clrxdisasm.pod

    r3139 r3272  
    99clrxdisasm [-mdcCfhar?] [-g GPUDEVICE] [-a ARCH] [-t VERSION] [--metadata] [--data]
    1010[--calNotes] [--config] [--floats] [--hexcode] [--all] [--raw] [--gpuType=GPUDEVICE]
    11 [--arch=ARCH] [--driverVersion=VERSION][--buggyFPLit] [--help] [--usage] [--version]
    12 [file...]
     11[--arch=ARCH] [--driverVersion=VERSION] [--llvmVersion=VERSION] [--buggyFPLit]
     12[--help] [--usage] [--version] [file...]
    1313
    1414=head1 DESCRIPTION
     
    8989Used for AMD OpenCL 2.0 binaries.
    9090
     91=item B<--llvmVersion=VERSION>
     92
     93Choose LLVM version that generates binaries.
     94Version is number in that form: MajorVersion*100 + MinorVersion.
     95
    9196=item B<--buggyFPLit>
    9297
  • CLRadeonExtender/trunk/tests/amdasm/DisasmDataTest.cpp

    r3259 r3272  
    185185static const GalliumDisasmInput galliumDisasmData =
    186186{
    187     GPUDeviceType::PITCAIRN, false, false, false,
     187    GPUDeviceType::PITCAIRN, false, false, false, false,
    188188    sizeof(galliumInput1Global), galliumInput1Global,
    189189    {
Note: See TracChangeset for help on using the changeset viewer.