- if (CE->getOpcode() == Instruction::Cast) {
- Constant *MV = cast<Constant>(MapValue(CE->getOperand(0), VM));
- return VMSlot = ConstantExpr::getCast(MV, CE->getType());
- } else if (CE->getOpcode() == Instruction::GetElementPtr) {
- std::vector<Constant*> Idx;
- Constant *MV = cast<Constant>(MapValue(CE->getOperand(0), VM));
- for (unsigned i = 1, e = CE->getNumOperands(); i != e; ++i)
- Idx.push_back(cast<Constant>(MapValue(CE->getOperand(i), VM)));
- return VMSlot = ConstantExpr::getGetElementPtr(MV, Idx);
- } else if (CE->getOpcode() == Instruction::Select) {
- Constant *MV1 = cast<Constant>(MapValue(CE->getOperand(0), VM));
- Constant *MV2 = cast<Constant>(MapValue(CE->getOperand(1), VM));
- Constant *MV3 = cast<Constant>(MapValue(CE->getOperand(2), VM));
- return VMSlot = ConstantExpr::getSelect(MV1, MV2, MV3);
- } else {
- assert(CE->getNumOperands() == 2 && "Must be binary operator?");
- Constant *MV1 = cast<Constant>(MapValue(CE->getOperand(0), VM));
- Constant *MV2 = cast<Constant>(MapValue(CE->getOperand(1), VM));
- return VMSlot = ConstantExpr::get(CE->getOpcode(), MV1, MV2);
+ std::vector<Constant*> Ops;
+ for (unsigned i = 0, e = CE->getNumOperands(); i != e; ++i)
+ Ops.push_back(cast<Constant>(MapValue(CE->getOperand(i), VM)));
+ return VM[V] = CE->getWithOperands(Ops);
+ } else if (ConstantVector *CP = dyn_cast<ConstantVector>(C)) {
+ for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i) {
+ Value *MV = MapValue(CP->getOperand(i), VM);
+ if (MV != CP->getOperand(i)) {
+ // This vector value must contain a reference to a global, make a new
+ // vector constant and return it.
+ //
+ std::vector<Constant*> Values;
+ Values.reserve(CP->getNumOperands());
+ for (unsigned j = 0; j != i; ++j)
+ Values.push_back(CP->getOperand(j));
+ Values.push_back(cast<Constant>(MV));
+ for (++i; i != e; ++i)
+ Values.push_back(cast<Constant>(MapValue(CP->getOperand(i), VM)));
+ return VM[V] = ConstantVector::get(Values);
+ }