#include "llvm/Transforms/IPO/MutateStructTypes.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Module.h"
-#include "llvm/Function.h"
-#include "llvm/BasicBlock.h"
-#include "llvm/GlobalVariable.h"
#include "llvm/SymbolTable.h"
#include "llvm/iPHINode.h"
#include "llvm/iMemory.h"
#include "llvm/iTerminators.h"
#include "llvm/iOther.h"
-#include "llvm/Argument.h"
#include "llvm/Constants.h"
#include "Support/STLExtras.h"
-#include "Support/StatisticReporter.h"
+#include "Support/Statistic.h"
#include <algorithm>
-#include <iostream>
+
using std::map;
using std::vector;
//
void MutateStructTypes::AdjustIndices(const CompositeType *OldTy,
vector<Value*> &Idx,
- unsigned i = 0) {
+ unsigned i) {
assert(i < Idx.size() && "i out of range!");
const CompositeType *NewCT = cast<CompositeType>(ConvertType(OldTy));
if (NewCT == OldTy) return; // No adjustment unless type changes
case Instruction::Invoke:
assert(0 && "Insn not implemented!");
- // Unary Instructions
- case Instruction::Not:
- NewI = UnaryOperator::create((Instruction::UnaryOps)I.getOpcode(),
- ConvertValue(I.getOperand(0)));
- break;
-
// Binary Instructions
case Instruction::Add:
case Instruction::Sub:
// Memory Instructions
case Instruction::Alloca:
NewI =
- new AllocaInst(ConvertType(I.getType()),
+ new MallocInst(
+ ConvertType(cast<PointerType>(I.getType())->getElementType()),
I.getNumOperands() ? ConvertValue(I.getOperand(0)) :0);
break;
case Instruction::Malloc:
NewI =
- new MallocInst(ConvertType(I.getType()),
+ new MallocInst(
+ ConvertType(cast<PointerType>(I.getType())->getElementType()),
I.getNumOperands() ? ConvertValue(I.getOperand(0)) :0);
break;
break;
case Instruction::Load:
+ NewI = new LoadInst(ConvertValue(I.getOperand(0)));
+ break;
case Instruction::Store:
+ NewI = new StoreInst(ConvertValue(I.getOperand(0)),
+ ConvertValue(I.getOperand(1)));
+ break;
case Instruction::GetElementPtr: {
- const MemAccessInst &MAI = cast<MemAccessInst>(I);
- vector<Value*> Indices(MAI.idx_begin(), MAI.idx_end());
- const Value *Ptr = MAI.getPointerOperand();
- Value *NewPtr = ConvertValue(Ptr);
+ const GetElementPtrInst &GEP = cast<GetElementPtrInst>(I);
+ vector<Value*> Indices(GEP.idx_begin(), GEP.idx_end());
if (!Indices.empty()) {
- const Type *PTy = cast<PointerType>(Ptr->getType())->getElementType();
+ const Type *PTy =
+ cast<PointerType>(GEP.getOperand(0)->getType())->getElementType();
AdjustIndices(cast<CompositeType>(PTy), Indices);
}
- if (isa<LoadInst>(I)) {
- NewI = new LoadInst(NewPtr, Indices);
- } else if (isa<StoreInst>(I)) {
- NewI = new StoreInst(ConvertValue(I.getOperand(0)), NewPtr, Indices);
- } else if (isa<GetElementPtrInst>(I)) {
- NewI = new GetElementPtrInst(NewPtr, Indices);
- } else {
- assert(0 && "Unknown memory access inst!!!");
- }
+ NewI = new GetElementPtrInst(ConvertValue(GEP.getOperand(0)), Indices);
break;
}