inline pointer operator*() const {
assert(isAtConstant() && "Dereferenced an iterator at the end!");
- return InstI->getOperand(OpIdx)->castConstantAsserting();
+ return cast<ConstPoolVal>(InstI->getOperand(OpIdx));
}
inline pointer operator->() const { return operator*(); }
namespace analysis {
-template <class Payload> class InstTreeNode;
-template<class Payload> class InstForest;
+template<class Payload> class InstTreeNode;
+template<class Payload> class InstForest;
//===----------------------------------------------------------------------===//
// Accessors for different node types...
inline ConstPoolVal *getConstant() {
- return getValue()->castConstantAsserting();
+ return cast<ConstPoolVal>(getValue());
}
inline const ConstPoolVal *getConstant() const {
- return getValue()->castConstantAsserting();
+ return cast<const ConstPoolVal>(getValue());
}
inline BasicBlock *getBasicBlock() {
return cast<BasicBlock>(getValue());
getTreeData().first.first = V; // Save tree node
if (!V->isInstruction()) {
- assert((V->isConstant() || V->isBasicBlock() ||
- V->isMethodArgument() || V->isGlobal()) &&
+ assert((isa<ConstPoolVal>(V) || isa<BasicBlock>(V) ||
+ isa<MethodArgument>(V) || isa<GlobalVariable>(V)) &&
"Unrecognized value type for InstForest Partition!");
- if (V->isConstant())
+ if (isa<ConstPoolVal>(V))
getTreeData().first.second = ConstNode;
- else if (V->isBasicBlock())
+ else if (isa<BasicBlock>(V))
getTreeData().first.second = BasicBlockNode;
else
getTreeData().first.second = TemporaryNode;
inline ostream &operator<<(ostream &o, const Value *I) {
switch (I->getValueType()) {
- case Value::TypeVal: return o << I->castTypeAsserting();
+ case Value::TypeVal: return o << cast<const Type>(I);
case Value::ConstantVal: WriteToAssembly((const ConstPoolVal*)I,o);break;
case Value::MethodArgumentVal: return o << I->getType() << " "<< I->getName();
case Value::InstructionVal:WriteToAssembly((const Instruction *)I, o);break;
// type NewType and for 'this' to be deleted.
//
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) {
+ return T->isDerivedType();
+ }
+ static inline bool isa(const Value *V) {
+ return ::isa<Type>(V) && isa(cast<const Type>(V));
+ }
};
return T->getPrimitiveID() == MethodTyID;
}
static inline bool isa(const Value *V) {
- return ::isa<Type>(V) && MethodType::isa(cast<const Type>(V));
+ return ::isa<Type>(V) && isa(cast<const Type>(V));
}
};
virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
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) {
+ return T->getPrimitiveID() == ArrayTyID;
+ }
+ static inline bool isa(const Value *V) {
+ return ::isa<Type>(V) && isa(cast<const Type>(V));
+ }
};
virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
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) {
+ return T->getPrimitiveID() == StructTyID;
+ }
+ static inline bool isa(const Value *V) {
+ return ::isa<Type>(V) && isa(cast<const Type>(V));
+ }
};
// concrete type.
//
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) {
+ return T->getPrimitiveID() == PointerTyID;
+ }
+ static inline bool isa(const Value *V) {
+ return ::isa<Type>(V) && isa(cast<const Type>(V));
+ }
};
static OpaqueType *get() {
return new OpaqueType(); // All opaque types are distinct
}
+
+ // 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) {
+ return T->getPrimitiveID() == OpaqueTyID;
+ }
+ static inline bool isa(const Value *V) {
+ return ::isa<Type>(V) && isa(cast<const Type>(V));
+ }
};
//
template <class TypeSubClass> void PATypeHandle<TypeSubClass>::addUser() {
if (Ty->isAbstract())
- Ty->castDerivedTypeAsserting()->addAbstractTypeUser(User);
+ cast<DerivedType>(Ty)->addAbstractTypeUser(User);
}
template <class TypeSubClass> void PATypeHandle<TypeSubClass>::removeUser() {
if (Ty->isAbstract())
- Ty->castDerivedTypeAsserting()->removeAbstractTypeUser(User);
+ cast<DerivedType>(Ty)->removeAbstractTypeUser(User);
}
#endif
//
inline bool hasInitializer() const { return !Operands.empty(); }
inline const ConstPoolVal *getInitializer() const {
- return Operands[0]->castConstantAsserting();
+ return (const ConstPoolVal*)Operands[0].get();
}
inline ConstPoolVal *getInitializer() {
- return Operands[0]->castConstantAsserting();
+ return (ConstPoolVal*)Operands[0].get();
}
inline void setInitializer(ConstPoolVal *CPV) { Operands[0] = (Value*)CPV; }
// leads to undefined behavior.
//
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) {
+ return V->getValueType() == Value::GlobalVal;
+ }
};
#endif
#include "llvm/Value.h"
#include <map>
+#ifndef NDEBUG // Only for assertions
+#include "llvm/Type.h"
+#include "llvm/ConstPoolVals.h"
+#endif
+
class Value;
class Type;
// (constant/type)s.
//
inline void insert(const string &Name, Value *V) {
- assert((V->isType() || V->isConstant()) &&
+ assert((isa<Type>(V) || isa<ConstPoolVal>(V)) &&
"Can only insert types and constants here!");
insertEntry(Name, V);
}
inline bool isPrimitiveType() const { return ID < FirstDerivedTyID; }
inline bool isDerivedType() const { return ID >= FirstDerivedTyID; }
- inline const DerivedType *castDerivedType() const {
- return isDerivedType() ? (const DerivedType*)this : 0;
- }
- inline const DerivedType *castDerivedTypeAsserting() const {
- assert(isDerivedType());
- return (const DerivedType*)this;
- }
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool isa(const Type *T) { return true; }
inline CLASS *cast##NAME() { /* nonconst version */ \
return is##NAME() ? (CLASS*)this : 0; \
} \
- inline const CLASS *cast##NAME##Asserting() const { /*const version */ \
- assert(is##NAME() && "Expected Value Type: " #NAME); \
- return (const CLASS*)this; \
- } \
- inline CLASS *cast##NAME##Asserting() { /* nonconst version */ \
- assert(is##NAME() && "Expected Value Type: " #NAME); \
- return (CLASS*)this; \
- } \
CAST_FN(Constant , ConstPoolVal )
CAST_FN(MethodArgument, MethodArgument)
CAST_FN(BasicBlock , BasicBlock )
CAST_FN(Method , Method )
CAST_FN(Global , GlobalVariable)
- CAST_FN(Module , Module )
#undef CAST_FN
- // Type value is special, because there is no nonconst version of functions!
- inline bool isType() const { return VTy == TypeVal; }
- inline const Type *castType() const {
- return (VTy == TypeVal) ? (const Type*)this : 0;
- }
- inline const Type *castTypeAsserting() const {
- assert(isType() && "Expected Value Type: Type");
- return (const Type*)this;
- }
-
// replaceAllUsesWith - Go through the uses list for this definition and make
// each use point to "D" instead of "this". After this completes, 'this's
// use list should be empty.
return isa<X>(Val) ? cast<X>(Val) : 0;
}
+
+// isa - Provide some specializations of isa so that we have to include the
+// subtype header files to test to see if the value is a subclass...
+//
+template <> bool isa<Type, Value*>(Value *Val) {
+ return Val->getValueType() == Value::TypeVal;
+}
+template <> bool isa<ConstPoolVal, Value*>(Value *Val) {
+ return Val->getValueType() == Value::ConstantVal;
+}
+template <> bool isa<MethodArgument, Value*>(Value *Val) {
+ return Val->getValueType() == Value::MethodArgumentVal;
+}
+template <> bool isa<Instruction, Value*>(Value *Val) {
+ return Val->getValueType() == Value::InstructionVal;
+}
+template <> bool isa<BasicBlock, Value*>(Value *Val) {
+ return Val->getValueType() == Value::BasicBlockVal;
+}
+template <> bool isa<Method, Value*>(Value *Val) {
+ return Val->getValueType() == Value::MethodVal;
+}
+template <> bool isa<GlobalVariable, Value*>(Value *Val) {
+ return Val->getValueType() == Value::GlobalVal;
+}
+template <> bool isa<Module, Value*>(Value *Val) {
+ return Val->getValueType() == Value::ModuleVal;
+}
+
#endif
// successor. WARNING: This does not gracefully accept idx's out of range!
inline const ConstPoolVal *getSuccessorValue(unsigned idx) const {
assert(idx < getNumSuccessors() && "Successor # out of range!");
- return Operands[idx*2]->castConstantAsserting();
+ return cast<const ConstPoolVal>(Operands[idx*2]);
}
inline ConstPoolVal *getSuccessorValue(unsigned idx) {
assert(idx < getNumSuccessors() && "Successor # out of range!");
- return Operands[idx*2]->castConstantAsserting();
+ return cast<ConstPoolVal>(Operands[idx*2]);
}
virtual unsigned getNumSuccessors() const { return Operands.size()/2; }
};
case Value::MethodArgumentVal: // nothing known, return variable itself
return Expr;
case Value::ConstantVal: // Constant value, just return constant
- ConstPoolVal *CPV = Expr->castConstantAsserting();
+ ConstPoolVal *CPV = cast<ConstPoolVal>(Expr);
if (CPV->getType()->isIntegral()) { // It's an integral constant!
ConstPoolInt *CPI = (ConstPoolInt*)Expr;
return ExprType(CPI->equalsInt(0) ? 0 : CPI);
}
D.destroy(); // Free old strdup'd memory...
- return N->castTypeAsserting();
+ return cast<const Type>(N);
}
default:
ThrowException("Invalid symbol type reference!");
case ValID::ConstNullVal:
if (!Ty->isPointerType())
ThrowException("Cannot create a a non pointer null!");
- CPV = ConstPoolPointer::getNullPointer(Ty->castPointerType());
+ CPV = ConstPoolPointer::getNullPointer(cast<PointerType>(Ty));
break;
default:
assert(0 && "Unhandled case!");
getLineNumFromPlaceHolder(V));
}
- assert(!V->isType() && "Types should be in LateResolveTypes!");
+ assert(!isa<Type>(V) && "Types should be in LateResolveTypes!");
V->replaceAllUsesWith(TheRealValue);
delete V;
getLineNumFromPlaceHolder(Ty));
}
- // FIXME: When types are not const
- DerivedType *DTy = const_cast<DerivedType*>(Ty->castDerivedTypeAsserting());
-
// Refine the opaque type we had to the new type we are getting.
- DTy->refineAbstractTypeTo(TheRealType);
+ cast<DerivedType>(Ty)->refineAbstractTypeTo(TheRealType);
// No need to delete type, refine does that for us.
LateResolveTypes.pop_back();
if (Existing) { // Inserting a name that is already defined???
// 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 = Existing->castType())
+ if (const Type *Ty = cast<const Type>(Existing))
if (Ty->isOpaqueType()) {
// We ARE replacing an opaque type!
- // TODO: FIXME when types are not const!
- const_cast<DerivedType*>(Ty->castDerivedTypeAsserting())->refineAbstractTypeTo(V->castTypeAsserting());
+ cast<DerivedType>(Ty)->refineAbstractTypeTo(cast<Type>(V));
return;
}
| ConstPool OptAssign GlobalType ResolvedVal {
const Type *Ty = $4->getType();
// Global declarations appear in Constant Pool
- ConstPoolVal *Initializer = $4->castConstant();
+ ConstPoolVal *Initializer = cast<ConstPoolVal>($4);
if (Initializer == 0)
ThrowException("Global value initializer is not a constant!");
| ConstPool OptAssign UNINIT GlobalType Types {
const Type *Ty = *$5;
// Global declarations appear in Constant Pool
- if (Ty->isArrayType() && Ty->castArrayType()->isUnsized()) {
+ if (isa<ArrayType>(Ty) && cast<ArrayType>(Ty)->isUnsized()) {
ThrowException("Type '" + Ty->getDescription() +
"' is not a sized type!");
}
JumpTable : JumpTable IntType ConstValueRef ',' LABEL ValueRef {
$$ = $1;
- ConstPoolVal *V = getVal($2, $3, true)->castConstantAsserting();
+ ConstPoolVal *V = cast<ConstPoolVal>(getVal($2, $3, true));
if (V == 0)
ThrowException("May only switch on a constant pool value!");
}
| IntType ConstValueRef ',' LABEL ValueRef {
$$ = new list<pair<ConstPoolVal*, BasicBlock*> >();
- ConstPoolVal *V = getVal($1, $2, true)->castConstantAsserting();
+ ConstPoolVal *V = cast<ConstPoolVal>(getVal($1, $2, true));
if (V == 0)
ThrowException("May only switch on a constant pool value!");
// abstract type to use the newty. This also will cause the opaque type
// to be deleted...
//
- // FIXME when types are not const
- const_cast<DerivedType*>(Tab[i+BaseLevel]->castDerivedTypeAsserting())->refineAbstractTypeTo(NewTy);
+ cast<DerivedType>(Tab[i+BaseLevel].get())->refineAbstractTypeTo(NewTy);
// This should have replace the old opaque type with the new type in the
// value table...
BCR_TRACE(5, "Resulting types:\n");
for (unsigned i = 0; i < NumEntries; i++) {
- BCR_TRACE(5, Tab[i+BaseLevel]->castTypeAsserting() << "\n");
+ BCR_TRACE(5, cast<Type>(Tab[i+BaseLevel]) << "\n");
}
return false;
}
const Value *D = getValue(Type::TypeTy, ID, false);
if (D == 0) return failure<const Type*>(0);
- return D->castTypeAsserting();
+ return cast<Type>(D);
}
bool BytecodeParser::insertValue(Value *Val, vector<ValueList> &ValueTab) {
Value *V = getValue(Ty->castPointerType()->getValueType(),
InitSlot, false);
if (V == 0) return failure(true);
- Initializer = V->castConstantAsserting();
+ Initializer = cast<ConstPoolVal>(V);
}
// Create the global variable...
if (!dontIgnore) // Don't ignore nonignorables!
if (D->getType() == Type::VoidTy || // Ignore void type nodes
(IgnoreNamedNodes && // Ignore named and constants
- (D->hasName() || D->isConstant()) && !D->isType())) {
+ (D->hasName() || isa<ConstPoolVal>(D)) && !isa<Type>(D))) {
SC_DEBUG("ignored value " << D << endl);
return -1; // We do need types unconditionally though
}
// If it's a type, make sure that all subtypes of the type are included...
- if (const Type *TheTy = D->castType()) {
+ if (const Type *TheTy = dyn_cast<const Type>(D)) {
SC_DEBUG(" Inserted type: " << TheTy->getDescription() << endl);
// Loop over any contained types in the definition... in reverse depth first
// Used for debugging DefSlot=-1 assertion...
//if (Typ == Type::TypeTy)
- // cerr << "Inserting type '" << D->castTypeAsserting()->getDescription() << "'!\n";
+ // cerr << "Inserting type '" << cast<Type>(D)->getDescription() << "'!\n";
if (Typ->isDerivedType()) {
int DefSlot = getValSlot(Typ);
unsigned NC = ValNo; // Number of constants
for (; NC < Plane.size() &&
- (Plane[NC]->isConstant() || Plane[NC]->isType()); NC++) /*empty*/;
+ (isa<ConstPoolVal>(Plane[NC]) ||
+ isa<Type>(Plane[NC])); NC++) /*empty*/;
NC -= ValNo; // Convert from index into count
if (NC == 0) continue; // Skip empty type planes...
case 208: // stmt: BrCond(boolconst)
{
// boolconst => boolean is a constant; use BA to first or second label
- ConstPoolVal* constVal =
- subtreeRoot->leftChild()->getValue()->castConstantAsserting();
+ ConstPoolVal* constVal =
+ cast<ConstPoolVal>(subtreeRoot->leftChild()->getValue());
unsigned dest = ((ConstPoolBool*) constVal)->getValue()? 0 : 1;
mvec[0] = new MachineInstr(BA);
void *D) {
const TargetData &TD = *(const TargetData*)D;
assert(AID == TD.AID && "Target data annotation ID mismatch!");
- const Type *Ty = ((const Value *)T)->castTypeAsserting();
+ const Type *Ty = cast<const Type>((const Value *)T);
assert(Ty->isStructType() &&
"Can only create StructLayout annotation on structs!");
return new StructLayout((const StructType *)Ty, TD);
SymbolTable::type_iterator B;
while ((B = Plane.begin()) != Plane.end()) { // Found nonempty type plane!
Value *V = B->second;
- if (V->isConstant() || V->isType())
+ if (isa<ConstPoolVal>(V) || isa<Type>(V))
SymTab->type_remove(B);
else
V->setName("", SymTab); // Set name to "", removing from symbol table!
for (; I != End; ++I) {
const Value *V = I->second;
- if (const ConstPoolVal *CPV = V->castConstant()) {
+ if (const ConstPoolVal *CPV = cast<const ConstPoolVal>(V)) {
processConstant(CPV);
- } else if (const Type *Ty = V->castType()) {
+ } else if (const Type *Ty = cast<const Type>(V)) {
Out << "\t%" << I->first << " = type " << Ty->getDescription() << endl;
}
}
string Result = "[";
if (Operands.size()) {
Result += " " + Operands[0]->getType()->getDescription() +
- " " + Operands[0]->castConstantAsserting()->getStrValue();
+ " " + cast<ConstPoolVal>(Operands[0])->getStrValue();
for (unsigned i = 1; i < Operands.size(); i++)
Result += ", " + Operands[i]->getType()->getDescription() +
- " " + Operands[i]->castConstantAsserting()->getStrValue();
+ " " + cast<ConstPoolVal>(Operands[i])->getStrValue();
}
return Result + " ]";
string Result = "{";
if (Operands.size()) {
Result += " " + Operands[0]->getType()->getDescription() +
- " " + Operands[0]->castConstantAsserting()->getStrValue();
+ " " + cast<ConstPoolVal>(Operands[0])->getStrValue();
for (unsigned i = 1; i < Operands.size(); i++)
Result += ", " + Operands[i]->getType()->getDescription() +
- " " + Operands[i]->castConstantAsserting()->getStrValue();
+ " " + cast<ConstPoolVal>(Operands[i])->getStrValue();
}
return Result + " }";
//
Annotation *ConstRules::find(AnnotationID AID, const Annotable *TyA, void *) {
assert(AID == ConstRules::AID && "Bad annotation for factory!");
- const Type *Ty = ((const Value*)TyA)->castTypeAsserting();
+ const Type *Ty = cast<Type>((const Value*)TyA);
switch (Ty->getPrimitiveID()) {
case Type::BoolTyID: return new BoolRules();
if (!dontIgnore) // Don't ignore nonignorables!
if (D->getType() == Type::VoidTy || // Ignore void type nodes
(IgnoreNamedNodes && // Ignore named and constants
- (D->hasName() || D->isConstant()) && !D->isType())) {
+ (D->hasName() || isa<ConstPoolVal>(D)) && !isa<Type>(D))) {
SC_DEBUG("ignored value " << D << endl);
return -1; // We do need types unconditionally though
}
// If it's a type, make sure that all subtypes of the type are included...
- if (const Type *TheTy = D->castType()) {
+ if (const Type *TheTy = dyn_cast<const Type>(D)) {
SC_DEBUG(" Inserted type: " << TheTy->getDescription() << endl);
// Loop over any contained types in the definition... in reverse depth first
// Used for debugging DefSlot=-1 assertion...
//if (Typ == Type::TypeTy)
- // cerr << "Inserting type '" << D->castTypeAsserting()->getDescription() << "'!\n";
+ // cerr << "Inserting type '" << cast<Type>(D)->getDescription() << "'!\n";
if (Typ->isDerivedType()) {
int DefSlot = getValSlot(Typ);
#include "llvm/InstrTypes.h"
#include "llvm/Support/StringExtras.h"
#include "llvm/DerivedTypes.h"
-#ifndef NDEBUG
-#include "llvm/BasicBlock.h" // Required for assertions to work.
-#include "llvm/Type.h"
-#endif
SymbolTable::~SymbolTable() {
// Drop all abstract type references in the type plane...
if (TyPlane != end()) {
VarMap &TyP = TyPlane->second;
for (VarMap::iterator I = TyP.begin(), E = TyP.end(); I != E; ++I) {
- const Type *Ty = I->second->castTypeAsserting();
+ const Type *Ty = cast<const Type>(I->second);
if (Ty->isAbstract()) // If abstract, drop the reference...
- Ty->castDerivedTypeAsserting()->removeAbstractTypeUser(this);
+ cast<DerivedType>(Ty)->removeAbstractTypeUser(this);
}
}
#ifndef NDEBUG // Only do this in -g mode...
bool LeftoverValues = true;
for (iterator i = begin(); i != end(); ++i) {
for (type_iterator I = i->second.begin(); I != i->second.end(); ++I)
- if (!I->second->isConstant() && !I->second->isType()) {
+ if (!isa<ConstPoolVal>(I->second) && !isa<Type>(I->second)) {
cerr << "Value still in symbol table! Type = '"
<< i->first->getDescription() << "' Name = '" << I->first << "'\n";
LeftoverValues = false;
// If we are removing an abstract type, remove the symbol table from it's use
// list...
if (Ty == Type::TypeTy) {
- const Type *T = Result->castTypeAsserting();
+ const Type *T = cast<const Type>(Result);
if (T->isAbstract())
- T->castDerivedTypeAsserting()->removeAbstractTypeUser(this);
+ cast<DerivedType>(T)->removeAbstractTypeUser(this);
}
return Result;
// If we are adding an abstract type, add the symbol table to it's use list.
if (VTy == Type::TypeTy) {
- const Type *T = V->castTypeAsserting();
+ const Type *T = cast<const Type>(V);
if (T->isAbstract())
- T->castDerivedTypeAsserting()->addAbstractTypeUser(this);
+ cast<DerivedType>(T)->addAbstractTypeUser(this);
}
}
OldType->removeAbstractTypeUser(this);
I->second = (Value*)NewType; // TODO FIXME when types aren't const
if (NewType->isAbstract())
- NewType->castDerivedTypeAsserting()->addAbstractTypeUser(this);
+ cast<const DerivedType>(NewType)->addAbstractTypeUser(this);
}
}