44 #include "llvm/ADT/Statistic.h"
45 #include "llvm/IR/Constants.h"
46 #include "llvm/IR/InstrTypes.h"
47 #include "llvm/IR/Instruction.h"
48 #include "llvm/IR/Instructions.h"
49 #include "llvm/IR/LLVMContext.h"
50 #include "llvm/IR/InstIterator.h"
65 #define DEBUG_TYPE "break-constgeps"
68 STATISTIC (GEPChanges,
"Number of Converted GEP Constant Expressions");
69 STATISTIC (TotalChanges,
"Number of Converted Constant Expressions");
89 if (
ConstantExpr * CE = SVFUtil::dyn_cast<ConstantExpr>(V))
91 if (CE->getOpcode() == Instruction::GetElementPtr)
114 if (
ConstantExpr * CE = SVFUtil::dyn_cast<ConstantExpr>(V))
116 if (Instruction::isBinaryOp(CE->getOpcode()) || Instruction::isUnaryOp(CE->getOpcode()))
167 if (CE->getOpcode() == Instruction::GetElementPtr)
171 Result->insertBefore(InsertPt);
188 bool modified =
false;
189 for (Module::iterator
F = module.begin(), E = module.end();
F != E; ++
F)
192 std::vector<Instruction* > Worklist;
198 for (Function::iterator BB = (*F).begin(); BB != (*F).end(); ++BB)
200 for (BasicBlock::iterator i = BB->begin(); i != BB->end(); ++i)
211 Worklist.push_back (I);
220 if (Worklist.size()) modified =
true;
227 while (Worklist.size())
238 if (
PHINode * PHI = SVFUtil::dyn_cast<PHINode>(I))
254 for (
u32_t i2 =
index; i2 < PHI->getNumIncomingValues(); ++i2)
256 if ((PHI->getIncomingBlock (i2)) == PHI->getIncomingBlock (
index))
257 PHI->setIncomingValue (i2, NewInst);
259 Worklist.push_back (NewInst);
275 I->replaceUsesOfWith (CE, NewInst);
276 Worklist.push_back (NewInst);
static Instruction * convertExpression(ConstantExpr *CE, Instruction *InsertPt)
STATISTIC(GEPChanges, "Number of Converted GEP Constant Expressions")
static ConstantExpr * hasConstantExpr(Value *V)
static ConstantExpr * hasConstantBinaryOrUnaryOp(Value *V)
static ConstantExpr * hasConstantGEP(Value *V)
virtual bool runOnModule(Module &M)
llvm::Instruction Instruction
llvm::Value Value
LLVM Basic classes.
llvm::ConstantExpr ConstantExpr