[llvm] r235178 - [mc] Clean up emission of byte sequences
Benjamin Kramer
benny.kra at googlemail.com
Fri Apr 17 04:12:43 PDT 2015
Author: d0k
Date: Fri Apr 17 06:12:43 2015
New Revision: 235178
URL: http://llvm.org/viewvc/llvm-project?rev=235178&view=rev
Log:
[mc] Clean up emission of byte sequences
No functional change intended.
Modified:
llvm/trunk/lib/MC/ELFObjectWriter.cpp
llvm/trunk/lib/MC/MachObjectWriter.cpp
llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp
llvm/trunk/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp
llvm/trunk/lib/Target/R600/MCTargetDesc/AMDGPUAsmBackend.cpp
Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=235178&r1=235177&r2=235178&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Fri Apr 17 06:12:43 2015
@@ -412,10 +412,7 @@ void ELFObjectWriter::WriteHeader(const
// emitWord method behaves differently for ELF32 and ELF64, writing
// 4 bytes in the former and 8 in the latter.
- Write8(0x7f); // e_ident[EI_MAG0]
- Write8('E'); // e_ident[EI_MAG1]
- Write8('L'); // e_ident[EI_MAG2]
- Write8('F'); // e_ident[EI_MAG3]
+ WriteBytes(ELF::ElfMagic); // e_ident[EI_MAG0] to e_ident[EI_MAG3]
Write8(is64Bit() ? ELF::ELFCLASS64 : ELF::ELFCLASS32); // e_ident[EI_CLASS]
Modified: llvm/trunk/lib/MC/MachObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MachObjectWriter.cpp?rev=235178&r1=235177&r2=235178&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MachObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/MachObjectWriter.cpp Fri Apr 17 06:12:43 2015
@@ -915,8 +915,7 @@ void MachObjectWriter::WriteObject(MCAss
Asm.writeSectionData(it, Layout);
uint64_t Pad = getPaddingSize(it, Layout);
- for (unsigned int i = 0; i < Pad; ++i)
- Write8(0);
+ WriteZeros(Pad);
}
// Write the extra padding.
Modified: llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp?rev=235178&r1=235177&r2=235178&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp Fri Apr 17 06:12:43 2015
@@ -530,8 +530,7 @@ void WinCOFFObjectWriter::WriteFileHeade
WriteLE16(COFF::BigObjHeader::MinBigObjectVersion);
WriteLE16(Header.Machine);
WriteLE32(Header.TimeDateStamp);
- for (uint8_t MagicChar : COFF::BigObjMagic)
- Write8(MagicChar);
+ WriteBytes(StringRef(COFF::BigObjMagic, sizeof(COFF::BigObjMagic)));
WriteLE32(0);
WriteLE32(0);
WriteLE32(0);
Modified: llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp?rev=235178&r1=235177&r2=235178&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp Fri Apr 17 06:12:43 2015
@@ -247,10 +247,7 @@ bool AArch64AsmBackend::writeNopData(uin
// If the count is not 4-byte aligned, we must be writing data into the text
// section (otherwise we have unaligned instructions, and thus have far
// bigger problems), so just write zeros instead.
- if ((Count & 3) != 0) {
- for (uint64_t i = 0, e = (Count & 3); i != e; ++i)
- OW->Write8(0);
- }
+ OW->WriteZeros(Count % 4);
// We are properly aligned, so write NOPs as requested.
Count /= 4;
Modified: llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp?rev=235178&r1=235177&r2=235178&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp Fri Apr 17 06:12:43 2015
@@ -394,12 +394,7 @@ bool MipsAsmBackend::writeNopData(uint64
// If the count is not 4-byte aligned, we must be writing data into the text
// section (otherwise we have unaligned instructions, and thus have far
// bigger problems), so just write zeros instead.
- for (uint64_t i = 0, e = Count % 4; i != e; ++i)
- OW->Write8(0);
-
- uint64_t NumNops = Count / 4;
- for (uint64_t i = 0; i != NumNops; ++i)
- OW->Write32(0);
+ OW->WriteZeros(Count);
return true;
}
Modified: llvm/trunk/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp?rev=235178&r1=235177&r2=235178&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp Fri Apr 17 06:12:43 2015
@@ -178,12 +178,7 @@ public:
for (uint64_t i = 0; i != NumNops; ++i)
OW->Write32(0x60000000);
- switch (Count % 4) {
- default: break; // No leftover bytes to write
- case 1: OW->Write8(0); break;
- case 2: OW->Write16(0); break;
- case 3: OW->Write16(0); OW->Write8(0); break;
- }
+ OW->WriteZeros(Count % 4);
return true;
}
Modified: llvm/trunk/lib/Target/R600/MCTargetDesc/AMDGPUAsmBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/R600/MCTargetDesc/AMDGPUAsmBackend.cpp?rev=235178&r1=235177&r2=235178&view=diff
==============================================================================
--- llvm/trunk/lib/Target/R600/MCTargetDesc/AMDGPUAsmBackend.cpp (original)
+++ llvm/trunk/lib/Target/R600/MCTargetDesc/AMDGPUAsmBackend.cpp Fri Apr 17 06:12:43 2015
@@ -115,8 +115,7 @@ const MCFixupKindInfo &AMDGPUAsmBackend:
}
bool AMDGPUAsmBackend::writeNopData(uint64_t Count, MCObjectWriter *OW) const {
- for (unsigned i = 0; i < Count; ++i)
- OW->Write8(0);
+ OW->WriteZeros(Count);
return true;
}
More information about the llvm-commits
mailing list