Chromium Code Reviews| Index: lib/Analysis/NaCl/SimplificationAnalyses.cpp |
| diff --git a/lib/Analysis/NaCl/SimplificationAnalyses.cpp b/lib/Analysis/NaCl/SimplificationAnalyses.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1d2e59482ba4f87616865d3dea752afb2ba0b2a4 |
| --- /dev/null |
| +++ b/lib/Analysis/NaCl/SimplificationAnalyses.cpp |
| @@ -0,0 +1,67 @@ |
| +//===- llvm/Analysis/NaCl/SimplificationAnalyses.cpp ------------*- 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 implementations of the analysis passes used by the PNaCl IR |
| +// simplification passes to remove extra passes over modules while progressive |
| +// simplifying the IR, allowing them direct access to what each pass needs to |
| +// expand. |
| +// |
| +//===----------------------------------------------------------------------===// |
| + |
| +#include "llvm/Analysis/NaCl/SimplificationAnalyses.h" |
| +#include "llvm/IR/InstIterator.h" |
| + |
| +using namespace llvm; |
| + |
| +AtomicInfo::AtomicInfo(Function &F) { |
| + for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) { |
|
JF
2015/07/23 22:44:38
Use inst_range instead? Or just make this an InstV
Richard Diamond
2015/07/24 19:54:38
Done.
|
| + if (AtomicCmpXchgInst *AI = dyn_cast<AtomicCmpXchgInst>(&*I)) { |
| + CmpXchgs.push_back(AI); |
| + } else if (LoadInst *LI = dyn_cast<LoadInst>(&*I)) { |
| + if (!LI->isSimple()) { |
| + Loads.push_back(LI); |
| + } |
| + } else if (StoreInst *SI = dyn_cast<StoreInst>(&*I)) { |
| + if (!SI->isSimple()) { |
| + Stores.push_back(SI); |
| + } |
| + } else if (AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(&*I)) { |
| + RMWs.push_back(RMWI); |
| + switch (RMWI->getOperation()) { |
| + default: |
| + NeedsAtomicExpand = true; |
| + case AtomicRMWInst::Add: |
| + case AtomicRMWInst::Sub: |
| + case AtomicRMWInst::And: |
| + case AtomicRMWInst::Or: |
| + case AtomicRMWInst::Xor: |
| + case AtomicRMWInst::Xchg: |
| + continue; |
| + } |
| + } else if (FenceInst *FI = dyn_cast<FenceInst>(&*I)) { |
| + Fences.push_back(FI); |
| + } |
| + } |
| +} |
| + |
| +char AtomicAnalysis::PassID; |
| + |
| +INITIALIZE_PASS(AtomicAnalysisWrapperPass, "pnacl-atomic-analysis", |
| + "Find atomic instruction to expand", true, true) |
| +char AtomicAnalysisWrapperPass::ID = 0; |
| + |
| +bool AtomicAnalysisWrapperPass::runOnFunction(Function &F) { |
| + releaseMemory(); |
| + Info = std::move(AtomicInfo(F)); |
| + return false; |
| +} |
| +void AtomicAnalysisWrapperPass::releaseMemory() { Info.releaseMemory(); } |
| +void AtomicAnalysisWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const { |
| + AU.setPreservesAll(); |
| +} |