mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-04-07 10:11:57 +00:00

This patch adds write methods to StringTableBuilder so that it is easier to change the underlying implementation. Using the write methods, avoid creating a temporary buffer when using mmaped output. It also uses a more compact key in the DenseMap. Overall this produces a slightly faster lld: firefox master 6.853419709 patch 6.841968912 1.00167361138x faster chromium master 4.297280174 patch 4.298712163 1.00033323147x slower chromium fast master 1.802335952 patch 1.806872459 1.00251701521x slower the gold plugin master 0.3247149 patch 0.321971644 1.00852017888x faster clang master 0.551279945 patch 0.543733194 1.01387951128x faster llvm-as master 0.032743458 patch 0.032143478 1.01866568391x faster the gold plugin fsds master 0.350814247 patch 0.348571741 1.00643341309x faster clang fsds master 0.6281672 patch 0.621130222 1.01132931187x faster llvm-as fsds master 0.030168899 patch 0.029797155 1.01247582194x faster scylla master 3.104222518 patch 3.059590248 1.01458766252x faster llvm-svn: 283266
107 lines
2.5 KiB
C++
107 lines
2.5 KiB
C++
//===----------- StringTableBuilderTest.cpp -------------------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/MC/StringTableBuilder.h"
|
|
#include "llvm/Support/Endian.h"
|
|
#include "gtest/gtest.h"
|
|
#include <string>
|
|
|
|
using namespace llvm;
|
|
|
|
namespace {
|
|
|
|
TEST(StringTableBuilderTest, BasicELF) {
|
|
StringTableBuilder B(StringTableBuilder::ELF);
|
|
|
|
B.add("foo");
|
|
B.add("bar");
|
|
B.add("foobar");
|
|
|
|
B.finalize();
|
|
|
|
std::string Expected;
|
|
Expected += '\x00';
|
|
Expected += "foobar";
|
|
Expected += '\x00';
|
|
Expected += "foo";
|
|
Expected += '\x00';
|
|
|
|
SmallString<64> Data;
|
|
raw_svector_ostream OS(Data);
|
|
B.write(OS);
|
|
|
|
EXPECT_EQ(Expected, Data);
|
|
EXPECT_EQ(1U, B.getOffset("foobar"));
|
|
EXPECT_EQ(4U, B.getOffset("bar"));
|
|
EXPECT_EQ(8U, B.getOffset("foo"));
|
|
}
|
|
|
|
TEST(StringTableBuilderTest, BasicWinCOFF) {
|
|
StringTableBuilder B(StringTableBuilder::WinCOFF);
|
|
|
|
// Strings must be 9 chars or longer to go in the table.
|
|
B.add("hippopotamus");
|
|
B.add("pygmy hippopotamus");
|
|
B.add("river horse");
|
|
|
|
B.finalize();
|
|
|
|
// size_field + "pygmy hippopotamus\0" + "river horse\0"
|
|
uint32_t ExpectedSize = 4 + 19 + 12;
|
|
EXPECT_EQ(ExpectedSize, B.getSize());
|
|
|
|
std::string Expected;
|
|
|
|
ExpectedSize =
|
|
support::endian::byte_swap<uint32_t, support::little>(ExpectedSize);
|
|
Expected.append((const char*)&ExpectedSize, 4);
|
|
Expected += "pygmy hippopotamus";
|
|
Expected += '\x00';
|
|
Expected += "river horse";
|
|
Expected += '\x00';
|
|
|
|
SmallString<64> Data;
|
|
raw_svector_ostream OS(Data);
|
|
B.write(OS);
|
|
|
|
EXPECT_EQ(Expected, Data);
|
|
EXPECT_EQ(4U, B.getOffset("pygmy hippopotamus"));
|
|
EXPECT_EQ(10U, B.getOffset("hippopotamus"));
|
|
EXPECT_EQ(23U, B.getOffset("river horse"));
|
|
}
|
|
|
|
TEST(StringTableBuilderTest, ELFInOrder) {
|
|
StringTableBuilder B(StringTableBuilder::ELF);
|
|
EXPECT_EQ(1U, B.add("foo"));
|
|
EXPECT_EQ(5U, B.add("bar"));
|
|
EXPECT_EQ(9U, B.add("foobar"));
|
|
|
|
B.finalizeInOrder();
|
|
|
|
std::string Expected;
|
|
Expected += '\x00';
|
|
Expected += "foo";
|
|
Expected += '\x00';
|
|
Expected += "bar";
|
|
Expected += '\x00';
|
|
Expected += "foobar";
|
|
Expected += '\x00';
|
|
|
|
SmallString<64> Data;
|
|
raw_svector_ostream OS(Data);
|
|
B.write(OS);
|
|
|
|
EXPECT_EQ(Expected, Data);
|
|
EXPECT_EQ(1U, B.getOffset("foo"));
|
|
EXPECT_EQ(5U, B.getOffset("bar"));
|
|
EXPECT_EQ(9U, B.getOffset("foobar"));
|
|
}
|
|
|
|
}
|