[llvm-commits] [llvm] r169644 - in /llvm/trunk: include/llvm/MC/MCAssembler.h include/llvm/MC/MCObjectWriter.h lib/MC/ELFObjectWriter.cpp lib/MC/MCAssembler.cpp
Eli Bendersky
eliben at google.com
Fri Dec 7 14:06:57 PST 2012
Author: eliben
Date: Fri Dec 7 16:06:56 2012
New Revision: 169644
URL: http://llvm.org/viewvc/llvm-project?rev=169644&view=rev
Log:
Make the contents of encoded sections SmallVector<char, N> instead of
SmallString. This makes it possible to use the length-erased SmallVectorImpl
in the interface without imposing buffer size. Thus, the size of MCInstFragment
is back down since a preallocated 8-byte contents buffer is enough.
It would be generally a good idea to rid all the fragments of SmallString as
contents, because a vector just makes more sense.
Modified:
llvm/trunk/include/llvm/MC/MCAssembler.h
llvm/trunk/include/llvm/MC/MCObjectWriter.h
llvm/trunk/lib/MC/ELFObjectWriter.cpp
llvm/trunk/lib/MC/MCAssembler.cpp
Modified: llvm/trunk/include/llvm/MC/MCAssembler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAssembler.h?rev=169644&r1=169643&r2=169644&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCAssembler.h (original)
+++ llvm/trunk/include/llvm/MC/MCAssembler.h Fri Dec 7 16:06:56 2012
@@ -113,8 +113,8 @@
typedef SmallVectorImpl<MCFixup>::const_iterator const_fixup_iterator;
typedef SmallVectorImpl<MCFixup>::iterator fixup_iterator;
- virtual SmallString<32> &getContents() = 0;
- virtual const SmallString<32> &getContents() const = 0;
+ virtual SmallVectorImpl<char> &getContents() = 0;
+ virtual const SmallVectorImpl<char> &getContents() const = 0;
virtual SmallVectorImpl<MCFixup> &getFixups() = 0;
virtual const SmallVectorImpl<MCFixup> &getFixups() const = 0;
@@ -132,7 +132,7 @@
class MCDataFragment : public MCEncodedFragment {
virtual void anchor();
- SmallString<32> Contents;
+ SmallVector<char, 32> Contents;
/// Fixups - The list of fixups in this fragment.
SmallVector<MCFixup, 4> Fixups;
@@ -142,8 +142,8 @@
: MCEncodedFragment(FT_Data, SD) {
}
- SmallString<32> &getContents() { return Contents; }
- const SmallString<32> &getContents() const { return Contents; }
+ virtual SmallVectorImpl<char> &getContents() { return Contents; }
+ virtual const SmallVectorImpl<char> &getContents() const { return Contents; }
SmallVectorImpl<MCFixup> &getFixups() {
return Fixups;
@@ -171,7 +171,7 @@
MCInst Inst;
/// Contents - Binary data for the currently encoded instruction.
- SmallString<32> Contents;
+ SmallVector<char, 8> Contents;
/// Fixups - The list of fixups in this fragment.
SmallVector<MCFixup, 1> Fixups;
@@ -181,8 +181,8 @@
: MCEncodedFragment(FT_Inst, SD), Inst(_Inst) {
}
- SmallString<32> &getContents() { return Contents; }
- const SmallString<32> &getContents() const { return Contents; }
+ virtual SmallVectorImpl<char> &getContents() { return Contents; }
+ virtual const SmallVectorImpl<char> &getContents() const { return Contents; }
unsigned getInstSize() const { return Contents.size(); }
const MCInst &getInst() const { return Inst; }
Modified: llvm/trunk/include/llvm/MC/MCObjectWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCObjectWriter.h?rev=169644&r1=169643&r2=169644&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCObjectWriter.h (original)
+++ llvm/trunk/include/llvm/MC/MCObjectWriter.h Fri Dec 7 16:06:56 2012
@@ -173,7 +173,13 @@
OS << StringRef(Zeros, N % 16);
}
+ void WriteBytes(SmallVectorImpl<char> &ByteVec, unsigned ZeroFillSize = 0) {
+ WriteBytes(StringRef(ByteVec.data(), ByteVec.size()), ZeroFillSize);
+ }
+
void WriteBytes(StringRef Str, unsigned ZeroFillSize = 0) {
+ // TODO: this version may need to go away once all fragment contents are
+ // converted to SmallVector<char, N>
assert((ZeroFillSize == 0 || Str.size () <= ZeroFillSize) &&
"data size greater than fill size, unexpected large write will occur");
OS << Str;
Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=169644&r1=169643&r2=169644&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Fri Dec 7 16:06:56 2012
@@ -203,7 +203,7 @@
void String8(MCDataFragment &F, uint8_t Value) {
char buf[1];
buf[0] = Value;
- F.getContents() += StringRef(buf, 1);
+ F.getContents().append(&buf[0], &buf[1]);
}
void String16(MCDataFragment &F, uint16_t Value) {
@@ -212,7 +212,7 @@
StringLE16(buf, Value);
else
StringBE16(buf, Value);
- F.getContents() += StringRef(buf, 2);
+ F.getContents().append(&buf[0], &buf[2]);
}
void String32(MCDataFragment &F, uint32_t Value) {
@@ -221,7 +221,7 @@
StringLE32(buf, Value);
else
StringBE32(buf, Value);
- F.getContents() += StringRef(buf, 4);
+ F.getContents().append(&buf[0], &buf[4]);
}
void String64(MCDataFragment &F, uint64_t Value) {
@@ -230,7 +230,7 @@
StringLE64(buf, Value);
else
StringBE64(buf, Value);
- F.getContents() += StringRef(buf, 8);
+ F.getContents().append(&buf[0], &buf[8]);
}
void WriteHeader(uint64_t SectionDataSize,
@@ -1186,7 +1186,7 @@
// The first entry of a string table holds a null character so skip
// section 0.
uint64_t Index = 1;
- F->getContents() += '\x00';
+ F->getContents().push_back('\x00');
for (unsigned int I = 0, E = Sections.size(); I != E; ++I) {
const MCSectionELF &Section = *Sections[I];
@@ -1204,8 +1204,8 @@
SectionStringTableIndex[&Section] = Index;
Index += Name.size() + 1;
- F->getContents() += Name;
- F->getContents() += '\x00';
+ F->getContents().append(Name.begin(), Name.end());
+ F->getContents().push_back('\x00');
}
}
@@ -1380,7 +1380,7 @@
++i) {
const MCFragment &F = *i;
assert(F.getKind() == MCFragment::FT_Data);
- WriteBytes(cast<MCDataFragment>(F).getContents().str());
+ WriteBytes(cast<MCDataFragment>(F).getContents());
}
} else {
Asm.writeSectionData(&SD, Layout);
Modified: llvm/trunk/lib/MC/MCAssembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAssembler.cpp?rev=169644&r1=169643&r2=169644&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAssembler.cpp (original)
+++ llvm/trunk/lib/MC/MCAssembler.cpp Fri Dec 7 16:06:56 2012
@@ -391,7 +391,7 @@
/// a MCEncodedFragment.
static void writeFragmentContents(const MCFragment &F, MCObjectWriter *OW) {
MCEncodedFragment &EF = cast<MCEncodedFragment>(F);
- OW->WriteBytes(EF.getContents().str());
+ OW->WriteBytes(EF.getContents());
}
/// \brief Write the fragment \p F to the output file.
More information about the llvm-commits
mailing list