: User(ty, vty, Ops, NumOps) {}
void destroyConstantImpl();
+
+ void setOperand(unsigned i, Value *V) {
+ User::setOperand(i, V);
+ }
public:
/// isNullValue - Return true if this is the value that would be returned by
/// getNullValue.
/// FIXME: This really should not be in VMCore.
PossibleRelocationsTy getRelocationInfo() const;
- // Specialize get/setOperand for Constants as their operands are always
- // constants as well.
- Constant *getOperand(unsigned i) {
- return static_cast<Constant*>(User::getOperand(i));
- }
- const Constant *getOperand(unsigned i) const {
- return static_cast<const Constant*>(User::getOperand(i));
+ // Specialize get/setOperand for Users as their operands are always
+ // constants or BasicBlocks as well.
+ User *getOperand(unsigned i) {
+ return static_cast<User*>(User::getOperand(i));
}
- void setOperand(unsigned i, Constant *C) {
- User::setOperand(i, C);
+ const User *getOperand(unsigned i) const {
+ return static_cast<const User*>(User::getOperand(i));
}
/// getVectorElements - This method, which is only valid on constant of vector
static BlockAddress *get(BasicBlock *BB);
/// Transparently provide more efficient getOperand methods.
- DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
+ DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Function *getFunction() const { return (Function*)Op<0>().get(); }
BasicBlock *getBasicBlock() const { return (BasicBlock*)Op<1>().get(); }
struct OperandTraits<BlockAddress> : public FixedNumOperandTraits<2> {
};
-DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(BlockAddress, Constant)
+DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(BlockAddress, Value)
//===----------------------------------------------------------------------===//
/// ConstantExpr - a constant value that is initialized with an expression using
assert (0 && "Unknown FP type!");
}
} else if (isa<ConstantArray>(C) && cast<ConstantArray>(C)->isString()) {
+ const ConstantArray *CA = cast<ConstantArray>(C);
// Emit constant strings specially.
- unsigned NumOps = C->getNumOperands();
+ unsigned NumOps = CA->getNumOperands();
// If this is a null-terminated string, use the denser CSTRING encoding.
- if (C->getOperand(NumOps-1)->isNullValue()) {
+ if (CA->getOperand(NumOps-1)->isNullValue()) {
Code = bitc::CST_CODE_CSTRING;
--NumOps; // Don't encode the null, which isn't allowed by char6.
} else {
bool isCStr7 = Code == bitc::CST_CODE_CSTRING;
bool isCStrChar6 = Code == bitc::CST_CODE_CSTRING;
for (unsigned i = 0; i != NumOps; ++i) {
- unsigned char V = cast<ConstantInt>(C->getOperand(i))->getZExtValue();
+ unsigned char V = cast<ConstantInt>(CA->getOperand(i))->getZExtValue();
Record.push_back(V);
isCStr7 &= (V & 128) == 0;
if (isCStrChar6)
case Type::StructTyID:
for (unsigned I = 0, E = C->getNumOperands(); I<E; I++) {
if (I!=0) Out << ",\n";
- printStaticConstant(C->getOperand(I),Offset);
+ printStaticConstant(cast<Constant>(C->getOperand(I)), Offset);
}
break;
case Type::PointerTyID:
static void RemoveDeadConstant(Constant *C) {
assert(C->use_empty() && "Constant is not dead!");
- SmallPtrSet<Constant *, 4> Operands;
+ SmallPtrSet<Constant*, 4> Operands;
for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i)
if (isa<DerivedType>(C->getOperand(i)->getType()) &&
OnlyUsedBy(C->getOperand(i), C))
- Operands.insert(C->getOperand(i));
+ Operands.insert(cast<Constant>(C->getOperand(i)));
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) {
if (!GV->hasLocalLinkage()) return; // Don't delete non static globals.
GV->eraseFromParent();
C->destroyConstant();
// If the constant referenced anything, see if we can delete it as well.
- for (SmallPtrSet<Constant *, 4>::iterator OI = Operands.begin(),
+ for (SmallPtrSet<Constant*, 4>::iterator OI = Operands.begin(),
OE = Operands.end(); OI != OE; ++OI)
RemoveDeadConstant(*OI);
}
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) {
if (GV->hasLocalLinkage())
RemoveDeadConstant(GV);
- }
- else
+ } else
RemoveDeadConstant(C);
}
switch (CE->getOpcode()) {
default: return 0;
case Instruction::Or: {
- Constant *RHS = ExtractConstantBytes(C->getOperand(1), ByteStart, ByteSize);
+ Constant *RHS = ExtractConstantBytes(CE->getOperand(1), ByteStart,ByteSize);
if (RHS == 0)
return 0;
if (RHSC->isAllOnesValue())
return RHSC;
- Constant *LHS = ExtractConstantBytes(C->getOperand(0), ByteStart, ByteSize);
+ Constant *LHS = ExtractConstantBytes(CE->getOperand(0), ByteStart,ByteSize);
if (LHS == 0)
return 0;
return ConstantExpr::getOr(LHS, RHS);
}
case Instruction::And: {
- Constant *RHS = ExtractConstantBytes(C->getOperand(1), ByteStart, ByteSize);
+ Constant *RHS = ExtractConstantBytes(CE->getOperand(1), ByteStart,ByteSize);
if (RHS == 0)
return 0;
if (RHS->isNullValue())
return RHS;
- Constant *LHS = ExtractConstantBytes(C->getOperand(0), ByteStart, ByteSize);
+ Constant *LHS = ExtractConstantBytes(CE->getOperand(0), ByteStart,ByteSize);
if (LHS == 0)
return 0;
return ConstantExpr::getAnd(LHS, RHS);
ByteSize*8));
// If the extract is known to be fully in the input, extract it.
if (ByteStart+ByteSize+ShAmt <= CSize)
- return ExtractConstantBytes(C->getOperand(0), ByteStart+ShAmt, ByteSize);
+ return ExtractConstantBytes(CE->getOperand(0), ByteStart+ShAmt, ByteSize);
// TODO: Handle the 'partially zero' case.
return 0;
ByteSize*8));
// If the extract is known to be fully in the input, extract it.
if (ByteStart >= ShAmt)
- return ExtractConstantBytes(C->getOperand(0), ByteStart-ShAmt, ByteSize);
+ return ExtractConstantBytes(CE->getOperand(0), ByteStart-ShAmt, ByteSize);
// TODO: Handle the 'partially zero' case.
return 0;
case Instruction::ZExt: {
unsigned SrcBitSize =
- cast<IntegerType>(C->getOperand(0)->getType())->getBitWidth();
+ cast<IntegerType>(CE->getOperand(0)->getType())->getBitWidth();
// If extracting something that is completely zero, return 0.
if (ByteStart*8 >= SrcBitSize)
// If exactly extracting the input, return it.
if (ByteStart == 0 && ByteSize*8 == SrcBitSize)
- return C->getOperand(0);
+ return CE->getOperand(0);
// If extracting something completely in the input, if if the input is a
// multiple of 8 bits, recurse.
if ((SrcBitSize&7) == 0 && (ByteStart+ByteSize)*8 <= SrcBitSize)
- return ExtractConstantBytes(C->getOperand(0), ByteStart, ByteSize);
+ return ExtractConstantBytes(CE->getOperand(0), ByteStart, ByteSize);
// Otherwise, if extracting a subset of the input, which is not multiple of
// 8 bits, do a shift and trunc to get the bits.
if ((ByteStart+ByteSize)*8 < SrcBitSize) {
assert((SrcBitSize&7) && "Shouldn't get byte sized case here");
- Constant *Res = C->getOperand(0);
+ Constant *Res = CE->getOperand(0);
if (ByteStart)
Res = ConstantExpr::getLShr(Res,
ConstantInt::get(Res->getType(), ByteStart*8));
Idxs + NumIdx));
// Otherwise recurse.
- return ConstantFoldExtractValueInstruction(Context, Agg->getOperand(*Idxs),
+ if (ConstantStruct *CS = dyn_cast<ConstantStruct>(Agg))
+ return ConstantFoldExtractValueInstruction(Context, CS->getOperand(*Idxs),
+ Idxs+1, NumIdx-1);
+
+ if (ConstantArray *CA = dyn_cast<ConstantArray>(Agg))
+ return ConstantFoldExtractValueInstruction(Context, CA->getOperand(*Idxs),
+ Idxs+1, NumIdx-1);
+ ConstantVector *CV = cast<ConstantVector>(Agg);
+ return ConstantFoldExtractValueInstruction(Context, CV->getOperand(*Idxs),
Idxs+1, NumIdx-1);
}
// Insertion of constant into aggregate constant.
std::vector<Constant*> Ops(Agg->getNumOperands());
for (unsigned i = 0; i < Agg->getNumOperands(); ++i) {
- Constant *Op =
- (*Idxs == i) ?
- ConstantFoldInsertValueInstruction(Context, Agg->getOperand(i),
- Val, Idxs+1, NumIdx-1) :
- Agg->getOperand(i);
+ Constant *Op = cast<Constant>(Agg->getOperand(i));
+ if (*Idxs == i)
+ Op = ConstantFoldInsertValueInstruction(Context, Op,
+ Val, Idxs+1, NumIdx-1);
Ops[i] = Op;
}
// ConstantExpr traps if any operands can trap.
for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
- if (getOperand(i)->canTrap())
+ if (CE->getOperand(i)->canTrap())
return true;
// Otherwise, only specific operations can trap.
case Instruction::SRem:
case Instruction::FRem:
// Div and rem can trap if the RHS is not known to be non-zero.
- if (!isa<ConstantInt>(getOperand(1)) || getOperand(1)->isNullValue())
+ if (!isa<ConstantInt>(CE->getOperand(1)) ||CE->getOperand(1)->isNullValue())
return true;
return false;
}
PossibleRelocationsTy Result = NoRelocation;
for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
- Result = std::max(Result, getOperand(i)->getRelocationInfo());
+ Result = std::max(Result,
+ cast<Constant>(getOperand(i))->getRelocationInfo());
return Result;
}