OLD | NEW |
---|---|
(Empty) | |
1 //===- llvm/Analysis/NaCl/SimplificationAnalyses.h --------------*- C++ -*-===// | |
2 // | |
3 // The LLVM Compiler Infrastructure | |
4 // | |
5 // This file is distributed under the University of Illinois Open Source | |
6 // License. See LICENSE.TXT for details. | |
7 // | |
8 //===----------------------------------------------------------------------===// | |
9 // | |
10 // This file houses analysis passes used by the PNaCl IR simplification passes | |
11 // to remove extra passes over modules while they progressively simplify the IR, | |
12 // allowing them direct access to what each pass needs to expand. | |
13 // | |
14 //===----------------------------------------------------------------------===// | |
15 | |
16 #include "llvm/ADT/SmallVector.h" | |
17 #include "llvm/IR/Function.h" | |
18 #include "llvm/IR/Instructions.h" | |
19 #include "llvm/Pass.h" | |
20 | |
21 namespace llvm { | |
22 | |
23 class AtomicInfo { | |
24 public: | |
25 SmallVectorImpl<AtomicCmpXchgInst *> &getCmpXchgs() { return CmpXchgs; } | |
26 const SmallVectorImpl<AtomicCmpXchgInst *> &getCmpXchgs() const { | |
27 return CmpXchgs; | |
28 } | |
29 SmallVectorImpl<LoadInst *> &getLoads() { return Loads; } | |
30 const SmallVectorImpl<LoadInst *> &getLoads() const { return Loads; } | |
31 SmallVectorImpl<StoreInst *> &getStores() { return Stores; } | |
32 const SmallVectorImpl<StoreInst *> &getStores() const { return Stores; } | |
33 SmallVectorImpl<AtomicRMWInst *> &getRMWs() { return RMWs; } | |
34 const SmallVectorImpl<AtomicRMWInst *> &getRMWs() const { return RMWs; } | |
35 SmallVectorImpl<FenceInst *> &getFences() { return Fences; } | |
36 const SmallVectorImpl<FenceInst *> &getFences() const { return Fences; } | |
JF
2015/07/23 22:44:38
Are these ever used in a non-const context by non-
Richard Diamond
2015/07/24 19:54:38
Probably not, removed.
| |
37 | |
38 bool needsAtomicExpand() const { return NeedsAtomicExpand; } | |
39 | |
40 AtomicInfo() {} | |
41 AtomicInfo(Function &F); | |
42 AtomicInfo(AtomicInfo &&Rhs) | |
43 : CmpXchgs(std::move(Rhs.CmpXchgs)), Loads(std::move(Rhs.Loads)), | |
44 Stores(std::move(Rhs.Stores)), RMWs(std::move(Rhs.RMWs)), | |
45 Fences(std::move(Rhs.Fences)), | |
46 NeedsAtomicExpand(Rhs.needsAtomicExpand()) {} | |
47 AtomicInfo &operator=(AtomicInfo &&Rhs) { | |
48 CmpXchgs = std::move(Rhs.CmpXchgs); | |
49 Loads = std::move(Rhs.Loads); | |
50 Stores = std::move(Rhs.Stores); | |
51 RMWs = std::move(Rhs.RMWs); | |
52 Fences = std::move(Rhs.Fences); | |
53 NeedsAtomicExpand = Rhs.needsAtomicExpand(); | |
54 return *this; | |
55 } | |
JF
2015/07/23 22:44:38
Do these ever get used? It doesn't seem like you s
Richard Diamond
2015/07/24 19:54:38
Yes, the legacy wrapper uses them when it's run ov
| |
56 | |
57 void releaseMemory() { | |
58 CmpXchgs.clear(); | |
59 Loads.clear(); | |
60 Stores.clear(); | |
61 RMWs.clear(); | |
62 Fences.clear(); | |
63 } | |
64 | |
65 private: | |
66 SmallVector<AtomicCmpXchgInst *, 8> CmpXchgs; | |
67 SmallVector<LoadInst *, 8> Loads; | |
68 SmallVector<StoreInst *, 8> Stores; | |
69 SmallVector<AtomicRMWInst *, 8> RMWs; | |
70 SmallVector<FenceInst *, 4> Fences; | |
71 | |
72 bool NeedsAtomicExpand = false; | |
73 }; | |
74 | |
75 /// \brief This is a very simple analysis pass that just collects the | |
76 /// instructions which need to be expanded into NaCl's stable atomic | |
77 /// intrinsics. | |
78 class AtomicAnalysis { | |
79 static char PassID; | |
80 | |
81 public: | |
82 typedef AtomicInfo Result; | |
83 | |
84 static void *ID() { return (void *)&PassID; } | |
85 static StringRef name() { return "AtomicInstructionsAnalysis"; } | |
86 | |
87 AtomicAnalysis() {} | |
88 AtomicAnalysis(const AtomicAnalysis &) {} | |
89 AtomicAnalysis(AtomicAnalysis &&) {} | |
90 AtomicAnalysis &operator=(const AtomicAnalysis &) { return *this; } | |
91 AtomicAnalysis &operator=(AtomicAnalysis &&) { return *this; } | |
92 | |
93 AtomicInfo run(Function &F) { return AtomicInfo(F); } | |
94 }; | |
95 | |
96 class AtomicAnalysisWrapperPass : public FunctionPass { | |
JF
2015/07/23 22:44:38
Why not just put everything in this class, instead
Richard Diamond
2015/07/24 19:54:38
`AtomicAnalysis` && `AtomicInfo` are for the new p
| |
97 AtomicInfo Info; | |
98 | |
99 public: | |
100 static char ID; | |
101 | |
102 AtomicAnalysisWrapperPass() : FunctionPass(ID) { | |
103 initializeAtomicAnalysisWrapperPassPass(*PassRegistry::getPassRegistry()); | |
104 } | |
105 | |
106 AtomicInfo &getInfo() { return Info; } | |
107 const AtomicInfo &getInfo() const { return Info; } | |
108 | |
109 bool runOnFunction(Function &F) override; | |
110 void releaseMemory() override; | |
111 void getAnalysisUsage(AnalysisUsage &AU) const; | |
112 }; | |
113 } | |
OLD | NEW |