summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-06-25 16:12:52 +0000
committerChris Lattner <sabre@nondot.org>2002-06-25 16:12:52 +0000
commit18961504fc2b299578dba817900a0696cf3ccc4d (patch)
treec34853ffc064b841932d0897e25305c81c3a7338
parenta2204e1ff25265a1da00ecbb3ebb22c05acf7194 (diff)
downloadllvm-18961504fc2b299578dba817900a0696cf3ccc4d.tar.gz
llvm-18961504fc2b299578dba817900a0696cf3ccc4d.tar.bz2
llvm-18961504fc2b299578dba817900a0696cf3ccc4d.tar.xz
*** empty log message ***
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2777 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Analysis/LiveVar/FunctionLiveVarInfo.h2
-rw-r--r--include/llvm/Analysis/LiveVar/ValueSet.h5
-rw-r--r--include/llvm/Argument.h11
-rw-r--r--include/llvm/BasicBlock.h38
-rw-r--r--include/llvm/Bytecode/WriteBytecodePass.h4
-rw-r--r--include/llvm/CodeGen/FunctionLiveVarInfo.h2
-rw-r--r--include/llvm/CodeGen/ValueSet.h5
-rw-r--r--include/llvm/DerivedTypes.h4
-rw-r--r--include/llvm/Function.h113
-rw-r--r--include/llvm/GlobalVariable.h16
-rw-r--r--include/llvm/Instruction.h18
-rw-r--r--include/llvm/Module.h37
-rw-r--r--include/llvm/Pass.h18
-rw-r--r--include/llvm/PassManager.h2
-rw-r--r--include/llvm/SymbolTableListTraits.h68
-rw-r--r--include/llvm/Transforms/FunctionInlining.h2
-rw-r--r--include/llvm/Transforms/IPO/ConstantMerge.h5
-rw-r--r--include/llvm/Transforms/Utils/BasicBlockUtils.h8
-rw-r--r--include/llvm/Transforms/Utils/Local.h7
-rw-r--r--include/llvm/Transforms/Utils/UnifyFunctionExitNodes.h2
-rw-r--r--include/llvm/Type.h7
-rw-r--r--include/llvm/Value.h80
-rw-r--r--include/llvm/ValueHolder.h132
-rw-r--r--lib/Analysis/DataStructure/DataStructure.cpp19
-rw-r--r--lib/Analysis/DataStructure/FunctionRepBuilder.cpp104
-rw-r--r--lib/Analysis/DataStructure/FunctionRepBuilder.h32
-rw-r--r--lib/Analysis/DataStructure/NodeImpl.cpp11
-rw-r--r--lib/Analysis/LiveVar/BBLiveVar.cpp22
-rw-r--r--lib/Analysis/LiveVar/BBLiveVar.h10
-rw-r--r--lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp16
-rw-r--r--lib/Analysis/LiveVar/ValueSet.cpp10
-rw-r--r--lib/Linker/LinkModules.cpp102
-rw-r--r--lib/Target/SparcV9/LiveVar/BBLiveVar.cpp22
-rw-r--r--lib/Target/SparcV9/LiveVar/BBLiveVar.h10
-rw-r--r--lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp16
-rw-r--r--lib/Target/SparcV9/LiveVar/ValueSet.cpp10
-rw-r--r--lib/Transforms/Utils/BasicBlockUtils.cpp43
-rw-r--r--lib/Transforms/Utils/CloneFunction.cpp36
-rw-r--r--lib/Transforms/Utils/Linker.cpp102
-rw-r--r--lib/Transforms/Utils/Local.cpp12
-rw-r--r--lib/Transforms/Utils/SimplifyCFG.cpp55
-rw-r--r--lib/Transforms/Utils/UnifyFunctionExitNodes.cpp16
-rw-r--r--lib/VMCore/Linker.cpp102
43 files changed, 652 insertions, 684 deletions
diff --git a/include/llvm/Analysis/LiveVar/FunctionLiveVarInfo.h b/include/llvm/Analysis/LiveVar/FunctionLiveVarInfo.h
index 816dd860d0..ee21d4fdbe 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 0c0aefad20..88897bf3ad 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 cd05ca4d5b..6c2458d9d0 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 d8bb660479..8fc25d58d4 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 84e491a7d9..297fbb76e1 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 816dd860d0..ee21d4fdbe 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 0c0aefad20..88897bf3ad 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 9e01ba37c9..9e6382328c 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 5bba530ed0..66a372e711 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 79507a5670..2e2dd2bb41 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 9ab6f8a106..7cdee5d2c1 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 3f142cbe0b..8e527d0960 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 f604921601..097fc34e61 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 644e30b50c..c012379b5a 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 0000000000..74aede11a3
--- /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 08fe9d93a6..e68b08136e 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 b25fb66670..1415339f61 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 08d173d4ef..282be5e909 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 69bb5a66e4..95aaffd538 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 0d54aca657..042a4191b2 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 125fbc1d27..e7a192bac9 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 004a8ff89e..573ca174de 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 abd863f995..0000000000
--- 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
diff --git a/lib/Analysis/DataStructure/DataStructure.cpp b/lib/Analysis/DataStructure/DataStructure.cpp
index 248ed918bb..8d53b41186 100644
--- a/lib/Analysis/DataStructure/DataStructure.cpp
+++ b/lib/Analysis/DataStructure/DataStructure.cpp
@@ -6,7 +6,6 @@
#include "llvm/Analysis/DataStructure.h"
#include "llvm/Module.h"
-#include "llvm/Function.h"
#include <fstream>
#include <algorithm>
@@ -42,9 +41,9 @@ void DataStructure::print(std::ostream &O, Module *M) const {
timeval TV1, TV2;
gettimeofday(&TV1, 0);
for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
- if (!(*I)->isExternal()) {
- getDSGraph(*I);
- getClosedDSGraph(*I);
+ if (!I->isExternal() && I->getName() == "main") {
+ //getDSGraph(*I);
+ getClosedDSGraph(I);
}
gettimeofday(&TV2, 0);
cerr << "Analysis took "
@@ -53,9 +52,9 @@ void DataStructure::print(std::ostream &O, Module *M) const {
}
for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
- if (!(*I)->isExternal()) {
+ if (!I->isExternal()) {
- string Filename = "ds." + (*I)->getName() + ".dot";
+ string Filename = "ds." + I->getName() + ".dot";
O << "Writing '" << Filename << "'...";
ofstream F(Filename.c_str());
if (F.good()) {
@@ -65,8 +64,8 @@ void DataStructure::print(std::ostream &O, Module *M) const {
<< "\tsize=\"10,7.5\";\n"
<< "\trotate=\"90\";\n";
- getDSGraph(*I).printFunction(F, "Local");
- getClosedDSGraph(*I).printFunction(F, "Closed");
+ getDSGraph(I).printFunction(F, "Local");
+ getClosedDSGraph(I).printFunction(F, "Closed");
F << "}\n";
} else {
@@ -74,8 +73,8 @@ void DataStructure::print(std::ostream &O, Module *M) const {
}
if (Time)
- O << " [" << getDSGraph(*I).getGraphSize() << ", "
- << getClosedDSGraph(*I).getGraphSize() << "]\n";
+ O << " [" << getDSGraph(I).getGraphSize() << ", "
+ << getClosedDSGraph(I).getGraphSize() << "]\n";
else
O << "\n";
}
diff --git a/lib/Analysis/DataStructure/FunctionRepBuilder.cpp b/lib/Analysis/DataStructure/FunctionRepBuilder.cpp
index 1566ca87da..1282d7a3b6 100644
--- a/lib/Analysis/DataStructure/FunctionRepBuilder.cpp
+++ b/lib/Analysis/DataStructure/FunctionRepBuilder.cpp
@@ -68,12 +68,12 @@ void InitVisitor::visitOperand(Value *V) {
// node if the call returns a pointer value. Check to see if the call node
// uses any global variables...
//
-void InitVisitor::visitCallInst(CallInst *CI) {
- CallDSNode *C = new CallDSNode(CI);
+void InitVisitor::visitCallInst(CallInst &CI) {
+ CallDSNode *C = new CallDSNode(&CI);
Rep->CallNodes.push_back(C);
- Rep->CallMap[CI] = C;
+ Rep->CallMap[&CI] = C;
- if (PointerType *PT = dyn_cast<PointerType>(CI->getType())) {
+ if (const PointerType *PT = dyn_cast<PointerType>(CI.getType())) {
// Create a critical shadow node to represent the memory object that the
// return value points to...
ShadowDSNode *Shad = new ShadowDSNode(PT->getElementType(),
@@ -86,17 +86,17 @@ void InitVisitor::visitCallInst(CallInst *CI) {
C->getLink(0).add(Shad);
// The call instruction returns a pointer to the shadow block...
- Rep->ValueMap[CI].add(Shad, CI);
+ Rep->ValueMap[&CI].add(Shad, &CI);
// If the call returns a value with pointer type, add all of the users
// of the call instruction to the work list...
- Rep->addAllUsesToWorkList(CI);
+ Rep->addAllUsesToWorkList(&CI);
}
// Loop over all of the operands of the call instruction (except the first
// one), to look for global variable references...
//
- for_each(CI->op_begin(), CI->op_end(),
+ for_each(CI.op_begin(), CI.op_end(),
bind_obj(this, &InitVisitor::visitOperand));
}
@@ -105,22 +105,22 @@ void InitVisitor::visitCallInst(CallInst *CI) {
// allocation instructions do not take pointer arguments, they cannot refer to
// global vars...
//
-void InitVisitor::visitAllocationInst(AllocationInst *AI) {
- AllocDSNode *N = new AllocDSNode(AI);
+void InitVisitor::visitAllocationInst(AllocationInst &AI) {
+ AllocDSNode *N = new AllocDSNode(&AI);
Rep->AllocNodes.push_back(N);
- Rep->ValueMap[AI].add(N, AI);
+ Rep->ValueMap[&AI].add(N, &AI);
// Add all of the users of the malloc instruction to the work list...
- Rep->addAllUsesToWorkList(AI);
+ Rep->addAllUsesToWorkList(&AI);
}
// Visit all other instruction types. Here we just scan, looking for uses of
// global variables...
//
-void InitVisitor::visitInstruction(Instruction *I) {
- for_each(I->op_begin(), I->op_end(),
+void InitVisitor::visitInstruction(Instruction &I) {
+ for_each(I.op_begin(), I.op_end(),
bind_obj(this, &InitVisitor::visitOperand));
}
@@ -150,20 +150,18 @@ void FunctionRepBuilder::initializeWorkList(Function *Func) {
// Add all of the arguments to the method to the graph and add all users to
// the worklists...
//
- for (Function::ArgumentListType::iterator I = Func->getArgumentList().begin(),
- E = Func->getArgumentList().end(); I != E; ++I) {
- Value *Arg = (Value*)(*I);
+ for (Function::aiterator I = Func->abegin(), E = Func->aend(); I != E; ++I) {
// Only process arguments that are of pointer type...
- if (PointerType *PT = dyn_cast<PointerType>(Arg->getType())) {
+ if (const PointerType *PT = dyn_cast<PointerType>(I->getType())) {
// Add a shadow value for it to represent what it is pointing to and add
// this to the value map...
ShadowDSNode *Shad = new ShadowDSNode(PT->getElementType(),
Func->getParent());
ShadowNodes.push_back(Shad);
- ValueMap[Arg].add(PointerVal(Shad), Arg);
+ ValueMap[I].add(PointerVal(Shad), I);
// Make sure that all users of the argument are processed...
- addAllUsesToWorkList(Arg);
+ addAllUsesToWorkList(I);
}
}
@@ -179,15 +177,15 @@ void FunctionRepBuilder::initializeWorkList(Function *Func) {
PointerVal FunctionRepBuilder::getIndexedPointerDest(const PointerVal &InP,
- const MemAccessInst *MAI) {
+ const MemAccessInst &MAI) {
unsigned Index = InP.Index;
- const Type *SrcTy = MAI->getPointerOperand()->getType();
+ const Type *SrcTy = MAI.getPointerOperand()->getType();
- for (MemAccessInst::const_op_iterator I = MAI->idx_begin(),
- E = MAI->idx_end(); I != E; ++I)
+ for (MemAccessInst::const_op_iterator I = MAI.idx_begin(),
+ E = MAI.idx_end(); I != E; ++I)
if ((*I)->getType() == Type::UByteTy) { // Look for struct indices...
- StructType *STy = cast<StructType>(SrcTy);
- unsigned StructIdx = cast<ConstantUInt>(*I)->getValue();
+ const StructType *STy = cast<StructType>(SrcTy);
+ unsigned StructIdx = cast<ConstantUInt>(I->get())->getValue();
for (unsigned i = 0; i != StructIdx; ++i)
Index += countPointerFields(STy->getContainedType(i));
@@ -211,11 +209,11 @@ static PointerValSet &getField(const PointerVal &DestPtr) {
// changing. This means that the set of possible values for the GEP
// needs to be expanded.
//
-void FunctionRepBuilder::visitGetElementPtrInst(GetElementPtrInst *GEP) {
- PointerValSet &GEPPVS = ValueMap[GEP]; // PointerValSet to expand
+void FunctionRepBuilder::visitGetElementPtrInst(GetElementPtrInst &GEP) {
+ PointerValSet &GEPPVS = ValueMap[&GEP]; // PointerValSet to expand
// Get the input pointer val set...
- const PointerValSet &SrcPVS = ValueMap[GEP->getOperand(0)];
+ const PointerValSet &SrcPVS = ValueMap[GEP.getOperand(0)];
bool Changed = false; // Process each input value... propogating it.
for (unsigned i = 0, e = SrcPVS.size(); i != e; ++i) {
@@ -230,20 +228,20 @@ void FunctionRepBuilder::visitGetElementPtrInst(GetElementPtrInst *GEP) {
// If our current value set changed, notify all of the users of our
// value.
//
- if (Changed) addAllUsesToWorkList(GEP);
+ if (Changed) addAllUsesToWorkList(&GEP);
}
-void FunctionRepBuilder::visitReturnInst(ReturnInst *RI) {
- RetNode.add(ValueMap[RI->getOperand(0)]);
+void FunctionRepBuilder::visitReturnInst(ReturnInst &RI) {
+ RetNode.add(ValueMap[RI.getOperand(0)]);
}
-void FunctionRepBuilder::visitLoadInst(LoadInst *LI) {
+void FunctionRepBuilder::visitLoadInst(LoadInst &LI) {
// Only loads that return pointers are interesting...
- const PointerType *DestTy = dyn_cast<PointerType>(LI->getType());
+ const PointerType *DestTy = dyn_cast<PointerType>(LI.getType());
if (DestTy == 0) return;
- const PointerValSet &SrcPVS = ValueMap[LI->getOperand(0)];
- PointerValSet &LIPVS = ValueMap[LI];
+ const PointerValSet &SrcPVS = ValueMap[LI.getOperand(0)];
+ PointerValSet &LIPVS = ValueMap[&LI];
bool Changed = false;
for (unsigned si = 0, se = SrcPVS.size(); si != se; ++si) {
@@ -264,18 +262,18 @@ void FunctionRepBuilder::visitLoadInst(LoadInst *LI) {
}
}
- if (Changed) addAllUsesToWorkList(LI);
+ if (Changed) addAllUsesToWorkList(&LI);
}
-void FunctionRepBuilder::visitStoreInst(StoreInst *SI) {
+void FunctionRepBuilder::visitStoreInst(StoreInst &SI) {
// The only stores that are interesting are stores the store pointers
// into data structures...
//
- if (!isa<PointerType>(SI->getOperand(0)->getType())) return;
- if (!ValueMap.count(SI->getOperand(0))) return; // Src scalar has no values!
+ if (!isa<PointerType>(SI.getOperand(0)->getType())) return;
+ if (!ValueMap.count(SI.getOperand(0))) return; // Src scalar has no values!
- const PointerValSet &SrcPVS = ValueMap[SI->getOperand(0)];
- const PointerValSet &PtrPVS = ValueMap[SI->getOperand(1)];
+ const PointerValSet &SrcPVS = ValueMap[SI.getOperand(0)];
+ const PointerValSet &PtrPVS = ValueMap[SI.getOperand(1)];
for (unsigned si = 0, se = SrcPVS.size(); si != se; ++si) {
const PointerVal &SrcPtr = SrcPVS[si];
@@ -301,24 +299,24 @@ void FunctionRepBuilder::visitStoreInst(StoreInst *SI) {
}
}
-void FunctionRepBuilder::visitCallInst(CallInst *CI) {
- CallDSNode *DSN = CallMap[CI];
+void FunctionRepBuilder::visitCallInst(CallInst &CI) {
+ CallDSNode *DSN = CallMap[&CI];
unsigned PtrNum = 0;
- for (unsigned i = 0, e = CI->getNumOperands(); i != e; ++i)
- if (isa<PointerType>(CI->getOperand(i)->getType()))
- DSN->addArgValue(PtrNum++, ValueMap[CI->getOperand(i)]);
+ for (unsigned i = 0, e = CI.getNumOperands(); i != e; ++i)
+ if (isa<PointerType>(CI.getOperand(i)->getType()))
+ DSN->addArgValue(PtrNum++, ValueMap[CI.getOperand(i)]);
}
-void FunctionRepBuilder::visitPHINode(PHINode *PN) {
- assert(isa<PointerType>(PN->getType()) && "Should only update ptr phis");
+void FunctionRepBuilder::visitPHINode(PHINode &PN) {
+ assert(isa<PointerType>(PN.getType()) && "Should only update ptr phis");
- PointerValSet &PN_PVS = ValueMap[PN];
+ PointerValSet &PN_PVS = ValueMap[&PN];
bool Changed = false;
- for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
- Changed |= PN_PVS.add(ValueMap[PN->getIncomingValue(i)],
- PN->getIncomingValue(i));
+ for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i)
+ Changed |= PN_PVS.add(ValueMap[PN.getIncomingValue(i)],
+ PN.getIncomingValue(i));
- if (Changed) addAllUsesToWorkList(PN);
+ if (Changed) addAllUsesToWorkList(&PN);
}
diff --git a/lib/Analysis/DataStructure/FunctionRepBuilder.h b/lib/Analysis/DataStructure/FunctionRepBuilder.h
index e45ea41998..9eedf0259a 100644
--- a/lib/Analysis/DataStructure/FunctionRepBuilder.h
+++ b/lib/Analysis/DataStructure/FunctionRepBuilder.h
@@ -27,9 +27,9 @@ class InitVisitor : public InstVisitor<InitVisitor> {
public:
InitVisitor(FunctionRepBuilder *R, Function *F) : Rep(R), Func(F) {}
- void visitCallInst(CallInst *CI);
- void visitAllocationInst(AllocationInst *AI);
- void visitInstruction(Instruction *I);
+ void visitCallInst(CallInst &CI);
+ void visitAllocationInst(AllocationInst &AI);
+ void visitInstruction(Instruction &I);
// visitOperand - If the specified instruction operand is a global value, add
// a node for it...
@@ -90,7 +90,7 @@ public:
const map<Value*, PointerValSet> &getValueMap() const { return ValueMap; }
private:
static PointerVal getIndexedPointerDest(const PointerVal &InP,
- const MemAccessInst *MAI);
+ const MemAccessInst &MAI);
void initializeWorkList(Function *Func);
void processWorkList() {
@@ -101,7 +101,7 @@ private:
cerr << "Processing worklist inst: " << I;
#endif
- visit(I); // Dispatch to a visitXXX function based on instruction type...
+ visit(*I); // Dispatch to a visitXXX function based on instruction type...
#ifdef DEBUG_DATA_STRUCTURE_CONSTRUCTION
if (I->hasName() && ValueMap.count(I)) {
cerr << "Inst %" << I->getName() << " value is:\n";
@@ -117,18 +117,16 @@ private:
// Allow the visitor base class to invoke these methods...
friend class InstVisitor<FunctionRepBuilder>;
- void visitGetElementPtrInst(GetElementPtrInst *GEP);
- void visitReturnInst(ReturnInst *RI);
- void visitLoadInst(LoadInst *LI);
- void visitStoreInst(StoreInst *SI);
- void visitCallInst(CallInst *CI);
- void visitPHINode(PHINode *PN);
- void visitSetCondInst(SetCondInst *SCI) {} // SetEQ & friends are ignored
- void visitFreeInst(FreeInst *FI) {} // Ignore free instructions
- void visitInstruction(Instruction *I) {
- std::cerr << "\n\n\nUNKNOWN INSTRUCTION type: ";
- I->dump();
- std::cerr << "\n\n\n";
+ void visitGetElementPtrInst(GetElementPtrInst &GEP);
+ void visitReturnInst(ReturnInst &RI);
+ void visitLoadInst(LoadInst &LI);
+ void visitStoreInst(StoreInst &SI);
+ void visitCallInst(CallInst &CI);
+ void visitPHINode(PHINode &PN);
+ void visitSetCondInst(SetCondInst &SCI) {} // SetEQ & friends are ignored
+ void visitFreeInst(FreeInst &FI) {} // Ignore free instructions
+ void visitInstruction(Instruction &I) {
+ std::cerr << "\n\n\nUNKNOWN INSTRUCTION type: " << I << "\n\n\n";
assert(0 && "Cannot proceed");
}
};
diff --git a/lib/Analysis/DataStructure/NodeImpl.cpp b/lib/Analysis/DataStructure/NodeImpl.cpp
index 76b82ba42e..bd279b6082 100644
--- a/lib/Analysis/DataStructure/NodeImpl.cpp
+++ b/lib/Analysis/DataStructure/NodeImpl.cpp
@@ -8,7 +8,6 @@
#include "llvm/Assembly/Writer.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Function.h"
-#include "llvm/BasicBlock.h"
#include "llvm/iMemory.h"
#include "llvm/iOther.h"
#include "Support/STLExtras.h"
@@ -18,6 +17,7 @@
bool AllocDSNode::isEquivalentTo(DSNode *Node) const {
if (AllocDSNode *N = dyn_cast<AllocDSNode>(Node))
return getType() == Node->getType();
+ //&& isAllocaNode() == N->isAllocaNode();
return false;
}
@@ -423,12 +423,11 @@ PointerValSet FunctionDSGraph::cloneFunctionIntoSelf(const FunctionDSGraph &DSG,
// Convert over the arguments...
Function *OF = DSG.getFunction();
- for (Function::ArgumentListType::iterator I = OF->getArgumentList().begin(),
- E = OF->getArgumentList().end(); I != E; ++I)
- if (isa<PointerType>(((Value*)*I)->getType())) {
+ for (Function::aiterator I = OF->abegin(), E = OF->aend(); I != E; ++I)
+ if (isa<PointerType>(I->getType())) {
PointerValSet ArgPVS;
- assert(DSG.getValueMap().find((Value*)*I) != DSG.getValueMap().end());
- MapPVS(ArgPVS, DSG.getValueMap().find((Value*)*I)->second, NodeMap);
+ assert(DSG.getValueMap().find(I) != DSG.getValueMap().end());
+ MapPVS(ArgPVS, DSG.getValueMap().find(I)->second, NodeMap);
assert(!ArgPVS.empty() && "Argument has no links!");
Args.push_back(ArgPVS);
}
diff --git a/lib/Analysis/LiveVar/BBLiveVar.cpp b/lib/Analysis/LiveVar/BBLiveVar.cpp
index 7d735b79e4..eb58671a79 100644
--- a/lib/Analysis/LiveVar/BBLiveVar.cpp
+++ b/lib/Analysis/LiveVar/BBLiveVar.cpp
@@ -18,23 +18,23 @@ using std::cerr;
static AnnotationID AID(AnnotationManager::getID("Analysis::BBLiveVar"));
-BBLiveVar *BBLiveVar::CreateOnBB(const BasicBlock *BB, unsigned POID) {
+BBLiveVar *BBLiveVar::CreateOnBB(const BasicBlock &BB, unsigned POID) {
BBLiveVar *Result = new BBLiveVar(BB, POID);
- BB->addAnnotation(Result);
+ BB.addAnnotation(Result);
return Result;
}
-BBLiveVar *BBLiveVar::GetFromBB(const BasicBlock *BB) {
- return (BBLiveVar*)BB->getAnnotation(AID);
+BBLiveVar *BBLiveVar::GetFromBB(const BasicBlock &BB) {
+ return (BBLiveVar*)BB.getAnnotation(AID);
}
-void BBLiveVar::RemoveFromBB(const BasicBlock *BB) {
- bool Deleted = BB->deleteAnnotation(AID);
+void BBLiveVar::RemoveFromBB(const BasicBlock &BB) {
+ bool Deleted = BB.deleteAnnotation(AID);
assert(Deleted && "BBLiveVar annotation did not exist!");
}
-BBLiveVar::BBLiveVar(const BasicBlock *bb, unsigned id)
+BBLiveVar::BBLiveVar(const BasicBlock &bb, unsigned id)
: Annotation(AID), BB(bb), POID(id) {
InSetChanged = OutSetChanged = false;
@@ -50,7 +50,7 @@ BBLiveVar::BBLiveVar(const BasicBlock *bb, unsigned id)
void BBLiveVar::calcDefUseSets() {
// get the iterator for machine instructions
- const MachineCodeForBasicBlock &MIVec = BB->getMachineInstrVec();
+ const MachineCodeForBasicBlock &MIVec = BB.getMachineInstrVec();
// iterate over all the machine instructions in BB
for (MachineCodeForBasicBlock::const_reverse_iterator MII = MIVec.rbegin(),
@@ -129,7 +129,7 @@ void BBLiveVar::calcDefUseSets() {
//-----------------------------------------------------------------------------
// To add an operand which is a def
//-----------------------------------------------------------------------------
-void BBLiveVar::addDef(const Value *Op) {
+void BBLiveVar::addDef(const Value *Op) {
DefSet.insert(Op); // operand is a def - so add to def set
InSet.erase(Op); // this definition kills any later uses
InSetChanged = true;
@@ -211,9 +211,9 @@ bool BBLiveVar::applyFlowFunc() {
//
bool needAnotherIt = false;
- for (pred_const_iterator PI = pred_begin(BB), PE = pred_end(BB);
+ for (pred_const_iterator PI = pred_begin(&BB), PE = pred_end(&BB);
PI != PE ; ++PI) {
- BBLiveVar *PredLVBB = BBLiveVar::GetFromBB(*PI);
+ BBLiveVar *PredLVBB = BBLiveVar::GetFromBB(**PI);
// do set union
if (setPropagate(&PredLVBB->OutSet, &InSet, *PI)) {
diff --git a/lib/Analysis/LiveVar/BBLiveVar.h b/lib/Analysis/LiveVar/BBLiveVar.h
index 79cf7dce07..0eed3375ab 100644
--- a/lib/Analysis/LiveVar/BBLiveVar.h
+++ b/lib/Analysis/LiveVar/BBLiveVar.h
@@ -24,7 +24,7 @@ enum LiveVarDebugLevel_t {
extern LiveVarDebugLevel_t DEBUG_LV;
class BBLiveVar : public Annotation {
- const BasicBlock *BB; // pointer to BasicBlock
+ const BasicBlock &BB; // pointer to BasicBlock
unsigned POID; // Post-Order ID
ValueSet DefSet; // Def set (with no preceding uses) for LV analysis
@@ -49,12 +49,12 @@ class BBLiveVar : public Annotation {
void calcDefUseSets(); // calculates the Def & Use sets for this BB
- BBLiveVar(const BasicBlock *BB, unsigned POID);
+ BBLiveVar(const BasicBlock &BB, unsigned POID);
~BBLiveVar() {} // make dtor private
public:
- static BBLiveVar *CreateOnBB(const BasicBlock *BB, unsigned POID);
- static BBLiveVar *GetFromBB(const BasicBlock *BB);
- static void RemoveFromBB(const BasicBlock *BB);
+ static BBLiveVar *CreateOnBB(const BasicBlock &BB, unsigned POID);
+ static BBLiveVar *GetFromBB(const BasicBlock &BB);
+ static void RemoveFromBB(const BasicBlock &BB);
inline bool isInSetChanged() const { return InSetChanged; }
inline bool isOutSetChanged() const { return OutSetChanged; }
diff --git a/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp b/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp
index 1105640612..ab0a761b73 100644
--- a/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp
+++ b/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp
@@ -33,12 +33,12 @@ static cl::Enum<LiveVarDebugLevel_t> DEBUG_LV_opt(DEBUG_LV, "dlivevar", cl::Hidd
// gets OutSet of a BB
const ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) const {
- return BBLiveVar::GetFromBB(BB)->getOutSet();
+ return BBLiveVar::GetFromBB(*BB)->getOutSet();
}
// gets InSet of a BB
const ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const {
- return BBLiveVar::GetFromBB(BB)->getInSet();
+ return BBLiveVar::GetFromBB(*BB)->getInSet();
}
@@ -46,15 +46,15 @@ const ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const {
// Performs live var analysis for a function
//-----------------------------------------------------------------------------
-bool FunctionLiveVarInfo::runOnFunction(Function *Meth) {
- M = Meth;
+bool FunctionLiveVarInfo::runOnFunction(Function &F) {
+ M = &F;
if (DEBUG_LV) std::cerr << "Analysing live variables ...\n";
// create and initialize all the BBLiveVars of the CFG
- constructBBs(Meth);
+ constructBBs(M);
unsigned int iter=0;
- while (doSingleBackwardPass(Meth, iter++))
+ while (doSingleBackwardPass(M, iter++))
; // Iterate until we are done.
if (DEBUG_LV) std::cerr << "Live Variable Analysis complete!\n";
@@ -71,7 +71,7 @@ void FunctionLiveVarInfo::constructBBs(const Function *M) {
for(po_iterator<const Function*> BBI = po_begin(M), BBE = po_end(M);
BBI != BBE; ++BBI, ++POId) {
- const BasicBlock *BB = *BBI; // get the current BB
+ const BasicBlock &BB = **BBI; // get the current BB
if (DEBUG_LV) std::cerr << " For BB " << RAV(BB) << ":\n";
@@ -105,7 +105,7 @@ bool FunctionLiveVarInfo::doSingleBackwardPass(const Function *M,
bool NeedAnotherIteration = false;
for (po_iterator<const Function*> BBI = po_begin(M), BBE = po_end(M);
BBI != BBE; ++BBI) {
- BBLiveVar *LVBB = BBLiveVar::GetFromBB(*BBI);
+ BBLiveVar *LVBB = BBLiveVar::GetFromBB(**BBI);
assert(LVBB && "BasicBlock information not set for block!");
if (DEBUG_LV) std::cerr << " For BB " << (*BBI)->getName() << ":\n";
diff --git a/lib/Analysis/LiveVar/ValueSet.cpp b/lib/Analysis/LiveVar/ValueSet.cpp
index 82fccb7e84..1914f03302 100644
--- a/lib/Analysis/LiveVar/ValueSet.cpp
+++ b/lib/Analysis/LiveVar/ValueSet.cpp
@@ -6,13 +6,13 @@
#include <iostream>
std::ostream &operator<<(std::ostream &O, RAV V) { // func to print a Value
- const Value *v = V.V;
- if (v->hasName())
- return O << (void*)v << "(" << v->getName() << ") ";
+ const Value &v = V.V;
+ if (v.hasName())
+ return O << (void*)&v << "(" << v.getName() << ") ";
else if (isa<Constant>(v))
- return O << (void*)v << "(" << v << ") ";
+ return O << (void*)&v << "(" << v << ") ";
else
- return O << (void*)v << " ";
+ return O << (void*)&v << " ";
}
void printSet(const ValueSet &S) {
diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp
index 7d43047c0a..fb83e027b0 100644
--- a/lib/Linker/LinkModules.cpp
+++ b/lib/Linker/LinkModules.cpp
@@ -96,20 +96,20 @@ static Value *RemapOperand(const Value *In, map<const Value*, Value*> &LocalMap,
}
// Check to see if it's a constant that we are interesting in transforming...
- if (Constant *CPV = dyn_cast<Constant>(In)) {
+ if (const Constant *CPV = dyn_cast<Constant>(In)) {
if (!isa<DerivedType>(CPV->getType()))
- return CPV; // Simple constants stay identical...
+ return const_cast<Constant*>(CPV); // Simple constants stay identical...
Constant *Result = 0;
- if (ConstantArray *CPA = dyn_cast<ConstantArray>(CPV)) {
+ if (const ConstantArray *CPA = dyn_cast<ConstantArray>(CPV)) {
const std::vector<Use> &Ops = CPA->getValues();
std::vector<Constant*> Operands(Ops.size());
for (unsigned i = 0; i < Ops.size(); ++i)
Operands[i] =
cast<Constant>(RemapOperand(Ops[i], LocalMap, GlobalMap));
Result = ConstantArray::get(cast<ArrayType>(CPA->getType()), Operands);
- } else if (ConstantStruct *CPS = dyn_cast<ConstantStruct>(CPV)) {
+ } else if (const ConstantStruct *CPS = dyn_cast<ConstantStruct>(CPV)) {
const std::vector<Use> &Ops = CPS->getValues();
std::vector<Constant*> Operands(Ops.size());
for (unsigned i = 0; i < Ops.size(); ++i)
@@ -117,8 +117,9 @@ static Value *RemapOperand(const Value *In, map<const Value*, Value*> &LocalMap,
cast<Constant>(RemapOperand(Ops[i], LocalMap, GlobalMap));
Result = ConstantStruct::get(cast<StructType>(CPS->getType()), Operands);
} else if (isa<ConstantPointerNull>(CPV)) {
- Result = CPV;
- } else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(CPV)) {
+ Result = const_cast<Constant*>(CPV);
+ } else if (const ConstantPointerRef *CPR =
+ dyn_cast<ConstantPointerRef>(CPV)) {
Value *V = RemapOperand(CPR->getValue(), LocalMap, GlobalMap);
Result = ConstantPointerRef::get(cast<GlobalValue>(V));
} else {
@@ -126,7 +127,7 @@ static Value *RemapOperand(const Value *In, map<const Value*, Value*> &LocalMap,
}
// Cache the mapping in our local map structure...
- LocalMap.insert(std::make_pair(In, CPV));
+ LocalMap.insert(std::make_pair(In, const_cast<Constant*>(CPV)));
return Result;
}
@@ -158,7 +159,7 @@ static bool LinkGlobals(Module *Dest, const Module *Src,
// Loop over all of the globals in the src module, mapping them over as we go
//
for (Module::const_giterator I = Src->gbegin(), E = Src->gend(); I != E; ++I){
- const GlobalVariable *SGV = *I;
+ const GlobalVariable *SGV = I;
Value *V;
// If the global variable has a name, and that name is already in use in the
@@ -211,7 +212,7 @@ static bool LinkGlobalInits(Module *Dest, const Module *Src,
// Loop over all of the globals in the src module, mapping them over as we go
//
for (Module::const_giterator I = Src->gbegin(), E = Src->gend(); I != E; ++I){
- const GlobalVariable *SGV = *I;
+ const GlobalVariable *SGV = I;
if (SGV->hasInitializer()) { // Only process initialized GV's
// Figure out what the initializer looks like in the dest module...
@@ -249,41 +250,41 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
// go
//
for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
- const Function *SM = *I; // SrcFunction
+ const Function *SF = I; // SrcFunction
Value *V;
// If the function has a name, and that name is already in use in the Dest
// module, make sure that the name is a compatible function...
//
- if (SM->hasExternalLinkage() && SM->hasName() &&
- (V = ST->lookup(SM->getType(), SM->getName())) &&
+ if (SF->hasExternalLinkage() && SF->hasName() &&
+ (V = ST->lookup(SF->getType(), SF->getName())) &&
cast<Function>(V)->hasExternalLinkage()) {
// The same named thing is a Function, because the only two things
// that may be in a module level symbol table are Global Vars and
// Functions, and they both have distinct, nonoverlapping, possible types.
//
- Function *DM = cast<Function>(V); // DestFunction
+ Function *DF = cast<Function>(V); // DestFunction
// Check to make sure the function is not defined in both modules...
- if (!SM->isExternal() && !DM->isExternal())
+ if (!SF->isExternal() && !DF->isExternal())
return Error(Err, "Function '" +
- SM->getFunctionType()->getDescription() + "':\"" +
- SM->getName() + "\" - Function is already defined!");
+ SF->getFunctionType()->getDescription() + "':\"" +
+ SF->getName() + "\" - Function is already defined!");
// Otherwise, just remember this mapping...
- ValueMap.insert(std::make_pair(SM, DM));
+ ValueMap.insert(std::make_pair(SF, DF));
} else {
// Function does not already exist, simply insert an external function
- // signature identical to SM into the dest module...
- Function *DM = new Function(SM->getFunctionType(),
- SM->hasInternalLinkage(),
- SM->getName());
+ // signature identical to SF into the dest module...
+ Function *DF = new Function(SF->getFunctionType(),
+ SF->hasInternalLinkage(),
+ SF->getName());
// Add the function signature to the dest module...
- Dest->getFunctionList().push_back(DM);
+ Dest->getFunctionList().push_back(DF);
// ... and remember this mapping...
- ValueMap.insert(std::make_pair(SM, DM));
+ ValueMap.insert(std::make_pair(SF, DF));
}
}
return false;
@@ -300,27 +301,22 @@ static bool LinkFunctionBody(Function *Dest, const Function *Src,
map<const Value*, Value*> LocalMap; // Map for function local values
// Go through and convert function arguments over...
- for (Function::ArgumentListType::const_iterator
- I = Src->getArgumentList().begin(),
- E = Src->getArgumentList().end(); I != E; ++I) {
- const Argument *SMA = *I;
-
+ for (Function::const_aiterator I = Src->abegin(), E = Src->aend();
+ I != E; ++I) {
// Create the new function argument and add to the dest function...
- Argument *DMA = new Argument(SMA->getType(), SMA->getName());
- Dest->getArgumentList().push_back(DMA);
+ Argument *DFA = new Argument(I->getType(), I->getName());
+ Dest->getArgumentList().push_back(DFA);
// Add a mapping to our local map
- LocalMap.insert(std::make_pair(SMA, DMA));
+ LocalMap.insert(std::make_pair(I, DFA));
}
// Loop over all of the basic blocks, copying the instructions over...
//
for (Function::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
- const BasicBlock *SBB = *I;
-
// Create new basic block and add to mapping and the Dest function...
- BasicBlock *DBB = new BasicBlock(SBB->getName(), Dest);
- LocalMap.insert(std::make_pair(SBB, DBB));
+ BasicBlock *DBB = new BasicBlock(I->getName(), Dest);
+ LocalMap.insert(std::make_pair(I, DBB));
// Loop over all of the instructions in the src basic block, copying them
// over. Note that this is broken in a strict sense because the cloned
@@ -328,13 +324,12 @@ static bool LinkFunctionBody(Function *Dest, const Function *Src,
// the remapped values. In our case, however, we will not get caught and
// so we can delay patching the values up until later...
//
- for (BasicBlock::const_iterator II = SBB->begin(), IE = SBB->end();
+ for (BasicBlock::const_iterator II = I->begin(), IE = I->end();
II != IE; ++II) {
- const Instruction *SI = *II;
- Instruction *DI = SI->clone();
- DI->setName(SI->getName());
+ Instruction *DI = II->clone();
+ DI->setName(II->getName());
DBB->getInstList().push_back(DI);
- LocalMap.insert(std::make_pair(SI, DI));
+ LocalMap.insert(std::make_pair(II, DI));
}
}
@@ -343,17 +338,11 @@ static bool LinkFunctionBody(Function *Dest, const Function *Src,
// the Source function as operands. Loop through all of the operands of the
// functions and patch them up to point to the local versions...
//
- for (Function::iterator BI = Dest->begin(), BE = Dest->end();
- BI != BE; ++BI) {
- BasicBlock *BB = *BI;
- for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) {
- Instruction *Inst = *I;
-
- for (Instruction::op_iterator OI = Inst->op_begin(), OE = Inst->op_end();
+ for (Function::iterator BB = Dest->begin(), BE = Dest->end(); BB != BE; ++BB)
+ for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
+ for (Instruction::op_iterator OI = I->op_begin(), OE = I->op_end();
OI != OE; ++OI)
*OI = RemapOperand(*OI, LocalMap, &GlobalMap);
- }
- }
return false;
}
@@ -370,20 +359,19 @@ static bool LinkFunctionBodies(Module *Dest, const Module *Src,
// Loop over all of the functions in the src module, mapping them over as we
// go
//
- for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
- const Function *SM = *I; // Source Function
- if (!SM->isExternal()) { // No body if function is external
- Function *DM = cast<Function>(ValueMap[SM]); // Destination function
+ for (Module::const_iterator SF = Src->begin(), E = Src->end(); SF != E; ++SF){
+ if (!SF->isExternal()) { // No body if function is external
+ Function *DF = cast<Function>(ValueMap[SF]); // Destination function
- // DM not external SM external?
- if (!DM->isExternal()) {
+ // DF not external SF external?
+ if (!DF->isExternal()) {
if (Err)
- *Err = "Function '" + (SM->hasName() ? SM->getName() : string("")) +
+ *Err = "Function '" + (SF->hasName() ? SF->getName() : string("")) +
"' body multiply defined!";
return true;
}
- if (LinkFunctionBody(DM, SM, ValueMap, Err)) return true;
+ if (LinkFunctionBody(DF, SF, ValueMap, Err)) return true;
}
}
return false;
diff --git a/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp b/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp
index 7d735b79e4..eb58671a79 100644
--- a/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp
+++ b/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp
@@ -18,23 +18,23 @@ using std::cerr;
static AnnotationID AID(AnnotationManager::getID("Analysis::BBLiveVar"));
-BBLiveVar *BBLiveVar::CreateOnBB(const BasicBlock *BB, unsigned POID) {
+BBLiveVar *BBLiveVar::CreateOnBB(const BasicBlock &BB, unsigned POID) {
BBLiveVar *Result = new BBLiveVar(BB, POID);
- BB->addAnnotation(Result);
+ BB.addAnnotation(Result);
return Result;
}
-BBLiveVar *BBLiveVar::GetFromBB(const BasicBlock *BB) {
- return (BBLiveVar*)BB->getAnnotation(AID);
+BBLiveVar *BBLiveVar::GetFromBB(const BasicBlock &BB) {
+ return (BBLiveVar*)BB.getAnnotation(AID);
}
-void BBLiveVar::RemoveFromBB(const BasicBlock *BB) {
- bool Deleted = BB->deleteAnnotation(AID);
+void BBLiveVar::RemoveFromBB(const BasicBlock &BB) {
+ bool Deleted = BB.deleteAnnotation(AID);
assert(Deleted && "BBLiveVar annotation did not exist!");
}
-BBLiveVar::BBLiveVar(const BasicBlock *bb, unsigned id)
+BBLiveVar::BBLiveVar(const BasicBlock &bb, unsigned id)
: Annotation(AID), BB(bb), POID(id) {
InSetChanged = OutSetChanged = false;
@@ -50,7 +50,7 @@ BBLiveVar::BBLiveVar(const BasicBlock *bb, unsigned id)
void BBLiveVar::calcDefUseSets() {
// get the iterator for machine instructions
- const MachineCodeForBasicBlock &MIVec = BB->getMachineInstrVec();
+ const MachineCodeForBasicBlock &MIVec = BB.getMachineInstrVec();
// iterate over all the machine instructions in BB
for (MachineCodeForBasicBlock::const_reverse_iterator MII = MIVec.rbegin(),
@@ -129,7 +129,7 @@ void BBLiveVar::calcDefUseSets() {
//-----------------------------------------------------------------------------
// To add an operand which is a def
//-----------------------------------------------------------------------------
-void BBLiveVar::addDef(const Value *Op) {
+void BBLiveVar::addDef(const Value *Op) {
DefSet.insert(Op); // operand is a def - so add to def set
InSet.erase(Op); // this definition kills any later uses
InSetChanged = true;
@@ -211,9 +211,9 @@ bool BBLiveVar::applyFlowFunc() {
//
bool needAnotherIt = false;
- for (pred_const_iterator PI = pred_begin(BB), PE = pred_end(BB);
+ for (pred_const_iterator PI = pred_begin(&BB), PE = pred_end(&BB);
PI != PE ; ++PI) {
- BBLiveVar *PredLVBB = BBLiveVar::GetFromBB(*PI);
+ BBLiveVar *PredLVBB = BBLiveVar::GetFromBB(**PI);
// do set union
if (setPropagate(&PredLVBB->OutSet, &InSet, *PI)) {
diff --git a/lib/Target/SparcV9/LiveVar/BBLiveVar.h b/lib/Target/SparcV9/LiveVar/BBLiveVar.h
index 79cf7dce07..0eed3375ab 100644
--- a/lib/Target/SparcV9/LiveVar/BBLiveVar.h
+++ b/lib/Target/SparcV9/LiveVar/BBLiveVar.h
@@ -24,7 +24,7 @@ enum LiveVarDebugLevel_t {
extern LiveVarDebugLevel_t DEBUG_LV;
class BBLiveVar : public Annotation {
- const BasicBlock *BB; // pointer to BasicBlock
+ const BasicBlock &BB; // pointer to BasicBlock
unsigned POID; // Post-Order ID
ValueSet DefSet; // Def set (with no preceding uses) for LV analysis
@@ -49,12 +49,12 @@ class BBLiveVar : public Annotation {
void calcDefUseSets(); // calculates the Def & Use sets for this BB
- BBLiveVar(const BasicBlock *BB, unsigned POID);
+ BBLiveVar(const BasicBlock &BB, unsigned POID);
~BBLiveVar() {} // make dtor private
public:
- static BBLiveVar *CreateOnBB(const BasicBlock *BB, unsigned POID);
- static BBLiveVar *GetFromBB(const BasicBlock *BB);
- static void RemoveFromBB(const BasicBlock *BB);
+ static BBLiveVar *CreateOnBB(const BasicBlock &BB, unsigned POID);
+ static BBLiveVar *GetFromBB(const BasicBlock &BB);
+ static void RemoveFromBB(const BasicBlock &BB);
inline bool isInSetChanged() const { return InSetChanged; }
inline bool isOutSetChanged() const { return OutSetChanged; }
diff --git a/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp b/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp
index 1105640612..ab0a761b73 100644
--- a/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp
+++ b/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp
@@ -33,12 +33,12 @@ static cl::Enum<LiveVarDebugLevel_t> DEBUG_LV_opt(DEBUG_LV, "dlivevar", cl::Hidd
// gets OutSet of a BB
const ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) const {
- return BBLiveVar::GetFromBB(BB)->getOutSet();
+ return BBLiveVar::GetFromBB(*BB)->getOutSet();
}
// gets InSet of a BB
const ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const {
- return BBLiveVar::GetFromBB(BB)->getInSet();
+ return BBLiveVar::GetFromBB(*BB)->getInSet();
}
@@ -46,15 +46,15 @@ const ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const {
// Performs live var analysis for a function
//-----------------------------------------------------------------------------
-bool FunctionLiveVarInfo::runOnFunction(Function *Meth) {
- M = Meth;
+bool FunctionLiveVarInfo::runOnFunction(Function &F) {
+ M = &F;
if (DEBUG_LV) std::cerr << "Analysing live variables ...\n";
// create and initialize all the BBLiveVars of the CFG
- constructBBs(Meth);
+ constructBBs(M);
unsigned int iter=0;
- while (doSingleBackwardPass(Meth, iter++))
+ while (doSingleBackwardPass(M, iter++))
; // Iterate until we are done.
if (DEBUG_LV) std::cerr << "Live Variable Analysis complete!\n";
@@ -71,7 +71,7 @@ void FunctionLiveVarInfo::constructBBs(const Function *M) {
for(po_iterator<const Function*> BBI = po_begin(M), BBE = po_end(M);
BBI != BBE; ++BBI, ++POId) {
- const BasicBlock *BB = *BBI; // get the current BB
+ const BasicBlock &BB = **BBI; // get the current BB
if (DEBUG_LV) std::cerr << " For BB " << RAV(BB) << ":\n";
@@ -105,7 +105,7 @@ bool FunctionLiveVarInfo::doSingleBackwardPass(const Function *M,
bool NeedAnotherIteration = false;
for (po_iterator<const Function*> BBI = po_begin(M), BBE = po_end(M);
BBI != BBE; ++BBI) {
- BBLiveVar *LVBB = BBLiveVar::GetFromBB(*BBI);
+ BBLiveVar *LVBB = BBLiveVar::GetFromBB(**BBI);
assert(LVBB && "BasicBlock information not set for block!");
if (DEBUG_LV) std::cerr << " For BB " << (*BBI)->getName() << ":\n";
diff --git a/lib/Target/SparcV9/LiveVar/ValueSet.cpp b/lib/Target/SparcV9/LiveVar/ValueSet.cpp
index 82fccb7e84..1914f03302 100644
--- a/lib/Target/SparcV9/LiveVar/ValueSet.cpp
+++ b/lib/Target/SparcV9/LiveVar/ValueSet.cpp
@@ -6,13 +6,13 @@
#include <iostream>
std::ostream &operator<<(std::ostream &O, RAV V) { // func to print a Value
- const Value *v = V.V;
- if (v->hasName())
- return O << (void*)v << "(" << v->getName() << ") ";
+ const Value &v = V.V;
+ if (v.hasName())
+ return O << (void*)&v << "(" << v.getName() << ") ";
else if (isa<Constant>(v))
- return O << (void*)v << "(" << v << ") ";
+ return O << (void*)&v << "(" << v << ") ";
else
- return O << (void*)v << " ";
+ return O << (void*)&v << " ";
}
void printSet(const ValueSet &S) {
diff --git a/lib/Transforms/Utils/BasicBlockUtils.cpp b/lib/Transforms/Utils/BasicBlockUtils.cpp
index 89078a12e9..aea0b94e10 100644
--- a/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -15,19 +15,18 @@
//
void ReplaceInstWithValue(BasicBlock::InstListType &BIL,
BasicBlock::iterator &BI, Value *V) {
- Instruction *I = *BI;
+ Instruction &I = *BI;
// Replaces all of the uses of the instruction with uses of the value
- I->replaceAllUsesWith(V);
+ I.replaceAllUsesWith(V);
- // Remove the unneccesary instruction now...
- BIL.remove(BI);
+ std::string OldName = I.getName();
+
+ // Delete the unneccesary instruction now...
+ BI = BIL.erase(BI);
// Make sure to propogate a name if there is one already...
- if (I->hasName() && !V->hasName())
- V->setName(I->getName(), BIL.getParent()->getSymbolTable());
-
- // Remove the dead instruction now...
- delete I;
+ if (OldName.size() && !V->hasName())
+ V->setName(OldName, BIL.getParent()->getSymbolTable());
}
@@ -41,13 +40,13 @@ void ReplaceInstWithInst(BasicBlock::InstListType &BIL,
"ReplaceInstWithInst: Instruction already inserted into basic block!");
// Insert the new instruction into the basic block...
- BI = BIL.insert(BI, I)+1; // Increment BI to point to instruction to delete
+ BasicBlock::iterator New = BIL.insert(BI, I);
// Replace all uses of the old instruction, and delete it.
ReplaceInstWithValue(BIL, BI, I);
// Move BI back to point to the newly inserted instruction
- --BI;
+ BI = New;
}
// ReplaceInstWithInst - Replace the instruction specified by From with the
@@ -56,24 +55,6 @@ void ReplaceInstWithInst(BasicBlock::InstListType &BIL,
// for the instruction.
//
void ReplaceInstWithInst(Instruction *From, Instruction *To) {
- BasicBlock *BB = From->getParent();
- BasicBlock::InstListType &BIL = BB->getInstList();
- BasicBlock::iterator BI = find(BIL.begin(), BIL.end(), From);
- assert(BI != BIL.end() && "Inst not in it's parents BB!");
- ReplaceInstWithInst(BIL, BI, To);
+ BasicBlock::iterator BI(From);
+ ReplaceInstWithInst(From->getParent()->getInstList(), BI, 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) {
- BasicBlock *BB = Existing->getParent();
- BasicBlock::InstListType &BIL = BB->getInstList();
- BasicBlock::iterator BI = find(BIL.begin(), BIL.end(), Existing);
- assert(BI != BIL.end() && "Inst not in it's parents BB!");
- return BIL.insert(BI, NewInst);
-}
-
diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp
index 6b1b24ac57..6bf7553e75 100644
--- a/lib/Transforms/Utils/CloneFunction.cpp
+++ b/lib/Transforms/Utils/CloneFunction.cpp
@@ -36,10 +36,9 @@ static inline void RemapInstruction(Instruction *I,
//
void CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
const std::vector<Value*> &ArgMap) {
- assert(OldFunc->getArgumentList().empty() ||
- !NewFunc->getArgumentList().empty() &&
+ assert(OldFunc->aempty() || !NewFunc->aempty() &&
"Synthesization of arguments is not implemented yet!");
- assert(OldFunc->getArgumentList().size() == ArgMap.size() &&
+ assert(OldFunc->asize() == ArgMap.size() &&
"Improper number of argument values to map specified!");
// Keep a mapping between the original function's values and the new
@@ -49,8 +48,10 @@ void CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
std::map<const Value *, Value*> ValueMap;
// Add all of the function arguments to the mapping...
- for (unsigned i = 0, e = ArgMap.size(); i != e; ++i)
- ValueMap[(Value*)OldFunc->getArgumentList()[i]] = ArgMap[i];
+ unsigned i = 0;
+ for (Function::const_aiterator I = OldFunc->abegin(), E = OldFunc->aend();
+ I != E; ++I, ++i)
+ ValueMap[I] = ArgMap[i];
// Loop over all of the basic blocks in the function, cloning them as
@@ -58,33 +59,32 @@ void CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
//
for (Function::const_iterator BI = OldFunc->begin(), BE = OldFunc->end();
BI != BE; ++BI) {
- const BasicBlock *BB = *BI;
- assert(BB->getTerminator() && "BasicBlock doesn't have terminator!?!?");
+ const BasicBlock &BB = *BI;
+ assert(BB.getTerminator() && "BasicBlock doesn't have terminator!?!?");
// Create a new basic block to copy instructions into!
- BasicBlock *CBB = new BasicBlock(BB->getName(), NewFunc);
- ValueMap[BB] = CBB; // Add basic block mapping.
+ BasicBlock *CBB = new BasicBlock(BB.getName(), NewFunc);
+ ValueMap[&BB] = CBB; // Add basic block mapping.
// Loop over all instructions copying them over...
- for (BasicBlock::const_iterator II = BB->begin(), IE = BB->end();
+ for (BasicBlock::const_iterator II = BB.begin(), IE = BB.end();
II != IE; ++II) {
- Instruction *NewInst = (*II)->clone();
- NewInst->setName((*II)->getName()); // Name is not cloned...
+ Instruction *NewInst = II->clone();
+ NewInst->setName(II->getName()); // Name is not cloned...
CBB->getInstList().push_back(NewInst);
- ValueMap[*II] = NewInst; // Add instruction map to value.
+ ValueMap[II] = NewInst; // Add instruction map to value.
}
}
// Loop over all of the instructions in the function, fixing up operand
// references as we go. This uses ValueMap to do all the hard work.
//
- for (Function::const_iterator BI = OldFunc->begin(), BE = OldFunc->end();
- BI != BE; ++BI) {
- const BasicBlock *BB = *BI;
+ for (Function::const_iterator BB = OldFunc->begin(), BE = OldFunc->end();
+ BB != BE; ++BB) {
BasicBlock *NBB = cast<BasicBlock>(ValueMap[BB]);
// Loop over all instructions, fixing each one as we find it...
- for (BasicBlock::iterator II = NBB->begin(); II != NBB->end(); II++)
- RemapInstruction(*II, ValueMap);
+ for (BasicBlock::iterator II = NBB->begin(); II != NBB->end(); ++II)
+ RemapInstruction(II, ValueMap);
}
}
diff --git a/lib/Transforms/Utils/Linker.cpp b/lib/Transforms/Utils/Linker.cpp
index 7d43047c0a..fb83e027b0 100644
--- a/lib/Transforms/Utils/Linker.cpp
+++ b/lib/Transforms/Utils/Linker.cpp
@@ -96,20 +96,20 @@ static Value *RemapOperand(const Value *In, map<const Value*, Value*> &LocalMap,
}
// Check to see if it's a constant that we are interesting in transforming...
- if (Constant *CPV = dyn_cast<Constant>(In)) {
+ if (const Constant *CPV = dyn_cast<Constant>(In)) {
if (!isa<DerivedType>(CPV->getType()))
- return CPV; // Simple constants stay identical...
+ return const_cast<Constant*>(CPV); // Simple constants stay identical...
Constant *Result = 0;
- if (ConstantArray *CPA = dyn_cast<ConstantArray>(CPV)) {
+ if (const ConstantArray *CPA = dyn_cast<ConstantArray>(CPV)) {
const std::vector<Use> &Ops = CPA->getValues();
std::vector<Constant*> Operands(Ops.size());
for (unsigned i = 0; i < Ops.size(); ++i)
Operands[i] =
cast<Constant>(RemapOperand(Ops[i], LocalMap, GlobalMap));
Result = ConstantArray::get(cast<ArrayType>(CPA->getType()), Operands);
- } else if (ConstantStruct *CPS = dyn_cast<ConstantStruct>(CPV)) {
+ } else if (const ConstantStruct *CPS = dyn_cast<ConstantStruct>(CPV)) {
const std::vector<Use> &Ops = CPS->getValues();
std::vector<Constant*> Operands(Ops.size());
for (unsigned i = 0; i < Ops.size(); ++i)
@@ -117,8 +117,9 @@ static Value *RemapOperand(const Value *In, map<const Value*, Value*> &LocalMap,
cast<Constant>(RemapOperand(Ops[i], LocalMap, GlobalMap));
Result = ConstantStruct::get(cast<StructType>(CPS->getType()), Operands);
} else if (isa<ConstantPointerNull>(CPV)) {
- Result = CPV;
- } else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(CPV)) {
+ Result = const_cast<Constant*>(CPV);
+ } else if (const ConstantPointerRef *CPR =
+ dyn_cast<ConstantPointerRef>(CPV)) {
Value *V = RemapOperand(CPR->getValue(), LocalMap, GlobalMap);
Result = ConstantPointerRef::get(cast<GlobalValue>(V));
} else {
@@ -126,7 +127,7 @@ static Value *RemapOperand(const Value *In, map<const Value*, Value*> &LocalMap,
}
// Cache the mapping in our local map structure...
- LocalMap.insert(std::make_pair(In, CPV));
+ LocalMap.insert(std::make_pair(In, const_cast<Constant*>(CPV)));
return Result;
}
@@ -158,7 +159,7 @@ static bool LinkGlobals(Module *Dest, const Module *Src,
// Loop over all of the globals in the src module, mapping them over as we go
//
for (Module::const_giterator I = Src->gbegin(), E = Src->gend(); I != E; ++I){
- const GlobalVariable *SGV = *I;
+ const GlobalVariable *SGV = I;
Value *V;
// If the global variable has a name, and that name is already in use in the
@@ -211,7 +212,7 @@ static bool LinkGlobalInits(Module *Dest, const Module *Src,
// Loop over all of the globals in the src module, mapping them over as we go
//
for (Module::const_giterator I = Src->gbegin(), E = Src->gend(); I != E; ++I){
- const GlobalVariable *SGV = *I;
+ const GlobalVariable *SGV = I;
if (SGV->hasInitializer()) { // Only process initialized GV's
// Figure out what the initializer looks like in the dest module...
@@ -249,41 +250,41 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
// go
//
for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
- const Function *SM = *I; // SrcFunction
+ const Function *SF = I; // SrcFunction
Value *V;
// If the function has a name, and that name is already in use in the Dest
// module, make sure that the name is a compatible function...
//
- if (SM->hasExternalLinkage() && SM->hasName() &&
- (V = ST->lookup(SM->getType(), SM->getName())) &&
+ if (SF->hasExternalLinkage() && SF->hasName() &&
+ (V = ST->lookup(SF->getType(), SF->getName())) &&
cast<Function>(V)->hasExternalLinkage()) {
// The same named thing is a Function, because the only two things
// that may be in a module level symbol table are Global Vars and
// Functions, and they both have distinct, nonoverlapping, possible types.
//
- Function *DM = cast<Function>(V); // DestFunction
+ Function *DF = cast<Function>(V); // DestFunction
// Check to make sure the function is not defined in both modules...
- if (!SM->isExternal() && !DM->isExternal())
+ if (!SF->isExternal() && !DF->isExternal())
return Error(Err, "Function '" +
- SM->getFunctionType()->getDescription() + "':\"" +
- SM->getName() + "\" - Function is already defined!");
+ SF->getFunctionType()->getDescription() + "':\"" +
+ SF->getName() + "\" - Function is already defined!");
// Otherwise, just remember this mapping...
- ValueMap.insert(std::make_pair(SM, DM));
+ ValueMap.insert(std::make_pair(SF, DF));
} else {
// Function does not already exist, simply insert an external function
- // signature identical to SM into the dest module...
- Function *DM = new Function(SM->getFunctionType(),
- SM->hasInternalLinkage(),
- SM->getName());
+ // signature identical to SF into the dest module...
+ Function *DF = new Function(SF->getFunctionType(),
+ SF->hasInternalLinkage(),
+ SF->getName());
// Add the function signature to the dest module...
- Dest->getFunctionList().push_back(DM);
+ Dest->getFunctionList().push_back(DF);
// ... and remember this mapping...
- ValueMap.insert(std::make_pair(SM, DM));
+ ValueMap.insert(std::make_pair(SF, DF));
}
}
return false;
@@ -300,27 +301,22 @@ static bool LinkFunctionBody(Function *Dest, const Function *Src,
map<const Value*, Value*> LocalMap; // Map for function local values
// Go through and convert function arguments over...
- for (Function::ArgumentListType::const_iterator
- I = Src->getArgumentList().begin(),
- E = Src->getArgumentList().end(); I != E; ++I) {
- const Argument *SMA = *I;
-
+ for (Function::const_aiterator I = Src->abegin(), E = Src->aend();
+ I != E; ++I) {
// Create the new function argument and add to the dest function...
- Argument *DMA = new Argument(SMA->getType(), SMA->getName());
- Dest->getArgumentList().push_back(DMA);
+ Argument *DFA = new Argument(I->getType(), I->getName());
+ Dest->getArgumentList().push_back(DFA);
// Add a mapping to our local map
- LocalMap.insert(std::make_pair(SMA, DMA));
+ LocalMap.insert(std::make_pair(I, DFA));
}
// Loop over all of the basic blocks, copying the instructions over...
//
for (Function::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
- const BasicBlock *SBB = *I;
-
// Create new basic block and add to mapping and the Dest function...
- BasicBlock *DBB = new BasicBlock(SBB->getName(), Dest);
- LocalMap.insert(std::make_pair(SBB, DBB));
+ BasicBlock *DBB = new BasicBlock(I->getName(), Dest);
+ LocalMap.insert(std::make_pair(I, DBB));
// Loop over all of the instructions in the src basic block, copying them
// over. Note that this is broken in a strict sense because the cloned
@@ -328,13 +324,12 @@ static bool LinkFunctionBody(Function *Dest, const Function *Src,
// the remapped values. In our case, however, we will not get caught and
// so we can delay patching the values up until later...
//
- for (BasicBlock::const_iterator II = SBB->begin(), IE = SBB->end();
+ for (BasicBlock::const_iterator II = I->begin(), IE = I->end();
II != IE; ++II) {
- const Instruction *SI = *II;
- Instruction *DI = SI->clone();
- DI->setName(SI->getName());
+ Instruction *DI = II->clone();
+ DI->setName(II->getName());
DBB->getInstList().push_back(DI);
- LocalMap.insert(std::make_pair(SI, DI));
+ LocalMap.insert(std::make_pair(II, DI));
}
}
@@ -343,17 +338,11 @@ static bool LinkFunctionBody(Function *Dest, const Function *Src,
// the Source function as operands. Loop through all of the operands of the
// functions and patch them up to point to the local versions...
//
- for (Function::iterator BI = Dest->begin(), BE = Dest->end();
- BI != BE; ++BI) {
- BasicBlock *BB = *BI;
- for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) {
- Instruction *Inst = *I;
-
- for (Instruction::op_iterator OI = Inst->op_begin(), OE = Inst->op_end();
+ for (Function::iterator BB = Dest->begin(), BE = Dest->end(); BB != BE; ++BB)
+ for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
+ for (Instruction::op_iterator OI = I->op_begin(), OE = I->op_end();
OI != OE; ++OI)
*OI = RemapOperand(*OI, LocalMap, &GlobalMap);
- }
- }
return false;
}
@@ -370,20 +359,19 @@ static bool LinkFunctionBodies(Module *Dest, const Module *Src,
// Loop over all of the functions in the src module, mapping them over as we
// go
//
- for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
- const Function *SM = *I; // Source Function
- if (!SM->isExternal()) { // No body if function is external
- Function *DM = cast<Function>(ValueMap[SM]); // Destination function
+ for (Module::const_iterator SF = Src->begin(), E = Src->end(); SF != E; ++SF){
+ if (!SF->isExternal()) { // No body if function is external
+ Function *DF = cast<Function>(ValueMap[SF]); // Destination function
- // DM not external SM external?
- if (!DM->isExternal()) {
+ // DF not external SF external?
+ if (!DF->isExternal()) {
if (Err)
- *Err = "Function '" + (SM->hasName() ? SM->getName() : string("")) +
+ *Err = "Function '" + (SF->hasName() ? SF->getName() : string("")) +
"' body multiply defined!";
return true;
}
- if (LinkFunctionBody(DM, SM, ValueMap, Err)) return true;
+ if (LinkFunctionBody(DF, SF, ValueMap, Err)) return true;
}
}
return false;
diff --git a/lib/Transforms/Utils/Local.cpp b/lib/Transforms/Utils/Local.cpp
index cc152c6c09..10028bacec 100644
--- a/lib/Transforms/Utils/Local.cpp
+++ b/lib/Transforms/Utils/Local.cpp
@@ -17,13 +17,12 @@
// them together...
//
bool doConstantPropogation(BasicBlock::iterator &II) {
- Instruction *Inst = *II;
- if (Constant *C = ConstantFoldInstruction(Inst)) {
+ if (Constant *C = ConstantFoldInstruction(II)) {
// Replaces all of the uses of a variable with uses of the constant.
- Inst->replaceAllUsesWith(C);
+ II->replaceAllUsesWith(C);
// Remove the instruction from the basic block...
- delete Inst->getParent()->getInstList().remove(II);
+ II = II->getParent()->getInstList().erase(II);
return true;
}
@@ -102,9 +101,8 @@ bool isInstructionTriviallyDead(Instruction *I) {
//
bool dceInstruction(BasicBlock::iterator &BBI) {
// Look for un"used" definitions...
- Instruction *I = *BBI;
- if (isInstructionTriviallyDead(I)) {
- delete I->getParent()->getInstList().remove(BBI); // Bye bye
+ if (isInstructionTriviallyDead(BBI)) {
+ BBI = BBI->getParent()->getInstList().erase(BBI); // Bye bye
return true;
}
return false;
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp
index 00a02dc61a..426d18ec9f 100644
--- a/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -46,7 +46,7 @@ static bool PropogatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ) {
// Loop over all of the PHI nodes in the successor BB
for (BasicBlock::iterator I = Succ->begin();
- PHINode *PN = dyn_cast<PHINode>(*I); ++I) {
+ PHINode *PN = dyn_cast<PHINode>(&*I); ++I) {
Value *OldVal = PN->removeIncomingValue(BB);
assert(OldVal && "No entry in PHI for Pred BB!");
@@ -69,13 +69,12 @@ static bool PropogatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ) {
//
// WARNING: The entry node of a function may not be simplified.
//
-bool SimplifyCFG(Function::iterator &BBIt) {
- BasicBlock *BB = *BBIt;
+bool SimplifyCFG(BasicBlock *BB) {
Function *M = BB->getParent();
assert(BB && BB->getParent() && "Block not embedded in function!");
assert(BB->getTerminator() && "Degenerate basic block encountered!");
- assert(BB->getParent()->front() != BB && "Can't Simplify entry block!");
+ assert(&BB->getParent()->front() != BB && "Can't Simplify entry block!");
// Remove basic blocks that have no predecessors... which are unreachable.
@@ -89,20 +88,20 @@ bool SimplifyCFG(Function::iterator &BBIt) {
std::bind2nd(std::mem_fun(&BasicBlock::removePredecessor), BB));
while (!BB->empty()) {
- Instruction *I = BB->back();
+ Instruction &I = BB->back();
// If this instruction is used, replace uses with an arbitrary
// constant value. Because control flow can't get here, we don't care
// what we replace the value with. Note that since this block is
// unreachable, and all values contained within it must dominate their
// uses, that all uses will eventually be removed.
- if (!I->use_empty())
+ if (!I.use_empty())
// Make all users of this instruction reference the constant instead
- I->replaceAllUsesWith(Constant::getNullValue(I->getType()));
+ I.replaceAllUsesWith(Constant::getNullValue(I.getType()));
// Remove the instruction from the basic block
- delete BB->getInstList().pop_back();
+ BB->getInstList().pop_back();
}
- delete M->getBasicBlocks().remove(BBIt);
+ M->getBasicBlockList().erase(BB);
return true;
}
@@ -110,7 +109,7 @@ bool SimplifyCFG(Function::iterator &BBIt) {
// successor. If so, replace block references with successor.
succ_iterator SI(succ_begin(BB));
if (SI != succ_end(BB) && ++SI == succ_end(BB)) { // One succ?
- if (BB->front()->isTerminator()) { // Terminator is the only instruction!
+ if (BB->front().isTerminator()) { // Terminator is the only instruction!
BasicBlock *Succ = *succ_begin(BB); // There is exactly one successor
if (Succ != BB) { // Arg, don't hurt infinite loops!
@@ -125,11 +124,13 @@ bool SimplifyCFG(Function::iterator &BBIt) {
//cerr << "Killing Trivial BB: \n" << BB;
BB->replaceAllUsesWith(Succ);
- BB = M->getBasicBlocks().remove(BBIt);
+ std::string OldName = BB->getName();
+
+ // Delete the old basic block...
+ M->getBasicBlockList().erase(BB);
- if (BB->hasName() && !Succ->hasName()) // Transfer name if we can
- Succ->setName(BB->getName());
- delete BB; // Delete basic block
+ if (!OldName.empty() && !Succ->hasName()) // Transfer name if we can
+ Succ->setName(OldName);
//cerr << "Function after removal: \n" << M;
return true;
@@ -168,28 +169,24 @@ bool SimplifyCFG(Function::iterator &BBIt) {
TerminatorInst *Term = OnlyPred->getTerminator();
// Delete the unconditional branch from the predecessor...
- BasicBlock::iterator DI = OnlyPred->end();
- delete OnlyPred->getInstList().remove(--DI); // Destroy branch
+ OnlyPred->getInstList().pop_back();
// Move all definitions in the succecessor to the predecessor...
- std::vector<Instruction*> Insts(BB->begin(), BB->end());
- BB->getInstList().remove(BB->begin(), BB->end());
- OnlyPred->getInstList().insert(OnlyPred->end(),
- Insts.begin(), Insts.end());
-
- // Remove basic block from the function... and advance iterator to the
- // next valid block...
- M->getBasicBlocks().remove(BBIt);
-
+ OnlyPred->getInstList().splice(OnlyPred->end(), BB->getInstList());
+
// Make all PHI nodes that refered to BB now refer to Pred as their
// source...
BB->replaceAllUsesWith(OnlyPred);
-
+
+ std::string OldName = BB->getName();
+
+ // Erase basic block from the function...
+ M->getBasicBlockList().erase(BB);
+
// Inherit predecessors name if it exists...
- if (BB->hasName() && !OnlyPred->hasName())
- OnlyPred->setName(BB->getName());
+ if (!OldName.empty() && !OnlyPred->hasName())
+ OnlyPred->setName(OldName);
- delete BB; // You ARE the weakest link... goodbye
return true;
}
}
diff --git a/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp b/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
index 64ae2e3ed5..9a65fcecf4 100644
--- a/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
+++ b/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
@@ -24,14 +24,14 @@ AnalysisID UnifyFunctionExitNodes::ID(AnalysisID::create<UnifyFunctionExitNodes>
//
// If there are no return stmts in the Function, a null pointer is returned.
//
-bool UnifyFunctionExitNodes::runOnFunction(Function *M) {
+bool UnifyFunctionExitNodes::runOnFunction(Function &F) {
// Loop over all of the blocks in a function, tracking all of the blocks that
// return.
//
vector<BasicBlock*> ReturningBlocks;
- for(Function::iterator I = M->begin(), E = M->end(); I != E; ++I)
- if (isa<ReturnInst>((*I)->getTerminator()))
- ReturningBlocks.push_back(*I);
+ for(Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
+ if (isa<ReturnInst>(I->getTerminator()))
+ ReturningBlocks.push_back(I);
if (ReturningBlocks.empty()) {
ExitNode = 0;
@@ -45,11 +45,11 @@ bool UnifyFunctionExitNodes::runOnFunction(Function *M) {
// node (if the function returns a value), and convert all of the return
// instructions into unconditional branches.
//
- BasicBlock *NewRetBlock = new BasicBlock("UnifiedExitNode", M);
+ BasicBlock *NewRetBlock = new BasicBlock("UnifiedExitNode", &F);
- if (M->getReturnType() != Type::VoidTy) {
+ if (F.getReturnType() != Type::VoidTy) {
// If the function doesn't return void... add a PHI node to the block...
- PHINode *PN = new PHINode(M->getReturnType(), "UnifiedRetVal");
+ PHINode *PN = new PHINode(F.getReturnType(), "UnifiedRetVal");
NewRetBlock->getInstList().push_back(PN);
// Add an incoming element to the PHI node for every return instruction that
@@ -70,7 +70,7 @@ bool UnifyFunctionExitNodes::runOnFunction(Function *M) {
//
for (vector<BasicBlock*>::iterator I = ReturningBlocks.begin(),
E = ReturningBlocks.end(); I != E; ++I) {
- delete (*I)->getInstList().pop_back(); // Remove the return insn
+ (*I)->getInstList().pop_back(); // Remove the return insn
(*I)->getInstList().push_back(new BranchInst(NewRetBlock));
}
ExitNode = NewRetBlock;
diff --git a/lib/VMCore/Linker.cpp b/lib/VMCore/Linker.cpp
index 7d43047c0a..fb83e027b0 100644
--- a/lib/VMCore/Linker.cpp
+++ b/lib/VMCore/Linker.cpp
@@ -96,20 +96,20 @@ static Value *RemapOperand(const Value *In, map<const Value*, Value*> &LocalMap,
}
// Check to see if it's a constant that we are interesting in transforming...
- if (Constant *CPV = dyn_cast<Constant>(In)) {
+ if (const Constant *CPV = dyn_cast<Constant>(In)) {
if (!isa<DerivedType>(CPV->getType()))
- return CPV; // Simple constants stay identical...
+ return const_cast<Constant*>(CPV); // Simple constants stay identical...
Constant *Result = 0;
- if (ConstantArray *CPA = dyn_cast<ConstantArray>(CPV)) {
+ if (const ConstantArray *CPA = dyn_cast<ConstantArray>(CPV)) {
const std::vector<Use> &Ops = CPA->getValues();
std::vector<Constant*> Operands(Ops.size());
for (unsigned i = 0; i < Ops.size(); ++i)
Operands[i] =
cast<Constant>(RemapOperand(Ops[i], LocalMap, GlobalMap));
Result = ConstantArray::get(cast<ArrayType>(CPA->getType()), Operands);
- } else if (ConstantStruct *CPS = dyn_cast<ConstantStruct>(CPV)) {
+ } else if (const ConstantStruct *CPS = dyn_cast<ConstantStruct>(CPV)) {
const std::vector<Use> &Ops = CPS->getValues();
std::vector<Constant*> Operands(Ops.size());
for (unsigned i = 0; i < Ops.size(); ++i)
@@ -117,8 +117,9 @@ static Value *RemapOperand(const Value *In, map<const Value*, Value*> &LocalMap,
cast<Constant>(RemapOperand(Ops[i], LocalMap, GlobalMap));
Result = ConstantStruct::get(cast<StructType>(CPS->getType()), Operands);
} else if (isa<ConstantPointerNull>(CPV)) {
- Result = CPV;
- } else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(CPV)) {
+ Result = const_cast<Constant*>(CPV);
+ } else if (const ConstantPointerRef *CPR =
+ dyn_cast<ConstantPointerRef>(CPV)) {
Value *V = RemapOperand(CPR->getValue(), LocalMap, GlobalMap);
Result = ConstantPointerRef::get(cast<GlobalValue>(V));
} else {
@@ -126,7 +127,7 @@ static Value *RemapOperand(const Value *In, map<const Value*, Value*> &LocalMap,
}
// Cache the mapping in our local map structure...
- LocalMap.insert(std::make_pair(In, CPV));
+ LocalMap.insert(std::make_pair(In, const_cast<Constant*>(CPV)));
return Result;
}
@@ -158,7 +159,7 @@ static bool LinkGlobals(Module *Dest, const Module *Src,
// Loop over all of the globals in the src module, mapping them over as we go
//
for (Module::const_giterator I = Src->gbegin(), E = Src->gend(); I != E; ++I){
- const GlobalVariable *SGV = *I;
+ const GlobalVariable *SGV = I;
Value *V;
// If the global variable has a name, and that name is already in use in the
@@ -211,7 +212,7 @@ static bool LinkGlobalInits(Module *Dest, const Module *Src,
// Loop over all of the globals in the src module, mapping them over as we go
//
for (Module::const_giterator I = Src->gbegin(), E = Src->gend(); I != E; ++I){
- const GlobalVariable *SGV = *I;
+ const GlobalVariable *SGV = I;
if (SGV->hasInitializer()) { // Only process initialized GV's
// Figure out what the initializer looks like in the dest module...
@@ -249,41 +250,41 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
// go
//
for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
- const Function *SM = *I; // SrcFunction
+ const Function *SF = I; // SrcFunction
Value *V;
// If the function has a name, and that name is already in use in the Dest
// module, make sure that the name is a compatible function...
//
- if (SM->hasExternalLinkage() && SM->hasName() &&
- (V = ST->lookup(SM->getType(), SM->getName())) &&
+ if (SF->hasExternalLinkage() && SF->hasName() &&
+ (V = ST->lookup(SF->getType(), SF->getName())) &&
cast<Function>(V)->hasExternalLinkage()) {
// The same named thing is a Function, because the only two things
// that may be in a module level symbol table are Global Vars and
// Functions, and they both have distinct, nonoverlapping, possible types.
//
- Function *DM = cast<Function>(V); // DestFunction
+ Function *DF = cast<Function>(V); // DestFunction
// Check to make sure the function is not defined in both modules...
- if (!SM->isExternal() && !DM->isExternal())
+ if (!SF->isExternal() && !DF->isExternal())
return Error(Err, "Function '" +
- SM->getFunctionType()->getDescription() + "':\"" +
- SM->getName() + "\" - Function is already defined!");
+ SF->getFunctionType()->getDescription() + "':\"" +
+ SF->getName() + "\" - Function is already defined!");
// Otherwise, just remember this mapping...
- ValueMap.insert(std::make_pair(SM, DM));
+ ValueMap.insert(std::make_pair(SF, DF));
} else {
// Function does not already exist, simply insert an external function
- // signature identical to SM into the dest module...
- Function *DM = new Function(SM->getFunctionType(),
- SM->hasInternalLinkage(),
- SM->getName());
+ // signature identical to SF into the dest module...
+ Function *DF = new Function(SF->getFunctionType(),
+ SF->hasInternalLinkage(),
+ SF->getName());
// Add the function signature to the dest module...
- Dest->getFunctionList().push_back(DM);
+ Dest->getFunctionList().push_back(DF);
// ... and remember this mapping...
- ValueMap.insert(std::make_pair(SM, DM));
+ ValueMap.insert(std::make_pair(SF, DF));
}
}
return false;
@@ -300,27 +301,22 @@ static bool LinkFunctionBody(Function *Dest, const Function *Src,
map<const Value*, Value*> LocalMap; // Map for function local values
// Go through and convert function arguments over...
- for (Function::ArgumentListType::const_iterator
- I = Src->getArgumentList().begin(),
- E = Src->getArgumentList().end(); I != E; ++I) {
- const Argument *SMA = *I;
-
+ for (Function::const_aiterator I = Src->abegin(), E = Src->aend();
+ I != E; ++I) {
// Create the new function argument and add to the dest function...
- Argument *DMA = new Argument(SMA->getType(), SMA->getName());
- Dest->getArgumentList().push_back(DMA);
+ Argument *DFA = new Argument(I->getType(), I->getName());
+ Dest->getArgumentList().push_back(DFA);
// Add a mapping to our local map
- LocalMap.insert(std::make_pair(SMA, DMA));
+ LocalMap.insert(std::make_pair(I, DFA));
}
// Loop over all of the basic blocks, copying the instructions over...
//
for (Function::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
- const BasicBlock *SBB = *I;
-
// Create new basic block and add to mapping and the Dest function...
- BasicBlock *DBB = new BasicBlock(SBB->getName(), Dest);
- LocalMap.insert(std::make_pair(SBB, DBB));
+ BasicBlock *DBB = new BasicBlock(I->getName(), Dest);
+ LocalMap.insert(std::make_pair(I, DBB));
// Loop over all of the instructions in the src basic block, copying them
// over. Note that this is broken in a strict sense because the cloned
@@ -328,13 +324,12 @@ static bool LinkFunctionBody(Function *Dest, const Function *Src,
// the remapped values. In our case, however, we will not get caught and
// so we can delay patching the values up until later...
//
- for (BasicBlock::const_iterator II = SBB->begin(), IE = SBB->end();
+ for (BasicBlock::const_iterator II = I->begin(), IE = I->end();
II != IE; ++II) {
- const Instruction *SI = *II;
- Instruction *DI = SI->clone();
- DI->setName(SI->getName());
+ Instruction *DI = II->clone();
+ DI->setName(II->getName());
DBB->getInstList().push_back(DI);
- LocalMap.insert(std::make_pair(SI, DI));
+ LocalMap.insert(std::make_pair(II, DI));
}
}
@@ -343,17 +338,11 @@ static bool LinkFunctionBody(Function *Dest, const Function *Src,
// the Source function as operands. Loop through all of the operands of the
// functions and patch them up to point to the local versions...
//
- for (Function::iterator BI = Dest->begin(), BE = Dest->end();
- BI != BE; ++BI) {
- BasicBlock *BB = *BI;
- for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) {
- Instruction *Inst = *I;
-
- for (Instruction::op_iterator OI = Inst->op_begin(), OE = Inst->op_end();
+ for (Function::iterator BB = Dest->begin(), BE = Dest->end(); BB != BE; ++BB)
+ for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
+ for (Instruction::op_iterator OI = I->op_begin(), OE = I->op_end();
OI != OE; ++OI)
*OI = RemapOperand(*OI, LocalMap, &GlobalMap);
- }
- }
return false;
}
@@ -370,20 +359,19 @@ static bool LinkFunctionBodies(Module *Dest, const Module *Src,
// Loop over all of the functions in the src module, mapping them over as we
// go
//
- for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
- const Function *SM = *I; // Source Function
- if (!SM->isExternal()) { // No body if function is external
- Function *DM = cast<Function>(ValueMap[SM]); // Destination function
+ for (Module::const_iterator SF = Src->begin(), E = Src->end(); SF != E; ++SF){
+ if (!SF->isExternal()) { // No body if function is external
+ Function *DF = cast<Function>(ValueMap[SF]); // Destination function
- // DM not external SM external?
- if (!DM->isExternal()) {
+ // DF not external SF external?
+ if (!DF->isExternal()) {
if (Err)
- *Err = "Function '" + (SM->hasName() ? SM->getName() : string("")) +
+ *Err = "Function '" + (SF->hasName() ? SF->getName() : string("")) +
"' body multiply defined!";
return true;
}
- if (LinkFunctionBody(DM, SM, ValueMap, Err)) return true;
+ if (LinkFunctionBody(DF, SF, ValueMap, Err)) return true;
}
}
return false;