mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-05 13:26:55 +00:00
Add more support for new style casts
Convert more code to use them git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@695 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -45,7 +45,7 @@ public:
|
||||
|
||||
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*(); }
|
||||
|
||||
|
@@ -20,8 +20,8 @@
|
||||
|
||||
namespace analysis {
|
||||
|
||||
template <class Payload> class InstTreeNode;
|
||||
template<class Payload> class InstForest;
|
||||
template<class Payload> class InstTreeNode;
|
||||
template<class Payload> class InstForest;
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
@@ -74,10 +74,10 @@ public:
|
||||
|
||||
// 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());
|
||||
@@ -230,12 +230,12 @@ InstTreeNode<Payload>::InstTreeNode(InstForest<Payload> &IF, Value *V,
|
||||
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;
|
||||
|
@@ -91,7 +91,7 @@ inline ostream &operator<<(ostream &o, const Type *T) {
|
||||
|
||||
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;
|
||||
|
@@ -78,6 +78,15 @@ public:
|
||||
// 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));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -129,7 +138,7 @@ public:
|
||||
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));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -170,6 +179,15 @@ public:
|
||||
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));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -206,6 +224,15 @@ public:
|
||||
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));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -240,6 +267,15 @@ public:
|
||||
// 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));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -261,6 +297,15 @@ public:
|
||||
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));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -272,11 +317,11 @@ public:
|
||||
//
|
||||
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
|
||||
|
@@ -46,10 +46,10 @@ public:
|
||||
//
|
||||
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; }
|
||||
|
||||
@@ -59,6 +59,12 @@ public:
|
||||
// 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
|
||||
|
@@ -19,6 +19,11 @@
|
||||
#include "llvm/Value.h"
|
||||
#include <map>
|
||||
|
||||
#ifndef NDEBUG // Only for assertions
|
||||
#include "llvm/Type.h"
|
||||
#include "llvm/ConstPoolVals.h"
|
||||
#endif
|
||||
|
||||
class Value;
|
||||
class Type;
|
||||
|
||||
@@ -63,7 +68,7 @@ public:
|
||||
// (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);
|
||||
}
|
||||
|
@@ -187,13 +187,6 @@ public:
|
||||
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; }
|
||||
|
@@ -98,14 +98,6 @@ public:
|
||||
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)
|
||||
@@ -113,19 +105,8 @@ public:
|
||||
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.
|
||||
@@ -256,4 +237,33 @@ X *dyn_cast(Y Val) {
|
||||
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
|
||||
|
@@ -154,11 +154,11 @@ public:
|
||||
// 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; }
|
||||
};
|
||||
|
Reference in New Issue
Block a user