diff options
Diffstat (limited to 'include')
23 files changed, 310 insertions, 276 deletions
diff --git a/include/llvm/Analysis/LiveVar/FunctionLiveVarInfo.h b/include/llvm/Analysis/LiveVar/FunctionLiveVarInfo.h index 816dd86..ee21d4f 100644 --- a/include/llvm/Analysis/LiveVar/FunctionLiveVarInfo.h +++ b/include/llvm/Analysis/LiveVar/FunctionLiveVarInfo.h @@ -98,7 +98,7 @@ public: // --------- Implement the FunctionPass interface ---------------------- // runOnFunction - Perform analysis, update internal data structures. - virtual bool runOnFunction(Function *F); + virtual bool runOnFunction(Function &F); // releaseMemory - After LiveVariable analysis has been used, forget! virtual void releaseMemory(); diff --git a/include/llvm/Analysis/LiveVar/ValueSet.h b/include/llvm/Analysis/LiveVar/ValueSet.h index 0c0aefa..88897bf 100644 --- a/include/llvm/Analysis/LiveVar/ValueSet.h +++ b/include/llvm/Analysis/LiveVar/ValueSet.h @@ -7,8 +7,9 @@ class Value; // RAV - Used to print values in a form used by the register allocator. // struct RAV { // Register Allocator Value - const Value *V; - RAV(const Value *v) : V(v) {} + const Value &V; + RAV(const Value *v) : V(*v) {} + RAV(const Value &v) : V(v) {} }; std::ostream &operator<<(std::ostream &out, RAV Val); diff --git a/include/llvm/Argument.h b/include/llvm/Argument.h index cd05ca4..6c2458d 100644 --- a/include/llvm/Argument.h +++ b/include/llvm/Argument.h @@ -13,7 +13,10 @@ class Argument : public Value { // Defined in the InstrType.cpp file Function *Parent; - friend class ValueHolder<Argument, Function, Function>; + Argument *Prev, *Next; // Next and Prev links for our intrusive linked list + void setNext(Argument *N) { Next = N; } + void setPrev(Argument *N) { Prev = N; } + friend class SymbolTableListTraits<Argument, Function, Function>; inline void setParent(Function *parent) { Parent = parent; } public: @@ -27,6 +30,12 @@ public: inline const Function *getParent() const { return Parent; } inline Function *getParent() { return Parent; } + + // getNext/Prev - Return the next or previous argument in the list. + Argument *getNext() { return Next; } + const Argument *getNext() const { return Next; } + Argument *getPrev() { return Prev; } + const Argument *getPrev() const { return Prev; } virtual void print(std::ostream &OS) const; diff --git a/include/llvm/BasicBlock.h b/include/llvm/BasicBlock.h index d8bb660..8fc25d5 100644 --- a/include/llvm/BasicBlock.h +++ b/include/llvm/BasicBlock.h @@ -20,23 +20,37 @@ #ifndef LLVM_BASICBLOCK_H #define LLVM_BASICBLOCK_H -#include "llvm/ValueHolder.h" -#include "llvm/Value.h" +#include "llvm/Instruction.h" +#include "llvm/SymbolTableListTraits.h" +#include "Support/ilist" class TerminatorInst; class MachineCodeForBasicBlock; template <class _Term, class _BB> class SuccIterator; // Successor Iterator template <class _Ptr, class _USE_iterator> class PredIterator; +template<> struct ilist_traits<Instruction> + : public SymbolTableListTraits<Instruction, BasicBlock, Function> { + // createNode is used to create a node that marks the end of the list... + static Instruction *createNode(); + static iplist<Instruction> &getList(BasicBlock *BB); +}; + class BasicBlock : public Value { // Basic blocks are data objects also public: - typedef ValueHolder<Instruction, BasicBlock, Function> InstListType; + typedef iplist<Instruction> InstListType; private : InstListType InstList; MachineCodeForBasicBlock* machineInstrVec; + BasicBlock *Prev, *Next; // Next and Prev links for our intrusive linked list - friend class ValueHolder<BasicBlock,Function,Function>; - void setParent(Function *parent); + void setParent(Function *parent) { InstList.setParent(parent); } + void setNext(BasicBlock *N) { Next = N; } + void setPrev(BasicBlock *N) { Prev = N; } + friend class SymbolTableListTraits<BasicBlock, Function, Function>; + + BasicBlock(const BasicBlock &); // Do not implement + void operator=(const BasicBlock &); // Do not implement public: // Instruction iterators... @@ -56,6 +70,12 @@ public: const Function *getParent() const { return InstList.getParent(); } Function *getParent() { return InstList.getParent(); } + // getNext/Prev - Return the next or previous basic block in the list. + BasicBlock *getNext() { return Next; } + const BasicBlock *getNext() const { return Next; } + BasicBlock *getPrev() { return Prev; } + const BasicBlock *getPrev() const { return Prev; } + // getTerminator() - If this is a well formed basic block, then this returns // a pointer to the terminator instruction. If it is not, then you get a null // pointer back. @@ -93,10 +113,10 @@ public: inline unsigned size() const { return InstList.size(); } inline bool empty() const { return InstList.empty(); } - inline const Instruction *front() const { return InstList.front(); } - inline Instruction *front() { return InstList.front(); } - inline const Instruction *back() const { return InstList.back(); } - inline Instruction *back() { return InstList.back(); } + inline const Instruction &front() const { return InstList.front(); } + inline Instruction &front() { return InstList.front(); } + inline const Instruction &back() const { return InstList.back(); } + inline Instruction &back() { return InstList.back(); } // getInstList() - Return the underlying instruction list container. You need // to access it directly if you want to modify it currently. diff --git a/include/llvm/Bytecode/WriteBytecodePass.h b/include/llvm/Bytecode/WriteBytecodePass.h index 84e491a..297fbb7 100644 --- a/include/llvm/Bytecode/WriteBytecodePass.h +++ b/include/llvm/Bytecode/WriteBytecodePass.h @@ -25,8 +25,8 @@ public: if (DeleteStream) delete Out; } - bool run(Module *M) { - WriteBytecodeToFile(M, *Out); + bool run(Module &M) { + WriteBytecodeToFile(&M, *Out); return false; } }; diff --git a/include/llvm/CodeGen/FunctionLiveVarInfo.h b/include/llvm/CodeGen/FunctionLiveVarInfo.h index 816dd86..ee21d4f 100644 --- a/include/llvm/CodeGen/FunctionLiveVarInfo.h +++ b/include/llvm/CodeGen/FunctionLiveVarInfo.h @@ -98,7 +98,7 @@ public: // --------- Implement the FunctionPass interface ---------------------- // runOnFunction - Perform analysis, update internal data structures. - virtual bool runOnFunction(Function *F); + virtual bool runOnFunction(Function &F); // releaseMemory - After LiveVariable analysis has been used, forget! virtual void releaseMemory(); diff --git a/include/llvm/CodeGen/ValueSet.h b/include/llvm/CodeGen/ValueSet.h index 0c0aefa..88897bf 100644 --- a/include/llvm/CodeGen/ValueSet.h +++ b/include/llvm/CodeGen/ValueSet.h @@ -7,8 +7,9 @@ class Value; // RAV - Used to print values in a form used by the register allocator. // struct RAV { // Register Allocator Value - const Value *V; - RAV(const Value *v) : V(v) {} + const Value &V; + RAV(const Value *v) : V(*v) {} + RAV(const Value &v) : V(v) {} }; std::ostream &operator<<(std::ostream &out, RAV Val); diff --git a/include/llvm/DerivedTypes.h b/include/llvm/DerivedTypes.h index 9e01ba3..9e63823 100644 --- a/include/llvm/DerivedTypes.h +++ b/include/llvm/DerivedTypes.h @@ -75,7 +75,7 @@ public: return T->isDerivedType(); } static inline bool classof(const Value *V) { - return isa<Type>(V) && classof(cast<const Type>(V)); + return isa<Type>(V) && classof(cast<Type>(V)); } }; @@ -377,7 +377,7 @@ public: return T->getPrimitiveID() == OpaqueTyID; } static inline bool classof(const Value *V) { - return isa<Type>(V) && classof(cast<const Type>(V)); + return isa<Type>(V) && classof(cast<Type>(V)); } }; diff --git a/include/llvm/Function.h b/include/llvm/Function.h index 5bba530..66a372e 100644 --- a/include/llvm/Function.h +++ b/include/llvm/Function.h @@ -13,31 +13,59 @@ #define LLVM_FUNCTION_H #include "llvm/GlobalValue.h" -#include "llvm/ValueHolder.h" +#include "llvm/BasicBlock.h" +#include "llvm/Argument.h" class FunctionType; +// Traits for intrusive list of instructions... +template<> struct ilist_traits<BasicBlock> + : public SymbolTableListTraits<BasicBlock, Function, Function> { + + // createNode is used to create a node that marks the end of the list... + static BasicBlock *createNode() { return new BasicBlock(); } + + static iplist<BasicBlock> &getList(Function *F); +}; + +template<> struct ilist_traits<Argument> + : public SymbolTableListTraits<Argument, Function, Function> { + + // createNode is used to create a node that marks the end of the list... + static Argument *createNode(); + static iplist<Argument> &getList(Function *F); +}; + class Function : public GlobalValue { public: - typedef ValueHolder<Argument , Function, Function> ArgumentListType; - typedef ValueHolder<BasicBlock, Function, Function> BasicBlocksType; + typedef iplist<Argument> ArgumentListType; + typedef iplist<BasicBlock> BasicBlockListType; // BasicBlock iterators... - typedef BasicBlocksType::iterator iterator; - typedef BasicBlocksType::const_iterator const_iterator; + typedef BasicBlockListType::iterator iterator; + typedef BasicBlockListType::const_iterator const_iterator; typedef std::reverse_iterator<const_iterator> const_reverse_iterator; typedef std::reverse_iterator<iterator> reverse_iterator; + typedef ArgumentListType::iterator aiterator; + typedef ArgumentListType::const_iterator const_aiterator; + typedef std::reverse_iterator<const_aiterator> const_reverse_aiterator; + typedef std::reverse_iterator<aiterator> reverse_aiterator; + private: // Important things that make up a function! - BasicBlocksType BasicBlocks; // The basic blocks + BasicBlockListType BasicBlocks; // The basic blocks ArgumentListType ArgumentList; // The formal arguments SymbolTable *SymTab, *ParentSymTab; - friend class ValueHolder<Function, Module, Module>; + friend class SymbolTableListTraits<Function, Module, Module>; + void setParent(Module *parent); + Function *Prev, *Next; + void setNext(Function *N) { Next = N; } + void setPrev(Function *N) { Prev = N; } public: Function(const FunctionType *Ty, bool isInternal, const std::string &N = ""); @@ -53,17 +81,24 @@ public: // this is true for external functions, defined as forward "declare"ations bool isExternal() const { return BasicBlocks.empty(); } + // getNext/Prev - Return the next or previous instruction in the list. The + // last node in the list is a terminator instruction. + Function *getNext() { return Next; } + const Function *getNext() const { return Next; } + Function *getPrev() { return Prev; } + const Function *getPrev() const { return Prev; } + // Get the underlying elements of the Function... both the argument list and // basic block list are empty for external functions. // - inline const ArgumentListType &getArgumentList() const{ return ArgumentList; } - inline ArgumentListType &getArgumentList() { return ArgumentList; } + const ArgumentListType &getArgumentList() const { return ArgumentList; } + ArgumentListType &getArgumentList() { return ArgumentList; } - inline const BasicBlocksType &getBasicBlocks() const { return BasicBlocks; } - inline BasicBlocksType &getBasicBlocks() { return BasicBlocks; } + const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; } + BasicBlockListType &getBasicBlockList() { return BasicBlocks; } - inline const BasicBlock *getEntryNode() const { return front(); } - inline BasicBlock *getEntryNode() { return front(); } + const BasicBlock &getEntryNode() const { return front(); } + BasicBlock &getEntryNode() { return front(); } //===--------------------------------------------------------------------===// // Symbol Table Accessing functions... @@ -89,22 +124,42 @@ public: //===--------------------------------------------------------------------===// // BasicBlock iterator forwarding functions // - inline iterator begin() { return BasicBlocks.begin(); } - inline const_iterator begin() const { return BasicBlocks.begin(); } - inline iterator end () { return BasicBlocks.end(); } - inline const_iterator end () const { return BasicBlocks.end(); } - - inline reverse_iterator rbegin() { return BasicBlocks.rbegin(); } - inline const_reverse_iterator rbegin() const { return BasicBlocks.rbegin(); } - inline reverse_iterator rend () { return BasicBlocks.rend(); } - inline const_reverse_iterator rend () const { return BasicBlocks.rend(); } - - inline unsigned size() const { return BasicBlocks.size(); } - inline bool empty() const { return BasicBlocks.empty(); } - inline const BasicBlock *front() const { return BasicBlocks.front(); } - inline BasicBlock *front() { return BasicBlocks.front(); } - inline const BasicBlock *back() const { return BasicBlocks.back(); } - inline BasicBlock *back() { return BasicBlocks.back(); } + iterator begin() { return BasicBlocks.begin(); } + const_iterator begin() const { return BasicBlocks.begin(); } + iterator end () { return BasicBlocks.end(); } + const_iterator end () const { return BasicBlocks.end(); } + + reverse_iterator rbegin() { return BasicBlocks.rbegin(); } + const_reverse_iterator rbegin() const { return BasicBlocks.rbegin(); } + reverse_iterator rend () { return BasicBlocks.rend(); } + const_reverse_iterator rend () const { return BasicBlocks.rend(); } + + unsigned size() const { return BasicBlocks.size(); } + bool empty() const { return BasicBlocks.empty(); } + const BasicBlock &front() const { return BasicBlocks.front(); } + BasicBlock &front() { return BasicBlocks.front(); } + const BasicBlock &back() const { return BasicBlocks.back(); } + BasicBlock &back() { return BasicBlocks.back(); } + + //===--------------------------------------------------------------------===// + // Argument iterator forwarding functions + // + aiterator abegin() { return ArgumentList.begin(); } + const_aiterator abegin() const { return ArgumentList.begin(); } + aiterator aend () { return ArgumentList.end(); } + const_aiterator aend () const { return ArgumentList.end(); } + + reverse_aiterator arbegin() { return ArgumentList.rbegin(); } + const_reverse_aiterator arbegin() const { return ArgumentList.rbegin(); } + reverse_aiterator arend () { return ArgumentList.rend(); } + const_reverse_aiterator arend () const { return ArgumentList.rend(); } + + unsigned asize() const { return ArgumentList.size(); } + bool aempty() const { return ArgumentList.empty(); } + const Argument &afront() const { return ArgumentList.front(); } + Argument &afront() { return ArgumentList.front(); } + const Argument &aback() const { return ArgumentList.back(); } + Argument &aback() { return ArgumentList.back(); } virtual void print(std::ostream &OS) const; diff --git a/include/llvm/GlobalVariable.h b/include/llvm/GlobalVariable.h index 79507a5..2e2dd2b 100644 --- a/include/llvm/GlobalVariable.h +++ b/include/llvm/GlobalVariable.h @@ -17,11 +17,19 @@ class Module; class Constant; class PointerType; +template<typename SC> struct ilist_traits; +template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass, + typename SubClass> class SymbolTableListTraits; class GlobalVariable : public GlobalValue { - friend class ValueHolder<GlobalVariable, Module, Module>; + friend class SymbolTableListTraits<GlobalVariable, Module, Module, + ilist_traits<GlobalVariable> >; void setParent(Module *parent) { Parent = parent; } + GlobalVariable *Prev, *Next; + void setNext(GlobalVariable *N) { Next = N; } + void setPrev(GlobalVariable *N) { Prev = N; } + bool isConstantGlobal; // Is this a global constant? public: GlobalVariable(const Type *Ty, bool isConstant, bool isInternal, @@ -52,6 +60,12 @@ public: } } + // getNext/Prev - Return the next or previous instruction in the list. The + // last node in the list is a terminator instruction. + GlobalVariable *getNext() { return Next; } + const GlobalVariable *getNext() const { return Next; } + GlobalVariable *getPrev() { return Prev; } + const GlobalVariable *getPrev() const { return Prev; } // If the value is a global constant, its value is immutable throughout the // runtime execution of the program. Assigning a value into the constant diff --git a/include/llvm/Instruction.h b/include/llvm/Instruction.h index 9ab6f8a..7cdee5d 100644 --- a/include/llvm/Instruction.h +++ b/include/llvm/Instruction.h @@ -9,11 +9,19 @@ #define LLVM_INSTRUCTION_H #include "llvm/User.h" +template<typename SC> struct ilist_traits; +template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass, + typename SubClass> class SymbolTableListTraits; class Instruction : public User { BasicBlock *Parent; + Instruction *Prev, *Next; // Next and Prev links for our intrusive linked list - friend class ValueHolder<Instruction,BasicBlock,Function>; + void setNext(Instruction *N) { Next = N; } + void setPrev(Instruction *N) { Prev = N; } + + friend class SymbolTableListTraits<Instruction, BasicBlock, Function, + ilist_traits<Instruction> >; inline void setParent(BasicBlock *P) { Parent = P; } protected: unsigned iType; // InstructionType @@ -37,6 +45,14 @@ public: // inline const BasicBlock *getParent() const { return Parent; } inline BasicBlock *getParent() { return Parent; } + + // getNext/Prev - Return the next or previous instruction in the list. The + // last node in the list is a terminator instruction. + Instruction *getNext() { return Next; } + const Instruction *getNext() const { return Next; } + Instruction *getPrev() { return Prev; } + const Instruction *getPrev() const { return Prev; } + virtual bool hasSideEffects() const { return false; } // Memory & Call insts // --------------------------------------------------------------------------- diff --git a/include/llvm/Module.h b/include/llvm/Module.h index 3f142cb..8e527d0 100644 --- a/include/llvm/Module.h +++ b/include/llvm/Module.h @@ -12,18 +12,31 @@ #ifndef LLVM_MODULE_H #define LLVM_MODULE_H -#include "llvm/Value.h" -#include "llvm/ValueHolder.h" +#include "llvm/Function.h" +#include "llvm/GlobalVariable.h" class GlobalVariable; class GlobalValueRefMap; // Used by ConstantVals.cpp class ConstantPointerRef; class FunctionType; class SymbolTable; +template<> struct ilist_traits<Function> + : public SymbolTableListTraits<Function, Module, Module> { + // createNode is used to create a node that marks the end of the list... + static Function *createNode(); + static iplist<Function> &getList(Module *M); +}; +template<> struct ilist_traits<GlobalVariable> + : public SymbolTableListTraits<GlobalVariable, Module, Module> { + // createNode is used to create a node that marks the end of the list... + static GlobalVariable *createNode(); + static iplist<GlobalVariable> &getList(Module *M); +}; + class Module : public Annotable { public: - typedef ValueHolder<GlobalVariable, Module, Module> GlobalListType; - typedef ValueHolder<Function, Module, Module> FunctionListType; + typedef iplist<GlobalVariable> GlobalListType; + typedef iplist<Function> FunctionListType; // Global Variable iterators... typedef GlobalListType::iterator giterator; @@ -119,10 +132,10 @@ public: inline unsigned gsize() const { return GlobalList.size(); } inline bool gempty() const { return GlobalList.empty(); } - inline const GlobalVariable *gfront() const { return GlobalList.front(); } - inline GlobalVariable *gfront() { return GlobalList.front(); } - inline const GlobalVariable *gback() const { return GlobalList.back(); } - inline GlobalVariable *gback() { return GlobalList.back(); } + inline const GlobalVariable &gfront() const { return GlobalList.front(); } + inline GlobalVariable &gfront() { return GlobalList.front(); } + inline const GlobalVariable &gback() const { return GlobalList.back(); } + inline GlobalVariable &gback() { return GlobalList.back(); } @@ -138,10 +151,10 @@ public: inline unsigned size() const { return FunctionList.size(); } inline bool empty() const { return FunctionList.empty(); } - inline const Function *front() const { return FunctionList.front(); } - inline Function *front() { return FunctionList.front(); } - inline const Function *back() const { return FunctionList.back(); } - inline Function *back() { return FunctionList.back(); } + inline const Function &front() const { return FunctionList.front(); } + inline Function &front() { return FunctionList.front(); } + inline const Function &back() const { return FunctionList.back(); } + inline Function &back() { return FunctionList.back(); } void print(std::ostream &OS) const; diff --git a/include/llvm/Pass.h b/include/llvm/Pass.h index f604921..097fc34 100644 --- a/include/llvm/Pass.h +++ b/include/llvm/Pass.h @@ -50,7 +50,7 @@ public: // run - Run this pass, returning true if a modification was made to the // module argument. This should be implemented by all concrete subclasses. // - virtual bool run(Module *M) = 0; + virtual bool run(Module &M) = 0; // getAnalysisUsage - This function should be overriden by passes that need // analysis information to do their job. If a pass specifies that it uses a @@ -122,26 +122,26 @@ struct FunctionPass : public Pass { // doInitialization - Virtual method overridden by subclasses to do // any neccesary per-module initialization. // - virtual bool doInitialization(Module *M) { return false; } + virtual bool doInitialization(Module &M) { return false; } // runOnFunction - Virtual method overriden by subclasses to do the // per-function processing of the pass. // - virtual bool runOnFunction(Function *F) = 0; + virtual bool runOnFunction(Function &F) = 0; // doFinalization - Virtual method overriden by subclasses to do any post // processing needed after all passes have run. // - virtual bool doFinalization(Module *M) { return false; } + virtual bool doFinalization(Module &M) { return false; } // run - On a module, we run this pass by initializing, ronOnFunction'ing once // for every function in the module, then by finalizing. // - virtual bool run(Module *M); + virtual bool run(Module &M); // run - On a function, we simply initialize, run the function, then finalize. // - bool run(Function *F); + bool run(Function &F); private: friend class PassManagerT<Module>; @@ -167,17 +167,17 @@ struct BasicBlockPass : public FunctionPass { // runOnBasicBlock - Virtual method overriden by subclasses to do the // per-basicblock processing of the pass. // - virtual bool runOnBasicBlock(BasicBlock *M) = 0; + virtual bool runOnBasicBlock(BasicBlock &BB) = 0; // To run this pass on a function, we simply call runOnBasicBlock once for // each function. // - virtual bool runOnFunction(Function *F); + virtual bool runOnFunction(Function &F); // To run directly on the basic block, we initialize, runOnBasicBlock, then // finalize. // - bool run(BasicBlock *BB); + bool run(BasicBlock &BB); private: friend class PassManagerT<Function>; diff --git a/include/llvm/PassManager.h b/include/llvm/PassManager.h index 644e30b..c012379 100644 --- a/include/llvm/PassManager.h +++ b/include/llvm/PassManager.h @@ -30,7 +30,7 @@ public: // run - Execute all of the passes scheduled for execution. Keep track of // whether any of the functions modifies the program, and if so, return true. // - bool run(Module *M); + bool run(Module &M); }; #endif diff --git a/include/llvm/SymbolTableListTraits.h b/include/llvm/SymbolTableListTraits.h new file mode 100644 index 0000000..74aede1 --- /dev/null +++ b/include/llvm/SymbolTableListTraits.h @@ -0,0 +1,68 @@ +//===-- llvm/SymbolTableListTraits.h - Traits for iplist -------*- C++ -*--===// +// +// This file defines a generic class that is used to implement the automatic +// symbol table manipulation that occurs when you put (for example) a named +// instruction into a basic block. +// +// The way that this is implemented is by using a special traits class with the +// intrusive list that makes up the list of instructions in a basic block. When +// a new element is added to the list of instructions, the traits class is +// notified, allowing the symbol table to be updated. +// +// This generic class implements the traits class. It must be generic so that +// it can work for all uses it, which include lists of instructions, basic +// blocks, arguments, functions, global variables, etc... +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_SYMBOLTABLELISTTRAITS_H +#define LLVM_SYMBOLTABLELISTTRAITS_H + +template<typename NodeTy> class ilist_iterator; +template<typename NodeTy, typename Traits> class iplist; +template<typename Ty> struct ilist_traits; + +// ValueSubClass - The type of objects that I hold +// ItemParentType - I call setParent() on all of my "ValueSubclass" items, and +// this is the value that I pass in. +// SymTabType - This is the class type, whose symtab I insert my +// ValueSubClass items into. Most of the time it is +// ItemParentType, but Instructions have item parents of BB's +// but symtabtype's of a Function +// +template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass, + typename SubClass=ilist_traits<ValueSubClass> > +class SymbolTableListTraits { + SymTabClass *SymTabObject; + ItemParentClass *ItemParent; +public: + SymbolTableListTraits() : SymTabObject(0), ItemParent(0) {} + + SymTabClass *getParent() { return SymTabObject; } + const SymTabClass *getParent() const { return SymTabObject; } + + static ValueSubClass *getPrev(ValueSubClass *V) { return V->getPrev(); } + static ValueSubClass *getNext(ValueSubClass *V) { return V->getNext(); } + static const ValueSubClass *getPrev(const ValueSubClass *V) { + return V->getPrev(); + } + static const ValueSubClass *getNext(const ValueSubClass *V) { + return V->getNext(); + } + + static void setPrev(ValueSubClass *V, ValueSubClass *P) { V->setPrev(P); } + static void setNext(ValueSubClass *V, ValueSubClass *N) { V->setNext(N); } + + void addNodeToList(ValueSubClass *V); + void removeNodeFromList(ValueSubClass *V); + void transferNodesFromList(iplist<ValueSubClass, + ilist_traits<ValueSubClass> > &L2, + ilist_iterator<ValueSubClass> first, + ilist_iterator<ValueSubClass> last); + +//private: + void setItemParent(ItemParentClass *IP) { ItemParent = IP; }//This is private! + void setParent(SymTabClass *Parent); // This is private! +}; + +#endif diff --git a/include/llvm/Transforms/FunctionInlining.h b/include/llvm/Transforms/FunctionInlining.h index 08fe9d9..e68b081 100644 --- a/include/llvm/Transforms/FunctionInlining.h +++ b/include/llvm/Transforms/FunctionInlining.h @@ -7,7 +7,6 @@ #ifndef LLVM_TRANSFORMS_FUNCTION_INLINING_H #define LLVM_TRANSFORMS_FUNCTION_INLINING_H -#include "llvm/BasicBlock.h" class CallInst; class Pass; @@ -24,6 +23,5 @@ Pass *createFunctionInliningPass(); // function by one level. // bool InlineFunction(CallInst *C); -bool InlineFunction(BasicBlock::iterator CI); // *CI must be CallInst #endif diff --git a/include/llvm/Transforms/IPO/ConstantMerge.h b/include/llvm/Transforms/IPO/ConstantMerge.h index b25fb66..1415339 100644 --- a/include/llvm/Transforms/IPO/ConstantMerge.h +++ b/include/llvm/Transforms/IPO/ConstantMerge.h @@ -8,10 +8,6 @@ // Algorithm: ConstantMerge is designed to build up a map of available constants // and elminate duplicates when it is initialized. // -// The DynamicConstantMerge method is a superset of the ConstantMerge algorithm -// that checks for each method to see if constants have been added to the -// constant pool since it was last run... if so, it processes them. -// //===----------------------------------------------------------------------===// #ifndef LLVM_TRANSFORMS_CONSTANTMERGE_H @@ -19,6 +15,5 @@ class Pass; Pass *createConstantMergePass(); -Pass *createDynamicConstantMergePass(); #endif diff --git a/include/llvm/Transforms/Utils/BasicBlockUtils.h b/include/llvm/Transforms/Utils/BasicBlockUtils.h index 08d173d..282be5e 100644 --- a/include/llvm/Transforms/Utils/BasicBlockUtils.h +++ b/include/llvm/Transforms/Utils/BasicBlockUtils.h @@ -34,12 +34,4 @@ void ReplaceInstWithInst(BasicBlock::InstListType &BIL, // void ReplaceInstWithInst(Instruction *From, Instruction *To); -// InsertInstBeforeInst - Insert 'NewInst' into the basic block that 'Existing' -// is already in, and put it right before 'Existing'. This instruction should -// only be used when there is no iterator to Existing already around. The -// returned iterator points to the new instruction. -// -BasicBlock::iterator InsertInstBeforeInst(Instruction *NewInst, - Instruction *Existing); - #endif diff --git a/include/llvm/Transforms/Utils/Local.h b/include/llvm/Transforms/Utils/Local.h index 69bb5a66..95aaffd 100644 --- a/include/llvm/Transforms/Utils/Local.h +++ b/include/llvm/Transforms/Utils/Local.h @@ -52,12 +52,11 @@ bool dceInstruction(BasicBlock::iterator &BBI); // SimplifyCFG - This function is used to do simplification of a CFG. For // example, it adjusts branches to branches to eliminate the extra hop, it // eliminates unreachable basic blocks, and does other "peephole" optimization -// of the CFG. It returns true if a modification was made, and returns an -// iterator that designates the first element remaining after the block that -// was deleted. +// of the CFG. It returns true if a modification was made, possibly deleting +// the basic block that was pointed to. // // WARNING: The entry node of a method may not be simplified. // -bool SimplifyCFG(Function::iterator &BBIt); +bool SimplifyCFG(BasicBlock *BB); #endif diff --git a/include/llvm/Transforms/Utils/UnifyFunctionExitNodes.h b/include/llvm/Transforms/Utils/UnifyFunctionExitNodes.h index 0d54aca..042a419 100644 --- a/include/llvm/Transforms/Utils/UnifyFunctionExitNodes.h +++ b/include/llvm/Transforms/Utils/UnifyFunctionExitNodes.h @@ -23,7 +23,7 @@ public: BasicBlock *getExitNode() const { return ExitNode; } virtual const char *getPassName() const { return "Unify Function Exit Nodes";} - virtual bool runOnFunction(Function *F); + virtual bool runOnFunction(Function &F); virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.addProvided(ID); } }; diff --git a/include/llvm/Type.h b/include/llvm/Type.h index 125fbc1..e7a192b 100644 --- a/include/llvm/Type.h +++ b/include/llvm/Type.h @@ -294,11 +294,8 @@ template <> struct GraphTraits<const Type*> { } }; -template <> inline bool isa<PointerType, const Type*>(const Type *Ty) { - return Ty->getPrimitiveID() == Type::PointerTyID; -} -template <> inline bool isa<PointerType, Type*>(Type *Ty) { - return Ty->getPrimitiveID() == Type::PointerTyID; +template <> inline bool isa_impl<PointerType, Type>(const Type &Ty) { + return Ty.getPrimitiveID() == Type::PointerTyID; } #endif diff --git a/include/llvm/Value.h b/include/llvm/Value.h index 004a8ff..573ca17 100644 --- a/include/llvm/Value.h +++ b/include/llvm/Value.h @@ -25,8 +25,6 @@ class GlobalValue; class Function; class GlobalVariable; class SymbolTable; -template<class ValueSubclass, class ItemParentType, class SymTabType> - class ValueHolder; //===----------------------------------------------------------------------===// // Value Class @@ -128,6 +126,11 @@ inline std::ostream &operator<<(std::ostream &OS, const Value *V) { return OS; } +inline std::ostream &operator<<(std::ostream &OS, const Value &V) { + V.print(OS); + return OS; +} + //===----------------------------------------------------------------------===// // UseTy Class @@ -178,61 +181,46 @@ public: typedef UseTy<Value> Use; // Provide Use as a common UseTy type -// Provide a specialization of real_type to work with use's... to make them a -// bit more transparent. -// -template <class X> class real_type <class UseTy<X> > { typedef X *Type; }; - +template<typename From> struct simplify_type<UseTy<From> > { + typedef typename simplify_type<From*>::SimpleType SimpleType; + + static SimpleType getSimplifiedValue(const UseTy<From> &Val) { + return (SimpleType)Val.get(); + } +}; +template<typename From> struct simplify_type<const UseTy<From> > { + typedef typename simplify_type<From*>::SimpleType SimpleType; + + static SimpleType getSimplifiedValue(const UseTy<From> &Val) { + return (SimpleType)Val.get(); + } +}; // isa - Provide some specializations of isa so that we don't have to include // the subtype header files to test to see if the value is a subclass... // -template <> inline bool isa<Type, const Value*>(const Value *Val) { - return Val->getValueType() == Value::TypeVal; -} -template <> inline bool isa<Type, Value*>(Value *Val) { - return Val->getValueType() == Value::TypeVal; -} -template <> inline bool isa<Constant, const Value*>(const Value *Val) { - return Val->getValueType() == Value::ConstantVal; -} -template <> inline bool isa<Constant, Value*>(Value *Val) { - return Val->getValueType() == Value::ConstantVal; -} -template <> inline bool isa<Argument, const Value*>(const Value *Val) { - return Val->getValueType() == Value::ArgumentVal; +template <> inline bool isa_impl<Type, Value>(const Value &Val) { + return Val.getValueType() == Value::TypeVal; } -template <> inline bool isa<Argument, Value*>(Value *Val) { - return Val->getValueType() == Value::ArgumentVal; +template <> inline bool isa_impl<Constant, Value>(const Value &Val) { + return Val.getValueType() == Value::ConstantVal; } -template <> inline bool isa<Instruction, const Value*>(const Value *Val) { - return Val->getValueType() == Value::InstructionVal; +template <> inline bool isa_impl<Argument, Value>(const Value &Val) { + return Val.getValueType() == Value::ArgumentVal; } -template <> inline bool isa<Instruction, Value*>(Value *Val) { - return Val->getValueType() == Value::InstructionVal; +template <> inline bool isa_impl<Instruction, Value>(const Value &Val) { + return Val.getValueType() == Value::InstructionVal; } -template <> inline bool isa<BasicBlock, const Value*>(const Value *Val) { - return Val->getValueType() == Value::BasicBlockVal; +template <> inline bool isa_impl<BasicBlock, Value>(const Value &Val) { + return Val.getValueType() == Value::BasicBlockVal; } -template <> inline bool isa<BasicBlock, Value*>(Value *Val) { - return Val->getValueType() == Value::BasicBlockVal; +template <> inline bool isa_impl<Function, Value>(const Value &Val) { + return Val.getValueType() == Value::FunctionVal; } -template <> inline bool isa<Function, const Value*>(const Value *Val) { - return Val->getValueType() == Value::FunctionVal; -} -template <> inline bool isa<Function, Value*>(Value *Val) { - return Val->getValueType() == Value::FunctionVal; -} -template <> inline bool isa<GlobalVariable, const Value*>(const Value *Val) { - return Val->getValueType() == Value::GlobalVariableVal; -} -template <> inline bool isa<GlobalVariable, Value*>(Value *Val) { - return Val->getValueType() == Value::GlobalVariableVal; -} -template <> inline bool isa<GlobalValue, const Value*>(const Value *Val) { - return isa<GlobalVariable>(Val) || isa<Function>(Val); +template <> inline bool isa_impl<GlobalVariable, Value>(const Value &Val) { + return Val.getValueType() == Value::GlobalVariableVal; } -template <> inline bool isa<GlobalValue, Value*>(Value *Val) { +template <> inline bool isa_impl<GlobalValue, Value>(const Value &Val) { return isa<GlobalVariable>(Val) || isa<Function>(Val); } diff --git a/include/llvm/ValueHolder.h b/include/llvm/ValueHolder.h deleted file mode 100644 index abd863f..0000000 --- a/include/llvm/ValueHolder.h +++ /dev/null @@ -1,132 +0,0 @@ -//===-- llvm/ValueHolder.h - Class to hold multiple values -------*- C++ -*--=// -// -// This defines a class that is used as a fancy Definition container. It is -// special because it helps keep the symbol table of the container function up -// to date with the goings on inside of it. -// -// This is used to represent things like the instructions of a basic block and -// the arguments to a function. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_VALUEHOLDER_H -#define LLVM_VALUEHOLDER_H - -#include <vector> - -// ValueSubClass - The type of objects that I hold -// ItemParentType - I call setParent() on all of my "ValueSubclass" items, and -// this is the value that I pass in. -// SymTabType - This is the class type, whose symtab I insert my -// ValueSubClass items into. Most of the time it is -// ItemParentType, but Instructions have item parents of BB's -// but symtabtype's of a Function -// -template<class ValueSubclass, class ItemParentType, class SymTabType> -class ValueHolder { - std::vector<ValueSubclass*> ValueList; - - ItemParentType *ItemParent; - SymTabType *Parent; - - ValueHolder(const ValueHolder &V); // DO NOT IMPLEMENT -public: - inline ValueHolder(ItemParentType *IP, SymTabType *parent = 0) { - assert(IP && "Item parent may not be null!"); - ItemParent = IP; - Parent = 0; - setParent(parent); - } - - inline ~ValueHolder() { - // The caller should have called delete_all first... - assert(empty() && "ValueHolder contains definitions!"); - assert(Parent == 0 && "Should have been unlinked from function!"); - } - - inline const SymTabType *getParent() const { return Parent; } - inline SymTabType *getParent() { return Parent; } - void setParent(SymTabType *Parent); // Defined in ValueHolderImpl.h - - inline unsigned size() const { return ValueList.size(); } - inline bool empty() const { return ValueList.empty(); } - inline const ValueSubclass *front() const { return ValueList.front(); } - inline ValueSubclass *front() { return ValueList.front(); } - inline const ValueSubclass *back() const { return ValueList.back(); } - inline ValueSubclass *back() { return ValueList.back(); } - inline const ValueSubclass *operator[](unsigned i) const { - return ValueList[i]; - } - inline ValueSubclass *operator[](unsigned i) { - return ValueList[i]; - } - - //===--------------------------------------------------------------------===// - // sub-Definition iterator code - //===--------------------------------------------------------------------===// - // - typedef std::vector<ValueSubclass*>::iterator iterator; - typedef std::vector<ValueSubclass*>::const_iterator const_iterator; - typedef std::reverse_iterator<const_iterator> const_reverse_iterator; - typedef std::reverse_iterator<iterator> reverse_iterator; - - inline iterator begin() { return ValueList.begin(); } - inline const_iterator begin() const { return ValueList.begin(); } - inline iterator end () { return ValueList.end(); } - inline const_iterator end () const { return ValueList.end(); } - - inline reverse_iterator rbegin() { return ValueList.rbegin(); } - inline const_reverse_iterator rbegin() const { return ValueList.rbegin(); } - inline reverse_iterator rend () { return ValueList.rend(); } - inline const_reverse_iterator rend () const { return ValueList.rend(); } - - // ValueHolder::remove(iterator &) this removes the element at the location - // specified by the iterator, and leaves the iterator pointing to the element - // that used to follow the element deleted. - // - ValueSubclass *remove(iterator &DI); - ValueSubclass *remove(const iterator &DI); - void remove(ValueSubclass *D); - void remove(iterator Start, iterator End); - ValueSubclass *pop_back(); - - // replaceWith - This removes the element pointed to by 'Where', and inserts - // NewValue in it's place. The old value is returned. 'Where' must be a - // valid iterator! - // - ValueSubclass *replaceWith(iterator &Where, ValueSubclass *NewValue); - - // delete_span - Remove the elements from begin to end, deleting them as we - // go. This leaves the iterator pointing to the element that used to be end. - // - iterator delete_span(iterator begin, iterator end) { - while (end != begin) - delete remove(--end); - return end; - } - - void delete_all() { // Delete all removes and deletes all elements - delete_span(begin(), end()); - } - - void push_front(ValueSubclass *Inst); // Defined in ValueHolderImpl.h - void push_back(ValueSubclass *Inst); // Defined in ValueHolderImpl.h - - // ValueHolder::insert - This method inserts the specified value *BEFORE* the - // indicated iterator position, and returns an interator to the newly inserted - // value. - // - iterator insert(iterator Pos, ValueSubclass *Inst); - - // ValueHolder::insert - This method inserts the specified _range_ of values - // before the 'Pos' iterator, returning a new iterator that points to the - // first item inserted. *This currently only works for vector iterators...* - // - // FIXME: This is not generic so that the code does not have to be around - // to be used... is this ok? - // - iterator insert(iterator Pos, // Where to insert - iterator First, iterator Last); // Vector to read insts from -}; - -#endif |