Index: include/llvm/Analysis/NaCl/PNaClSimplificationAnalyses.h |
diff --git a/include/llvm/Analysis/NaCl/PNaClSimplificationAnalyses.h b/include/llvm/Analysis/NaCl/PNaClSimplificationAnalyses.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..79a4d95342ac89d4bacd725d6f3cbbf8d4cd7eaf |
--- /dev/null |
+++ b/include/llvm/Analysis/NaCl/PNaClSimplificationAnalyses.h |
@@ -0,0 +1,102 @@ |
+//===- llvm/Analysis/NaCl/PNaClSimplificationAnalyses.h ---------*- C++ -*-===// |
+// |
+// The LLVM Compiler Infrastructure |
+// |
+// This file is distributed under the University of Illinois Open Source |
+// License. See LICENSE.TXT for details. |
+// |
+//===----------------------------------------------------------------------===// |
+// |
+// This file houses analysis passes used by the PNaCl IR simplification passes |
+// to remove extra passes over modules while they progressively simplify the IR, |
+// allowing them direct access to what each pass needs to expand. |
+// |
+//===----------------------------------------------------------------------===// |
+ |
+#include "llvm/ADT/SmallVector.h" |
+#include "llvm/IR/Function.h" |
+#include "llvm/IR/Instructions.h" |
+#include "llvm/Pass.h" |
+ |
+namespace llvm { |
+ |
+class AtomicInfo { |
+public: |
+ const SmallVectorImpl<AtomicCmpXchgInst *> &getCmpXchgs() const { |
+ return CmpXchgs; |
+ } |
+ const SmallVectorImpl<LoadInst *> &getLoads() const { return Loads; } |
+ const SmallVectorImpl<StoreInst *> &getStores() const { return Stores; } |
+ const SmallVectorImpl<AtomicRMWInst *> &getRMWs() const { return RMWs; } |
+ const SmallVectorImpl<FenceInst *> &getFences() const { return Fences; } |
+ |
+ AtomicInfo() {} |
+ AtomicInfo(Function &F); |
+ AtomicInfo(AtomicInfo &&Rhs) |
+ : CmpXchgs(std::move(Rhs.CmpXchgs)), Loads(std::move(Rhs.Loads)), |
+ Stores(std::move(Rhs.Stores)), RMWs(std::move(Rhs.RMWs)), |
+ Fences(std::move(Rhs.Fences)) {} |
+ AtomicInfo &operator=(AtomicInfo &&Rhs) { |
+ CmpXchgs = std::move(Rhs.CmpXchgs); |
+ Loads = std::move(Rhs.Loads); |
+ Stores = std::move(Rhs.Stores); |
+ RMWs = std::move(Rhs.RMWs); |
+ Fences = std::move(Rhs.Fences); |
+ return *this; |
+ } |
+ |
+ void releaseMemory() { |
+ CmpXchgs.clear(); |
+ Loads.clear(); |
+ Stores.clear(); |
+ RMWs.clear(); |
+ Fences.clear(); |
+ } |
+ |
+private: |
+ SmallVector<AtomicCmpXchgInst *, 8> CmpXchgs; |
+ SmallVector<LoadInst *, 8> Loads; |
+ SmallVector<StoreInst *, 8> Stores; |
+ SmallVector<AtomicRMWInst *, 8> RMWs; |
+ SmallVector<FenceInst *, 4> Fences; |
+}; |
+ |
+/// \brief This is a very simple analysis pass that just collects the |
+/// instructions which need to be expanded into NaCl's stable atomic |
+/// intrinsics. |
+class AtomicAnalysis { |
+ static char PassID; |
+ |
+public: |
+ typedef AtomicInfo Result; |
+ |
+ static void *ID() { return (void *)&PassID; } |
+ static StringRef name() { return "AtomicInstructionsAnalysis"; } |
+ |
+ AtomicAnalysis() {} |
+ AtomicAnalysis(const AtomicAnalysis &) {} |
+ AtomicAnalysis(AtomicAnalysis &&) {} |
+ AtomicAnalysis &operator=(const AtomicAnalysis &) { return *this; } |
+ AtomicAnalysis &operator=(AtomicAnalysis &&) { return *this; } |
+ |
+ AtomicInfo run(Function &F) { return AtomicInfo(F); } |
+}; |
+ |
+class AtomicAnalysisWrapperPass : public FunctionPass { |
+ AtomicInfo Info; |
+ |
+public: |
+ static char ID; |
+ |
+ AtomicAnalysisWrapperPass() : FunctionPass(ID) { |
+ initializeAtomicAnalysisWrapperPassPass(*PassRegistry::getPassRegistry()); |
+ } |
+ |
+ AtomicInfo &getInfo() { return Info; } |
+ const AtomicInfo &getInfo() const { return Info; } |
+ |
+ bool runOnFunction(Function &F) override; |
+ void releaseMemory() override; |
+ void getAnalysisUsage(AnalysisUsage &AU) const override; |
+}; |
+} |