Chromium Code Reviews| Index: include/llvm/Analysis/NaCl/SimplificationAnalyses.h |
| diff --git a/include/llvm/Analysis/NaCl/SimplificationAnalyses.h b/include/llvm/Analysis/NaCl/SimplificationAnalyses.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2f9135b39e7b779cbc59615ab2da7235c242a7d4 |
| --- /dev/null |
| +++ b/include/llvm/Analysis/NaCl/SimplificationAnalyses.h |
| @@ -0,0 +1,113 @@ |
| +//===- llvm/Analysis/NaCl/SimplificationAnalyses.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: |
| + SmallVectorImpl<AtomicCmpXchgInst *> &getCmpXchgs() { return CmpXchgs; } |
| + const SmallVectorImpl<AtomicCmpXchgInst *> &getCmpXchgs() const { |
| + return CmpXchgs; |
| + } |
| + SmallVectorImpl<LoadInst *> &getLoads() { return Loads; } |
| + const SmallVectorImpl<LoadInst *> &getLoads() const { return Loads; } |
| + SmallVectorImpl<StoreInst *> &getStores() { return Stores; } |
| + const SmallVectorImpl<StoreInst *> &getStores() const { return Stores; } |
| + SmallVectorImpl<AtomicRMWInst *> &getRMWs() { return RMWs; } |
| + const SmallVectorImpl<AtomicRMWInst *> &getRMWs() const { return RMWs; } |
| + SmallVectorImpl<FenceInst *> &getFences() { return Fences; } |
| + 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.
|
| + |
| + bool needsAtomicExpand() const { return NeedsAtomicExpand; } |
| + |
| + 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)), |
| + NeedsAtomicExpand(Rhs.needsAtomicExpand()) {} |
| + 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); |
| + NeedsAtomicExpand = Rhs.needsAtomicExpand(); |
| + return *this; |
| + } |
|
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
|
| + |
| + 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; |
| + |
| + bool NeedsAtomicExpand = false; |
| +}; |
| + |
| +/// \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 { |
|
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
|
| + 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; |
| +}; |
| +} |