#include "TransformInternals.h"
#include "llvm/Constants.h"
-#include "llvm/iOther.h"
-#include "llvm/iPHINode.h"
-#include "llvm/iMemory.h"
-
+#include "llvm/Instructions.h"
#include "llvm/Analysis/Expressions.h"
-#include "Support/STLExtras.h"
-#include "Support/Debug.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/Debug.h"
#include <algorithm>
using namespace llvm;
// If it's a constant... all constants can be converted to a different
// type.
//
- if (Constant *CPV = dyn_cast<Constant>(V))
+ if (isa<Constant>(V) && !isa<GlobalValue>(V))
return true;
CTMap[V] = Ty;
}
case Instruction::PHI: {
PHINode *PN = cast<PHINode>(I);
+ // Be conservative if we find a giant PHI node.
+ if (PN->getNumIncomingValues() > 32) return false;
+
for (unsigned i = 0; i < PN->getNumIncomingValues(); ++i)
if (!ExpressionConvertibleToType(PN->getIncomingValue(i), Ty, CTMap, TD))
return false;
return VMCI->second;
}
- DEBUG(std::cerr << "CETT: " << (void*)V << " " << V);
+ DEBUG(std::cerr << "CETT: " << (void*)V << " " << *V);
Instruction *I = dyn_cast<Instruction>(V);
if (I == 0) {
if (NumUses == OldSize) ++It;
}
- DEBUG(std::cerr << "ExpIn: " << (void*)I << " " << I
- << "ExpOut: " << (void*)Res << " " << Res);
+ DEBUG(std::cerr << "ExpIn: " << (void*)I << " " << *I
+ << "ExpOut: " << (void*)Res << " " << *Res);
return Res;
}
// stream, so we have to delete it when we're done.
//
if (DataSize != 1) {
- // FIXME, PR82
- TempScale = BinaryOperator::create(Instruction::Mul, Index,
- ConstantSInt::get(Type::LongTy,
- DataSize));
+ Value *CST;
+ if (Index->getType()->isSigned())
+ CST = ConstantSInt::get(Index->getType(), DataSize);
+ else
+ CST = ConstantUInt::get(Index->getType(), DataSize);
+
+ TempScale = BinaryOperator::create(Instruction::Mul, Index, CST);
Index = TempScale;
}
case Instruction::PHI: {
PHINode *PN = cast<PHINode>(I);
+ // Be conservative if we find a giant PHI node.
+ if (PN->getNumIncomingValues() > 32) return false;
+
for (unsigned i = 0; i < PN->getNumIncomingValues(); ++i)
if (!ExpressionConvertibleToType(PN->getIncomingValue(i), Ty, CTMap, TD))
return false;
}
case Instruction::Call: {
- User::op_iterator OI = find(I->op_begin(), I->op_end(), V);
+ User::op_iterator OI = std::find(I->op_begin(), I->op_end(), V);
assert (OI != I->op_end() && "Not using value!");
unsigned OpNum = OI - I->op_begin();
unsigned OtherIdx = (OldVal == I->getOperand(0)) ? 1 : 0;
Value *OtherOp = I->getOperand(OtherIdx);
+ Res->setOperand(!OtherIdx, NewVal);
Value *NewOther = ConvertExpressionToType(OtherOp, NewTy, VMC, TD);
-
Res->setOperand(OtherIdx, NewOther);
- Res->setOperand(!OtherIdx, NewVal);
break;
}
case Instruction::Shl:
if (const CompositeType *CT = dyn_cast<CompositeType>(LoadedTy)) {
std::vector<Value*> Indices;
- // FIXME, PR82
- Indices.push_back(ConstantSInt::get(Type::LongTy, 0));
+ Indices.push_back(Constant::getNullValue(Type::UIntTy));
unsigned Offset = 0; // No offset, get first leaf.
LoadedTy = getStructOffsetType(CT, Offset, Indices, TD, false);
const StructType *SElTy = cast<StructType>(ElTy);
std::vector<Value*> Indices;
- // FIXME, PR82
- Indices.push_back(Constant::getNullValue(Type::LongTy));
+ Indices.push_back(Constant::getNullValue(Type::UIntTy));
unsigned Offset = 0;
const Type *Ty = getStructOffsetType(ElTy, Offset, Indices, TD,false);
if (isa<StructType>(ValTy)) {
std::vector<Value*> Indices;
- // FIXME: PR82
- Indices.push_back(Constant::getNullValue(Type::LongTy));
+ Indices.push_back(Constant::getNullValue(Type::UIntTy));
unsigned Offset = 0;
ValTy = getStructOffsetType(ValTy, Offset, Indices, TD, false);
if (DataSize != 1) {
// Insert a multiply of the old element type is not a unit size...
- Index = BinaryOperator::create(Instruction::Mul, Index,
- // FIXME: PR82
- ConstantSInt::get(Type::LongTy, DataSize),
- "scale", It);
+ Value *CST;
+ if (Index->getType()->isSigned())
+ CST = ConstantSInt::get(Index->getType(), DataSize);
+ else
+ CST = ConstantUInt::get(Index->getType(), DataSize);
+
+ Index = BinaryOperator::create(Instruction::Mul, Index, CST, "scale", It);
}
// Perform the conversion now...
while (OldPN->getNumOperands()) {
BasicBlock *BB = OldPN->getIncomingBlock(0);
Value *OldVal = OldPN->getIncomingValue(0);
+ ValueHandle OldValHandle(VMC, OldVal);
OldPN->removeIncomingValue(BB, false);
Value *V = ConvertExpressionToType(OldVal, NewTy, VMC, TD);
NewPN->addIncoming(V, BB);
} else { // Changing an argument, must be in vararg area
std::vector<Value*>::iterator OI =
- find(Params.begin(), Params.end(), OldVal);
+ std::find(Params.begin(), Params.end(), OldVal);
assert (OI != Params.end() && "Not using value!");
*OI = NewVal;
assert(It != BB->end() && "Instruction not in own basic block??");
BB->getInstList().insert(It, Res); // Keep It pointing to old instruction
- DEBUG(std::cerr << "COT CREATED: " << (void*)Res << " " << Res
- << "In: " << (void*)I << " " << I << "Out: " << (void*)Res
- << " " << Res);
+ DEBUG(std::cerr << "COT CREATED: " << (void*)Res << " " << *Res
+ << "In: " << (void*)I << " " << *I << "Out: " << (void*)Res
+ << " " << *Res);
// Add the instruction to the expression map
VMC.ExprMap[I] = Res;