aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-10-01 16:18:37 +0000
committerChris Lattner <sabre@nondot.org>2001-10-01 16:18:37 +0000
commit9636a91649f168f41b477cba705287665e054f79 (patch)
tree5922b723abd6338e86c5c09ecb880f129cd85401 /include
parent7295eb4ea3e3a81e697600cbca681674e4b35a20 (diff)
downloadexternal_llvm-9636a91649f168f41b477cba705287665e054f79.tar.gz
external_llvm-9636a91649f168f41b477cba705287665e054f79.tar.bz2
external_llvm-9636a91649f168f41b477cba705287665e054f79.zip
Add support for new style casts
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@694 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/Analysis/InstForest.h22
-rw-r--r--include/llvm/BasicBlock.h8
-rw-r--r--include/llvm/CodeGen/MachineInstr.h2
-rw-r--r--include/llvm/ConstPoolVals.h6
-rw-r--r--include/llvm/DerivedTypes.h10
-rw-r--r--include/llvm/Function.h5
-rw-r--r--include/llvm/Module.h5
-rw-r--r--include/llvm/Value.h25
-rw-r--r--include/llvm/iOther.h14
-rw-r--r--include/llvm/iTerminators.h12
10 files changed, 78 insertions, 31 deletions
diff --git a/include/llvm/Analysis/InstForest.h b/include/llvm/Analysis/InstForest.h
index 12fcd3026d..fd9677d961 100644
--- a/include/llvm/Analysis/InstForest.h
+++ b/include/llvm/Analysis/InstForest.h
@@ -80,26 +80,26 @@ public:
return getValue()->castConstantAsserting();
}
inline BasicBlock *getBasicBlock() {
- return getValue()->castBasicBlockAsserting();
+ return cast<BasicBlock>(getValue());
}
inline const BasicBlock *getBasicBlock() const {
- return getValue()->castBasicBlockAsserting();
+ return cast<const BasicBlock>(getValue());
}
inline Instruction *getInstruction() {
assert(isInstruction() && "getInstruction() on non instruction node!");
- return getValue()->castInstructionAsserting();
+ return cast<Instruction>(getValue());
}
inline const Instruction *getInstruction() const {
assert(isInstruction() && "getInstruction() on non instruction node!");
- return getValue()->castInstructionAsserting();
+ return cast<Instruction>(getValue());
}
inline Instruction *getTemporary() {
assert(isTemporary() && "getTemporary() on non temporary node!");
- return getValue()->castInstructionAsserting();
+ return cast<Instruction>(getValue());
}
inline const Instruction *getTemporary() const {
assert(isTemporary() && "getTemporary() on non temporary node!");
- return getValue()->castInstructionAsserting();
+ return cast<Instruction>(getValue());
}
public:
@@ -216,7 +216,7 @@ inline ostream &operator<<(ostream &o, const InstForest<Payload> &IF) {
template <class Payload>
bool InstTreeNode<Payload>::CanMergeInstIntoTree(Instruction *I) {
if (I->use_size() > 1) return false;
- return I->getParent() == getValue()->castInstructionAsserting()->getParent();
+ return I->getParent() == cast<Instruction>(getValue())->getParent();
}
@@ -244,7 +244,7 @@ InstTreeNode<Payload>::InstTreeNode(InstForest<Payload> &IF, Value *V,
}
// Must be an instruction then... see if we can include it in this tree!
- Instruction *I = V->castInstructionAsserting();
+ Instruction *I = cast<Instruction>(V);
if (Parent && !Parent->CanMergeInstIntoTree(I)) {
// Not root node of tree, but mult uses?
getTreeData().first.second = TemporaryNode; // Must be a temporary!
@@ -264,10 +264,10 @@ InstTreeNode<Payload>::InstTreeNode(InstForest<Payload> &IF, Value *V,
//
for (Instruction::op_iterator OI = I->op_begin(); OI != I->op_end(); ++OI) {
Value *Operand = *OI;
- InstTreeNode<Payload> *IN = IF.getInstNode(Operand->castInstruction());
- if (IN && CanMergeInstIntoTree(Operand->castInstructionAsserting())) {
+ InstTreeNode<Payload> *IN = IF.getInstNode(dyn_cast<Instruction>(Operand));
+ if (IN && CanMergeInstIntoTree(cast<Instruction>(Operand))) {
Children.push_back(IN);
- IF.removeInstFromRootList(Operand->castInstructionAsserting());
+ IF.removeInstFromRootList(cast<Instruction>(Operand));
} else {
// No node for this child yet... create one now!
Children.push_back(new InstTreeNode(IF, *OI, this));
diff --git a/include/llvm/BasicBlock.h b/include/llvm/BasicBlock.h
index 08516c8ca8..1d1623bf97 100644
--- a/include/llvm/BasicBlock.h
+++ b/include/llvm/BasicBlock.h
@@ -109,6 +109,12 @@ public:
const InstListType &getInstList() const { return InstList; }
InstListType &getInstList() { return InstList; }
+ // Methods for support type inquiry through isa, cast, and dyn_cast:
+ static inline bool isa(const BasicBlock *BB) { return true; }
+ static inline bool isa(const Value *V) {
+ return V->getValueType() == Value::BasicBlockVal;
+ }
+
// hasConstantPoolReferences() - This predicate is true if there is a
// reference to this basic block in the constant pool for this method. For
// example, if a block is reached through a switch table, that table resides
@@ -163,7 +169,7 @@ public:
// TODO: This is bad
// Loop to ignore constant pool references
while (It != BB->use_end() &&
- ((!isa<Instruction>(*It)) ||
+ (((*It)->getValueType() != Value::InstructionVal) ||
!(((Instruction*)(*It))->isTerminator())))
++It;
}
diff --git a/include/llvm/CodeGen/MachineInstr.h b/include/llvm/CodeGen/MachineInstr.h
index c9c5c51ed1..21976a099b 100644
--- a/include/llvm/CodeGen/MachineInstr.h
+++ b/include/llvm/CodeGen/MachineInstr.h
@@ -402,7 +402,7 @@ public:
// and inlining it avoids a serious circurality in link order.
inline void dropAllReferences() {
for (unsigned i=0, N=tempVec.size(); i < N; i++)
- if (Instruction *I = tempVec[i]->castInstruction())
+ if (Instruction *I = dyn_cast<Instruction>(tempVec[i]))
I->dropAllReferences();
}
};
diff --git a/include/llvm/ConstPoolVals.h b/include/llvm/ConstPoolVals.h
index 7ebe3f3ce2..1bd2dce811 100644
--- a/include/llvm/ConstPoolVals.h
+++ b/include/llvm/ConstPoolVals.h
@@ -32,6 +32,12 @@ public:
// Static constructor to get a '0' constant of arbitrary type...
static ConstPoolVal *getNullConstant(const Type *Ty);
+
+ // Methods for support type inquiry through isa, cast, and dyn_cast:
+ static inline bool isa(const ConstPoolVal *) { return true; }
+ static inline bool isa(const Value *V) {
+ return V->getValueType() == Value::ConstantVal;
+ }
};
diff --git a/include/llvm/DerivedTypes.h b/include/llvm/DerivedTypes.h
index 3f93459b23..4bc4f0ddb8 100644
--- a/include/llvm/DerivedTypes.h
+++ b/include/llvm/DerivedTypes.h
@@ -121,6 +121,16 @@ public:
virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
static MethodType *get(const Type *Result, const vector<const Type*> &Params);
+
+
+ // Methods for support type inquiry through isa, cast, and dyn_cast:
+ static inline bool isa(const MethodType *T) { return true; }
+ static inline bool isa(const Type *T) {
+ return T->getPrimitiveID() == MethodTyID;
+ }
+ static inline bool isa(const Value *V) {
+ return ::isa<Type>(V) && MethodType::isa(cast<const Type>(V));
+ }
};
diff --git a/include/llvm/Function.h b/include/llvm/Function.h
index a7075af0cc..f6c8aa214c 100644
--- a/include/llvm/Function.h
+++ b/include/llvm/Function.h
@@ -92,6 +92,11 @@ public:
inline BasicBlock *back() { return BasicBlocks.back(); }
+ // Methods for support type inquiry through isa, cast, and dyn_cast:
+ static inline bool isa(const Method *T) { return true; }
+ static inline bool isa(const Value *V) {
+ return V->getValueType() == Value::MethodVal;
+ }
// dropAllReferences() - This function causes all the subinstructions to "let
// go" of all references that they are maintaining. This allows one to
diff --git a/include/llvm/Module.h b/include/llvm/Module.h
index bf710d1223..a9f920edcb 100644
--- a/include/llvm/Module.h
+++ b/include/llvm/Module.h
@@ -93,6 +93,11 @@ public:
inline const Method *back() const { return MethodList.back(); }
inline Method *back() { return MethodList.back(); }
+ // Methods for support type inquiry through isa, cast, and dyn_cast:
+ static inline bool isa(const Module *T) { return true; }
+ static inline bool isa(const Value *V) {
+ return V->getValueType() == Value::ModuleVal;
+ }
// dropAllReferences() - This function causes all the subinstructions to "let
// go" of all references that they are maintaining. This allows one to
diff --git a/include/llvm/Value.h b/include/llvm/Value.h
index 14794dc4c9..271d2d4dfe 100644
--- a/include/llvm/Value.h
+++ b/include/llvm/Value.h
@@ -77,9 +77,7 @@ public:
// Methods for determining the subtype of this Value. The getValueType()
// method returns the type of the value directly. The cast*() methods are
// equivalent to using dynamic_cast<>... if the cast is successful, this is
- // returned, otherwise you get a null pointer, allowing expressions like:
- //
- // if (Instruction *I = Val->castInstruction()) { ... }
+ // returned, otherwise you get a null pointer.
//
// This section also defines a family of isType, isConstant,
// isMethodArgument, etc functions...
@@ -197,6 +195,9 @@ public:
inline ValueSubclass *operator->() { return Val; }
inline const ValueSubclass *operator->() const { return Val; }
+ inline ValueSubclass *get() { return Val; }
+ inline const ValueSubclass *get() const { return Val; }
+
inline UseTy<ValueSubclass> &operator=(const UseTy<ValueSubclass> &user) {
if (Val) Val->killUse(U);
Val = user.Val;
@@ -207,6 +208,13 @@ public:
typedef UseTy<Value> Use; // Provide Use as a common UseTy type
+// real_type - Provide a macro to get the real type of a value that might be
+// a use. This provides a typedef 'Type' that is the argument type for all
+// non UseTy types, and is the contained pointer type of the use if it is a
+// UseTy.
+//
+template <class X> class real_type { typedef X Type; };
+template <class X> class real_type <class UseTy<X> > { typedef X *Type; };
//===----------------------------------------------------------------------===//
// Type Checking Templates
@@ -218,7 +226,7 @@ typedef UseTy<Value> Use; // Provide Use as a common UseTy type
// if (isa<Type>(myVal)) { ... }
//
template <class X, class Y>
-bool isa(Y *Val) { return X::isa(Val); }
+bool isa(Y Val) { return X::isa(Val); }
// cast<X> - Return the argument parameter cast to the specified type. This
@@ -229,9 +237,9 @@ bool isa(Y *Val) { return X::isa(Val); }
// cast<const Instruction>(myVal)->getParent()
//
template <class X, class Y>
-X *cast(Y *Val) {
+X *cast(Y Val) {
assert(isa<X>(Val) && "Invalid cast argument type!");
- return (X*)Val;
+ return (X*)(real_type<Y>::Type)Val;
}
@@ -242,9 +250,10 @@ X *cast(Y *Val) {
//
// if (const Instruction *I = dyn_cast<const Instruction>(myVal)) { ... }
//
+
template <class X, class Y>
-X *dyn_cast(Y *Val) {
- return isa<X>(Val) ? (X*)Val : 0;
+X *dyn_cast(Y Val) {
+ return isa<X>(Val) ? cast<X>(Val) : 0;
}
#endif
diff --git a/include/llvm/iOther.h b/include/llvm/iOther.h
index e723d4e975..1e4733d79a 100644
--- a/include/llvm/iOther.h
+++ b/include/llvm/iOther.h
@@ -43,10 +43,10 @@ public:
// getIncomingBlock - Return incoming basic block #x
inline const BasicBlock *getIncomingBlock(unsigned i) const {
- return Operands[i*2+1]->castBasicBlockAsserting();
+ return cast<const BasicBlock>(Operands[i*2+1]);
}
inline BasicBlock *getIncomingBlock(unsigned i) {
- return Operands[i*2+1]->castBasicBlockAsserting();
+ return cast<BasicBlock>(Operands[i*2+1]);
}
// addIncoming - Add an incoming value to the end of the PHI list
@@ -103,6 +103,12 @@ public:
inline const Method *getParent() const { return Parent; }
inline Method *getParent() { return Parent; }
+
+ // Methods for support type inquiry through isa, cast, and dyn_cast:
+ static inline bool isa(const MethodArgument *) { return true; }
+ static inline bool isa(const Value *V) {
+ return V->getValueType() == MethodArgumentVal;
+ }
};
@@ -122,10 +128,10 @@ public:
const Method *getCalledMethod() const {
- return Operands[0]->castMethodAsserting();
+ return cast<Method>(Operands[0]);
}
Method *getCalledMethod() {
- return Operands[0]->castMethodAsserting();
+ return cast<Method>(Operands[0]);
}
};
diff --git a/include/llvm/iTerminators.h b/include/llvm/iTerminators.h
index d43c7e5582..43cf509a70 100644
--- a/include/llvm/iTerminators.h
+++ b/include/llvm/iTerminators.h
@@ -96,9 +96,9 @@ public:
// terminator instruction.
//
virtual const BasicBlock *getSuccessor(unsigned i) const {
- return (i == 0) ? Operands[0]->castBasicBlockAsserting() :
+ return (i == 0) ? cast<const BasicBlock>(Operands[0]) :
((i == 1 && Operands.size() > 1)
- ? Operands[1]->castBasicBlockAsserting() : 0);
+ ? cast<const BasicBlock>(Operands[1]) : 0);
}
inline BasicBlock *getSuccessor(unsigned idx) {
return (BasicBlock*)((const BranchInst *)this)->getSuccessor(idx);
@@ -127,10 +127,10 @@ public:
inline const Value *getCondition() const { return Operands[0]; }
inline Value *getCondition() { return Operands[0]; }
inline const BasicBlock *getDefaultDest() const {
- return Operands[1]->castBasicBlockAsserting();
+ return cast<const BasicBlock>(Operands[1]);
}
inline BasicBlock *getDefaultDest() {
- return Operands[1]->castBasicBlockAsserting();
+ return cast<BasicBlock>(Operands[1]);
}
void dest_push_back(ConstPoolVal *OnVal, BasicBlock *Dest);
@@ -143,11 +143,11 @@ public:
//
virtual const BasicBlock *getSuccessor(unsigned idx) const {
if (idx >= Operands.size()/2) return 0;
- return Operands[idx*2+1]->castBasicBlockAsserting();
+ return cast<const BasicBlock>(Operands[idx*2+1]);
}
inline BasicBlock *getSuccessor(unsigned idx) {
if (idx >= Operands.size()/2) return 0;
- return Operands[idx*2+1]->castBasicBlockAsserting();
+ return cast<BasicBlock>(Operands[idx*2+1]);
}
// getSuccessorValue - Return the value associated with the specified