diff options
author | Valery Pykhtin <Valery.Pykhtin@amd.com> | 2016-04-06 15:55:10 +0000 |
---|---|---|
committer | Valery Pykhtin <Valery.Pykhtin@amd.com> | 2016-04-06 15:55:10 +0000 |
commit | 496db860118a1e6d0286e3a8c59f857496228f74 (patch) | |
tree | 7023b2a1386921befb88378243d6df86160e2984 /tools | |
parent | 505761b9d2be7bb4fdf64227af023fbb8b0b7245 (diff) |
[AMDGPU] llvm-objdump: Minimal HSA Code Object disassembler support.
Differential revision: http://reviews.llvm.org/D16998
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@265550 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/llvm-objdump/llvm-objdump.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index 28d667a486e..ccd98147ac3 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -384,12 +384,41 @@ public: } }; HexagonPrettyPrinter HexagonPrettyPrinterInst; + +class AMDGCNPrettyPrinter : public PrettyPrinter { +public: + void printInst(MCInstPrinter &IP, + const MCInst *MI, + ArrayRef<uint8_t> Bytes, + uint64_t Address, + raw_ostream &OS, + StringRef Annot, + MCSubtargetInfo const &STI) override { + SmallString<40> InstStr; + raw_svector_ostream IS(InstStr); + + IP.printInst(MI, IS, "", STI); + + OS << left_justify(IS.str(), 60) << format("// %012X: ", Address); + typedef support::ulittle32_t U32; + for (auto D : makeArrayRef(reinterpret_cast<const U32*>(Bytes.data()), + Bytes.size() / sizeof(U32))) + OS << format("%08X ", D); + + if (!Annot.empty()) + OS << "// " << Annot; + } +}; +AMDGCNPrettyPrinter AMDGCNPrettyPrinterInst; + PrettyPrinter &selectPrettyPrinter(Triple const &Triple) { switch(Triple.getArch()) { default: return PrettyPrinterInst; case Triple::hexagon: return HexagonPrettyPrinterInst; + case Triple::amdgcn: + return AMDGCNPrettyPrinterInst; } } } @@ -1046,6 +1075,18 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { if (Start >= End) continue; + if (Obj->isELF() && Obj->getArch() == Triple::amdgcn) { + // make size 4 bytes folded + End = Start + ((End - Start) & ~0x3ull); + Start += 256; // add sizeof(amd_kernel_code_t) + // cut trailing zeroes - up to 256 bytes (align) + const uint64_t EndAlign = 256; + const auto Limit = End - (std::min)(EndAlign, End - Start); + while (End > Limit && + *reinterpret_cast<const support::ulittle32_t*>(&Bytes[End - 4]) == 0) + End -= 4; + } + outs() << '\n' << Symbols[si].second << ":\n"; #ifndef NDEBUG |