[PATCH] D52824: [AMDGPU] Implemented MCELFNoteDisassembler for PAL metadata note
Tim Renouf via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 3 01:32:19 PDT 2018
tpr created this revision.
Herald added subscribers: llvm-commits, t-tye, dstuttard, yaxunl, nhaehnle, wdng, jvesely, kzhuravl, arsenm.
Change-Id: I3749ab42309fd056f8cf5d58633891607b626820
Repository:
rL LLVM
https://reviews.llvm.org/D52824
Files:
lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.h
Index: lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.h
===================================================================
--- lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.h
+++ lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.h
@@ -20,6 +20,7 @@
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCInstrInfo.h"
#include "llvm/MC/MCDisassembler/MCDisassembler.h"
+#include "llvm/MC/MCDisassembler/MCELFNoteDisassembler.h"
#include "llvm/MC/MCDisassembler/MCRelocationInfo.h"
#include "llvm/MC/MCDisassembler/MCSymbolizer.h"
#include "llvm/Object/ELFNoteDumper.h"
@@ -169,6 +170,21 @@
support::endianness TargetEndianness, raw_ostream &OS) override;
};
+//===----------------------------------------------------------------------===//
+// AMDGPUMCELFNoteDisassembler
+//===----------------------------------------------------------------------===//
+
+class AMDGPUMCELFNoteDisassembler : public MCELFNoteDisassembler {
+public:
+ AMDGPUMCELFNoteDisassembler(MCContext &Ctx, const MCSubtargetInfo *STI)
+ : MCELFNoteDisassembler(Ctx, STI) {}
+
+ // Disassemble one note from the ELF .note section.
+ // Returns false if the note type is not recognized or disassembly fails.
+ virtual bool disassembleNote(unsigned Type, StringRef Name, StringRef Desc,
+ support::endianness TargetEndianness, MCTargetStreamer *TS) override;
+};
+
} // end namespace llvm
#endif // LLVM_LIB_TARGET_AMDGPU_DISASSEMBLER_AMDGPUDISASSEMBLER_H
Index: lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
===================================================================
--- lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
+++ lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
@@ -970,6 +970,37 @@
}
//===----------------------------------------------------------------------===//
+// AMDGPUMCELFNoteDisassembler
+//===----------------------------------------------------------------------===//
+
+// Disassemble one note from the ELF .note section.
+// Returns false if the note type is not recognized or disassembly fails.
+bool AMDGPUMCELFNoteDisassembler::disassembleNote(unsigned Type, StringRef Name,
+ StringRef Desc, support::endianness TargetEndianness,
+ MCTargetStreamer *TS) {
+ if (Name != "AMD")
+ return false;
+ auto ATS = static_cast<AMDGPUTargetStreamer *>(TS);
+ switch (Type) {
+
+ // PAL metadata is in 32-bit words and only exists on AMDGPU, which is
+ // always little endian, so the following does not work if running
+ // llvm-readobj on a big-endian host.
+#if BYTE_ORDER == LITTLE_ENDIAN
+ case ELF::NT_AMD_AMDGPU_PAL_METADATA: {
+ ArrayRef<uint32_t> DescAsU32(
+ reinterpret_cast<const uint32_t *>(Desc.data()),
+ Desc.size() / sizeof(uint32_t));
+ AMDGPU::PALMD::Metadata MD(DescAsU32.begin(), DescAsU32.end());
+ ATS->EmitPALMetadata(MD);
+ ATS->getStreamer().AddBlankLine();
+ return true;
+ }
+#endif
+ return false;
+}
+
+//===----------------------------------------------------------------------===//
// Initialization
//===----------------------------------------------------------------------===//
@@ -992,11 +1023,18 @@
return new AMDGPUELFNoteDumper();
}
+static MCELFNoteDisassembler *createAMDGPUMCELFNoteDisassembler(const Target &T,
+ MCContext &Ctx, const MCSubtargetInfo &STI) {
+ return new AMDGPUMCELFNoteDisassembler(Ctx, &STI);
+}
+
extern "C" void LLVMInitializeAMDGPUDisassembler() {
TargetRegistry::RegisterMCDisassembler(getTheGCNTarget(),
createAMDGPUDisassembler);
TargetRegistry::RegisterMCSymbolizer(getTheGCNTarget(),
createAMDGPUSymbolizer);
TargetRegistry::RegisterELFNoteDumper(getTheGCNTarget(),
createAMDGPUELFNoteDumper);
+ TargetRegistry::RegisterMCELFNoteDisassembler(getTheGCNTarget(),
+ createAMDGPUMCELFNoteDisassembler);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52824.168084.patch
Type: text/x-patch
Size: 4008 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181003/da6d9d8f/attachment.bin>
More information about the llvm-commits
mailing list