[llvm] 87c7f4a - [MC] Remove unnecessary reversal of relocations. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 23 10:03:14 PDT 2024
Author: Fangrui Song
Date: 2024-03-23T10:03:09-07:00
New Revision: 87c7f4a12b2a1b723a78d760761ee473f52c4cee
URL: https://github.com/llvm/llvm-project/commit/87c7f4a12b2a1b723a78d760761ee473f52c4cee
DIFF: https://github.com/llvm/llvm-project/commit/87c7f4a12b2a1b723a78d760761ee473f52c4cee.diff
LOG: [MC] Remove unnecessary reversal of relocations. NFC
Commit f44db24e1fd948c75c87aea017646f16553d3361 (2015) enabled this
simplication.
Added:
Modified:
llvm/lib/MC/ELFObjectWriter.cpp
llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index 3c4d3ab9a508b3..a6fb6b5c1a4ee3 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -939,18 +939,11 @@ void ELFWriter::writeRelocations(const MCAssembler &Asm,
const MCSectionELF &Sec) {
std::vector<ELFRelocationEntry> &Relocs = OWriter.Relocations[&Sec];
- // We record relocations by pushing to the end of a vector. Reverse the vector
- // to get the relocations in the order they were created.
- // In most cases that is not important, but it can be for special sections
- // (.eh_frame) or specific relocations (TLS optimizations on SystemZ).
- std::reverse(Relocs.begin(), Relocs.end());
-
// Sort the relocation entries. MIPS needs this.
OWriter.TargetObjectWriter->sortRelocs(Asm, Relocs);
const bool Rela = usesRela(Sec);
- for (unsigned i = 0, e = Relocs.size(); i != e; ++i) {
- const ELFRelocationEntry &Entry = Relocs[e - i - 1];
+ for (const ELFRelocationEntry &Entry : Relocs) {
unsigned Index = Entry.Symbol ? Entry.Symbol->getIndex() : 0;
if (is64Bit()) {
diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
index 181b82f14bfe86..4d6a00c14a3575 100644
--- a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
+++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
@@ -498,10 +498,9 @@ void MipsELFObjectWriter::sortRelocs(const MCAssembler &Asm,
assert(Relocs.size() == Sorted.size() && "Some relocs were not consumed");
- // Overwrite the original vector with the sorted elements. The caller expects
- // them in reverse order.
+ // Overwrite the original vector with the sorted elements.
unsigned CopyTo = 0;
- for (const auto &R : reverse(Sorted))
+ for (const auto &R : Sorted)
Relocs[CopyTo++] = R.R;
}
More information about the llvm-commits
mailing list