[lld] r177556 - Devirtualize Reference::kind.
Michael J. Spencer
bigcheesegs at gmail.com
Wed Mar 20 11:57:53 PDT 2013
Author: mspencer
Date: Wed Mar 20 13:57:52 2013
New Revision: 177556
URL: http://llvm.org/viewvc/llvm-project?rev=177556&view=rev
Log:
Devirtualize Reference::kind.
Improves performance.
Modified:
lld/trunk/include/lld/Core/Reference.h
lld/trunk/include/lld/ReaderWriter/Simple.h
lld/trunk/lib/ReaderWriter/ELF/Atoms.h
lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp
lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
Modified: lld/trunk/include/lld/Core/Reference.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/Reference.h?rev=177556&r1=177555&r2=177556&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/Reference.h (original)
+++ lld/trunk/include/lld/Core/Reference.h Wed Mar 20 13:57:52 2013
@@ -45,11 +45,11 @@ public:
typedef int64_t Addend;
/// What sort of reference this is.
- virtual Kind kind() const = 0;
+ Kind kind() const { return _kind; }
/// During linking, some optimizations may change the code gen and
/// hence the reference kind.
- virtual void setKind(Kind) = 0;
+ void setKind(Kind kind) { _kind = kind; };
virtual StringRef kindToString() const {
switch (kind()) {
@@ -102,6 +102,8 @@ protected:
/// delete on an Reference. In fact, some File objects may bulk allocate
/// an array of References, so they cannot be individually deleted by anyone.
virtual ~Reference() {}
+
+ Kind _kind;
};
} // namespace lld
Modified: lld/trunk/include/lld/ReaderWriter/Simple.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/Simple.h?rev=177556&r1=177555&r2=177556&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/Simple.h (original)
+++ lld/trunk/include/lld/ReaderWriter/Simple.h Wed Mar 20 13:57:52 2013
@@ -75,14 +75,12 @@ class SimpleReference : public Reference
public:
SimpleReference(Reference::Kind k, uint64_t off, const Atom *t,
Reference::Addend a)
- : _target(t), _offsetInAtom(off), _addend(a), _kind(k) {}
+ : _target(t), _offsetInAtom(off), _addend(a) {
+ _kind = k;
+ }
virtual uint64_t offsetInAtom() const { return _offsetInAtom; }
- virtual Kind kind() const { return _kind; }
-
- virtual void setKind(Kind k) { _kind = k; }
-
virtual const Atom *target() const { return _target; }
virtual Addend addend() const { return _addend; }
@@ -94,7 +92,6 @@ private:
const Atom *_target;
uint64_t _offsetInAtom;
Addend _addend;
- Kind _kind;
};
class SimpleDefinedAtom : public DefinedAtom {
Modified: lld/trunk/lib/ReaderWriter/ELF/Atoms.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Atoms.h?rev=177556&r1=177555&r2=177556&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Atoms.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Atoms.h Wed Mar 20 13:57:52 2013
@@ -35,28 +35,23 @@ public:
ELFReference(const Elf_Rela *rela, uint64_t offset, const Atom *target)
: _target(target), _targetSymbolIndex(rela->getSymbol()),
- _offsetInAtom(offset), _addend(rela->r_addend),
- _kind((Kind) rela->getType()) {
+ _offsetInAtom(offset), _addend(rela->r_addend) {
+ _kind = (Kind) rela->getType();
}
ELFReference(const Elf_Rel *rel, uint64_t offset, const Atom *target)
: _target(target), _targetSymbolIndex(rel->getSymbol()),
- _offsetInAtom(offset), _addend(0), _kind((Kind) rel->getType()) {
+ _offsetInAtom(offset), _addend(0) {
+ _kind = (Kind) rel->getType();
}
ELFReference(Kind kind)
- : _target(nullptr), _targetSymbolIndex(0), _offsetInAtom(0), _addend(0),
- _kind(kind) {
+ : _target(nullptr), _targetSymbolIndex(0), _offsetInAtom(0), _addend(0) {
+ _kind = kind;
}
virtual uint64_t offsetInAtom() const { return _offsetInAtom; }
- virtual Kind kind() const { return _kind; }
-
- virtual void setKind(Kind kind) {
- _kind = kind;
- }
-
virtual const Atom *target() const {
return _target;
}
@@ -81,7 +76,6 @@ private:
uint64_t _targetSymbolIndex;
uint64_t _offsetInAtom;
Addend _addend;
- Kind _kind;
};
/// \brief These atoms store symbols that are fixed to a particular address.
Modified: lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp?rev=177556&r1=177555&r2=177556&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp (original)
+++ lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp Wed Mar 20 13:57:52 2013
@@ -203,19 +203,15 @@ private:
//
class NativeReferenceV1 : public Reference {
public:
- NativeReferenceV1(const File& f,
- const NativeReferenceIvarsV1* ivarData)
- : _file(&f), _ivarData(ivarData) { }
+ NativeReferenceV1(const File& f, const NativeReferenceIvarsV1* ivarData)
+ : _file(&f), _ivarData(ivarData) {
+ setKind(ivarData->kind);
+ }
virtual uint64_t offsetInAtom() const {
return _ivarData->offsetInAtom;
}
- virtual Kind kind() const {
- return _ivarData->kind;
- }
-
- virtual void setKind(Kind);
virtual const Atom* target() const;
virtual Addend addend() const;
virtual void setTarget(const Atom* newAtom);
@@ -903,11 +899,6 @@ inline Reference::Addend NativeReference
return _file->addend(_ivarData->addendIndex);
}
-inline void NativeReferenceV1::setKind(Kind k) {
- this->cloneIvarData();
- const_cast<NativeReferenceIvarsV1*>(_ivarData)->kind = k;
-}
-
inline void NativeReferenceV1::setTarget(const Atom* newAtom) {
return _file->setTarget(_ivarData->targetIndex, newAtom);
}
Modified: lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp?rev=177556&r1=177555&r2=177556&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp (original)
+++ lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp Wed Mar 20 13:57:52 2013
@@ -777,15 +777,16 @@ struct MappingTraits<const lld::Referenc
class NormalizedReference : public lld::Reference {
public:
NormalizedReference(IO &io)
- : _target(nullptr), _targetName(), _offset(0), _addend(0) , _kind(0) {
- }
+ : _target(nullptr), _targetName(), _offset(0), _addend(0) {}
+
NormalizedReference(IO &io, const lld::Reference *ref)
: _target(nullptr),
_targetName(targetName(io, ref)),
_offset(ref->offsetInAtom()),
_addend(ref->addend()),
- _kind(ref->kind()) {
+ _mappedKind(ref->kind()) {
}
+
const lld::Reference *denormalize(IO &io) {
ContextInfo *info = reinterpret_cast<ContextInfo*>(io.getContext());
assert(info != nullptr);
@@ -797,16 +798,15 @@ struct MappingTraits<const lld::Referenc
<< "created Reference to name: '" << _targetName
<< "' (" << (void*)_targetName.data() << ", "
<< _targetName.size() << ")\n");
+ setKind(_mappedKind);
return this;
}
void bind(const RefNameResolver&);
static StringRef targetName(IO &io, const lld::Reference *ref);
virtual uint64_t offsetInAtom() const { return _offset; }
- virtual Kind kind() const { return _kind; }
virtual const lld::Atom *target() const { return _target; }
virtual Addend addend() const { return _addend; }
- virtual void setKind(Kind k) { _kind = k; }
virtual void setAddend(Addend a) { _addend = a; }
virtual void setTarget(const lld::Atom *a) { _target = a; }
@@ -814,7 +814,7 @@ struct MappingTraits<const lld::Referenc
StringRef _targetName;
uint32_t _offset;
Addend _addend;
- RefKind _kind;
+ RefKind _mappedKind;
};
@@ -822,7 +822,7 @@ struct MappingTraits<const lld::Referenc
MappingNormalizationHeap<NormalizedReference,
const lld::Reference*> keys(io, ref);
- io.mapRequired("kind", keys->_kind);
+ io.mapRequired("kind", keys->_mappedKind);
io.mapOptional("offset", keys->_offset);
io.mapOptional("target", keys->_targetName);
io.mapOptional("addend", keys->_addend, (lld::Reference::Addend)0);
More information about the llvm-commits
mailing list