LLVM: lib/Transforms/Utils/Mem2Reg.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
27#include
28
29using namespace llvm;
30
31#define DEBUG_TYPE "mem2reg"
32
33STATISTIC(NumPromoted, "Number of alloca's promoted");
34
37 std::vector<AllocaInst *> Allocas;
38 BasicBlock &BB = F.getEntryBlock();
40
41 while (true) {
42 Allocas.clear();
43
44
45
49 Allocas.push_back(AI);
50
51 if (Allocas.empty())
52 break;
53
55 NumPromoted += Allocas.size();
57 }
59}
60
71
72namespace {
73
74struct PromoteLegacyPass : public FunctionPass {
75
76 static char ID;
77
80 }
81
82
83
85 if (skipFunction(F))
86 return false;
87
88 DominatorTree &DT = getAnalysis().getDomTree();
90 getAnalysis().getAssumptionCache(F);
92 }
93
94 void getAnalysisUsage(AnalysisUsage &AU) const override {
96 AU.addRequired();
98 }
99};
100
101}
102
103char PromoteLegacyPass::ID = 0;
104
106 "Register",
107 false, false)
112
113
115 return new PromoteLegacyPass();
116}
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static bool runOnFunction(Function &F, bool PostInlining)
This header defines various interfaces for pass management in LLVM.
static bool promoteMemoryToRegister(Function &F, DominatorTree &DT, AssumptionCache &AC)
Definition Mem2Reg.cpp:35
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
an instruction to allocate memory on the stack
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
AnalysisUsage & addRequired()
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
A function analysis which provides an AssumptionCache.
An immutable pass that tracks lazily created AssumptionCache objects.
A cache of @llvm.assume calls within a function.
LLVM Basic Block Representation.
iterator begin()
Instruction iterator methods.
InstListType::iterator iterator
Instruction iterators...
Represents analyses that only rely on functions' control flow.
Analysis pass which computes a DominatorTree.
Legacy analysis pass which computes a DominatorTree.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
FunctionPass class - This class is used to implement most global optimizations.
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI FunctionPass * createPromoteMemoryToRegisterPass()
Definition Mem2Reg.cpp:114
LLVM_ABI void PromoteMemToReg(ArrayRef< AllocaInst * > Allocas, DominatorTree &DT, AssumptionCache *AC=nullptr)
Promote the specified list of alloca instructions into scalar registers, inserting PHI nodes as appro...
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
LLVM_ABI bool isAllocaPromotable(const AllocaInst *AI)
Return true if this alloca is legal for promotion.
LLVM_ABI void initializePromoteLegacyPassPass(PassRegistry &)
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.