[llvm] r261326 - Add support for merging strings with alignment larger than one char.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 19 06:13:52 PST 2016
Author: rafael
Date: Fri Feb 19 08:13:52 2016
New Revision: 261326
URL: http://llvm.org/viewvc/llvm-project?rev=261326&view=rev
Log:
Add support for merging strings with alignment larger than one char.
This will be used in a lld patch.
Modified:
llvm/trunk/include/llvm/MC/StringTableBuilder.h
llvm/trunk/lib/MC/StringTableBuilder.cpp
Modified: llvm/trunk/include/llvm/MC/StringTableBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/StringTableBuilder.h?rev=261326&r1=261325&r2=261326&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/StringTableBuilder.h (original)
+++ llvm/trunk/include/llvm/MC/StringTableBuilder.h Fri Feb 19 08:13:52 2016
@@ -26,11 +26,12 @@ private:
DenseMap<StringRef, size_t> StringIndexMap;
size_t Size = 0;
Kind K;
+ unsigned Alignment;
void finalizeStringTable(bool Optimize);
public:
- StringTableBuilder(Kind K);
+ StringTableBuilder(Kind K, unsigned Alignment = 1);
/// \brief Add a string to the builder. Returns the position of S in the
/// table. The position will be changed if finalize is used.
Modified: llvm/trunk/lib/MC/StringTableBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/StringTableBuilder.cpp?rev=261326&r1=261325&r2=261326&view=diff
==============================================================================
--- llvm/trunk/lib/MC/StringTableBuilder.cpp (original)
+++ llvm/trunk/lib/MC/StringTableBuilder.cpp Fri Feb 19 08:13:52 2016
@@ -16,7 +16,8 @@
using namespace llvm;
-StringTableBuilder::StringTableBuilder(Kind K) : K(K) {
+StringTableBuilder::StringTableBuilder(Kind K, unsigned Alignment)
+ : K(K), Alignment(Alignment) {
// Account for leading bytes in table so that offsets returned from add are
// correct.
switch (K) {
@@ -125,15 +126,21 @@ void StringTableBuilder::finalizeStringT
assert(S.size() > COFF::NameSize && "Short string in COFF string table!");
if (Optimize && Previous.endswith(S)) {
- P->second = StringTable.size() - S.size() - (K != RAW);
- continue;
+ size_t Pos = StringTable.size() - S.size() - (K != RAW);
+ if (!(Pos & (Alignment - 1))) {
+ P->second = Pos;
+ continue;
+ }
}
- if (Optimize)
- P->second = StringTable.size();
- else
+ if (Optimize) {
+ size_t Start = alignTo(StringTable.size(), Alignment);
+ P->second = Start;
+ StringTable.append(Start - StringTable.size(), '\0');
+ } else {
assert(P->second == StringTable.size() &&
"different strtab offset after finalization");
+ }
StringTable += S;
if (K != RAW)
@@ -176,8 +183,9 @@ size_t StringTableBuilder::getOffset(Str
size_t StringTableBuilder::add(StringRef S) {
assert(!isFinalized());
- auto P = StringIndexMap.insert(std::make_pair(S, Size));
+ size_t Start = alignTo(Size, Alignment);
+ auto P = StringIndexMap.insert(std::make_pair(S, Start));
if (P.second)
- Size += S.size() + (K != RAW);
+ Size = Start + S.size() + (K != RAW);
return P.first->second;
}
More information about the llvm-commits
mailing list