[lld] r177555 - Devirtualize File::kind.
Michael J. Spencer
bigcheesegs at gmail.com
Wed Mar 20 11:57:27 PDT 2013
Author: mspencer
Date: Wed Mar 20 13:57:27 2013
New Revision: 177555
URL: http://llvm.org/viewvc/llvm-project?rev=177555&view=rev
Log:
Devirtualize File::kind.
This is the standard way of implementing LLVM RTTI.
Modified:
lld/trunk/include/lld/Core/ArchiveLibraryFile.h
lld/trunk/include/lld/Core/File.h
lld/trunk/include/lld/Core/SharedLibraryFile.h
lld/trunk/lib/ReaderWriter/ELF/File.h
lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp
lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
lld/trunk/lib/ReaderWriter/ReaderLinkerScript.cpp
lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
Modified: lld/trunk/include/lld/Core/ArchiveLibraryFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/ArchiveLibraryFile.h?rev=177555&r1=177554&r2=177555&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/ArchiveLibraryFile.h (original)
+++ lld/trunk/include/lld/Core/ArchiveLibraryFile.h Wed Mar 20 13:57:27 2013
@@ -26,11 +26,6 @@ namespace lld {
///
class ArchiveLibraryFile : public File {
public:
-
- virtual Kind kind() const {
- return kindArchiveLibrary;
- }
-
static inline bool classof(const File *f) {
return f->kind() == kindArchiveLibrary;
}
@@ -44,7 +39,7 @@ public:
protected:
/// only subclasses of ArchiveLibraryFile can be instantiated
ArchiveLibraryFile(const TargetInfo &ti, StringRef path)
- : File(path), _targetInfo(ti) {
+ : File(path, kindArchiveLibrary), _targetInfo(ti) {
}
private:
Modified: lld/trunk/include/lld/Core/File.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/File.h?rev=177555&r1=177554&r2=177555&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/File.h (original)
+++ lld/trunk/include/lld/Core/File.h Wed Mar 20 13:57:27 2013
@@ -48,8 +48,8 @@ public:
};
/// \brief Returns file kind. Need for dyn_cast<> on File objects.
- virtual Kind kind() const {
- return kindObject;
+ Kind kind() const {
+ return _kind;
}
/// \brief For error messages and debugging, this returns the path to the file
@@ -158,7 +158,7 @@ public:
protected:
/// \brief only subclasses of File can be instantiated
- File(StringRef p) : _path(p), _ordinal(UINT64_MAX) {}
+ File(StringRef p, Kind kind) : _path(p), _kind(kind), _ordinal(UINT64_MAX) {}
/// \brief This is a convenience class for File subclasses which manage their
/// atoms as a simple std::vector<>.
@@ -215,6 +215,7 @@ protected:
static atom_collection_empty<AbsoluteAtom> _noAbsoluteAtoms;
StringRef _path;
+ Kind _kind;
mutable uint64_t _ordinal;
};
@@ -232,7 +233,8 @@ public:
protected:
/// \brief only subclasses of MutableFile can be instantiated
- MutableFile(const TargetInfo &ti, StringRef p) : File(p), _targetInfo(ti) {}
+ MutableFile(const TargetInfo &ti, StringRef p)
+ : File(p, kindObject), _targetInfo(ti) {}
private:
const TargetInfo &_targetInfo;
Modified: lld/trunk/include/lld/Core/SharedLibraryFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/SharedLibraryFile.h?rev=177555&r1=177554&r2=177555&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/SharedLibraryFile.h (original)
+++ lld/trunk/include/lld/Core/SharedLibraryFile.h Wed Mar 20 13:57:27 2013
@@ -22,20 +22,11 @@ namespace lld {
///
class SharedLibraryFile : public File {
public:
- virtual ~SharedLibraryFile() {
- }
-
- virtual Kind kind() const {
- return kindSharedLibrary;
- }
+ virtual ~SharedLibraryFile() {}
static inline bool classof(const File *f) {
return f->kind() == kindSharedLibrary;
}
- static inline bool classof(const SharedLibraryFile *) {
- return true;
- }
-
/// Check if the shared library exports a symbol with the specified name.
/// If so, return a SharedLibraryAtom which represents that exported
@@ -44,7 +35,7 @@ public:
bool dataSymbolOnly) const = 0;
protected:
/// only subclasses of SharedLibraryFile can be instantiated
- SharedLibraryFile(StringRef path) : File(path) {}
+ SharedLibraryFile(StringRef path) : File(path, kindSharedLibrary) {}
};
} // namespace lld
Modified: lld/trunk/lib/ReaderWriter/ELF/File.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/File.h?rev=177555&r1=177554&r2=177555&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/File.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/File.h Wed Mar 20 13:57:27 2013
@@ -117,12 +117,11 @@ template <class ELFT> class ELFFile : pu
public:
ELFFile(const ELFTargetInfo &ti, StringRef name)
- : File(name), _elfTargetInfo(ti) {
- }
+ : File(name, kindObject), _elfTargetInfo(ti) {}
ELFFile(const ELFTargetInfo &ti, std::unique_ptr<llvm::MemoryBuffer> MB,
llvm::error_code &EC)
- : File(MB->getBufferIdentifier()), _elfTargetInfo(ti) {
+ : File(MB->getBufferIdentifier(), kindObject), _elfTargetInfo(ti) {
llvm::OwningPtr<llvm::object::Binary> binaryFile;
EC = createBinary(MB.release(), binaryFile);
if (EC)
Modified: lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp?rev=177555&r1=177554&r2=177555&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp (original)
+++ lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp Wed Mar 20 13:57:27 2013
@@ -732,7 +732,7 @@ private:
// private constructor, only called by make()
File(const TargetInfo &ti, std::unique_ptr<llvm::MemoryBuffer> mb,
StringRef path)
- : lld::File(path),
+ : lld::File(path, kindObject),
_buffer(std::move(mb)), // Reader now takes ownership of buffer
_header(nullptr), _targetsTable(nullptr), _targetsTableCount(0),
_strings(nullptr), _stringsMaxOffset(0), _addends(nullptr),
Modified: lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp?rev=177555&r1=177554&r2=177555&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp Wed Mar 20 13:57:27 2013
@@ -213,7 +213,7 @@ class FileCOFF : public File {
public:
FileCOFF(const TargetInfo &ti, std::unique_ptr<llvm::MemoryBuffer> MB,
llvm::error_code &EC)
- : File(MB->getBufferIdentifier()), _targetInfo(ti) {
+ : File(MB->getBufferIdentifier(), kindObject), _targetInfo(ti) {
llvm::OwningPtr<llvm::object::Binary> Bin;
EC = llvm::object::createBinary(MB.release(), Bin);
if (EC)
Modified: lld/trunk/lib/ReaderWriter/ReaderLinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ReaderLinkerScript.cpp?rev=177555&r1=177554&r2=177555&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ReaderLinkerScript.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ReaderLinkerScript.cpp Wed Mar 20 13:57:27 2013
@@ -30,8 +30,6 @@ public:
return std::move(file);
}
- virtual Kind kind() const { return kindLinkerScript; }
-
static inline bool classof(const File *f) {
return f->kind() == kindLinkerScript;
}
@@ -64,7 +62,7 @@ public:
private:
LinkerScriptFile(const TargetInfo &ti, std::unique_ptr<llvm::MemoryBuffer> mb)
- : File(mb->getBufferIdentifier()),
+ : File(mb->getBufferIdentifier(), kindLinkerScript),
_targetInfo(ti),
_lexer(std::move(mb)),
_parser(_lexer),
Modified: lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp?rev=177555&r1=177554&r2=177555&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp (original)
+++ lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp Wed Mar 20 13:57:27 2013
@@ -668,9 +668,9 @@ struct MappingTraits<const lld::File*> {
class NormalizedFile : public lld::File {
public:
- NormalizedFile(IO &io) : File(""), _IO(io), _rnb(nullptr) {}
+ NormalizedFile(IO &io) : File("", kindObject), _IO(io), _rnb(nullptr) {}
NormalizedFile(IO &io, const lld::File *file)
- : File(file->path()), _IO(io), _rnb(new RefNameBuilder(*file)),
+ : File(file->path(), kindObject), _IO(io), _rnb(new RefNameBuilder(*file)),
_path(file->path()) {
for (const lld::DefinedAtom *a : file->defined())
_definedAtoms.push_back(a);
More information about the llvm-commits
mailing list