[PATCH] D17408: Add support for merging string with alignment larger than one char
Rafael Ávila de Espíndola via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 18 13:19:00 PST 2016
rafael created this revision.
rafael added a reviewer: ruiu.
rafael added a subscriber: llvm-commits.
This will be used in a lld patch.
http://reviews.llvm.org/D17408
Files:
include/llvm/MC/StringTableBuilder.h
lib/MC/StringTableBuilder.cpp
Index: lib/MC/StringTableBuilder.cpp
===================================================================
--- lib/MC/StringTableBuilder.cpp
+++ lib/MC/StringTableBuilder.cpp
@@ -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 @@
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 == 0) {
+ 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,11 @@
size_t StringTableBuilder::add(StringRef S) {
assert(!isFinalized());
- auto P = StringIndexMap.insert(std::make_pair(S, Size));
- if (P.second)
+ size_t Start = alignTo(Size, Alignment);
+ auto P = StringIndexMap.insert(std::make_pair(S, Start));
+ if (P.second) {
+ Size = Start;
Size += S.size() + (K != RAW);
+ }
return P.first->second;
}
Index: include/llvm/MC/StringTableBuilder.h
===================================================================
--- include/llvm/MC/StringTableBuilder.h
+++ include/llvm/MC/StringTableBuilder.h
@@ -26,11 +26,12 @@
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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17408.48393.patch
Type: text/x-patch
Size: 2283 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160218/498ed22f/attachment.bin>
More information about the llvm-commits
mailing list