-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeadStoreElimination.h
73 lines (61 loc) · 2.63 KB
/
DeadStoreElimination.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#undef DEBUG_TYPE
#define DEBUG_TYPE "dead-store-elimination"
#include <sstream>
#include <set>
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/AliasSetTracker.h"
#include "llvm/Analysis/MemoryBuiltins.h"
#include "llvm/Pass.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/Analysis/MemoryDependenceAnalysis.h"
#include "llvm/Analysis/ValueTracking.h"
namespace llvm {
STATISTIC(RemovedStores, "Number of removed stores.");
STATISTIC(FunctionsCount, "Total number of functions.");
STATISTIC(FunctionsCloned, "Number of functions cloned.");
STATISTIC(ClonesCount, "Number of functions that are clones.");
STATISTIC(CallsCount, "Total number of calls.");
STATISTIC(PromissorCalls, "Number of promissor calls.");
STATISTIC(CallsReplaced, "Number of calls replaced.");
enum OverwriteResult {
OverwriteComplete,
OverwriteEnd,
OverwriteUnknown
};
class DeadStoreEliminationPass : public ModulePass {
// Functions that store on arguments
std::map<Function*, std::set<Value*> > fnThatStoreOnArgs;
// Arguments that have dead stores
std::map< Instruction*, std::set<Value*> > deadArguments;
// Function to be cloned
std::map<Function*, std::vector<Instruction*> > fn2Clone;
// VisitedPHIs - The set of PHI nodes visited when determining
/// if a variable's reference has been taken. This set
/// is maintained to ensure we don't visit the same PHI node multiple
/// times.
SmallPtrSet<const PHINode*, 16> VisitedPHIs;
AliasAnalysis *AA;
MemoryDependenceAnalysis *MDA;
public:
static char ID;
DeadStoreEliminationPass();
Function* cloneFunctionWithoutDeadStore(Function *Fn, Instruction* caller, std::string suffix);
OverwriteResult isOverwrite(const AliasAnalysis::Location &Later, const AliasAnalysis::Location &Earlier, AliasAnalysis &AA, int64_t &EarlierOff, int64_t &LaterOff);
bool changeLinkageTypes(Module &M);
bool cloneFunctions();
bool hasAddressTaken(const Instruction *AI, CallSite& CS);
bool isRefAfterCallSite(Value* v, CallSite &CS);
bool runOnModule(Module &M);
int getFnThatStoreOnArgs(Module &M);
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
void print(raw_ostream &O, const Module *M) const;
void printSet(raw_ostream &O, AliasSetTracker &myset) const;
void replaceCallingInst(Instruction* caller, Function* fn);
void runNotUsedDeadStoreAnalysis();
void runOverwrittenDeadStoreAnalysis(Module &M);
void runOverwrittenDeadStoreAnalysisOnFn(Function &F);
};
char DeadStoreEliminationPass::ID = 0;
}