[llvm] 09d26b7 - [NFC] Refactor the tuple of symbol information with structure for llvm-objdump
via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 10 16:23:26 PST 2020
Author: diggerlin
Date: 2020-02-10T19:23:01-05:00
New Revision: 09d26b79d295f1d2efb94c0ebc5db9d0d881454e
URL: https://github.com/llvm/llvm-project/commit/09d26b79d295f1d2efb94c0ebc5db9d0d881454e
DIFF: https://github.com/llvm/llvm-project/commit/09d26b79d295f1d2efb94c0ebc5db9d0d881454e.diff
LOG: [NFC] Refactor the tuple of symbol information with structure for llvm-objdump
SUMMARY:
refator the std::tuple<uint64_t, StringRef, uint8_t> to structor
Reviewers: daltenty
Subscribers: wuzish, nemanjai, hiraditya
Differential Revision: https://reviews.llvm.org/D74240
Added:
Modified:
llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h
llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
llvm/tools/llvm-objdump/llvm-objdump.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h b/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h
index 76c5215264bc..05e47deadfc6 100644
--- a/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h
+++ b/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h
@@ -9,12 +9,26 @@
#ifndef LLVM_MC_MCDISASSEMBLER_MCDISASSEMBLER_H
#define LLVM_MC_MCDISASSEMBLER_MCDISASSEMBLER_H
+#include "llvm/ADT/StringRef.h"
#include "llvm/MC/MCDisassembler/MCSymbolizer.h"
#include <cstdint>
#include <memory>
+#include <vector>
namespace llvm {
+struct SymbolInfoTy {
+ uint64_t Addr;
+ StringRef Name;
+ uint8_t Type;
+
+ SymbolInfoTy(uint64_t Addr, StringRef Name, uint8_t Type):
+ Addr(Addr),Name(Name),Type(Type) {};
+};
+
+using SectionSymbolsTy = std::vector<SymbolInfoTy>;
+
+
template <typename T> class ArrayRef;
class StringRef;
class MCContext;
diff --git a/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp b/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
index 419513bdc248..8945b576ae78 100644
--- a/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
+++ b/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
@@ -1202,8 +1202,6 @@ bool AMDGPUSymbolizer::tryAddingSymbolicOperand(MCInst &Inst,
raw_ostream &/*cStream*/, int64_t Value,
uint64_t /*Address*/, bool IsBranch,
uint64_t /*Offset*/, uint64_t /*InstSize*/) {
- using SymbolInfoTy = std::tuple<uint64_t, StringRef, uint8_t>;
- using SectionSymbolsTy = std::vector<SymbolInfoTy>;
if (!IsBranch) {
return false;
@@ -1215,11 +1213,11 @@ bool AMDGPUSymbolizer::tryAddingSymbolicOperand(MCInst &Inst,
auto Result = std::find_if(Symbols->begin(), Symbols->end(),
[Value](const SymbolInfoTy& Val) {
- return std::get<0>(Val) == static_cast<uint64_t>(Value)
- && std::get<2>(Val) == ELF::STT_NOTYPE;
+ return Val.Addr == static_cast<uint64_t>(Value)
+ && Val.Type == ELF::STT_NOTYPE;
});
if (Result != Symbols->end()) {
- auto *Sym = Ctx.getOrCreateSymbol(std::get<1>(*Result));
+ auto *Sym = Ctx.getOrCreateSymbol(Result->Name);
const auto *Add = MCSymbolRefExpr::create(Sym, Ctx);
Inst.addOperand(MCOperand::createExpr(Add));
return true;
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index dc8a4b705c53..6719aed44912 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -341,7 +341,15 @@ static StringSet<> DisasmFuncsSet;
StringSet<> FoundSectionSet;
static StringRef ToolName;
-typedef std::vector<std::tuple<uint64_t, StringRef, uint8_t>> SectionSymbolsTy;
+static bool operator<(const SymbolInfoTy& P1 ,const SymbolInfoTy& P2) {
+ if (P1.Addr < P2.Addr)
+ return true;
+
+ if (P1.Addr == P2.Addr)
+ return P1.Name < P2.Name;
+
+ return false;
+}
namespace {
struct FilterResult {
@@ -1229,8 +1237,8 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
std::vector<MappingSymbolPair> MappingSymbols;
if (hasMappingSymbols(Obj)) {
for (const auto &Symb : Symbols) {
- uint64_t Address = std::get<0>(Symb);
- StringRef Name = std::get<1>(Symb);
+ uint64_t Address = Symb.Addr;
+ StringRef Name = Symb.Name;
if (Name.startswith("$d"))
MappingSymbols.emplace_back(Address - SectionAddr, 'd');
if (Name.startswith("$x"))
@@ -1264,10 +1272,10 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
StringRef SectionName = unwrapOrError(Section.getName(), Obj->getFileName());
// If the section has no symbol at the start, just insert a dummy one.
- if (Symbols.empty() || std::get<0>(Symbols[0]) != 0) {
+ if (Symbols.empty() || Symbols[0].Addr != 0) {
Symbols.insert(
Symbols.begin(),
- std::make_tuple(SectionAddr, SectionName,
+ SymbolInfoTy(SectionAddr, SectionName,
Section.isText() ? ELF::STT_FUNC : ELF::STT_OBJECT));
}
@@ -1289,7 +1297,7 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
std::vector<RelocationRef>::const_iterator RelEnd = Rels.end();
// Disassemble symbol by symbol.
for (unsigned SI = 0, SE = Symbols.size(); SI != SE; ++SI) {
- std::string SymbolName = std::get<1>(Symbols[SI]).str();
+ std::string SymbolName = Symbols[SI].Name.str();
if (Demangle)
SymbolName = demangle(SymbolName);
@@ -1298,7 +1306,7 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
if (!DisasmFuncsSet.empty() && !DisasmFuncsSet.count(SymbolName))
continue;
- uint64_t Start = std::get<0>(Symbols[SI]);
+ uint64_t Start = Symbols[SI].Addr;
if (Start < SectionAddr || StopAddress <= Start)
continue;
else
@@ -1308,7 +1316,7 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
// --stop-address.
uint64_t End = std::min<uint64_t>(SectionAddr + SectSize, StopAddress);
if (SI + 1 < SE)
- End = std::min(End, std::get<0>(Symbols[SI + 1]));
+ End = std::min(End, Symbols[SI + 1].Addr);
if (Start >= End || End <= StartAddress)
continue;
Start -= SectionAddr;
@@ -1323,12 +1331,12 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
}
if (Obj->isELF() && Obj->getArch() == Triple::amdgcn) {
- if (std::get<2>(Symbols[SI]) == ELF::STT_AMDGPU_HSA_KERNEL) {
+ if (Symbols[SI].Type == ELF::STT_AMDGPU_HSA_KERNEL) {
// skip amd_kernel_code_t at the begining of kernel symbol (256 bytes)
Start += 256;
}
if (SI == SE - 1 ||
- std::get<2>(Symbols[SI + 1]) == ELF::STT_AMDGPU_HSA_KERNEL) {
+ Symbols[SI + 1].Type == ELF::STT_AMDGPU_HSA_KERNEL) {
// cut trailing zeroes at the end of kernel
// cut up to 256 bytes
const uint64_t EndAlign = 256;
@@ -1367,7 +1375,7 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
// only disassembling text (applicable all architectures), we are in a
// situation where we must print the data and not disassemble it.
if (Obj->isELF() && !DisassembleAll && Section.isText()) {
- uint8_t SymTy = std::get<2>(Symbols[SI]);
+ uint8_t SymTy = Symbols[SI].Type;
if (SymTy == ELF::STT_OBJECT || SymTy == ELF::STT_COMMON) {
dumpELFData(SectionAddr, Index, End, Bytes);
Index = End;
@@ -1375,7 +1383,7 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
}
bool CheckARMELFData = hasMappingSymbols(Obj) &&
- std::get<2>(Symbols[SI]) != ELF::STT_OBJECT &&
+ Symbols[SI].Type != ELF::STT_OBJECT &&
!DisassembleAll;
while (Index < End) {
// ARM and AArch64 ELF binaries can interleave data and text in the
@@ -1472,21 +1480,21 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
// the target, find the nearest preceding absolute symbol.
auto TargetSym = partition_point(
*TargetSectionSymbols,
- [=](const std::tuple<uint64_t, StringRef, uint8_t> &O) {
- return std::get<0>(O) <= Target;
+ [=](const SymbolInfoTy &O) {
+ return O.Addr <= Target;
});
if (TargetSym == TargetSectionSymbols->begin()) {
TargetSectionSymbols = &AbsoluteSymbols;
TargetSym = partition_point(
AbsoluteSymbols,
- [=](const std::tuple<uint64_t, StringRef, uint8_t> &O) {
- return std::get<0>(O) <= Target;
+ [=](const SymbolInfoTy &O) {
+ return O.Addr <= Target;
});
}
if (TargetSym != TargetSectionSymbols->begin()) {
--TargetSym;
- uint64_t TargetAddress = std::get<0>(*TargetSym);
- StringRef TargetName = std::get<1>(*TargetSym);
+ uint64_t TargetAddress = TargetSym->Addr;
+ StringRef TargetName = TargetSym->Name;
outs() << " <" << TargetName;
uint64_t Disp = Target - TargetAddress;
if (Disp)
More information about the llvm-commits
mailing list