#include "llvm/Transforms/IPO/CalledValuePropagation.h"
#include "llvm/Analysis/SparsePropagation.h"
#include "llvm/Analysis/ValueLatticeUtils.h"
-#include "llvm/IR/InstVisitor.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/InitializePasses.h"
#include "llvm/Support/CommandLine.h"
SparseSolver<CVPLatticeKey, CVPLatticeVal> &SS) override {
switch (I.getOpcode()) {
case Instruction::Call:
- return visitCallSite(cast<CallInst>(&I), ChangedValues, SS);
case Instruction::Invoke:
- return visitCallSite(cast<InvokeInst>(&I), ChangedValues, SS);
+ return visitCallBase(cast<CallBase>(I), ChangedValues, SS);
case Instruction::Load:
return visitLoad(*cast<LoadInst>(&I), ChangedValues, SS);
case Instruction::Ret:
/// We collect a set of indirect calls when visiting call sites. This method
/// returns a reference to that set.
- SmallPtrSetImpl<Instruction *> &getIndirectCalls() { return IndirectCalls; }
+ SmallPtrSetImpl<CallBase *> &getIndirectCalls() { return IndirectCalls; }
private:
/// Holds the indirect calls we encounter during the analysis. We will attach
/// metadata to these calls after the analysis indicating the functions the
/// calls can possibly target.
- SmallPtrSet<Instruction *, 32> IndirectCalls;
+ SmallPtrSet<CallBase *, 32> IndirectCalls;
/// Compute a new lattice value for the given constant. The constant, after
/// stripping any pointer casts, should be a Function. We ignore null
/// the merge of the argument state with the call sites corresponding actual
/// argument state. The call site state is the merge of the call site state
/// with the returned value state of the called function.
- void visitCallSite(CallSite CS,
+ void visitCallBase(CallBase &CB,
DenseMap<CVPLatticeKey, CVPLatticeVal> &ChangedValues,
SparseSolver<CVPLatticeKey, CVPLatticeVal> &SS) {
- Function *F = CS.getCalledFunction();
- Instruction *I = CS.getInstruction();
- auto RegI = CVPLatticeKey(I, IPOGrouping::Register);
+ Function *F = CB.getCalledFunction();
+ auto RegI = CVPLatticeKey(&CB, IPOGrouping::Register);
// If this is an indirect call, save it so we can quickly revisit it when
// attaching metadata.
if (!F)
- IndirectCalls.insert(I);
+ IndirectCalls.insert(&CB);
// If we can't track the function's return values, there's nothing to do.
if (!F || !canTrackReturnsInterprocedurally(F)) {
// Void return, No need to create and update CVPLattice state as no one
// can use it.
- if (I->getType()->isVoidTy())
+ if (CB.getType()->isVoidTy())
return;
ChangedValues[RegI] = getOverdefinedVal();
return;
for (Argument &A : F->args()) {
auto RegFormal = CVPLatticeKey(&A, IPOGrouping::Register);
auto RegActual =
- CVPLatticeKey(CS.getArgument(A.getArgNo()), IPOGrouping::Register);
+ CVPLatticeKey(CB.getArgOperand(A.getArgNo()), IPOGrouping::Register);
ChangedValues[RegFormal] =
MergeValues(SS.getValueState(RegFormal), SS.getValueState(RegActual));
}
// Void return, No need to create and update CVPLattice state as no one can
// use it.
- if (I->getType()->isVoidTy())
+ if (CB.getType()->isVoidTy())
return;
ChangedValues[RegI] =
// the set of functions they can possibly target.
bool Changed = false;
MDBuilder MDB(M.getContext());
- for (Instruction *C : Lattice.getIndirectCalls()) {
- CallSite CS(C);
- auto RegI = CVPLatticeKey(CS.getCalledValue(), IPOGrouping::Register);
+ for (CallBase *C : Lattice.getIndirectCalls()) {
+ auto RegI = CVPLatticeKey(C->getCalledValue(), IPOGrouping::Register);
CVPLatticeVal LV = Solver.getExistingValueState(RegI);
if (!LV.isFunctionSet() || LV.getFunctions().empty())
continue;