Skip to content

Commit

Permalink
[weak vtables] Remove a bunch of weak vtables
Browse files Browse the repository at this point in the history
This patch removes most of the trivial cases of weak vtables by pinning them to
a single object file. The memory leaks in this version have been fixed. Thanks
Alexey for pointing them out.

Differential Revision: http://llvm-reviews.chandlerc.com/D2068

Reviewed by Andy

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@195064 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
ributzka committed Nov 19, 2013
1 parent 26efdc5 commit 3543625
Show file tree
Hide file tree
Showing 113 changed files with 505 additions and 151 deletions.
4 changes: 3 additions & 1 deletion examples/ExceptionDemo/ExceptionDemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1577,9 +1577,11 @@ class OurCppRunException : public std::runtime_error {
std::runtime_error::operator=(toCopy)));
}

~OurCppRunException (void) throw () {}
~OurCppRunException (void) throw ();
};

// Provide out-of-line definition to prevent weak vtable.
OurCppRunException::~OurCppRunException() throw () {}

/// Throws foreign C++ exception.
/// @param ignoreIt unused parameter that allows function to match implied
Expand Down
13 changes: 12 additions & 1 deletion examples/Kaleidoscope/Chapter2/toy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,26 +79,29 @@ static int gettok() {
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
virtual ~ExprAST() {}
virtual ~ExprAST();
};

/// NumberExprAST - Expression class for numeric literals like "1.0".
class NumberExprAST : public ExprAST {
public:
NumberExprAST(double val) {}
virtual ~NumberExprAST();
};

/// VariableExprAST - Expression class for referencing a variable, like "a".
class VariableExprAST : public ExprAST {
std::string Name;
public:
VariableExprAST(const std::string &name) : Name(name) {}
virtual ~VariableExprAST();
};

/// BinaryExprAST - Expression class for a binary operator.
class BinaryExprAST : public ExprAST {
public:
BinaryExprAST(char op, ExprAST *lhs, ExprAST *rhs) {}
virtual ~BinaryExprAST();
};

/// CallExprAST - Expression class for function calls.
Expand All @@ -108,8 +111,16 @@ class CallExprAST : public ExprAST {
public:
CallExprAST(const std::string &callee, std::vector<ExprAST*> &args)
: Callee(callee), Args(args) {}
virtual ~CallExprAST();
};

// Provide out-of-line definitions to prevent weak vtables.
ExprAST::~ExprAST() {}
NumberExprAST::~NumberExprAST() {}
VariableExprAST::~VariableExprAST() {}
BinaryExprAST::~BinaryExprAST() {}
CallExprAST::~CallExprAST() {}

/// PrototypeAST - This class represents the "prototype" for a function,
/// which captures its name, and its argument names (thus implicitly the number
/// of arguments the function takes).
Expand Down
5 changes: 4 additions & 1 deletion examples/Kaleidoscope/Chapter3/toy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,13 @@ static int gettok() {
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
virtual ~ExprAST() {}
virtual ~ExprAST();
virtual Value *Codegen() = 0;
};

// Provide out-of-line definition to prevent weak vtable.
ExprAST::~ExprAST() {}

/// NumberExprAST - Expression class for numeric literals like "1.0".
class NumberExprAST : public ExprAST {
double Val;
Expand Down
5 changes: 4 additions & 1 deletion examples/Kaleidoscope/Chapter4/toy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,13 @@ static int gettok() {
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
virtual ~ExprAST() {}
virtual ~ExprAST();
virtual Value *Codegen() = 0;
};

// Provide out-of-line definition to prevent weak vtable.
ExprAST::~ExprAST() {}

/// NumberExprAST - Expression class for numeric literals like "1.0".
class NumberExprAST : public ExprAST {
double Val;
Expand Down
5 changes: 4 additions & 1 deletion examples/Kaleidoscope/Chapter5/toy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,13 @@ static int gettok() {
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
virtual ~ExprAST() {}
virtual ~ExprAST();
virtual Value *Codegen() = 0;
};

// Provide out-of-line definition to prevent weak vtable.
ExprAST::~ExprAST() {}

/// NumberExprAST - Expression class for numeric literals like "1.0".
class NumberExprAST : public ExprAST {
double Val;
Expand Down
5 changes: 4 additions & 1 deletion examples/Kaleidoscope/Chapter6/toy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,13 @@ static int gettok() {
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
virtual ~ExprAST() {}
virtual ~ExprAST();
virtual Value *Codegen() = 0;
};

// Provide out-of-line definition to prevent weak vtable.
ExprAST::~ExprAST() {}

/// NumberExprAST - Expression class for numeric literals like "1.0".
class NumberExprAST : public ExprAST {
double Val;
Expand Down
5 changes: 4 additions & 1 deletion examples/Kaleidoscope/Chapter7/toy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,13 @@ static int gettok() {
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
virtual ~ExprAST() {}
virtual ~ExprAST();
virtual Value *Codegen() = 0;
};

// Provide out-of-line definition to prevent weak vtable.
ExprAST::~ExprAST() {}

/// NumberExprAST - Expression class for numeric literals like "1.0".
class NumberExprAST : public ExprAST {
double Val;
Expand Down
3 changes: 2 additions & 1 deletion include/llvm/CodeGen/MachineRegisterInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ class PSetIterator;
class MachineRegisterInfo {
public:
class Delegate {
virtual void anchor();
public:
virtual void MRI_NoteNewVirtualRegister(unsigned Reg) {}
virtual void MRI_NoteNewVirtualRegister(unsigned Reg) = 0;

virtual ~Delegate() {}
};
Expand Down
2 changes: 2 additions & 0 deletions include/llvm/CodeGen/MachineScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ struct MachineSchedPolicy {
/// Initialization sequence:
/// initPolicy -> shouldTrackPressure -> initialize(DAG) -> registerRoots
class MachineSchedStrategy {
virtual void anchor();
public:
virtual ~MachineSchedStrategy() {}

Expand Down Expand Up @@ -262,6 +263,7 @@ class ReadyQueue {

/// Mutate the DAG as a postpass after normal DAG building.
class ScheduleDAGMutation {
virtual void anchor();
public:
virtual ~ScheduleDAGMutation() {}

Expand Down
2 changes: 2 additions & 0 deletions include/llvm/ExecutionEngine/ObjectBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace llvm {
/// ObjectFile) as needed, but the MemoryBuffer instance returned does not own the
/// actual memory it points to.
class ObjectBuffer {
virtual void anchor();
public:
ObjectBuffer() {}
ObjectBuffer(MemoryBuffer* Buf) : Buffer(Buf) {}
Expand All @@ -56,6 +57,7 @@ class ObjectBuffer {
/// while providing a common ObjectBuffer interface for access to the
/// memory once the object has been generated.
class ObjectBufferStream : public ObjectBuffer {
virtual void anchor();
public:
ObjectBufferStream() : OS(SV) {}
virtual ~ObjectBufferStream() {}
Expand Down
1 change: 1 addition & 0 deletions include/llvm/ExecutionEngine/ObjectCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Module;
/// ExecutionEngine for the purpose of avoiding compilation for Modules that
/// have already been compiled and an object file is available.
class ObjectCache {
virtual void anchor();
public:
ObjectCache() { }

Expand Down
1 change: 1 addition & 0 deletions include/llvm/ExecutionEngine/ObjectImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace llvm {
class ObjectImage {
ObjectImage() LLVM_DELETED_FUNCTION;
ObjectImage(const ObjectImage &other) LLVM_DELETED_FUNCTION;
virtual void anchor();

protected:
OwningPtr<ObjectBuffer> Buffer;
Expand Down
1 change: 1 addition & 0 deletions include/llvm/MC/MCAtom.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class MCDataAtom;
/// \brief Represents a contiguous range of either instructions (a TextAtom)
/// or data (a DataAtom). Address ranges are expressed as _closed_ intervals.
class MCAtom {
virtual void anchor();
public:
virtual ~MCAtom() {}

Expand Down
1 change: 1 addition & 0 deletions include/llvm/MC/MCStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class MCTargetStreamer {
// FIXME: declared here because it is used from
// lib/CodeGen/AsmPrinter/ARMException.cpp.
class ARMTargetStreamer : public MCTargetStreamer {
virtual void anchor();
public:
virtual void emitFnStart() = 0;
virtual void emitFnEnd() = 0;
Expand Down
1 change: 1 addition & 0 deletions include/llvm/MC/MCWinCOFFObjectWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace llvm {
class raw_ostream;

class MCWinCOFFObjectTargetWriter {
virtual void anchor();
const unsigned Machine;

protected:
Expand Down
4 changes: 4 additions & 0 deletions include/llvm/Support/CommandLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ struct cat {
struct GenericOptionValue {
virtual ~GenericOptionValue() {}
virtual bool compare(const GenericOptionValue &V) const = 0;

private:
virtual void anchor();
};

template<class DataType> struct OptionValue;
Expand Down Expand Up @@ -1752,6 +1755,7 @@ void getRegisteredOptions(StringMap<Option*> &Map);
/// \brief Saves strings in the inheritor's stable storage and returns a stable
/// raw character pointer.
class StringSaver {
virtual void anchor();
public:
virtual const char *SaveString(const char *Str) = 0;
virtual ~StringSaver() {}; // Pacify -Wnon-virtual-dtor.
Expand Down
5 changes: 3 additions & 2 deletions include/llvm/Support/ValueHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ class TrackingVH : public ValueHandleBase {
/// rearrange itself when the pointer changes). Unlike ValueHandleBase, this
/// class has a vtable and a virtual destructor.
class CallbackVH : public ValueHandleBase {
virtual void anchor();
protected:
CallbackVH(const CallbackVH &RHS)
: ValueHandleBase(Callback, RHS) {}
Expand All @@ -365,13 +366,13 @@ class CallbackVH : public ValueHandleBase {
///
/// All implementations must remove the reference from this object to the
/// Value that's being destroyed.
virtual void deleted();
virtual void deleted() { setValPtr(NULL); }

/// Called when this->getValPtr()->replaceAllUsesWith(new_value) is called,
/// _before_ any of the uses have actually been replaced. If WeakVH were
/// implemented as a CallbackVH, it would use this method to call
/// setValPtr(new_value). AssertingVH would do nothing in this method.
virtual void allUsesReplacedWith(Value *);
virtual void allUsesReplacedWith(Value *) {}
};

} // End llvm namespace
Expand Down
7 changes: 7 additions & 0 deletions include/llvm/Support/YAMLParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class Stream {

/// @brief Abstract base class for all Nodes.
class Node {
virtual void anchor();
public:
enum NodeKind {
NK_Null,
Expand Down Expand Up @@ -175,6 +176,7 @@ class Node {
/// Example:
/// !!null null
class NullNode : public Node {
virtual void anchor();
public:
NullNode(OwningPtr<Document> &D)
: Node(NK_Null, D, StringRef(), StringRef()) {}
Expand All @@ -190,6 +192,7 @@ class NullNode : public Node {
/// Example:
/// Adena
class ScalarNode : public Node {
virtual void anchor();
public:
ScalarNode(OwningPtr<Document> &D, StringRef Anchor, StringRef Tag,
StringRef Val)
Expand Down Expand Up @@ -231,6 +234,7 @@ class ScalarNode : public Node {
/// Example:
/// Section: .text
class KeyValueNode : public Node {
virtual void anchor();
public:
KeyValueNode(OwningPtr<Document> &D)
: Node(NK_KeyValue, D, StringRef(), StringRef())
Expand Down Expand Up @@ -342,6 +346,7 @@ void skip(CollectionType &C) {
/// Name: _main
/// Scope: Global
class MappingNode : public Node {
virtual void anchor();
public:
enum MappingType {
MT_Block,
Expand Down Expand Up @@ -391,6 +396,7 @@ class MappingNode : public Node {
/// - Hello
/// - World
class SequenceNode : public Node {
virtual void anchor();
public:
enum SequenceType {
ST_Block,
Expand Down Expand Up @@ -446,6 +452,7 @@ class SequenceNode : public Node {
/// Example:
/// *AnchorName
class AliasNode : public Node {
virtual void anchor();
public:
AliasNode(OwningPtr<Document> &D, StringRef Val)
: Node(NK_Alias, D, StringRef(), StringRef()), Name(Val) {}
Expand Down
5 changes: 3 additions & 2 deletions include/llvm/Support/YAMLTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ class Input : public IO {
virtual bool canElideEmptySequence();

class HNode {
virtual void anchor();
public:
HNode(Node *n) : _node(n) { }
virtual ~HNode() { }
Expand All @@ -734,19 +735,19 @@ class Input : public IO {
};

class EmptyHNode : public HNode {
virtual void anchor();
public:
EmptyHNode(Node *n) : HNode(n) { }
virtual ~EmptyHNode() {}
static inline bool classof(const HNode *n) {
return NullNode::classof(n->_node);
}
static inline bool classof(const EmptyHNode *) { return true; }
};

class ScalarHNode : public HNode {
virtual void anchor();
public:
ScalarHNode(Node *n, StringRef s) : HNode(n), _value(s) { }
virtual ~ScalarHNode() { }

StringRef value() const { return _value; }

Expand Down
3 changes: 3 additions & 0 deletions lib/CodeGen/MachineRegisterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

using namespace llvm;

// Pin the vtable to this file.
void MachineRegisterInfo::Delegate::anchor() {}

MachineRegisterInfo::MachineRegisterInfo(const TargetMachine &TM)
: TM(TM), TheDelegate(0), IsSSA(true), TracksLiveness(true) {
VRegInfo.reserve(256);
Expand Down
4 changes: 4 additions & 0 deletions lib/CodeGen/MachineScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ static cl::opt<bool> VerifyScheduling("verify-misched", cl::Hidden,
// DAG subtrees must have at least this many nodes.
static const unsigned MinSubtreeSize = 8;

// Pin the vtables to this file.
void MachineSchedStrategy::anchor() {}
void ScheduleDAGMutation::anchor() {}

//===----------------------------------------------------------------------===//
// Machine Instruction Scheduling Pass and Registry
//===----------------------------------------------------------------------===//
Expand Down
3 changes: 3 additions & 0 deletions lib/CodeGen/RegAllocBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ bool RegAllocBase::VerifyEnabled = false;
// RegAllocBase Implementation
//===----------------------------------------------------------------------===//

// Pin the vtable to this file.
void RegAllocBase::anchor() {}

void RegAllocBase::init(VirtRegMap &vrm,
LiveIntervals &lis,
LiveRegMatrix &mat) {
Expand Down
1 change: 1 addition & 0 deletions lib/CodeGen/RegAllocBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Spiller;
/// live range splitting. They must also override enqueue/dequeue to provide an
/// assignment order.
class RegAllocBase {
virtual void anchor();
protected:
const TargetRegisterInfo *TRI;
MachineRegisterInfo *MRI;
Expand Down
Loading

0 comments on commit 3543625

Please sign in to comment.