diff options
author | Sam Clegg <sbc@chromium.org> | 2017-09-15 20:34:47 +0000 |
---|---|---|
committer | Sam Clegg <sbc@chromium.org> | 2017-09-15 20:34:47 +0000 |
commit | 66a99e41cdc8d1ddd67860f7d97d861f654f1dbd (patch) | |
tree | 1a16a1862c0a527303792304cab8c61e1041cf7c /llvm/lib/MC | |
parent | 04370d3a820f65ac91faae9eb026ddea33b4f16e (diff) | |
download | bcm5719-llvm-66a99e41cdc8d1ddd67860f7d97d861f654f1dbd.tar.gz bcm5719-llvm-66a99e41cdc8d1ddd67860f7d97d861f654f1dbd.zip |
Change encodeU/SLEB128 to pad to certain number of bytes
Previously the 'Padding' argument was the number of padding
bytes to add. However most callers that use 'Padding' know
how many overall bytes they need to write. With the previous
code this would mean encoding the LEB once to find out how
many bytes it would occupy and then using this to calulate
the 'Padding' value.
See: https://reviews.llvm.org/D36595
Differential Revision: https://reviews.llvm.org/D37494
llvm-svn: 313393
Diffstat (limited to 'llvm/lib/MC')
-rw-r--r-- | llvm/lib/MC/MCStreamer.cpp | 8 | ||||
-rw-r--r-- | llvm/lib/MC/WasmObjectWriter.cpp | 19 |
2 files changed, 9 insertions, 18 deletions
diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp index a3756c97a1e..cd5be8816ac 100644 --- a/llvm/lib/MC/MCStreamer.cpp +++ b/llvm/lib/MC/MCStreamer.cpp @@ -105,13 +105,17 @@ void MCStreamer::EmitIntValue(uint64_t Value, unsigned Size) { /// EmitULEB128Value - Special case of EmitULEB128Value that avoids the /// client having to pass in a MCExpr for constant integers. -void MCStreamer::EmitULEB128IntValue(uint64_t Value, unsigned Padding) { +void MCStreamer::EmitPaddedULEB128IntValue(uint64_t Value, unsigned PadTo) { SmallString<128> Tmp; raw_svector_ostream OSE(Tmp); - encodeULEB128(Value, OSE, Padding); + encodeULEB128(Value, OSE, PadTo); EmitBytes(OSE.str()); } +void MCStreamer::EmitULEB128IntValue(uint64_t Value) { + EmitPaddedULEB128IntValue(Value, 0); +} + /// EmitSLEB128Value - Special case of EmitSLEB128Value that avoids the /// client having to pass in a MCExpr for constant integers. void MCStreamer::EmitSLEB128IntValue(int64_t Value) { diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp index a71a3d414e7..f601c144c30 100644 --- a/llvm/lib/MC/WasmObjectWriter.cpp +++ b/llvm/lib/MC/WasmObjectWriter.cpp @@ -297,16 +297,6 @@ private: WasmObjectWriter::~WasmObjectWriter() {} -// Return the padding size to write a 32-bit value into a 5-byte ULEB128. -static unsigned PaddingFor5ByteULEB128(uint32_t X) { - return X == 0 ? 4 : (4u - (31u - countLeadingZeros(X)) / 7u); -} - -// Return the padding size to write a 32-bit value into a 5-byte SLEB128. -static unsigned PaddingFor5ByteSLEB128(int32_t X) { - return 5 - getSLEB128Size(X); -} - // Write out a section header and a patchable section size field. void WasmObjectWriter::startSection(SectionBookkeeping &Section, unsigned SectionId, @@ -341,12 +331,11 @@ void WasmObjectWriter::endSection(SectionBookkeeping &Section) { report_fatal_error("section size does not fit in a uint32_t"); DEBUG(dbgs() << "endSection size=" << Size << "\n"); - unsigned Padding = PaddingFor5ByteULEB128(Size); // Write the final section size to the payload_len field, which follows // the section id byte. uint8_t Buffer[16]; - unsigned SizeLen = encodeULEB128(Size, Buffer, Padding); + unsigned SizeLen = encodeULEB128(Size, Buffer, 5); assert(SizeLen == 5); getStream().pwrite((char *)Buffer, SizeLen, Section.SizeOffset); } @@ -453,8 +442,7 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm, static void WritePatchableLEB(raw_pwrite_stream &Stream, uint32_t X, uint64_t Offset) { uint8_t Buffer[5]; - unsigned Padding = PaddingFor5ByteULEB128(X); - unsigned SizeLen = encodeULEB128(X, Buffer, Padding); + unsigned SizeLen = encodeULEB128(X, Buffer, 5); assert(SizeLen == 5); Stream.pwrite((char *)Buffer, SizeLen, Offset); } @@ -464,8 +452,7 @@ WritePatchableLEB(raw_pwrite_stream &Stream, uint32_t X, uint64_t Offset) { static void WritePatchableSLEB(raw_pwrite_stream &Stream, int32_t X, uint64_t Offset) { uint8_t Buffer[5]; - unsigned Padding = PaddingFor5ByteSLEB128(X); - unsigned SizeLen = encodeSLEB128(X, Buffer, Padding); + unsigned SizeLen = encodeSLEB128(X, Buffer, 5); assert(SizeLen == 5); Stream.pwrite((char *)Buffer, SizeLen, Offset); } |