Convert more code to use new style casts
Eliminate old style casts from value.h
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@696 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/llvm/Analysis/ConstantsScanner.h b/include/llvm/Analysis/ConstantsScanner.h
index cbf9765..4c86834 100644
--- a/include/llvm/Analysis/ConstantsScanner.h
+++ b/include/llvm/Analysis/ConstantsScanner.h
@@ -24,7 +24,7 @@
inline bool isAtConstant() const {
assert(!InstI.atEnd() && OpIdx < InstI->getNumOperands() &&
"isAtConstant called with invalid arguments!");
- return InstI->getOperand(OpIdx)->isConstant();
+ return isa<ConstPoolVal>(InstI->getOperand(OpIdx));
}
public:
diff --git a/include/llvm/Analysis/InstForest.h b/include/llvm/Analysis/InstForest.h
index eac08f9..967ed45 100644
--- a/include/llvm/Analysis/InstForest.h
+++ b/include/llvm/Analysis/InstForest.h
@@ -116,7 +116,7 @@
}
o << getValue();
- if (!getValue()->isInstruction()) o << "\n";
+ if (!isa<Instruction>(getValue())) o << "\n";
for (unsigned i = 0; i < getNumChildren(); ++i)
getChild(i)->print(o, Indent+1);
@@ -229,7 +229,7 @@
InstTreeNode *Parent) : super(Parent) {
getTreeData().first.first = V; // Save tree node
- if (!V->isInstruction()) {
+ if (!isa<Instruction>(V)) {
assert((isa<ConstPoolVal>(V) || isa<BasicBlock>(V) ||
isa<MethodArgument>(V) || isa<GlobalVariable>(V)) &&
"Unrecognized value type for InstForest Partition!");
diff --git a/include/llvm/ConstPoolVals.h b/include/llvm/ConstPoolVals.h
index 1bd2dce..342070c 100644
--- a/include/llvm/ConstPoolVals.h
+++ b/include/llvm/ConstPoolVals.h
@@ -66,6 +66,15 @@
virtual string getStrValue() const;
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) {
+ return (CPV == True) | (CPV == False);
+ }
+ static inline bool isa(const Value *V) {
+ return ::isa<ConstPoolVal>(V) && isa(cast<ConstPoolVal>(V));
+ }
};
@@ -97,6 +106,13 @@
// specified value. as above, we work only with very small values here.
//
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));
+ }
};
@@ -117,7 +133,6 @@
inline int64_t getValue() const { return Val.Signed; }
};
-
//===---------------------------------------------------------------------------
// ConstPoolUInt - Unsigned Integer Values [ubyte, ushort, uint, ulong]
//
diff --git a/include/llvm/Value.h b/include/llvm/Value.h
index 3ef46ca..1acf2e2 100644
--- a/include/llvm/Value.h
+++ b/include/llvm/Value.h
@@ -79,34 +79,12 @@
// equivalent to using dynamic_cast<>... if the cast is successful, this is
// returned, otherwise you get a null pointer.
//
- // This section also defines a family of isType, isConstant,
- // isMethodArgument, etc functions...
- //
// The family of functions Val->cast<type>Asserting() is used in the same
// way as the Val->cast<type>() instructions, but they assert the expected
// type instead of checking it at runtime.
//
inline ValueTy getValueType() const { return VTy; }
- // Use a macro to define the functions, otherwise these definitions are just
- // really long and ugly.
-#define CAST_FN(NAME, CLASS) \
- inline bool is##NAME() const { return VTy == NAME##Val; } \
- inline const CLASS *cast##NAME() const { /*const version */ \
- return is##NAME() ? (const CLASS*)this : 0; \
- } \
- inline CLASS *cast##NAME() { /* nonconst version */ \
- return is##NAME() ? (CLASS*)this : 0; \
- } \
-
- CAST_FN(Constant , ConstPoolVal )
- CAST_FN(MethodArgument, MethodArgument)
- CAST_FN(Instruction , Instruction )
- CAST_FN(BasicBlock , BasicBlock )
- CAST_FN(Method , Method )
- CAST_FN(Global , GlobalVariable)
-#undef CAST_FN
-
// 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.
@@ -207,7 +185,7 @@
// if (isa<Type>(myVal)) { ... }
//
template <class X, class Y>
-bool isa(Y Val) { return X::isa(Val); }
+inline bool isa(Y Val) { return X::isa(Val); }
// cast<X> - Return the argument parameter cast to the specified type. This
@@ -218,7 +196,7 @@
// cast<const Instruction>(myVal)->getParent()
//
template <class X, class Y>
-X *cast(Y Val) {
+inline X *cast(Y Val) {
assert(isa<X>(Val) && "Invalid cast argument type!");
return (X*)(real_type<Y>::Type)Val;
}
@@ -233,7 +211,7 @@
//
template <class X, class Y>
-X *dyn_cast(Y Val) {
+inline X *dyn_cast(Y Val) {
return isa<X>(Val) ? cast<X>(Val) : 0;
}
@@ -241,28 +219,52 @@
// 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) {
+template <> inline bool isa<Type, const Value*>(const Value *Val) {
return Val->getValueType() == Value::TypeVal;
}
-template <> bool isa<ConstPoolVal, Value*>(Value *Val) {
+template <> inline bool isa<Type, Value*>(Value *Val) {
+ return Val->getValueType() == Value::TypeVal;
+}
+template <> inline bool isa<ConstPoolVal, const Value*>(const Value *Val) {
return Val->getValueType() == Value::ConstantVal;
}
-template <> bool isa<MethodArgument, Value*>(Value *Val) {
+template <> inline bool isa<ConstPoolVal, Value*>(Value *Val) {
+ return Val->getValueType() == Value::ConstantVal;
+}
+template <> inline bool isa<MethodArgument, const Value*>(const Value *Val) {
return Val->getValueType() == Value::MethodArgumentVal;
}
-template <> bool isa<Instruction, Value*>(Value *Val) {
+template <> inline bool isa<MethodArgument, Value*>(Value *Val) {
+ return Val->getValueType() == Value::MethodArgumentVal;
+}
+template <> inline bool isa<Instruction, const Value*>(const Value *Val) {
return Val->getValueType() == Value::InstructionVal;
}
-template <> bool isa<BasicBlock, Value*>(Value *Val) {
+template <> inline bool isa<Instruction, Value*>(Value *Val) {
+ return Val->getValueType() == Value::InstructionVal;
+}
+template <> inline bool isa<BasicBlock, const Value*>(const Value *Val) {
return Val->getValueType() == Value::BasicBlockVal;
}
-template <> bool isa<Method, Value*>(Value *Val) {
+template <> inline bool isa<BasicBlock, Value*>(Value *Val) {
+ return Val->getValueType() == Value::BasicBlockVal;
+}
+template <> inline bool isa<Method, const Value*>(const Value *Val) {
return Val->getValueType() == Value::MethodVal;
}
-template <> bool isa<GlobalVariable, Value*>(Value *Val) {
+template <> inline bool isa<Method, Value*>(Value *Val) {
+ return Val->getValueType() == Value::MethodVal;
+}
+template <> inline bool isa<GlobalVariable, const Value*>(const Value *Val) {
return Val->getValueType() == Value::GlobalVal;
}
-template <> bool isa<Module, Value*>(Value *Val) {
+template <> inline bool isa<GlobalVariable, Value*>(Value *Val) {
+ return Val->getValueType() == Value::GlobalVal;
+}
+template <> inline bool isa<Module, const Value*>(const Value *Val) {
+ return Val->getValueType() == Value::ModuleVal;
+}
+template <> inline bool isa<Module, Value*>(Value *Val) {
return Val->getValueType() == Value::ModuleVal;
}
diff --git a/lib/Analysis/Expressions.cpp b/lib/Analysis/Expressions.cpp
index 8c9d75f..cb83d41 100644
--- a/lib/Analysis/Expressions.cpp
+++ b/lib/Analysis/Expressions.cpp
@@ -16,14 +16,17 @@
using namespace analysis;
ExprType::ExprType(Value *Val) {
- if (Val && Val->isConstant() && Val->getType()->isIntegral()) {
- Offset = (ConstPoolInt*)Val->castConstant();
- Var = 0;
- ExprTy = Constant;
- } else {
- Var = Val; Offset = 0;
- ExprTy = Var ? Linear : Constant;
- }
+ if (Val)
+ if (ConstPoolInt *CPI = dyn_cast<ConstPoolInt>(Val)) {
+ Offset = CPI;
+ Var = 0;
+ ExprTy = Constant;
+ Scale = 0;
+ return;
+ }
+
+ Var = Val; Offset = 0;
+ ExprTy = Var ? Linear : Constant;
Scale = 0;
}
diff --git a/lib/AsmParser/ParserInternals.h b/lib/AsmParser/ParserInternals.h
index 88986c2..bedb65f 100644
--- a/lib/AsmParser/ParserInternals.h
+++ b/lib/AsmParser/ParserInternals.h
@@ -167,10 +167,7 @@
};
struct MethPlaceHolderHelper : public Method {
- MethPlaceHolderHelper(const Type *Ty)
- : Method((const MethodType*)Ty) {
- assert(Ty->isMethodType() && "Method placeholders must be method types!");
- }
+ MethPlaceHolderHelper(const Type *Ty) : Method(cast<const MethodType>(Ty)) {}
};
typedef PlaceholderValue<TypePlaceHolderHelper> TypePlaceHolder;
diff --git a/lib/Bytecode/Reader/ConstantReader.cpp b/lib/Bytecode/Reader/ConstantReader.cpp
index 67cfff7..aaecedd 100644
--- a/lib/Bytecode/Reader/ConstantReader.cpp
+++ b/lib/Bytecode/Reader/ConstantReader.cpp
@@ -241,8 +241,8 @@
unsigned Slot;
if (read_vbr(Buf, EndBuf, Slot)) return failure(true);
Value *V = getValue(AT->getElementType(), Slot, false);
- if (!V || !V->isConstant()) return failure(true);
- Elements.push_back((ConstPoolVal*)V);
+ if (!V || !isa<ConstPoolVal>(V)) return failure(true);
+ Elements.push_back(cast<ConstPoolVal>(V));
}
V = ConstPoolArray::get(AT, Elements);
break;
@@ -257,9 +257,9 @@
unsigned Slot;
if (read_vbr(Buf, EndBuf, Slot)) return failure(true);
Value *V = getValue(ET[i], Slot, false);
- if (!V || !V->isConstant())
+ if (!V || !isa<ConstPoolVal>(V))
return failure(true);
- Elements.push_back((ConstPoolVal*)V);
+ Elements.push_back(cast<ConstPoolVal>(V));
}
V = ConstPoolStruct::get(ST, Elements);
diff --git a/lib/Bytecode/Reader/InstructionReader.cpp b/lib/Bytecode/Reader/InstructionReader.cpp
index 8c3e08f..300c409 100644
--- a/lib/Bytecode/Reader/InstructionReader.cpp
+++ b/lib/Bytecode/Reader/InstructionReader.cpp
@@ -266,25 +266,25 @@
case 0: cerr << "Invalid load encountered!\n"; return failure(true);
case 1: break;
case 2: V = getValue(Type::UByteTy, Raw.Arg2);
- if (!V->isConstant()) return failure(true);
- Idx.push_back(V->castConstant());
+ if (!isa<ConstPoolVal>(V)) return failure(true);
+ Idx.push_back(cast<ConstPoolVal>(V));
break;
case 3: V = getValue(Type::UByteTy, Raw.Arg2);
- if (!V->isConstant()) return failure(true);
- Idx.push_back(V->castConstant());
+ if (!isa<ConstPoolVal>(V)) return failure(true);
+ Idx.push_back(cast<ConstPoolVal>(V));
V = getValue(Type::UByteTy, Raw.Arg3);
- if (!V->isConstant()) return failure(true);
- Idx.push_back(V->castConstant());
+ if (!isa<ConstPoolVal>(V)) return failure(true);
+ Idx.push_back(cast<ConstPoolVal>(V));
break;
default:
V = getValue(Type::UByteTy, Raw.Arg2);
- if (!V->isConstant()) return failure(true);
- Idx.push_back(V->castConstant());
+ if (!isa<ConstPoolVal>(V)) return failure(true);
+ Idx.push_back(cast<ConstPoolVal>(V));
vector<unsigned> &args = *Raw.VarArgs;
for (unsigned i = 0, E = args.size(); i != E; ++i) {
V = getValue(Type::UByteTy, args[i]);
- if (!V->isConstant()) return failure(true);
- Idx.push_back(V->castConstant());
+ if (!isa<ConstPoolVal>(V)) return failure(true);
+ Idx.push_back(cast<ConstPoolVal>(V));
}
delete Raw.VarArgs;
break;
@@ -304,15 +304,15 @@
case 1: cerr << "Invalid store encountered!\n"; return failure(true);
case 2: break;
case 3: V = getValue(Type::UByteTy, Raw.Arg3);
- if (!V->isConstant()) return failure(true);
- Idx.push_back(V->castConstant());
+ if (!isa<ConstPoolVal>(V)) return failure(true);
+ Idx.push_back(cast<ConstPoolVal>(V));
break;
default:
vector<unsigned> &args = *Raw.VarArgs;
for (unsigned i = 0, E = args.size(); i != E; ++i) {
V = getValue(Type::UByteTy, args[i]);
- if (!V->isConstant()) return failure(true);
- Idx.push_back(V->castConstant());
+ if (!isa<ConstPoolVal>(V)) return failure(true);
+ Idx.push_back(cast<ConstPoolVal>(V));
}
delete Raw.VarArgs;
break;
diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp
index b7904bb..0e48830 100644
--- a/lib/Bytecode/Reader/Reader.cpp
+++ b/lib/Bytecode/Reader/Reader.cpp
@@ -206,7 +206,7 @@
return failure(true);
}
BCR_TRACE(4, "Map: '" << Name << "' to #" << slot << ":" << D;
- if (!D->isInstruction()) cerr << endl);
+ if (!isa<Instruction>(D)) cerr << endl);
D->setName(Name, ST);
}
@@ -291,7 +291,7 @@
Value *MethPHolder = getValue(MTy, MethSlot, false);
assert(MethPHolder && "Something is broken no placeholder found!");
- assert(MethPHolder->isMethod() && "Not a method?");
+ assert(isa<Method>(MethPHolder) && "Not a method?");
unsigned type; // Type slot
assert(!getTypeSlot(MTy, type) && "How can meth type not exist?");
@@ -359,7 +359,7 @@
if (read_vbr(Buf, End, MethSignature)) return failure(true);
while (MethSignature != Type::VoidTyID) { // List is terminated by Void
const Type *Ty = getType(MethSignature);
- if (!Ty || !Ty->isMethodType()) {
+ if (!Ty || !isa<MethodType>(Ty)) {
cerr << "Method not meth type! Ty = " << Ty << endl;
return failure(true);
}
diff --git a/lib/Bytecode/Reader/ReaderInternals.h b/lib/Bytecode/Reader/ReaderInternals.h
index ed4f1a4..cf5a43e 100644
--- a/lib/Bytecode/Reader/ReaderInternals.h
+++ b/lib/Bytecode/Reader/ReaderInternals.h
@@ -129,8 +129,7 @@
struct MethPlaceHolderHelper : public Method {
MethPlaceHolderHelper(const Type *Ty)
- : Method((const MethodType*)Ty) {
- assert(Ty->isMethodType() && "Method placeholders must be method types!");
+ : Method(cast<const MethodType>(Ty)) {
}
};
diff --git a/lib/Bytecode/Writer/SlotCalculator.cpp b/lib/Bytecode/Writer/SlotCalculator.cpp
index d0f37fb..38980e5 100644
--- a/lib/Bytecode/Writer/SlotCalculator.cpp
+++ b/lib/Bytecode/Writer/SlotCalculator.cpp
@@ -106,7 +106,7 @@
for (SymbolTable::const_iterator I = ST->begin(), E = ST->end(); I != E; ++I)
for (SymbolTable::type_const_iterator TI = I->second.begin(),
TE = I->second.end(); TI != TE; ++TI)
- if (TI->second->isConstant())
+ if (isa<ConstPoolVal>(TI->second))
insertValue(TI->second);
}
@@ -223,7 +223,7 @@
int SlotCalculator::insertValue(const Value *D) {
- if (D->isConstant() || D->isGlobal()) {
+ if (isa<ConstPoolVal>(D) || isa<GlobalVariable>(D)) {
const User *U = (const User *)D;
// This makes sure that if a constant has uses (for example an array
// of const ints), that they are inserted also. Same for global variable
diff --git a/lib/Bytecode/Writer/Writer.cpp b/lib/Bytecode/Writer/Writer.cpp
index 94cbcec..5df2fda 100644
--- a/lib/Bytecode/Writer/Writer.cpp
+++ b/lib/Bytecode/Writer/Writer.cpp
@@ -79,7 +79,7 @@
ValNo = Type::FirstDerivedTyID; // Start emitting at the derived types...
// Scan through and ignore method arguments...
- for (; ValNo < Plane.size() && Plane[ValNo]->isMethodArgument(); ValNo++)
+ for (; ValNo < Plane.size() && isa<MethodArgument>(Plane[ValNo]); ValNo++)
/*empty*/;
unsigned NC = ValNo; // Number of constants
@@ -103,7 +103,7 @@
for (unsigned i = ValNo; i < ValNo+NC; ++i) {
const Value *V = Plane[i];
- if (const ConstPoolVal *CPV = V->castConstant()) {
+ if (const ConstPoolVal *CPV = dyn_cast<ConstPoolVal>(V)) {
//cerr << "Serializing value: <" << V->getType() << ">: "
// << ((const ConstPoolVal*)V)->getStrValue() << ":"
// << Out.size() << "\n";
@@ -127,7 +127,7 @@
// Fields: bit0 = isConstant, bit1 = hasInitializer, bit2+ = slot#
unsigned oSlot = ((unsigned)Slot << 2) | (GV->hasInitializer() << 1) |
- GV->isConstant();
+ isa<ConstPoolVal>(GV);
output_vbr(oSlot, Out);
// If we have an initialized, output it now.
diff --git a/lib/CodeGen/InstrSched/SchedGraph.cpp b/lib/CodeGen/InstrSched/SchedGraph.cpp
index 4060130..852c4f2 100644
--- a/lib/CodeGen/InstrSched/SchedGraph.cpp
+++ b/lib/CodeGen/InstrSched/SchedGraph.cpp
@@ -532,7 +532,7 @@
const Value* val,
const TargetMachine& target)
{
- if (!val->isInstruction()) return;
+ if (!isa<Instruction>(val)) return;
const Instruction* thisVMInstr = node->getInstr();
const Instruction* defVMInstr = cast<const Instruction>(val);
@@ -642,7 +642,6 @@
SchedGraph::addNonSSAEdgesForValue(const Instruction* instr,
const TargetMachine& target)
{
- assert(instr->isInstruction());
if (instr->isPHINode())
return;
diff --git a/lib/CodeGen/InstrSelection/InstrForest.cpp b/lib/CodeGen/InstrSelection/InstrForest.cpp
index 9f4df08..f5a5247 100644
--- a/lib/CodeGen/InstrSelection/InstrForest.cpp
+++ b/lib/CodeGen/InstrSelection/InstrForest.cpp
@@ -275,12 +275,12 @@
// Check latter condition here just to simplify the next IF.
bool includeAddressOperand =
- (operand->isBasicBlock() || operand->isMethod())
+ (isa<BasicBlock>(operand) || isa<Method>(operand))
&& !instr->isTerminator();
- if (includeAddressOperand || operand->isInstruction() ||
- operand->isConstant() || operand->isMethodArgument() ||
- operand->isGlobal())
+ if (includeAddressOperand || isa<Instruction>(operand) ||
+ isa<ConstPoolVal>(operand) || isa<MethodArgument>(operand) ||
+ isa<GlobalVariable>(operand))
{
// This operand is a data value
@@ -300,15 +300,15 @@
// is used directly, i.e., made a child of the instruction node.
//
InstrTreeNode* opTreeNode;
- if (operand->isInstruction() && operand->use_size() == 1 &&
- ((Instruction*)operand)->getParent() == instr->getParent() &&
+ if (isa<Instruction>(operand) && operand->use_size() == 1 &&
+ cast<Instruction>(operand)->getParent() == instr->getParent() &&
! instr->isPHINode() &&
instr->getOpcode() != Instruction::Call)
{
// Recursively create a treeNode for it.
opTreeNode = buildTreeForInstruction((Instruction*)operand);
}
- else if (ConstPoolVal *CPV = operand->castConstant())
+ else if (ConstPoolVal *CPV = dyn_cast<ConstPoolVal>(operand))
{
// Create a leaf node for a constant
opTreeNode = new ConstantNode(CPV);
diff --git a/lib/CodeGen/MachineInstr.cpp b/lib/CodeGen/MachineInstr.cpp
index 1e33007..6407628 100644
--- a/lib/CodeGen/MachineInstr.cpp
+++ b/lib/CodeGen/MachineInstr.cpp
@@ -141,7 +141,7 @@
case MachineOperand::MO_PCRelativeDisp:
{
const Value* opVal = mop.getVRegValue();
- bool isLabel = opVal->isMethod() || opVal->isBasicBlock();
+ bool isLabel = isa<Method>(opVal) || isa<BasicBlock>(opVal);
return os << "%disp("
<< (isLabel? "label " : "addr-of-val ")
<< opVal << ")";
@@ -221,7 +221,7 @@
minstr->SetMachineOperand(op1Position, /*regNum*/ target.zeroRegNum);
else
{
- if (op1Value->isConstant())
+ if (isa<ConstPoolVal>(op1Value))
{
// value is constant and must be loaded from constant pool
returnFlags = returnFlags | (1 << op1Position);
@@ -247,7 +247,7 @@
minstr->SetMachineOperand(op2Position, machineRegNum);
else if (op2type == MachineOperand::MO_VirtualRegister)
{
- if (op2Value->isConstant())
+ if (isa<ConstPoolVal>(op2Value))
{
// value is constant and must be loaded from constant pool
returnFlags = returnFlags | (1 << op2Position);
@@ -318,7 +318,7 @@
// Check for the common case first: argument is not constant
//
- ConstPoolVal *CPV = val->castConstant();
+ ConstPoolVal *CPV = dyn_cast<ConstPoolVal>(val);
if (!CPV) return opType;
if (CPV->getType() == Type::BoolTy)
diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp
index 3ecc3ec..d88d91f 100644
--- a/lib/ExecutionEngine/Interpreter/Execution.cpp
+++ b/lib/ExecutionEngine/Interpreter/Execution.cpp
@@ -25,7 +25,7 @@
case Type::TY##TyID: Result.TY##Val = ((CLASS*)CPV)->getValue(); break
static GenericValue getOperandValue(Value *V, ExecutionContext &SF) {
- if (ConstPoolVal *CPV = V->castConstant()) {
+ if (ConstPoolVal *CPV = dyn_cast<ConstPoolVal>(V)) {
GenericValue Result;
switch (CPV->getType()->getPrimitiveID()) {
GET_CONST_VAL(Bool , ConstPoolBool);
@@ -48,7 +48,7 @@
}
static void printOperandInfo(Value *V, ExecutionContext &SF) {
- if (!V->isConstant()) {
+ if (!isa<ConstPoolVal>(V)) {
unsigned TyP = V->getType()->getUniqueID(); // TypePlane for value
unsigned Slot = getOperandSlot(V);
cout << "Value=" << (void*)V << " TypeID=" << TyP << " Slot=" << Slot
diff --git a/lib/ExecutionEngine/Interpreter/UserInput.cpp b/lib/ExecutionEngine/Interpreter/UserInput.cpp
index eb5725f..e9fc9db 100644
--- a/lib/ExecutionEngine/Interpreter/UserInput.cpp
+++ b/lib/ExecutionEngine/Interpreter/UserInput.cpp
@@ -134,7 +134,7 @@
vector<Value*> Options = LookupMatchingNames(Name);
for (unsigned i = 0; i < Options.size(); ++i) { // Remove nonmethod matches...
- if (!Options[i]->isMethod()) {
+ if (!isa<Method>(Options[i])) {
Options.erase(Options.begin()+i);
--i;
}
diff --git a/lib/Target/SparcV9/InstrSched/SchedGraph.cpp b/lib/Target/SparcV9/InstrSched/SchedGraph.cpp
index 4060130..852c4f2 100644
--- a/lib/Target/SparcV9/InstrSched/SchedGraph.cpp
+++ b/lib/Target/SparcV9/InstrSched/SchedGraph.cpp
@@ -532,7 +532,7 @@
const Value* val,
const TargetMachine& target)
{
- if (!val->isInstruction()) return;
+ if (!isa<Instruction>(val)) return;
const Instruction* thisVMInstr = node->getInstr();
const Instruction* defVMInstr = cast<const Instruction>(val);
@@ -642,7 +642,6 @@
SchedGraph::addNonSSAEdgesForValue(const Instruction* instr,
const TargetMachine& target)
{
- assert(instr->isInstruction());
if (instr->isPHINode())
return;
diff --git a/lib/Target/SparcV9/InstrSelection/InstrForest.cpp b/lib/Target/SparcV9/InstrSelection/InstrForest.cpp
index 9f4df08..f5a5247 100644
--- a/lib/Target/SparcV9/InstrSelection/InstrForest.cpp
+++ b/lib/Target/SparcV9/InstrSelection/InstrForest.cpp
@@ -275,12 +275,12 @@
// Check latter condition here just to simplify the next IF.
bool includeAddressOperand =
- (operand->isBasicBlock() || operand->isMethod())
+ (isa<BasicBlock>(operand) || isa<Method>(operand))
&& !instr->isTerminator();
- if (includeAddressOperand || operand->isInstruction() ||
- operand->isConstant() || operand->isMethodArgument() ||
- operand->isGlobal())
+ if (includeAddressOperand || isa<Instruction>(operand) ||
+ isa<ConstPoolVal>(operand) || isa<MethodArgument>(operand) ||
+ isa<GlobalVariable>(operand))
{
// This operand is a data value
@@ -300,15 +300,15 @@
// is used directly, i.e., made a child of the instruction node.
//
InstrTreeNode* opTreeNode;
- if (operand->isInstruction() && operand->use_size() == 1 &&
- ((Instruction*)operand)->getParent() == instr->getParent() &&
+ if (isa<Instruction>(operand) && operand->use_size() == 1 &&
+ cast<Instruction>(operand)->getParent() == instr->getParent() &&
! instr->isPHINode() &&
instr->getOpcode() != Instruction::Call)
{
// Recursively create a treeNode for it.
opTreeNode = buildTreeForInstruction((Instruction*)operand);
}
- else if (ConstPoolVal *CPV = operand->castConstant())
+ else if (ConstPoolVal *CPV = dyn_cast<ConstPoolVal>(operand))
{
// Create a leaf node for a constant
opTreeNode = new ConstantNode(CPV);
diff --git a/lib/Target/SparcV9/SparcV9InstrSelection.cpp b/lib/Target/SparcV9/SparcV9InstrSelection.cpp
index 572e1b1..b1b5e01 100644
--- a/lib/Target/SparcV9/SparcV9InstrSelection.cpp
+++ b/lib/Target/SparcV9/SparcV9InstrSelection.cpp
@@ -60,7 +60,7 @@
GetConstantValueAsSignedInt(const Value *V,
bool &isValidConstant)
{
- if (!V->isConstant())
+ if (!isa<ConstPoolVal>(V))
{
isValidConstant = false;
return 0;
@@ -374,8 +374,8 @@
MachineOpCode opCode = INVALID_OPCODE;
if (resultType->isIntegral() ||
- resultType->isPointerType() ||
- resultType->isMethodType() ||
+ isa<PointerType>(resultType) ||
+ isa<MethodType>(resultType) ||
resultType->isLabelType() ||
resultType == Type::BoolTy)
{
@@ -419,7 +419,7 @@
MachineInstr* minstr = NULL;
Value* constOp = ((InstrTreeNode*) instrNode->rightChild())->getValue();
- assert(constOp->isConstant());
+ assert(isa<ConstPoolVal>(constOp));
// Cases worth optimizing are:
// (1) Add with 0 for float or double: use an FMOV of appropriate type,
@@ -469,7 +469,7 @@
MachineInstr* minstr = NULL;
Value* constOp = ((InstrTreeNode*) instrNode->rightChild())->getValue();
- assert(constOp->isConstant());
+ assert(isa<ConstPoolVal>(constOp));
// Cases worth optimizing are:
// (1) Sub with 0 for float or double: use an FMOV of appropriate type,
@@ -575,7 +575,7 @@
bool needNeg = false;
Value* constOp = ((InstrTreeNode*) instrNode->rightChild())->getValue();
- assert(constOp->isConstant());
+ assert(isa<ConstPoolVal>(constOp));
// Cases worth optimizing are:
// (1) Multiply by 0 or 1 for any type: replace with copy (ADD or FMOV)
@@ -699,7 +699,7 @@
getMinstr2 = NULL;
Value* constOp = ((InstrTreeNode*) instrNode->rightChild())->getValue();
- assert(constOp->isConstant());
+ assert(isa<ConstPoolVal>(constOp));
// Cases worth optimizing are:
// (1) Divide by 1 for any type: replace with copy (ADD or FMOV)
@@ -952,7 +952,7 @@
assert(arrayOffsetVal != NULL
&& "Expect to be given Value* for array offsets");
- if (ConstPoolVal *CPV = arrayOffsetVal->castConstant())
+ if (ConstPoolVal *CPV = dyn_cast<ConstPoolVal>(arrayOffsetVal))
{
isConstantOffset = true; // always constant for structs
assert(arrayOffsetVal->getType()->isIntegral());
@@ -1037,7 +1037,7 @@
Instruction* dest,
MachineInstr*& getMinstr2)
{
- assert(val->isConstant());
+ assert(isa<ConstPoolVal>(val));
MachineInstr* minstr1 = NULL;
@@ -1183,7 +1183,7 @@
Value* opValue = mop.getVRegValue();
- if (opValue->isConstant())
+ if (isa<ConstPoolVal>(opValue))
{
unsigned int machineRegNum;
int64_t immedValue;
@@ -1298,7 +1298,7 @@
// if `src' is a constant that doesn't fit in the immed field, generate
// a load instruction instead of an add
- if (src->isConstant())
+ if (isa<ConstPoolVal>(src))
{
unsigned int machineRegNum;
int64_t immedValue;
diff --git a/lib/Transforms/IPO/InlineSimple.cpp b/lib/Transforms/IPO/InlineSimple.cpp
index 27ef66e..8bc0a77 100644
--- a/lib/Transforms/IPO/InlineSimple.cpp
+++ b/lib/Transforms/IPO/InlineSimple.cpp
@@ -40,7 +40,7 @@
for (unsigned op = 0, E = I->getNumOperands(); op != E; ++op) {
const Value *Op = I->getOperand(op);
Value *V = ValueMap[Op];
- if (!V && (Op->isMethod() || Op->isConstant()))
+ if (!V && (isa<Method>(Op) || isa<ConstPoolVal>(Op)))
continue; // Methods and constants don't get relocated
if (!V) {
diff --git a/lib/Transforms/Scalar/ConstantProp.cpp b/lib/Transforms/Scalar/ConstantProp.cpp
index 8b87916..d43f693 100644
--- a/lib/Transforms/Scalar/ConstantProp.cpp
+++ b/lib/Transforms/Scalar/ConstantProp.cpp
@@ -88,9 +88,9 @@
BasicBlock *Dest1 = cast<BasicBlock>(BI->getOperand(0));
BasicBlock *Dest2 = cast<BasicBlock>(BI->getOperand(1));
- if (BI->getCondition()->isConstant()) { // Are we branching on constant?
+ if (ConstPoolBool *Cond = dyn_cast<ConstPoolBool>(BI->getCondition())) {
+ // Are we branching on constant?
// YES. Change to unconditional branch...
- ConstPoolBool *Cond = (ConstPoolBool*)BI->getCondition();
BasicBlock *Destination = Cond->getValue() ? Dest1 : Dest2;
BasicBlock *OldDest = Cond->getValue() ? Dest2 : Dest1;
@@ -137,14 +137,14 @@
ConstantFoldInstruction(Method *M, Method::inst_iterator &II) {
Instruction *Inst = *II;
if (Inst->isBinaryOp()) {
- ConstPoolVal *D1 = Inst->getOperand(0)->castConstant();
- ConstPoolVal *D2 = Inst->getOperand(1)->castConstant();
+ 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);
} else if (Inst->isUnaryOp()) {
- ConstPoolVal *D = Inst->getOperand(0)->castConstant();
+ 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);
diff --git a/lib/Transforms/Scalar/InductionVars.cpp b/lib/Transforms/Scalar/InductionVars.cpp
index 6815ccb..f2dcb45 100644
--- a/lib/Transforms/Scalar/InductionVars.cpp
+++ b/lib/Transforms/Scalar/InductionVars.cpp
@@ -36,9 +36,9 @@
// an interval invariant computation.
//
static bool isLoopInvariant(cfg::Interval *Int, Value *V) {
- assert(V->isConstant() || V->isInstruction() || V->isMethodArgument());
+ assert(isa<ConstPoolVal>(V) || isa<Instruction>(V) || isa<MethodArgument>(V));
- if (!V->isInstruction())
+ if (!isa<Instruction>(V))
return true; // Constants and arguments are always loop invariant
BasicBlock *ValueBlock = ((Instruction*)V)->getParent();
@@ -132,7 +132,7 @@
static inline bool isSimpleInductionVar(PHINode *PN) {
assert(PN->getNumIncomingValues() == 2 && "Must have cannonical PHI node!");
Value *Initializer = PN->getIncomingValue(0);
- if (!Initializer->isConstant()) return false;
+ if (!isa<ConstPoolVal>(Initializer)) return false;
if (Initializer->getType()->isSigned()) { // Signed constant value...
if (((ConstPoolSInt*)Initializer)->getValue() != 0) return false;
@@ -143,18 +143,18 @@
}
Value *StepExpr = PN->getIncomingValue(1);
- if (!StepExpr->isInstruction() ||
+ if (!isa<Instruction>(StepExpr) ||
((Instruction*)StepExpr)->getOpcode() != Instruction::Add)
return false;
BinaryOperator *I = (BinaryOperator*)StepExpr;
- assert(I->getOperand(0)->isInstruction() &&
+ assert(isa<Instruction>(I->getOperand(0)) &&
((Instruction*)I->getOperand(0))->isPHINode() &&
"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.
Value *StepSize = I->getOperand(1);
- if (!StepSize->isConstant()) return false;
+ if (!isa<ConstPoolVal>(StepSize)) return false;
if (StepSize->getType()->isSigned()) { // Signed constant value...
if (((ConstPoolSInt*)StepSize)->getValue() != 1) return false;
diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp
index 78b6c3d..91e002d 100644
--- a/lib/Transforms/Scalar/SCCP.cpp
+++ b/lib/Transforms/Scalar/SCCP.cpp
@@ -146,9 +146,9 @@
map<Value*, InstVal>::iterator I = ValueState.find(V);
if (I != ValueState.end()) return I->second; // Common case, in the map
- if (ConstPoolVal *CPV = V->castConstant()) { // Constants are constant
+ if (ConstPoolVal *CPV = dyn_cast<ConstPoolVal>(V)) {//Constants are constant
ValueState[CPV].markConstant(CPV);
- } else if (V->isMethodArgument()) { // MethodArgs are overdefined
+ } else if (isa<MethodArgument>(V)) { // MethodArgs are overdefined
ValueState[V].markOverdefined();
}
// All others are underdefined by default...
diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp
index 3c67c2c..b9a1c6d 100644
--- a/lib/VMCore/AsmWriter.cpp
+++ b/lib/VMCore/AsmWriter.cpp
@@ -143,9 +143,9 @@
for (; I != End; ++I) {
const Value *V = I->second;
- if (const ConstPoolVal *CPV = cast<const ConstPoolVal>(V)) {
+ if (const ConstPoolVal *CPV = dyn_cast<const ConstPoolVal>(V)) {
processConstant(CPV);
- } else if (const Type *Ty = cast<const Type>(V)) {
+ } else if (const Type *Ty = dyn_cast<const Type>(V)) {
Out << "\t%" << I->first << " = type " << Ty->getDescription() << endl;
}
}
diff --git a/lib/VMCore/BasicBlock.cpp b/lib/VMCore/BasicBlock.cpp
index 7d97c85..81c1f11 100644
--- a/lib/VMCore/BasicBlock.cpp
+++ b/lib/VMCore/BasicBlock.cpp
@@ -77,7 +77,7 @@
//
bool BasicBlock::hasConstantPoolReferences() const {
for (use_const_iterator I = use_begin(), E = use_end(); I != E; ++I)
- if ((*I)->isConstant())
+ if (::isa<ConstPoolVal>(*I))
return true;
return false;
diff --git a/lib/VMCore/ConstPoolVals.cpp b/lib/VMCore/ConstPoolVals.cpp
index 374c583..bf538bd 100644
--- a/lib/VMCore/ConstPoolVals.cpp
+++ b/lib/VMCore/ConstPoolVals.cpp
@@ -51,7 +51,9 @@
}
}
-
+bool ConstPoolInt::isa(const ConstPoolVal *CPV) {
+ return CPV->getType()->isIntegral();
+}
//===----------------------------------------------------------------------===//
// ConstPoolXXX Classes
diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp
index 5d1132f..9eb8277 100644
--- a/lib/VMCore/Function.cpp
+++ b/lib/VMCore/Function.cpp
@@ -28,7 +28,7 @@
Method::Method(const MethodType *Ty, const string &name)
: Value(Ty, Value::MethodVal, name), SymTabValue(this), BasicBlocks(this),
ArgumentList(this, this) {
- assert(Ty->isMethodType() && "Method signature must be of method type!");
+ assert(::isa<MethodType>(Ty) && "Method signature must be of method type!");
Parent = 0;
}
diff --git a/lib/VMCore/SlotCalculator.cpp b/lib/VMCore/SlotCalculator.cpp
index d0f37fb..38980e5 100644
--- a/lib/VMCore/SlotCalculator.cpp
+++ b/lib/VMCore/SlotCalculator.cpp
@@ -106,7 +106,7 @@
for (SymbolTable::const_iterator I = ST->begin(), E = ST->end(); I != E; ++I)
for (SymbolTable::type_const_iterator TI = I->second.begin(),
TE = I->second.end(); TI != TE; ++TI)
- if (TI->second->isConstant())
+ if (isa<ConstPoolVal>(TI->second))
insertValue(TI->second);
}
@@ -223,7 +223,7 @@
int SlotCalculator::insertValue(const Value *D) {
- if (D->isConstant() || D->isGlobal()) {
+ if (isa<ConstPoolVal>(D) || isa<GlobalVariable>(D)) {
const User *U = (const User *)D;
// This makes sure that if a constant has uses (for example an array
// of const ints), that they are inserted also. Same for global variable