2006-08-01 18:31:08 +02:00
|
|
|
//===-- llvm/CodeGen/MachinePassRegistry.h ----------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:59:42 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-08-01 18:31:08 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2006-08-01 20:29:48 +02:00
|
|
|
//
|
|
|
|
// This file contains the mechanics for machine function pass registries. A
|
|
|
|
// function pass registry (MachinePassRegistry) is auto filled by the static
|
|
|
|
// constructors of MachinePassRegistryNode. Further there is a command line
|
|
|
|
// parser (RegisterPassParser) which listens to each registry for additions
|
|
|
|
// and deletions, so that the appropriate command option is updated.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2006-08-01 18:31:08 +02:00
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_MACHINEPASSREGISTRY_H
|
|
|
|
#define LLVM_CODEGEN_MACHINEPASSREGISTRY_H
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/Passes.h"
|
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2006-08-02 14:30:23 +02:00
|
|
|
typedef void *(*MachinePassCtor)();
|
|
|
|
|
2006-08-01 18:31:08 +02:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// MachinePassRegistryListener - Listener to adds and removals of nodes in
|
|
|
|
/// registration list.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
class MachinePassRegistryListener {
|
|
|
|
public:
|
|
|
|
MachinePassRegistryListener() {}
|
|
|
|
virtual ~MachinePassRegistryListener() {}
|
2006-08-02 14:30:23 +02:00
|
|
|
virtual void NotifyAdd(const char *N, MachinePassCtor C, const char *D) = 0;
|
|
|
|
virtual void NotifyRemove(const char *N) = 0;
|
2006-08-01 18:31:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// MachinePassRegistryNode - Machine pass node stored in registration list.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
class MachinePassRegistryNode {
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2006-08-02 14:30:23 +02:00
|
|
|
MachinePassRegistryNode *Next; // Next function pass in list.
|
2006-08-01 18:31:08 +02:00
|
|
|
const char *Name; // Name of function pass.
|
|
|
|
const char *Description; // Description string.
|
2006-08-02 14:30:23 +02:00
|
|
|
MachinePassCtor Ctor; // Function pass creator.
|
2006-08-01 18:31:08 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2006-08-02 14:30:23 +02:00
|
|
|
MachinePassRegistryNode(const char *N, const char *D, MachinePassCtor C)
|
2006-08-01 18:31:08 +02:00
|
|
|
: Next(NULL)
|
|
|
|
, Name(N)
|
|
|
|
, Description(D)
|
|
|
|
, Ctor(C)
|
|
|
|
{}
|
|
|
|
|
|
|
|
// Accessors
|
2006-08-02 14:30:23 +02:00
|
|
|
MachinePassRegistryNode *getNext() const { return Next; }
|
|
|
|
MachinePassRegistryNode **getNextAddress() { return &Next; }
|
2006-08-01 18:31:08 +02:00
|
|
|
const char *getName() const { return Name; }
|
|
|
|
const char *getDescription() const { return Description; }
|
2006-08-02 14:30:23 +02:00
|
|
|
MachinePassCtor getCtor() const { return Ctor; }
|
|
|
|
void setNext(MachinePassRegistryNode *N) { Next = N; }
|
2006-08-01 18:31:08 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// MachinePassRegistry - Track the registration of machine passes.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
class MachinePassRegistry {
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2006-08-02 14:30:23 +02:00
|
|
|
MachinePassRegistryNode *List; // List of registry nodes.
|
|
|
|
MachinePassCtor Default; // Default function pass creator.
|
2006-08-01 18:31:08 +02:00
|
|
|
MachinePassRegistryListener* Listener;// Listener for list adds are removes.
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// NO CONSTRUCTOR - we don't want static constructor ordering to mess
|
|
|
|
// with the registry.
|
|
|
|
|
|
|
|
// Accessors.
|
|
|
|
//
|
2006-08-02 14:30:23 +02:00
|
|
|
MachinePassRegistryNode *getList() { return List; }
|
|
|
|
MachinePassCtor getDefault() { return Default; }
|
|
|
|
void setDefault(MachinePassCtor C) { Default = C; }
|
2006-08-01 18:31:08 +02:00
|
|
|
void setListener(MachinePassRegistryListener *L) { Listener = L; }
|
|
|
|
|
|
|
|
/// Add - Adds a function pass to the registration list.
|
|
|
|
///
|
2006-08-02 14:30:23 +02:00
|
|
|
void Add(MachinePassRegistryNode *Node);
|
2006-08-01 18:31:08 +02:00
|
|
|
|
|
|
|
/// Remove - Removes a function pass from the registration list.
|
|
|
|
///
|
2006-08-02 14:30:23 +02:00
|
|
|
void Remove(MachinePassRegistryNode *Node);
|
2006-08-01 18:31:08 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// RegisterPassParser class - Handle the addition of new machine passes.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
template<class RegistryClass>
|
|
|
|
class RegisterPassParser : public MachinePassRegistryListener,
|
2006-08-02 14:30:23 +02:00
|
|
|
public cl::parser<typename RegistryClass::FunctionPassCtor> {
|
2006-08-01 18:31:08 +02:00
|
|
|
public:
|
|
|
|
RegisterPassParser() {}
|
2006-08-01 20:29:48 +02:00
|
|
|
~RegisterPassParser() { RegistryClass::setListener(NULL); }
|
2006-08-01 18:31:08 +02:00
|
|
|
|
|
|
|
void initialize(cl::Option &O) {
|
2006-08-02 14:30:23 +02:00
|
|
|
cl::parser<typename RegistryClass::FunctionPassCtor>::initialize(O);
|
2006-08-01 18:31:08 +02:00
|
|
|
|
|
|
|
// Add existing passes to option.
|
|
|
|
for (RegistryClass *Node = RegistryClass::getList();
|
|
|
|
Node; Node = Node->getNext()) {
|
2009-12-18 00:49:16 +01:00
|
|
|
this->addLiteralOption(Node->getName(),
|
2006-08-02 14:30:23 +02:00
|
|
|
(typename RegistryClass::FunctionPassCtor)Node->getCtor(),
|
2009-12-18 00:49:16 +01:00
|
|
|
Node->getDescription());
|
2006-08-01 18:31:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure we listen for list changes.
|
|
|
|
RegistryClass::setListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implement the MachinePassRegistryListener callbacks.
|
|
|
|
//
|
2006-08-02 14:30:23 +02:00
|
|
|
virtual void NotifyAdd(const char *N,
|
|
|
|
MachinePassCtor C,
|
|
|
|
const char *D) {
|
|
|
|
this->addLiteralOption(N, (typename RegistryClass::FunctionPassCtor)C, D);
|
2006-08-01 18:31:08 +02:00
|
|
|
}
|
2006-08-02 14:30:23 +02:00
|
|
|
virtual void NotifyRemove(const char *N) {
|
|
|
|
this->removeLiteralOption(N);
|
2006-08-01 18:31:08 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|