OLD | NEW |
(Empty) | |
| 1 //===- llvm/Analysis/NaCl/PNaClSimplificationAnalyses.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 const SmallVectorImpl<AtomicCmpXchgInst *> &getCmpXchgs() const { |
| 26 return CmpXchgs; |
| 27 } |
| 28 const SmallVectorImpl<LoadInst *> &getLoads() const { return Loads; } |
| 29 const SmallVectorImpl<StoreInst *> &getStores() const { return Stores; } |
| 30 const SmallVectorImpl<AtomicRMWInst *> &getRMWs() const { return RMWs; } |
| 31 const SmallVectorImpl<FenceInst *> &getFences() const { return Fences; } |
| 32 |
| 33 AtomicInfo() {} |
| 34 AtomicInfo(Function &F); |
| 35 AtomicInfo(AtomicInfo &&Rhs) |
| 36 : CmpXchgs(std::move(Rhs.CmpXchgs)), Loads(std::move(Rhs.Loads)), |
| 37 Stores(std::move(Rhs.Stores)), RMWs(std::move(Rhs.RMWs)), |
| 38 Fences(std::move(Rhs.Fences)) {} |
| 39 AtomicInfo &operator=(AtomicInfo &&Rhs) { |
| 40 CmpXchgs = std::move(Rhs.CmpXchgs); |
| 41 Loads = std::move(Rhs.Loads); |
| 42 Stores = std::move(Rhs.Stores); |
| 43 RMWs = std::move(Rhs.RMWs); |
| 44 Fences = std::move(Rhs.Fences); |
| 45 return *this; |
| 46 } |
| 47 |
| 48 void releaseMemory() { |
| 49 CmpXchgs.clear(); |
| 50 Loads.clear(); |
| 51 Stores.clear(); |
| 52 RMWs.clear(); |
| 53 Fences.clear(); |
| 54 } |
| 55 |
| 56 private: |
| 57 SmallVector<AtomicCmpXchgInst *, 8> CmpXchgs; |
| 58 SmallVector<LoadInst *, 8> Loads; |
| 59 SmallVector<StoreInst *, 8> Stores; |
| 60 SmallVector<AtomicRMWInst *, 8> RMWs; |
| 61 SmallVector<FenceInst *, 4> Fences; |
| 62 }; |
| 63 |
| 64 /// \brief This is a very simple analysis pass that just collects the |
| 65 /// instructions which need to be expanded into NaCl's stable atomic |
| 66 /// intrinsics. |
| 67 class AtomicAnalysis { |
| 68 static char PassID; |
| 69 |
| 70 public: |
| 71 typedef AtomicInfo Result; |
| 72 |
| 73 static void *ID() { return (void *)&PassID; } |
| 74 static StringRef name() { return "AtomicInstructionsAnalysis"; } |
| 75 |
| 76 AtomicAnalysis() {} |
| 77 AtomicAnalysis(const AtomicAnalysis &) {} |
| 78 AtomicAnalysis(AtomicAnalysis &&) {} |
| 79 AtomicAnalysis &operator=(const AtomicAnalysis &) { return *this; } |
| 80 AtomicAnalysis &operator=(AtomicAnalysis &&) { return *this; } |
| 81 |
| 82 AtomicInfo run(Function &F) { return AtomicInfo(F); } |
| 83 }; |
| 84 |
| 85 class AtomicAnalysisWrapperPass : public FunctionPass { |
| 86 AtomicInfo Info; |
| 87 |
| 88 public: |
| 89 static char ID; |
| 90 |
| 91 AtomicAnalysisWrapperPass() : FunctionPass(ID) { |
| 92 initializeAtomicAnalysisWrapperPassPass(*PassRegistry::getPassRegistry()); |
| 93 } |
| 94 |
| 95 AtomicInfo &getInfo() { return Info; } |
| 96 const AtomicInfo &getInfo() const { return Info; } |
| 97 |
| 98 bool runOnFunction(Function &F) override; |
| 99 void releaseMemory() override; |
| 100 void getAnalysisUsage(AnalysisUsage &AU) const override; |
| 101 }; |
| 102 } |
OLD | NEW |