Devirtualize Reference::kind.

Improves performance.

llvm-svn: 177556
This commit is contained in:
Michael J. Spencer 2013-03-20 18:57:52 +00:00
parent 0f3dd616bd
commit fa405277cb
5 changed files with 24 additions and 40 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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.

View File

@ -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 NativeReferenceV1::addend() const {
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);
}

View File

@ -777,15 +777,16 @@ struct MappingTraits<const lld::Reference*> {
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::Reference*> {
<< "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::Reference*> {
StringRef _targetName;
uint32_t _offset;
Addend _addend;
RefKind _kind;
RefKind _mappedKind;
};
@ -822,7 +822,7 @@ struct MappingTraits<const lld::Reference*> {
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);