#include "llvm/ConstantHandling.h"
#include "llvm/Analysis/Expressions.h"
#include "Support/STLExtras.h"
-#include "Support/StatisticReporter.h"
+#include "Support/Statistic.h"
#include <algorithm>
using std::cerr;
if (!Expr.Offset && !Expr.Scale && OldTypeSize == 1) return false;
// Get the offset and scale of the allocation...
- int OffsetVal = Expr.Offset ? getConstantValue(Expr.Offset) : 0;
- int ScaleVal = Expr.Scale ? getConstantValue(Expr.Scale) : (Expr.Var ? 1 : 0);
+ int64_t OffsetVal = Expr.Offset ? getConstantValue(Expr.Offset) : 0;
+ int64_t ScaleVal = Expr.Scale ? getConstantValue(Expr.Scale) :(Expr.Var != 0);
// The old type might not be of unit size, take old size into consideration
// here...
- int Offset = OffsetVal * OldTypeSize;
- int Scale = ScaleVal * OldTypeSize;
+ int64_t Offset = OffsetVal * OldTypeSize;
+ int64_t Scale = ScaleVal * OldTypeSize;
// In order to be successful, both the scale and the offset must be a multiple
// of the requested data type's size.
unsigned OldTypeSize = TD.getTypeSize(MI->getType()->getElementType());
// Get the offset and scale coefficients that we are allocating...
- int OffsetVal = (Expr.Offset ? getConstantValue(Expr.Offset) : 0);
- int ScaleVal = Expr.Scale ? getConstantValue(Expr.Scale) : (Expr.Var ? 1 : 0);
+ int64_t OffsetVal = (Expr.Offset ? getConstantValue(Expr.Offset) : 0);
+ int64_t ScaleVal = Expr.Scale ? getConstantValue(Expr.Scale) : (Expr.Var !=0);
// The old type might not be of unit size, take old size into consideration
// here...
- unsigned Offset = (unsigned)OffsetVal * OldTypeSize / DataSize;
- unsigned Scale = (unsigned)ScaleVal * OldTypeSize / DataSize;
+ unsigned Offset = (uint64_t)OffsetVal * OldTypeSize / DataSize;
+ unsigned Scale = (uint64_t)ScaleVal * OldTypeSize / DataSize;
// Locate the malloc instruction, because we may be inserting instructions
It = MI;
}
assert(AllocTy == Ty);
- return = new MallocInst(AllocTy, Expr.Var, Name);
+ return new MallocInst(AllocTy->getElementType(), Expr.Var, Name);
}
const Type *BaseType = GEP->getPointerOperand()->getType();
const Type *ElTy = 0;
- while (!Indices.empty() && isa<ConstantUInt>(Indices.back()) &&
- cast<ConstantUInt>(Indices.back())->getValue() == 0) {
+ while (!Indices.empty() &&
+ Indices.back() == Constant::getNullValue(Indices.back()->getType())){
Indices.pop_back();
ElTy = GetElementPtrInst::getIndexedType(BaseType, Indices, true);
if (ElTy == PVTy)
if (ElTy) break; // Found a number of zeros we can strip off!
// Otherwise, we can convert a GEP from one form to the other iff the
- // current gep is of the form 'getelementptr sbyte*, unsigned N
+ // current gep is of the form 'getelementptr sbyte*, long N
// and we could convert this to an appropriate GEP for the new type.
//
if (GEP->getNumOperands() == 2 &&
- GEP->getOperand(1)->getType() == Type::UIntTy &&
+ GEP->getOperand(1)->getType() == Type::LongTy &&
GEP->getType() == PointerType::get(Type::SByteTy)) {
// Do not Check to see if our incoming pointer can be converted
}
// Otherwise, it could be that we have something like this:
- // getelementptr [[sbyte] *] * %reg115, uint %reg138 ; [sbyte]**
+ // getelementptr [[sbyte] *] * %reg115, long %reg138 ; [sbyte]**
// and want to convert it into something like this:
- // getelemenptr [[int] *] * %reg115, uint %reg138 ; [int]**
+ // getelemenptr [[int] *] * %reg115, long %reg138 ; [int]**
//
if (GEP->getNumOperands() == 2 &&
- GEP->getOperand(1)->getType() == Type::UIntTy &&
+ GEP->getOperand(1)->getType() == Type::LongTy &&
TD.getTypeSize(PTy->getElementType()) ==
TD.getTypeSize(GEP->getType()->getElementType())) {
const PointerType *NewSrcTy = PointerType::get(PVTy);
const Type *BaseType = GEP->getPointerOperand()->getType();
const Type *PVTy = cast<PointerType>(Ty)->getElementType();
Res = 0;
- while (!Indices.empty() && isa<ConstantUInt>(Indices.back()) &&
- cast<ConstantUInt>(Indices.back())->getValue() == 0) {
+ while (!Indices.empty() &&
+ Indices.back() == Constant::getNullValue(Indices.back()->getType())){
Indices.pop_back();
if (GetElementPtrInst::getIndexedType(BaseType, Indices, true) == PVTy) {
- if (Indices.size() == 0) {
- Res = new CastInst(GEP->getPointerOperand(), BaseType); // NOOP
- } else {
+ if (Indices.size() == 0)
+ Res = new CastInst(GEP->getPointerOperand(), BaseType); // NOOP CAST
+ else
Res = new GetElementPtrInst(GEP->getPointerOperand(), Indices, Name);
- }
break;
}
}
if (Res == 0 && GEP->getNumOperands() == 2 &&
- GEP->getOperand(1)->getType() == Type::UIntTy &&
+ GEP->getOperand(1)->getType() == Type::LongTy &&
GEP->getType() == PointerType::get(Type::SByteTy)) {
// Otherwise, we can convert a GEP from one form to the other iff the
//
if (DataSize != 1) {
TempScale = BinaryOperator::create(Instruction::Mul, Index,
- ConstantUInt::get(Type::UIntTy,
+ ConstantSInt::get(Type::LongTy,
DataSize));
Index = TempScale;
}
if (const CompositeType *CT = dyn_cast<CompositeType>(LoadedTy)) {
std::vector<Value*> Indices;
- Indices.push_back(ConstantUInt::get(Type::UIntTy, 0));
+ Indices.push_back(ConstantSInt::get(Type::LongTy, 0));
unsigned Offset = 0; // No offset, get first leaf.
LoadedTy = getStructOffsetType(CT, Offset, Indices, false);
const StructType *SElTy = cast<StructType>(ElTy);
std::vector<Value*> Indices;
- Indices.push_back(ConstantUInt::get(Type::UIntTy, 0));
+ Indices.push_back(Constant::getNullValue(Type::LongTy));
unsigned Offset = 0;
const Type *Ty = getStructOffsetType(ElTy, Offset, Indices, false);
if (isa<StructType>(ValTy)) {
std::vector<Value*> Indices;
- Indices.push_back(ConstantUInt::get(Type::UIntTy, 0));
+ Indices.push_back(Constant::getNullValue(Type::LongTy));
unsigned Offset = 0;
ValTy = getStructOffsetType(ValTy, Offset, Indices, false);
if (DataSize != 1) {
// Insert a multiply of the old element type is not a unit size...
Index = BinaryOperator::create(Instruction::Mul, Index,
- ConstantUInt::get(Type::UIntTy, DataSize),
+ ConstantSInt::get(Type::LongTy, DataSize),
"scale", It);
}