aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCSymbol.cpp
diff options
context:
space:
mode:
authorPete Cooper <peter_cooper@apple.com>2015-06-09 18:36:13 +0000
committerPete Cooper <peter_cooper@apple.com>2015-06-09 18:36:13 +0000
commit234b87569048e2bea9ab4f3fa444239b658faf7a (patch)
tree3ab4dc54c80348367304da6eb849a7f9e93d54ad /llvm/lib/MC/MCSymbol.cpp
parent7e226271a1aef7c73ac0bb980fd36a13a448f8aa (diff)
downloadllvm-234b87569048e2bea9ab4f3fa444239b658faf7a.zip
llvm-234b87569048e2bea9ab4f3fa444239b658faf7a.tar.gz
llvm-234b87569048e2bea9ab4f3fa444239b658faf7a.tar.bz2
Allocate space for MCSymbol::Name only if required.
Similarly to User which allocates a number of Use's prior to the this pointer, allocate space for the Name* for MCSymbol only when we need a name. Given that an MCSymbol is 48-bytes on 64-bit systems, this saves a decent % of space. Given the verify_uselistorder test case with debug info and llc, 50k symbols have names out of 700k so this optimises for the common case of temporary unnamed symbols. Reviewed by David Blaikie. llvm-svn: 239423
Diffstat (limited to 'llvm/lib/MC/MCSymbol.cpp')
-rw-r--r--llvm/lib/MC/MCSymbol.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/llvm/lib/MC/MCSymbol.cpp b/llvm/lib/MC/MCSymbol.cpp
index 8d07b76..7eba5e0 100644
--- a/llvm/lib/MC/MCSymbol.cpp
+++ b/llvm/lib/MC/MCSymbol.cpp
@@ -9,6 +9,7 @@
#include "llvm/MC/MCSymbol.h"
#include "llvm/MC/MCAsmInfo.h"
+#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
@@ -18,6 +19,20 @@ using namespace llvm;
// Sentinel value for the absolute pseudo section.
MCSection *MCSymbol::AbsolutePseudoSection = reinterpret_cast<MCSection *>(1);
+void *MCSymbol::operator new(size_t s, NameEntryTy *Name, MCContext &Ctx) {
+ size_t Size = s + (Name ? sizeof(Name) : 0);
+
+ // For safety, ensure that the alignment of a pointer is enough for an
+ // MCSymbol. This also ensures we don't need padding between the name and
+ // symbol.
+ assert(alignOf<MCSymbol>() <= alignof(NameEntryTy *) &&
+ "Bad alignment of MCSymbol");
+ void *Storage = Ctx.allocate(Size, alignof(NameEntryTy *));
+ NameEntryTy **Start = static_cast<NameEntryTy**>(Storage);
+ NameEntryTy **End = Start + (Name ? 1 : 0);
+ return End;
+}
+
void MCSymbol::setVariableValue(const MCExpr *Value) {
assert(!IsUsed && "Cannot set a variable that has already been used.");
assert(Value && "Invalid variable value!");