Commit more code over to new cast style

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@697 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2001-10-02 03:41:24 +00:00
parent 1d87bcf490
commit b00c582b6d
42 changed files with 349 additions and 233 deletions

View File

@ -1,3 +1,6 @@
* grep '[A-Za-z][A-Za-z]*\*)' `./getsrcs.sh ` | & less
* Need to implement getelementptr, load, and store for indirection through
arrays and multidim arrays
* Indirect calls should use the icall instruction

View File

@ -262,7 +262,7 @@ To further assist with debugging, make sure to put some kind of error message in
<pre>
inline Value *getOperand(unsigned i) {
assert(i < Operands.size() && "getOperand() out of range!");
assert(i &lt; Operands.size() && "getOperand() out of range!");
return Operands[i];
}
</pre>
@ -270,15 +270,15 @@ To further assist with debugging, make sure to put some kind of error message in
Here are some examples:
<pre>
assert(Ty->isPointerType() && "Can't allocate a non pointer type!");
assert(Ty-&gt;isPointerType() && "Can't allocate a non pointer type!");
assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!");
assert(idx < getNumSuccessors() && "Successor # out of range!");
assert(idx &lt; getNumSuccessors() && "Successor # out of range!");
assert(V1.getType() == V2.getType() && "Constant types must be identical!");
assert(Succ->front()->isPHINode() && "Only works on PHId BBs!");
assert(isa&lt;PHINode&gt;(Succ-&gt;front()) && "Only works on PHId BBs!");
</pre><p>
You get the idea...<p>
@ -646,7 +646,7 @@ If you get some free time, and you haven't read them: do so, you might learn som
<address><a href="mailto:sabre@nondot.org">Chris Lattner</a></address>
<!-- Created: Tue Jan 23 15:19:28 CST 2001 -->
<!-- hhmts start -->
Last modified: Mon Oct 1 08:17:21 CDT 2001
Last modified: Mon Oct 1 15:33:40 CDT 2001
<!-- hhmts end -->
</font>
</body></html>

View File

@ -92,13 +92,13 @@ inline ostream &operator<<(ostream &o, const Type *T) {
inline ostream &operator<<(ostream &o, const Value *I) {
switch (I->getValueType()) {
case Value::TypeVal: return o << cast<const Type>(I);
case Value::ConstantVal: WriteToAssembly((const ConstPoolVal*)I,o);break;
case Value::ConstantVal: WriteToAssembly(cast<ConstPoolVal>(I) , o); break;
case Value::MethodArgumentVal: return o << I->getType() << " "<< I->getName();
case Value::InstructionVal:WriteToAssembly((const Instruction *)I, o);break;
case Value::BasicBlockVal: WriteToAssembly((const BasicBlock *)I, o);break;
case Value::MethodVal: WriteToAssembly((const Method *)I, o);break;
case Value::GlobalVal: WriteToAssembly((const GlobalVariable*)I,o);break;
case Value::ModuleVal: WriteToAssembly((const Module *)I,o); break;
case Value::InstructionVal:WriteToAssembly(cast<Instruction>(I) , o); break;
case Value::BasicBlockVal: WriteToAssembly(cast<BasicBlock>(I) , o); break;
case Value::MethodVal: WriteToAssembly(cast<Method>(I) , o); break;
case Value::GlobalVal: WriteToAssembly(cast<GlobalVariable>(I), o); break;
case Value::ModuleVal: WriteToAssembly(cast<Module>(I) , o); break;
default: return o << "<unknown value type: " << I->getValueType() << ">";
}
return o;

View File

@ -110,8 +110,8 @@ public:
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) {
static inline bool classof(const BasicBlock *BB) { return true; }
static inline bool classof(const Value *V) {
return V->getValueType() == Value::BasicBlockVal;
}
@ -168,9 +168,7 @@ public:
inline void advancePastConstPool() {
// TODO: This is bad
// Loop to ignore constant pool references
while (It != BB->use_end() &&
(((*It)->getValueType() != Value::InstructionVal) ||
!(((Instruction*)(*It))->isTerminator())))
while (It != BB->use_end() && !isa<TerminatorInst>(*It))
++It;
}

View File

@ -171,7 +171,7 @@ public:
Instruction *getInstruction() const {
assert(treeNodeType == NTInstructionNode);
return (Instruction*)val;
return cast<Instruction>(val);
}
protected:
virtual void dumpNode(int indent) const;

View File

@ -34,8 +34,8 @@ public:
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) {
static inline bool classof(const ConstPoolVal *) { return true; }
static inline bool classof(const Value *V) {
return V->getValueType() == Value::ConstantVal;
}
};
@ -68,12 +68,12 @@ public:
inline bool getValue() const { return Val; }
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool isa(const ConstPoolBool *) { return true; }
static bool isa(const ConstPoolVal *CPV) {
static inline bool classof(const ConstPoolBool *) { return true; }
static bool classof(const ConstPoolVal *CPV) {
return (CPV == True) | (CPV == False);
}
static inline bool isa(const Value *V) {
return ::isa<ConstPoolVal>(V) && isa(cast<ConstPoolVal>(V));
static inline bool classof(const Value *V) {
return isa<ConstPoolVal>(V) && classof(cast<ConstPoolVal>(V));
}
};
@ -108,10 +108,10 @@ public:
static ConstPoolInt *get(const Type *Ty, unsigned char V);
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool isa(const ConstPoolInt *) { return true; }
static bool isa(const ConstPoolVal *CPV); // defined in CPV.cpp
static inline bool isa(const Value *V) {
return ::isa<ConstPoolVal>(V) && isa(cast<ConstPoolVal>(V));
static inline bool classof(const ConstPoolInt *) { return true; }
static bool classof(const ConstPoolVal *CPV); // defined in CPV.cpp
static inline bool classof(const Value *V) {
return isa<ConstPoolVal>(V) && classof(cast<ConstPoolVal>(V));
}
};

View File

@ -80,12 +80,12 @@ public:
void refineAbstractTypeTo(const Type *NewType);
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool isa(const DerivedType *T) { return true; }
static inline bool isa(const Type *T) {
static inline bool classof(const DerivedType *T) { return true; }
static inline bool classof(const Type *T) {
return T->isDerivedType();
}
static inline bool isa(const Value *V) {
return ::isa<Type>(V) && isa(cast<const Type>(V));
static inline bool classof(const Value *V) {
return isa<Type>(V) && classof(cast<const Type>(V));
}
};
@ -133,12 +133,12 @@ public:
// 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) {
static inline bool classof(const MethodType *T) { return true; }
static inline bool classof(const Type *T) {
return T->getPrimitiveID() == MethodTyID;
}
static inline bool isa(const Value *V) {
return ::isa<Type>(V) && isa(cast<const Type>(V));
static inline bool classof(const Value *V) {
return isa<Type>(V) && classof(cast<const Type>(V));
}
};
@ -181,12 +181,12 @@ public:
static ArrayType *get(const Type *ElementType, int NumElements = -1);
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool isa(const ArrayType *T) { return true; }
static inline bool isa(const Type *T) {
static inline bool classof(const ArrayType *T) { return true; }
static inline bool classof(const Type *T) {
return T->getPrimitiveID() == ArrayTyID;
}
static inline bool isa(const Value *V) {
return ::isa<Type>(V) && isa(cast<const Type>(V));
static inline bool classof(const Value *V) {
return isa<Type>(V) && classof(cast<const Type>(V));
}
};
@ -226,12 +226,12 @@ public:
static StructType *get(const vector<const Type*> &Params);
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool isa(const StructType *T) { return true; }
static inline bool isa(const Type *T) {
static inline bool classof(const StructType *T) { return true; }
static inline bool classof(const Type *T) {
return T->getPrimitiveID() == StructTyID;
}
static inline bool isa(const Value *V) {
return ::isa<Type>(V) && isa(cast<const Type>(V));
static inline bool classof(const Value *V) {
return isa<Type>(V) && classof(cast<const Type>(V));
}
};
@ -269,12 +269,12 @@ public:
virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool isa(const PointerType *T) { return true; }
static inline bool isa(const Type *T) {
static inline bool classof(const PointerType *T) { return true; }
static inline bool classof(const Type *T) {
return T->getPrimitiveID() == PointerTyID;
}
static inline bool isa(const Value *V) {
return ::isa<Type>(V) && isa(cast<const Type>(V));
static inline bool classof(const Value *V) {
return isa<Type>(V) && classof(cast<const Type>(V));
}
};
@ -299,12 +299,12 @@ public:
}
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool isa(const OpaqueType *T) { return true; }
static inline bool isa(const Type *T) {
static inline bool classof(const OpaqueType *T) { return true; }
static inline bool classof(const Type *T) {
return T->getPrimitiveID() == OpaqueTyID;
}
static inline bool isa(const Value *V) {
return ::isa<Type>(V) && isa(cast<const Type>(V));
static inline bool classof(const Value *V) {
return isa<Type>(V) && classof(cast<const Type>(V));
}
};

View File

@ -93,8 +93,8 @@ public:
// 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) {
static inline bool classof(const Method *T) { return true; }
static inline bool classof(const Value *V) {
return V->getValueType() == Value::MethodVal;
}

View File

@ -61,8 +61,8 @@ public:
inline bool isConstant() const { return Constant; }
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool isa(const GlobalVariable *) { return true; }
static inline bool isa(const Value *V) {
static inline bool classof(const GlobalVariable *) { return true; }
static inline bool classof(const Value *V) {
return V->getValueType() == Value::GlobalVal;
}
};

View File

@ -40,6 +40,15 @@ public:
inline BasicBlock *getSuccessor(unsigned idx) {
return (BasicBlock*)((const TerminatorInst *)this)->getSuccessor(idx);
}
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const TerminatorInst *) { return true; }
static inline bool classof(const Instruction *I) {
return I->getOpcode() >= FirstTermOp && I->getOpcode() < NumTermOps;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
@ -70,6 +79,15 @@ public:
}
virtual const char *getOpcodeName() const = 0;
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const UnaryOperator *) { return true; }
static inline bool classof(const Instruction *I) {
return I->getOpcode() >= FirstUnaryOp && I->getOpcode() < NumUnaryOps;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
@ -111,6 +129,15 @@ public:
void swapOperands() {
swap(Operands[0], Operands[1]);
}
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const BinaryOperator *) { return true; }
static inline bool classof(const Instruction *I) {
return I->getOpcode() >= FirstBinaryOp && I->getOpcode() < NumBinaryOps;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
#endif

View File

@ -76,9 +76,6 @@ public:
return iType >= FirstBinaryOp && iType < NumBinaryOps;
}
// isPHINode() - This is used frequently enough to allow it to exist
inline bool isPHINode() const { return iType == PHINode; }
// dropAllReferences() - This function is in charge of "letting go" of all
// objects that this Instruction refers to. This first lets go of all
// references to hidden values generated code for this instruction,
@ -88,8 +85,8 @@ public:
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool isa(const Instruction *I) { return true; }
static inline bool isa(const Value *V) {
static inline bool classof(const Instruction *I) { return true; }
static inline bool classof(const Value *V) {
return V->getValueType() == Value::InstructionVal;
}

View File

@ -94,8 +94,8 @@ public:
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) {
static inline bool classof(const Module *T) { return true; }
static inline bool classof(const Value *V) {
return V->getValueType() == Value::ModuleVal;
}

View File

@ -189,42 +189,19 @@ public:
inline bool isDerivedType() const { return ID >= FirstDerivedTyID; }
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool isa(const Type *T) { return true; }
static inline bool isa(const Value *V) {
static inline bool classof(const Type *T) { return true; }
static inline bool classof(const Value *V) {
return V->getValueType() == Value::TypeVal;
}
// Methods for determining the subtype of this Type. The cast*() methods are
// equilivent to using dynamic_cast<>... if the cast is successful, this is
// returned, otherwise you get a null pointer, allowing expressions like this:
//
// if (MethodType *MTy = Ty->dyncastMethodType()) { ... }
//
// This section also defines a family of isArrayType(), isLabelType(),
// etc functions...
//
// The family of functions Ty->cast<type>() is used in the same way as the
// Ty->dyncast<type>() instructions, but they assert the expected type instead
// of checking it at runtime.
// Methods for determining the subtype of this Type. This section defines a
// family of isArrayType(), isLabelType(), etc functions...
//
#define HANDLE_PRIM_TYPE(NAME, SIZE) \
inline bool is##NAME##Type() const { return ID == NAME##TyID; }
#define HANDLE_DERV_TYPE(NAME, CLASS) \
inline bool is##NAME##Type() const { return ID == NAME##TyID; } \
inline const CLASS *dyncast##NAME##Type() const { /*const version */ \
return is##NAME##Type() ? (const CLASS*)this : 0; \
} \
inline CLASS *dyncast##NAME##Type() { /* nonconst version */ \
return is##NAME##Type() ? (CLASS*)this : 0; \
} \
inline const CLASS *cast##NAME##Type() const { /*const version */ \
assert(is##NAME##Type() && "Expected TypeTy: " #NAME); \
return (const CLASS*)this; \
} \
inline CLASS *cast##NAME##Type() { /* nonconst version */ \
assert(is##NAME##Type() && "Expected TypeTy: " #NAME); \
return (CLASS*)this; \
}
inline bool is##NAME##Type() const { return ID == NAME##TyID; }
#include "llvm/Type.def"
private:

View File

@ -185,7 +185,7 @@ template <class X> class real_type <class UseTy<X> > { typedef X *Type; };
// if (isa<Type>(myVal)) { ... }
//
template <class X, class Y>
inline bool isa(Y Val) { return X::isa(Val); }
inline bool isa(Y Val) { return X::classof(Val); }
// cast<X> - Return the argument parameter cast to the specified type. This

View File

@ -27,8 +27,8 @@ public:
if (ArraySize) {
// Make sure they didn't try to specify a size for !(unsized array) type
assert((getType()->getValueType()->isArrayType() &&
((const ArrayType*)getType()->getValueType())->isUnsized()) &&
assert(getType()->getValueType()->isArrayType() &&
cast<ArrayType>(getType()->getValueType())->isUnsized() &&
"Trying to allocate something other than unsized array, with size!");
Operands.reserve(1);
@ -36,7 +36,7 @@ public:
} else {
// Make sure that the pointer is not to an unsized array!
assert(!getType()->getValueType()->isArrayType() ||
((const ArrayType*)getType()->getValueType())->isSized() &&
cast<const ArrayType>(getType()->getValueType())->isSized() &&
"Trying to allocate unsized array without size!");
}
}
@ -64,6 +64,15 @@ public:
}
virtual const char *getOpcodeName() const { return "malloc"; }
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const MallocInst *) { return true; }
static inline bool classof(const Instruction *I) {
return (I->getOpcode() == Instruction::Malloc);
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
@ -81,6 +90,15 @@ public:
}
virtual const char *getOpcodeName() const { return "alloca"; }
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const AllocaInst *) { return true; }
static inline bool classof(const Instruction *I) {
return (I->getOpcode() == Instruction::Alloca);
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
@ -102,6 +120,15 @@ public:
virtual const char *getOpcodeName() const { return "free"; }
virtual bool hasSideEffects() const { return true; }
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const FreeInst *) { return true; }
static inline bool classof(const Instruction *I) {
return (I->getOpcode() == Instruction::Free);
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
@ -160,6 +187,15 @@ public:
virtual const char* getOpcodeName() const { return "load"; }
virtual Value* getPtrOperand() { return this->getOperand(0); }
virtual int getFirstOffsetIdx() const { return (this->getNumOperands() > 1)? 1 : -1;}
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const LoadInst *) { return true; }
static inline bool classof(const Instruction *I) {
return (I->getOpcode() == Instruction::Load);
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
@ -182,6 +218,15 @@ public:
virtual bool hasSideEffects() const { return true; }
virtual Value* getPtrOperand() { return this->getOperand(1); }
virtual int getFirstOffsetIdx() const { return (this->getNumOperands() > 2)? 2 : -1;}
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const StoreInst *) { return true; }
static inline bool classof(const Instruction *I) {
return (I->getOpcode() == Instruction::Store);
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
@ -206,6 +251,16 @@ public:
inline bool isArraySelector() const { return !isStructSelector(); }
bool isStructSelector() const;
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const GetElementPtrInst *) { return true; }
static inline bool classof(const Instruction *I) {
return (I->getOpcode() == Instruction::GetElementPtr);
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
#endif // LLVM_IMEMORY_H

View File

@ -55,6 +55,16 @@ public:
// removeIncomingValue - Remove an incoming value. This is useful if a
// predecessor basic block is deleted. The value removed is returned.
Value *removeIncomingValue(const BasicBlock *BB);
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const PHINode *) { return true; }
static inline bool classof(const Instruction *I) {
return I->getOpcode() == Instruction::PHINode;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
@ -79,6 +89,15 @@ public:
virtual Instruction *clone() const { return new CastInst(*this); }
virtual const char *getOpcodeName() const { return "cast"; }
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const CastInst *) { return true; }
static inline bool classof(const Instruction *I) {
return I->getOpcode() == Cast;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
@ -105,8 +124,8 @@ public:
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) {
static inline bool classof(const MethodArgument *) { return true; }
static inline bool classof(const Value *V) {
return V->getValueType() == MethodArgumentVal;
}
};
@ -133,6 +152,15 @@ public:
Method *getCalledMethod() {
return cast<Method>(Operands[0]);
}
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const CallInst *) { return true; }
static inline bool classof(const Instruction *I) {
return I->getOpcode() == Instruction::Call;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
@ -161,6 +189,16 @@ public:
virtual const char *getOpcodeName() const {
return getOpcode() == Shl ? "shl" : "shr";
}
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ShiftInst *) { return true; }
static inline bool classof(const Instruction *I) {
return (I->getOpcode() == Instruction::Shr) |
(I->getOpcode() == Instruction::Shl);
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
#endif

View File

@ -56,6 +56,15 @@ public:
//
virtual const BasicBlock *getSuccessor(unsigned idx) const { return 0; }
virtual unsigned getNumSuccessors() const { return 0; }
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ReturnInst *) { return true; }
static inline bool classof(const Instruction *I) {
return (I->getOpcode() == Instruction::Ret);
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
@ -105,6 +114,15 @@ public:
}
virtual unsigned getNumSuccessors() const { return 1+!isUnconditional(); }
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const BranchInst *) { return true; }
static inline bool classof(const Instruction *I) {
return (I->getOpcode() == Instruction::Br);
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
@ -161,6 +179,15 @@ public:
return cast<ConstPoolVal>(Operands[idx*2]);
}
virtual unsigned getNumSuccessors() const { return Operands.size()/2; }
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const SwitchInst *) { return true; }
static inline bool classof(const Instruction *I) {
return (I->getOpcode() == Instruction::Switch);
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
#endif

View File

@ -97,7 +97,7 @@ static const ConstPoolInt *Add(const ConstPoolInt *Arg1,
ConstPoolVal *Result = *Arg1 + *Arg2;
assert(Result && Result->getType() == Arg1->getType() &&
"Couldn't perform addition!");
ConstPoolInt *ResultI = (ConstPoolInt*)Result;
ConstPoolInt *ResultI = cast<ConstPoolInt>(Result);
// Check to see if the result is one of the special cases that we want to
// recognize...
@ -147,7 +147,7 @@ inline const ConstPoolInt *Mul(const ConstPoolInt *Arg1,
ConstPoolVal *Result = *Arg1 * *Arg2;
assert(Result && Result->getType() == Arg1->getType() &&
"Couldn't perform mult!");
ConstPoolInt *ResultI = (ConstPoolInt*)Result;
ConstPoolInt *ResultI = cast<ConstPoolInt>(Result);
// Check to see if the result is one of the special cases that we want to
// recognize...
@ -203,7 +203,7 @@ static inline ExprType negate(const ExprType &E, Value *V) {
const Type *ETy = E.getExprType(Ty);
ConstPoolInt *Zero = getUnsignedConstant(0, ETy);
ConstPoolInt *One = getUnsignedConstant(1, ETy);
ConstPoolInt *NegOne = (ConstPoolInt*)(*Zero - *One);
ConstPoolInt *NegOne = cast<ConstPoolInt>(*Zero - *One);
if (NegOne == 0) return V; // Couldn't subtract values...
return ExprType(DefOne (E.Scale , Ty) * NegOne, E.Var,
@ -230,7 +230,7 @@ ExprType analysis::ClassifyExpression(Value *Expr) {
case Value::ConstantVal: // Constant value, just return constant
ConstPoolVal *CPV = cast<ConstPoolVal>(Expr);
if (CPV->getType()->isIntegral()) { // It's an integral constant!
ConstPoolInt *CPI = (ConstPoolInt*)Expr;
ConstPoolInt *CPI = cast<ConstPoolInt>(Expr);
return ExprType(CPI->equalsInt(0) ? 0 : CPI);
}
return Expr;
@ -297,7 +297,7 @@ ExprType analysis::ClassifyExpression(Value *Expr) {
const ConstPoolVal *CPV =ConstRules::get(*Offs)->castTo(Offs, DestTy);
if (!CPV) return I;
assert(CPV->getType()->isIntegral() && "Must have an integral type!");
return (ConstPoolInt*)CPV;
return cast<ConstPoolInt>(CPV);
} // end case Instruction::Cast
// TODO: Handle SUB, SHR?

View File

@ -38,12 +38,10 @@ void CallGraph::addToCallGraph(Method *M) {
for (Method::inst_iterator II = M->inst_begin(), IE = M->inst_end();
II != IE; ++II) {
if (II->getOpcode() == Instruction::Call) {
CallInst *CI = (CallInst*)*II;
if (CallInst *CI = dyn_cast<CallInst>(*II))
Node->addCalledMethod(getNodeFor(CI->getCalledMethod()));
}
}
}
CallGraph::CallGraph(Module *TheModule) {
Mod = TheModule;

View File

@ -46,7 +46,7 @@ inline bool ModuleAnalyzer::handleType(set<const Type *> &TypeSet,
break;
case Type::StructTyID: {
const StructType *ST = (const StructType*)T;
const StructType *ST = cast<const StructType>(T);
const StructType::ElementTypes &Elements = ST->getElementTypes();
for (StructType::ElementTypes::const_iterator I = Elements.begin();
I != Elements.end(); ++I)

View File

@ -397,10 +397,9 @@ static void setValueName(Value *V, char *NameStr) {
// There is only one case where this is allowed: when we are refining an
// opaque type. In this case, Existing will be an opaque type.
if (const Type *Ty = cast<const Type>(Existing))
if (Ty->isOpaqueType()) {
if (OpaqueType *OpTy = dyn_cast<OpaqueType>(Ty)) {
// We ARE replacing an opaque type!
cast<DerivedType>(Ty)->refineAbstractTypeTo(cast<Type>(V));
OpTy->refineAbstractTypeTo(cast<Type>(V));
return;
}
@ -1232,7 +1231,7 @@ InstVal : BinaryOps Types ValueRef ',' ValueRef {
while ($2->begin() != $2->end()) {
if ($2->front().first->getType() != Ty)
ThrowException("All elements of a PHI node must be of the same type!");
((PHINode*)$$)->addIncoming($2->front().first, $2->front().second);
cast<PHINode>($$)->addIncoming($2->front().first, $2->front().second);
$2->pop_front();
}
delete $2; // Free the list...
@ -1291,7 +1290,7 @@ MemoryInst : MALLOC Types {
delete $2;
}
| MALLOC Types ',' UINT ValueRef {
if (!(*$2)->isArrayType() || ((const ArrayType*)$2->get())->isSized())
if (!(*$2)->isArrayType() || cast<const ArrayType>($2->get())->isSized())
ThrowException("Trying to allocate " + (*$2)->getName() +
" as unsized array!");
const Type *Ty = PointerType::get(*$2);
@ -1303,7 +1302,7 @@ MemoryInst : MALLOC Types {
delete $2;
}
| ALLOCA Types ',' UINT ValueRef {
if (!(*$2)->isArrayType() || ((const ArrayType*)$2->get())->isSized())
if (!(*$2)->isArrayType() || cast<const ArrayType>($2->get())->isSized())
ThrowException("Trying to allocate " + (*$2)->getName() +
" as unsized array!");
const Type *Ty = PointerType::get(*$2);

View File

@ -229,7 +229,7 @@ bool BytecodeParser::parseConstPoolValue(const uchar *&Buf,
abort();
case Type::ArrayTyID: {
const ArrayType *AT = (const ArrayType*)Ty;
const ArrayType *AT = cast<const ArrayType>(Ty);
unsigned NumElements;
if (AT->isSized()) // Sized array, # elements stored in type!
NumElements = (unsigned)AT->getNumElements();
@ -249,7 +249,7 @@ bool BytecodeParser::parseConstPoolValue(const uchar *&Buf,
}
case Type::StructTyID: {
const StructType *ST = Ty->castStructType();
const StructType *ST = cast<StructType>(Ty);
const StructType::ElementTypes &ET = ST->getElementTypes();
vector<ConstPoolVal *> Elements;
@ -267,7 +267,7 @@ bool BytecodeParser::parseConstPoolValue(const uchar *&Buf,
}
case Type::PointerTyID: {
const PointerType *PT = Ty->castPointerType();
const PointerType *PT = cast<const PointerType>(Ty);
unsigned SubClass;
if (read_vbr(Buf, EndBuf, SubClass)) return failure(true);
if (SubClass != 0) return failure(true);

View File

@ -122,11 +122,11 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
delete PN;
return failure(true);
case 2: PN->addIncoming(getValue(Raw.Ty, Raw.Arg1),
(BasicBlock*)getValue(Type::LabelTy, Raw.Arg2));
cast<BasicBlock>(getValue(Type::LabelTy,Raw.Arg2)));
break;
default:
PN->addIncoming(getValue(Raw.Ty, Raw.Arg1),
(BasicBlock*)getValue(Type::LabelTy, Raw.Arg2));
cast<BasicBlock>(getValue(Type::LabelTy, Raw.Arg2)));
if (Raw.VarArgs->size() & 1) {
cerr << "PHI Node with ODD number of arguments!\n";
delete PN;
@ -135,7 +135,7 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
vector<unsigned> &args = *Raw.VarArgs;
for (unsigned i = 0; i < args.size(); i+=2)
PN->addIncoming(getValue(Raw.Ty, args[i]),
(BasicBlock*)getValue(Type::LabelTy, args[i+1]));
cast<BasicBlock>(getValue(Type::LabelTy, args[i+1])));
}
delete Raw.VarArgs;
break;
@ -160,11 +160,11 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
case Instruction::Br:
if (Raw.NumOperands == 1) {
Res = new BranchInst((BasicBlock*)getValue(Type::LabelTy, Raw.Arg1));
Res = new BranchInst(cast<BasicBlock>(getValue(Type::LabelTy, Raw.Arg1)));
return false;
} else if (Raw.NumOperands == 3) {
Res = new BranchInst((BasicBlock*)getValue(Type::LabelTy, Raw.Arg1),
(BasicBlock*)getValue(Type::LabelTy, Raw.Arg2),
Res = new BranchInst(cast<BasicBlock>(getValue(Type::LabelTy, Raw.Arg1)),
cast<BasicBlock>(getValue(Type::LabelTy, Raw.Arg2)),
getValue(Type::BoolTy , Raw.Arg3));
return false;
}
@ -173,7 +173,7 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
case Instruction::Switch: {
SwitchInst *I =
new SwitchInst(getValue(Raw.Ty, Raw.Arg1),
(BasicBlock*)getValue(Type::LabelTy, Raw.Arg2));
cast<BasicBlock>(getValue(Type::LabelTy, Raw.Arg2)));
Res = I;
if (Raw.NumOperands < 3) return false; // No destinations? Wierd.
@ -185,15 +185,15 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
vector<unsigned> &args = *Raw.VarArgs;
for (unsigned i = 0; i < args.size(); i += 2)
I->dest_push_back((ConstPoolVal*)getValue(Raw.Ty, args[i]),
(BasicBlock*)getValue(Type::LabelTy, args[i+1]));
I->dest_push_back(cast<ConstPoolVal>(getValue(Raw.Ty, args[i])),
cast<BasicBlock>(getValue(Type::LabelTy, args[i+1])));
delete Raw.VarArgs;
return false;
}
case Instruction::Call: {
Method *M = (Method*)getValue(Raw.Ty, Raw.Arg1);
Method *M = cast<Method>(getValue(Raw.Ty, Raw.Arg1));
if (M == 0) return failure(true);
vector<Value *> Params;

View File

@ -338,7 +338,7 @@ bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End,
unsigned InitSlot;
if (read_vbr(Buf, End, InitSlot)) return failure(true);
Value *V = getValue(Ty->castPointerType()->getValueType(),
Value *V = getValue(cast<const PointerType>(Ty)->getValueType(),
InitSlot, false);
if (V == 0) return failure(true);
Initializer = cast<ConstPoolVal>(V);
@ -382,7 +382,7 @@ bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End,
// Keep track of this information in a linked list that is emptied as
// methods are loaded...
//
MethodSignatureList.push_back(make_pair((const MethodType*)Ty, SlotNo));
MethodSignatureList.push_back(make_pair(cast<const MethodType>(Ty),SlotNo));
if (read_vbr(Buf, End, MethSignature)) return failure(true);
BCR_TRACE(2, "Method of type: " << Ty << endl);
}

View File

@ -23,7 +23,7 @@ void BytecodeWriter::outputType(const Type *T) {
switch (T->getPrimitiveID()) { // Handle derived types now.
case Type::MethodTyID: {
const MethodType *MT = (const MethodType*)T;
const MethodType *MT = cast<const MethodType>(T);
int Slot = Table.getValSlot(MT->getReturnType());
assert(Slot != -1 && "Type used but not available!!");
output_vbr((unsigned)Slot, Out);
@ -46,7 +46,7 @@ void BytecodeWriter::outputType(const Type *T) {
}
case Type::ArrayTyID: {
const ArrayType *AT = (const ArrayType*)T;
const ArrayType *AT = cast<const ArrayType>(T);
int Slot = Table.getValSlot(AT->getElementType());
assert(Slot != -1 && "Type used but not available!!");
output_vbr((unsigned)Slot, Out);
@ -57,7 +57,7 @@ void BytecodeWriter::outputType(const Type *T) {
}
case Type::StructTyID: {
const StructType *ST = (const StructType*)T;
const StructType *ST = cast<const StructType>(T);
// Output all of the element types...
StructType::ElementTypes::const_iterator I = ST->getElementTypes().begin();
@ -73,7 +73,7 @@ void BytecodeWriter::outputType(const Type *T) {
}
case Type::PointerTyID: {
const PointerType *PT = (const PointerType*)T;
const PointerType *PT = cast<const PointerType>(T);
int Slot = Table.getValSlot(PT->getValueType());
assert(Slot != -1 && "Type used but not available!!");
output_vbr((unsigned)Slot, Out);
@ -91,7 +91,7 @@ void BytecodeWriter::outputType(const Type *T) {
bool BytecodeWriter::outputConstant(const ConstPoolVal *CPV) {
switch (CPV->getType()->getPrimitiveID()) {
case Type::BoolTyID: // Boolean Types
if (((const ConstPoolBool*)CPV)->getValue())
if (cast<const ConstPoolBool>(CPV)->getValue())
output_vbr((unsigned)1, Out);
else
output_vbr((unsigned)0, Out);

View File

@ -21,6 +21,7 @@
#include "llvm/Target/MachineInstrInfo.h"
#include "llvm/Target/MachineRegInfo.h"
#include "llvm/Support/StringExtras.h"
#include "llvm/iOther.h"
#include <algorithm>
@ -540,7 +541,7 @@ SchedGraph::addSSAEdge(SchedGraphNode* node,
// Phi instructions are the only ones that produce a value but don't get
// any non-dummy machine instructions. Return here as an optimization.
//
if (defVMInstr->isPHINode())
if (isa<PHINode>(defVMInstr))
return;
// Now add the graph edge for the appropriate machine instruction(s).
@ -642,7 +643,7 @@ void
SchedGraph::addNonSSAEdgesForValue(const Instruction* instr,
const TargetMachine& target)
{
if (instr->isPHINode())
if (isa<PHINode>(instr))
return;
MachineCodeForVMInstr& mvec = instr->getMachineInstrVec();

View File

@ -26,6 +26,7 @@
#include "llvm/Method.h"
#include "llvm/iTerminators.h"
#include "llvm/iMemory.h"
#include "llvm/iOther.h"
#include "llvm/ConstPoolVals.h"
#include "llvm/BasicBlock.h"
#include "llvm/CodeGen/MachineInstr.h"
@ -57,11 +58,11 @@ InstructionNode::InstructionNode(Instruction* I)
// Distinguish special cases of some instructions such as Ret and Br
//
if (opLabel == Instruction::Ret && ((ReturnInst*)I)->getReturnValue())
if (opLabel == Instruction::Ret && cast<ReturnInst>(I)->getReturnValue())
{
opLabel = RetValueOp; // ret(value) operation
}
else if (opLabel == Instruction::Br && ! ((BranchInst*)I)->isUnconditional())
else if (opLabel ==Instruction::Br && !cast<BranchInst>(I)->isUnconditional())
{
opLabel = BrCondOp; // br(cond) operation
}
@ -302,7 +303,7 @@ InstrForest::buildTreeForInstruction(Instruction *instr)
InstrTreeNode* opTreeNode;
if (isa<Instruction>(operand) && operand->use_size() == 1 &&
cast<Instruction>(operand)->getParent() == instr->getParent() &&
! instr->isPHINode() &&
!isa<PHINode>(instr) &&
instr->getOpcode() != Instruction::Call)
{
// Recursively create a treeNode for it.

View File

@ -351,9 +351,9 @@ void Interpreter::executeAllocInst(AllocationInst *I, ExecutionContext &SF) {
unsigned NumElements = 1;
if (I->getNumOperands()) { // Allocating a unsized array type?
assert(Ty->isArrayType() && Ty->castArrayType()->isUnsized() &&
assert(isa<ArrayType>(Ty) && cast<const ArrayType>(Ty)->isUnsized() &&
"Allocation inst with size operand for !unsized array type???");
Ty = ((const ArrayType*)Ty)->getElementType(); // Get the actual type...
Ty = cast<const ArrayType>(Ty)->getElementType(); // Get the actual type...
// Get the number of elements being allocated by the array...
GenericValue NumEl = getOperandValue(I->getOperand(0), SF);
@ -665,16 +665,16 @@ bool Interpreter::executeInstruction() {
// Memory Instructions
case Instruction::Alloca:
case Instruction::Malloc: executeAllocInst ((AllocationInst*)I, SF); break;
case Instruction::Free: executeFreeInst ((FreeInst*) I, SF); break;
case Instruction::Load: executeLoadInst ((LoadInst*) I, SF); break;
case Instruction::Store: executeStoreInst ((StoreInst*) I, SF); break;
case Instruction::Free: executeFreeInst (cast<FreeInst> (I), SF); break;
case Instruction::Load: executeLoadInst (cast<LoadInst> (I), SF); break;
case Instruction::Store: executeStoreInst (cast<StoreInst>(I), SF); break;
// Miscellaneous Instructions
case Instruction::Call: executeCallInst ((CallInst*) I, SF); break;
case Instruction::PHINode: executePHINode ((PHINode*) I, SF); break;
case Instruction::Shl: executeShlInst ((ShiftInst*) I, SF); break;
case Instruction::Shr: executeShrInst ((ShiftInst*) I, SF); break;
case Instruction::Cast: executeCastInst ((CastInst*) I, SF); break;
case Instruction::Call: executeCallInst (cast<CallInst> (I), SF); break;
case Instruction::PHINode: executePHINode (cast<PHINode> (I), SF); break;
case Instruction::Shl: executeShlInst (cast<ShiftInst>(I), SF); break;
case Instruction::Shr: executeShrInst (cast<ShiftInst>(I), SF); break;
case Instruction::Cast: executeCastInst (cast<CastInst> (I), SF); break;
default:
cout << "Don't know how to execute this instruction!\n-->" << I;
}

View File

@ -21,6 +21,7 @@
#include "llvm/Target/MachineInstrInfo.h"
#include "llvm/Target/MachineRegInfo.h"
#include "llvm/Support/StringExtras.h"
#include "llvm/iOther.h"
#include <algorithm>
@ -540,7 +541,7 @@ SchedGraph::addSSAEdge(SchedGraphNode* node,
// Phi instructions are the only ones that produce a value but don't get
// any non-dummy machine instructions. Return here as an optimization.
//
if (defVMInstr->isPHINode())
if (isa<PHINode>(defVMInstr))
return;
// Now add the graph edge for the appropriate machine instruction(s).
@ -642,7 +643,7 @@ void
SchedGraph::addNonSSAEdgesForValue(const Instruction* instr,
const TargetMachine& target)
{
if (instr->isPHINode())
if (isa<PHINode>(instr))
return;
MachineCodeForVMInstr& mvec = instr->getMachineInstrVec();

View File

@ -26,6 +26,7 @@
#include "llvm/Method.h"
#include "llvm/iTerminators.h"
#include "llvm/iMemory.h"
#include "llvm/iOther.h"
#include "llvm/ConstPoolVals.h"
#include "llvm/BasicBlock.h"
#include "llvm/CodeGen/MachineInstr.h"
@ -57,11 +58,11 @@ InstructionNode::InstructionNode(Instruction* I)
// Distinguish special cases of some instructions such as Ret and Br
//
if (opLabel == Instruction::Ret && ((ReturnInst*)I)->getReturnValue())
if (opLabel == Instruction::Ret && cast<ReturnInst>(I)->getReturnValue())
{
opLabel = RetValueOp; // ret(value) operation
}
else if (opLabel == Instruction::Br && ! ((BranchInst*)I)->isUnconditional())
else if (opLabel ==Instruction::Br && !cast<BranchInst>(I)->isUnconditional())
{
opLabel = BrCondOp; // br(cond) operation
}
@ -302,7 +303,7 @@ InstrForest::buildTreeForInstruction(Instruction *instr)
InstrTreeNode* opTreeNode;
if (isa<Instruction>(operand) && operand->use_size() == 1 &&
cast<Instruction>(operand)->getParent() == instr->getParent() &&
! instr->isPHINode() &&
!isa<PHINode>(instr) &&
instr->getOpcode() != Instruction::Call)
{
// Recursively create a treeNode for it.

View File

@ -2010,9 +2010,8 @@ GetInstructionsByRule(InstructionNode* subtreeRoot,
// Also, mark the operands of the Call as implicit operands
// of the machine instruction.
{
CallInst* callInstr = (CallInst*) subtreeRoot->getInstruction();
CallInst *callInstr = cast<CallInst>(subtreeRoot->getInstruction());
Method* callee = callInstr->getCalledMethod();
assert(callInstr->getOpcode() == Instruction::Call);
Instruction* jmpAddrReg = new TmpInstruction(Instruction::UserOp1,
callee, NULL);

View File

@ -147,14 +147,14 @@ unsigned char TargetData::getTypeAlignment(const Type *Ty) const {
unsigned TargetData::getIndexedOffset(const Type *ptrTy,
const vector<ConstPoolVal*> &Idx) const {
const PointerType *PtrTy = ptrTy->castPointerType();
const PointerType *PtrTy = cast<const PointerType>(ptrTy);
unsigned Result = 0;
// Get the type pointed to...
const Type *Ty = PtrTy->getValueType();
for (unsigned CurIDX = 0; CurIDX < Idx.size(); ++CurIDX) {
if (const StructType *STy = Ty->dyncastStructType()) {
if (const StructType *STy = dyn_cast<const StructType>(Ty)) {
assert(Idx[CurIDX]->getType() == Type::UByteTy && "Illegal struct idx");
unsigned FieldNo = ((ConstPoolUInt*)Idx[CurIDX++])->getValue();
@ -168,7 +168,7 @@ unsigned TargetData::getIndexedOffset(const Type *ptrTy,
// Update Ty to refer to current element
Ty = STy->getElementTypes()[FieldNo];
} else if (const ArrayType *ATy = Ty->dyncastArrayType()) {
} else if (const ArrayType *ATy = dyn_cast<const ArrayType>(Ty)) {
assert(0 && "Loading from arrays not implemented yet!");
} else {
assert(0 && "Indexing type that is not struct or array?");

View File

@ -63,12 +63,11 @@ static inline void RemapInstruction(Instruction *I,
// method by one level.
//
bool opt::InlineMethod(BasicBlock::iterator CIIt) {
assert((*CIIt)->getOpcode() == Instruction::Call &&
"InlineMethod only works on CallInst nodes!");
assert(isa<CallInst>(*CIIt) && "InlineMethod only works on CallInst nodes!");
assert((*CIIt)->getParent() && "Instruction not embedded in basic block!");
assert((*CIIt)->getParent()->getParent() && "Instruction not in method!");
CallInst *CI = (CallInst*)*CIIt;
CallInst *CI = cast<CallInst>(*CIIt);
const Method *CalledMeth = CI->getCalledMethod();
if (CalledMeth->isExternal()) return false; // Can't inline external method!
Method *CurrentMeth = CI->getParent()->getParent();
@ -152,13 +151,13 @@ bool opt::InlineMethod(BasicBlock::iterator CIIt) {
// Copy over the terminator now...
switch (TI->getOpcode()) {
case Instruction::Ret: {
const ReturnInst *RI = (const ReturnInst*)TI;
const ReturnInst *RI = cast<const ReturnInst>(TI);
if (PHI) { // The PHI node should include this value!
assert(RI->getReturnValue() && "Ret should have value!");
assert(RI->getReturnValue()->getType() == PHI->getType() &&
"Ret value not consistent in method!");
PHI->addIncoming((Value*)RI->getReturnValue(), (BasicBlock*)BB);
PHI->addIncoming((Value*)RI->getReturnValue(), cast<BasicBlock>(BB));
}
// Add a branch to the code that was after the original Call.
@ -236,9 +235,8 @@ static inline bool ShouldInlineMethod(const CallInst *CI, const Method *M) {
static inline bool DoMethodInlining(BasicBlock *BB) {
for (BasicBlock::iterator I = BB->begin(); I != BB->end(); ++I) {
if ((*I)->getOpcode() == Instruction::Call) {
if (CallInst *CI = dyn_cast<CallInst>(*I)) {
// Check to see if we should inline this method
CallInst *CI = (CallInst*)*I;
Method *M = CI->getCalledMethod();
if (ShouldInlineMethod(CI, M))
return InlineMethod(I);

View File

@ -14,6 +14,7 @@
#include "llvm/Support/DepthFirstIterator.h"
#include "llvm/Analysis/Writer.h"
#include "llvm/iTerminators.h"
#include "llvm/iOther.h"
#include <set>
#include <algorithm>
@ -171,15 +172,15 @@ bool ADCE::doADCE() {
set<BasicBlock*> VisitedBlocks;
BasicBlock *EntryBlock = fixupCFG(M->front(), VisitedBlocks, AliveBlocks);
if (EntryBlock && EntryBlock != M->front()) {
if (EntryBlock->front()->isPHINode()) {
if (isa<PHINode>(EntryBlock->front())) {
// Cannot make the first block be a block with a PHI node in it! Instead,
// strip the first basic block of the method to contain no instructions,
// then add a simple branch to the "real" entry node...
//
BasicBlock *E = M->front();
if (!E->front()->isTerminator() || // Check for an actual change...
((TerminatorInst*)E->front())->getNumSuccessors() != 1 ||
((TerminatorInst*)E->front())->getSuccessor(0) != EntryBlock) {
if (!isa<TerminatorInst>(E->front()) || // Check for an actual change...
cast<TerminatorInst>(E->front())->getNumSuccessors() != 1 ||
cast<TerminatorInst>(E->front())->getSuccessor(0) != EntryBlock) {
E->getInstList().delete_all(); // Delete all instructions in block
E->getInstList().push_back(new BranchInst(EntryBlock));
MadeChanges = true;

View File

@ -82,8 +82,7 @@ ConstantFoldBinaryInst(Method *M, Method::inst_iterator &DI,
//
bool opt::ConstantFoldTerminator(TerminatorInst *T) {
// Branch - See if we are conditional jumping on constant
if (T->getOpcode() == Instruction::Br) {
BranchInst *BI = (BranchInst*)T;
if (BranchInst *BI = dyn_cast<BranchInst>(T)) {
if (BI->isUnconditional()) return false; // Can't optimize uncond branch
BasicBlock *Dest1 = cast<BasicBlock>(BI->getOperand(0));
BasicBlock *Dest2 = cast<BasicBlock>(BI->getOperand(1));
@ -136,21 +135,21 @@ bool opt::ConstantFoldTerminator(TerminatorInst *T) {
inline static bool
ConstantFoldInstruction(Method *M, Method::inst_iterator &II) {
Instruction *Inst = *II;
if (Inst->isBinaryOp()) {
if (BinaryOperator *BInst = dyn_cast<BinaryOperator>(Inst)) {
ConstPoolVal *D1 = dyn_cast<ConstPoolVal>(Inst->getOperand(0));
ConstPoolVal *D2 = dyn_cast<ConstPoolVal>(Inst->getOperand(1));
if (D1 && D2)
return ConstantFoldBinaryInst(M, II, (BinaryOperator*)Inst, D1, D2);
return ConstantFoldBinaryInst(M, II, cast<BinaryOperator>(Inst), D1, D2);
} else if (Inst->isUnaryOp()) {
ConstPoolVal *D = dyn_cast<ConstPoolVal>(Inst->getOperand(0));
if (D) return ConstantFoldUnaryInst(M, II, (UnaryOperator*)Inst, D);
} else if (Inst->isTerminator()) {
return opt::ConstantFoldTerminator((TerminatorInst*)Inst);
} else if (UnaryOperator *UInst = dyn_cast<UnaryOperator>(Inst)) {
ConstPoolVal *D = dyn_cast<ConstPoolVal>(UInst->getOperand(0));
if (D) return ConstantFoldUnaryInst(M, II, UInst, D);
} else if (TerminatorInst *TInst = dyn_cast<TerminatorInst>(Inst)) {
return opt::ConstantFoldTerminator(TInst);
} else if (Inst->isPHINode()) {
PHINode *PN = (PHINode*)Inst; // If it's a PHI node and only has one operand
} else if (PHINode *PN = dyn_cast<PHINode>(Inst)) {
// If it's a PHI node and only has one operand
// Then replace it directly with that operand.
assert(PN->getOperand(0) && "PHI Node must have at least one operand!");
if (PN->getNumOperands() == 1) { // If the PHI Node has exactly 1 operand

View File

@ -84,7 +84,7 @@ static bool RemoveSingularPHIs(BasicBlock *BB) {
return false; // More than one predecessor...
Instruction *I = BB->front();
if (!I->isPHINode()) return false; // No PHI nodes
if (!isa<PHINode>(I)) return false; // No PHI nodes
//cerr << "Killing PHIs from " << BB;
//cerr << "Pred #0 = " << *BB->pred_begin();
@ -92,7 +92,7 @@ static bool RemoveSingularPHIs(BasicBlock *BB) {
//cerr << "Method == " << BB->getParent();
do {
PHINode *PN = (PHINode*)I;
PHINode *PN = cast<PHINode>(I);
assert(PN->getNumOperands() == 2 && "PHI node should only have one value!");
Value *V = PN->getOperand(0);
@ -100,7 +100,7 @@ static bool RemoveSingularPHIs(BasicBlock *BB) {
delete BB->getInstList().remove(BB->begin());
I = BB->front();
} while (I->isPHINode());
} while (isa<PHINode>(I));
return true; // Yes, we nuked at least one phi node
}
@ -120,7 +120,7 @@ static void ReplaceUsesWithConstant(Instruction *I) {
// Assumption: BB is the single predecessor of Succ.
//
static void PropogatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ) {
assert(Succ->front()->isPHINode() && "Only works on PHId BBs!");
assert(isa<PHINode>(Succ->front()) && "Only works on PHId BBs!");
// If there is more than one predecessor, and there are PHI nodes in
// the successor, then we need to add incoming edges for the PHI nodes
@ -129,7 +129,7 @@ static void PropogatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ) {
BasicBlock::iterator I = Succ->begin();
do { // Loop over all of the PHI nodes in the successor BB
PHINode *PN = (PHINode*)*I;
PHINode *PN = cast<PHINode>(*I);
Value *OldVal = PN->removeIncomingValue(BB);
assert(OldVal && "No entry in PHI for Pred BB!");
@ -140,7 +140,7 @@ static void PropogatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ) {
}
++I;
} while ((*I)->isPHINode());
} while (isa<PHINode>(*I));
}
@ -198,7 +198,7 @@ bool opt::SimplifyCFG(Method::iterator &BBIt) {
//cerr << "Killing Trivial BB: \n" << BB;
if (Succ != BB) { // Arg, don't hurt infinite loops!
if (Succ->front()->isPHINode()) {
if (isa<PHINode>(Succ->front())) {
// If our successor has PHI nodes, then we need to update them to
// include entries for BB's predecessors, not for BB itself.
//

View File

@ -41,7 +41,7 @@ static bool isLoopInvariant(cfg::Interval *Int, Value *V) {
if (!isa<Instruction>(V))
return true; // Constants and arguments are always loop invariant
BasicBlock *ValueBlock = ((Instruction*)V)->getParent();
BasicBlock *ValueBlock = cast<Instruction>(V)->getParent();
assert(ValueBlock && "Instruction not embedded in basic block!");
// For now, only consider values from outside of the interval, regardless of
@ -80,8 +80,8 @@ static LIVType isLinearInductionVariableH(cfg::Interval *Int, Value *V,
switch (I->getOpcode()) { // Handle each instruction seperately
case Instruction::Add:
case Instruction::Sub: {
Value *SubV1 = ((BinaryOperator*)I)->getOperand(0);
Value *SubV2 = ((BinaryOperator*)I)->getOperand(1);
Value *SubV1 = cast<BinaryOperator>(I)->getOperand(0);
Value *SubV2 = cast<BinaryOperator>(I)->getOperand(1);
LIVType SubLIVType1 = isLinearInductionVariableH(Int, SubV1, PN);
if (SubLIVType1 == isOther) return isOther; // Early bailout
LIVType SubLIVType2 = isLinearInductionVariableH(Int, SubV2, PN);
@ -144,12 +144,11 @@ static inline bool isSimpleInductionVar(PHINode *PN) {
Value *StepExpr = PN->getIncomingValue(1);
if (!isa<Instruction>(StepExpr) ||
((Instruction*)StepExpr)->getOpcode() != Instruction::Add)
cast<Instruction>(StepExpr)->getOpcode() != Instruction::Add)
return false;
BinaryOperator *I = (BinaryOperator*)StepExpr;
assert(isa<Instruction>(I->getOperand(0)) &&
((Instruction*)I->getOperand(0))->isPHINode() &&
BinaryOperator *I = cast<BinaryOperator>(StepExpr);
assert(isa<PHINode>(I->getOperand(0)) &&
"PHI node should be first operand of ADD instruction!");
// Get the right hand side of the ADD node. See if it is a constant 1.
@ -225,7 +224,7 @@ static PHINode *InjectSimpleInductionVariable(cfg::Interval *Int) {
// Insert the Add instruction as the first (non-phi) instruction in the
// header node's basic block.
BasicBlock::iterator I = IL.begin();
while ((*I)->isPHINode()) ++I;
while (isa<PHINode>(*I)) ++I;
IL.insert(I, AddNode);
return PN;
}
@ -256,8 +255,8 @@ static bool ProcessInterval(cfg::Interval *Int) {
BasicBlock *Header = Int->getHeaderNode();
// Loop over all of the PHI nodes in the interval header...
for (BasicBlock::iterator I = Header->begin(), E = Header->end();
I != E && (*I)->isPHINode(); ++I) {
PHINode *PN = (PHINode*)*I;
I != E && isa<PHINode>(*I); ++I) {
PHINode *PN = cast<PHINode>(*I);
if (PN->getNumIncomingValues() != 2) { // These should be eliminated by now.
cerr << "Found interval header with more than 2 predecessors! Ignoring\n";
return false; // Todo, make an assertion.

View File

@ -270,7 +270,7 @@ bool SCCP::doSCCP() {
MadeChanges = true;
continue; // Skip the ++II at the end of the loop here...
} else if (Inst->isTerminator()) {
MadeChanges |= opt::ConstantFoldTerminator((TerminatorInst*)Inst);
MadeChanges |= opt::ConstantFoldTerminator(cast<TerminatorInst>(Inst));
}
++II;
@ -312,7 +312,7 @@ void SCCP::UpdateInstruction(Instruction *I) {
// Handle PHI nodes...
//
case Instruction::PHINode: {
PHINode *PN = (PHINode*)I;
PHINode *PN = cast<PHINode>(I);
unsigned NumValues = PN->getNumIncomingValues(), i;
InstVal *OperandIV = 0;
@ -380,7 +380,7 @@ void SCCP::UpdateInstruction(Instruction *I) {
//
case Instruction::Ret: return; // Method return doesn't affect anything
case Instruction::Br: { // Handle conditional branches...
BranchInst *BI = (BranchInst*)I;
BranchInst *BI = cast<BranchInst>(I);
if (BI->isUnconditional())
return; // Unconditional branches are already handled!
@ -391,7 +391,7 @@ void SCCP::UpdateInstruction(Instruction *I) {
markExecutable(BI->getSuccessor(1));
} else if (BCValue.isConstant()) {
// Constant condition variables mean the branch can only go a single way.
ConstPoolBool *CPB = (ConstPoolBool*)BCValue.getConstant();
ConstPoolBool *CPB = cast<ConstPoolBool>(BCValue.getConstant());
if (CPB->getValue()) // If the branch condition is TRUE...
markExecutable(BI->getSuccessor(0));
else // Else if the br cond is FALSE...
@ -401,7 +401,7 @@ void SCCP::UpdateInstruction(Instruction *I) {
}
case Instruction::Switch: {
SwitchInst *SI = (SwitchInst*)I;
SwitchInst *SI = cast<SwitchInst>(I);
InstVal &SCValue = getValueState(SI->getCondition());
if (SCValue.isOverdefined()) { // Overdefined condition? All dests are exe
for(unsigned i = 0; BasicBlock *Succ = SI->getSuccessor(i); ++i)
@ -432,9 +432,9 @@ void SCCP::UpdateInstruction(Instruction *I) {
// Also treated as unary here, are cast instructions and getelementptr
// instructions on struct* operands.
//
if (I->isUnaryOp() || I->getOpcode() == Instruction::Cast ||
(I->getOpcode() == Instruction::GetElementPtr &&
((GetElementPtrInst*)I)->isStructSelector())) {
if (isa<UnaryOperator>(I) || isa<CastInst>(I) ||
(isa<GetElementPtrInst>(I) &&
cast<GetElementPtrInst>(I)->isStructSelector())) {
Value *V = I->getOperand(0);
InstVal &VState = getValueState(V);
@ -458,8 +458,7 @@ void SCCP::UpdateInstruction(Instruction *I) {
//===-----------------------------------------------------------------===//
// Handle Binary instructions...
//
if (I->isBinaryOp() || I->getOpcode() == Instruction::Shl ||
I->getOpcode() == Instruction::Shr) {
if (isa<BinaryOperator>(I) || isa<ShiftInst>(I)) {
Value *V1 = I->getOperand(0);
Value *V2 = I->getOperand(1);

View File

@ -192,7 +192,7 @@ void AssemblyWriter::processMethod(const Method *M) {
// Finish printing arguments...
const MethodType *MT = (const MethodType*)M->getType();
const MethodType *MT = cast<const MethodType>(M->getType());
if (MT->isVarArg()) {
if (MT->getParamTypes().size()) Out << ", ";
Out << "..."; // Output varargs portion of signature!
@ -287,7 +287,7 @@ void AssemblyWriter::processInstruction(const Instruction *I) {
writeOperand(I->getOperand(op+1), true);
}
Out << "\n\t]";
} else if (I->isPHINode()) {
} else if (isa<PHINode>(I)) {
Out << " " << Operand->getType();
Out << " ["; writeOperand(Operand, false); Out << ",";
@ -311,7 +311,7 @@ void AssemblyWriter::processInstruction(const Instruction *I) {
Out << " )";
} else if (I->getOpcode() == Instruction::Malloc ||
I->getOpcode() == Instruction::Alloca) {
Out << " " << ((const PointerType*)I->getType())->getValueType();
Out << " " << cast<const PointerType>(I->getType())->getValueType();
if (I->getNumOperands()) {
Out << ",";
writeOperand(I->getOperand(0), true);

View File

@ -54,14 +54,14 @@ void BasicBlock::setParent(Method *parent) {
TerminatorInst *BasicBlock::getTerminator() {
if (InstList.empty()) return 0;
Instruction *T = InstList.back();
if (T->isTerminator()) return (TerminatorInst*)T;
if (isa<TerminatorInst>(T)) return cast<TerminatorInst>(T);
return 0;
}
const TerminatorInst *const BasicBlock::getTerminator() const {
if (InstList.empty()) return 0;
const Instruction *T = InstList.back();
if (T->isTerminator()) return (TerminatorInst*)T;
if (const TerminatorInst *TI = dyn_cast<TerminatorInst>(InstList.back()))
return TI;
return 0;
}
@ -92,7 +92,7 @@ bool BasicBlock::hasConstantPoolReferences() const {
void BasicBlock::removePredecessor(BasicBlock *Pred) {
assert(find(pred_begin(), pred_end(), Pred) != pred_end() &&
"removePredecessor: BB is not a predecessor!");
if (!front()->isPHINode()) return; // Quick exit.
if (!isa<PHINode>(front())) return; // Quick exit.
pred_iterator PI(pred_begin()), EI(pred_end());
unsigned max_idx;
@ -105,8 +105,8 @@ void BasicBlock::removePredecessor(BasicBlock *Pred) {
// altogether.
assert(max_idx != 0 && "PHI Node in block with 0 predecessors!?!?!");
if (max_idx <= 2) { // <= Two predecessors BEFORE I remove one?
while (front()->isPHINode()) { // Yup, loop through and nuke the PHI nodes
PHINode *PN = (PHINode*)front();
// Yup, loop through and nuke the PHI nodes
while (PHINode *PN = dyn_cast<PHINode>(front())) {
PN->removeIncomingValue(Pred); // Remove the predecessor first...
assert(PN->getNumIncomingValues() == max_idx-1 &&
@ -121,10 +121,8 @@ void BasicBlock::removePredecessor(BasicBlock *Pred) {
// Okay, now we know that we need to remove predecessor #pred_idx from all
// PHI nodes. Iterate over each PHI node fixing them up
iterator II(begin());
for (; (*II)->isPHINode(); ++II) {
PHINode *PN = (PHINode*)*II;
PN->removeIncomingValue(Pred);
}
for (; isa<PHINode>(*II); ++II)
cast<PHINode>(*II)->removeIncomingValue(Pred);
}
}

View File

@ -45,13 +45,13 @@ ConstPoolVal *ConstPoolVal::getNullConstant(const Type *Ty) {
case Type::DoubleTyID: return ConstPoolFP::get(Ty, 0);
case Type::PointerTyID:
return ConstPoolPointer::getNullPointer(Ty->castPointerType());
return ConstPoolPointer::getNullPointer(cast<PointerType>(Ty));
default:
return 0;
}
}
bool ConstPoolInt::isa(const ConstPoolVal *CPV) {
bool ConstPoolInt::classof(const ConstPoolVal *CPV) {
return CPV->getType()->isIntegral();
}

View File

@ -192,7 +192,7 @@ static string getTypeProps(const Type *Ty, vector<const Type *> &TypeStack,
if (!Ty->isAbstract() && !Ty->isRecursive() && // Base case for the recursion
Ty->getDescription().size()) {
Result = Ty->getDescription(); // Primitive = leaf type
} else if (Ty->isOpaqueType()) { // Base case for the recursion
} else if (isa<OpaqueType>(Ty)) { // Base case for the recursion
Result = Ty->getDescription(); // Opaque = leaf type
isAbstract = true; // This whole type is abstract!
} else {
@ -212,7 +212,7 @@ static string getTypeProps(const Type *Ty, vector<const Type *> &TypeStack,
switch (Ty->getPrimitiveID()) {
case Type::MethodTyID: {
const MethodType *MTy = (const MethodType*)Ty;
const MethodType *MTy = cast<const MethodType>(Ty);
Result = getTypeProps(MTy->getReturnType(), TypeStack,
isAbstract, isRecursive)+" (";
for (MethodType::ParamTypes::const_iterator
@ -230,7 +230,7 @@ static string getTypeProps(const Type *Ty, vector<const Type *> &TypeStack,
break;
}
case Type::StructTyID: {
const StructType *STy = (const StructType*)Ty;
const StructType *STy = cast<const StructType>(Ty);
Result = "{ ";
for (StructType::ElementTypes::const_iterator
I = STy->getElementTypes().begin(),
@ -243,13 +243,13 @@ static string getTypeProps(const Type *Ty, vector<const Type *> &TypeStack,
break;
}
case Type::PointerTyID: {
const PointerType *PTy = (const PointerType*)Ty;
const PointerType *PTy = cast<const PointerType>(Ty);
Result = getTypeProps(PTy->getValueType(), TypeStack,
isAbstract, isRecursive) + " *";
break;
}
case Type::ArrayTyID: {
const ArrayType *ATy = (const ArrayType*)Ty;
const ArrayType *ATy = cast<const ArrayType>(Ty);
int NumElements = ATy->getNumElements();
Result = "[";
if (NumElements != -1) Result += itostr(NumElements) + " x ";
@ -319,8 +319,8 @@ static bool TypesEqual(const Type *Ty, const Type *Ty2,
// algorithm is the fact that arraytypes have sizes that differentiates types,
// consider this now.
if (Ty->isArrayType())
if (((const ArrayType*)Ty)->getNumElements() !=
((const ArrayType*)Ty2)->getNumElements()) return false;
if (cast<const ArrayType>(Ty)->getNumElements() !=
cast<const ArrayType>(Ty2)->getNumElements()) return false;
return I == IE && I2 == IE2; // Types equal if both iterators are done
}