llvm.org GIT mirror llvm / 7430989
[PM] Port LowerAtomic to the new pass manager. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269511 91177308-0d34-0410-b5e6-96231b3b80d8 Davide Italiano 3 years ago
7 changed file(s) with 89 addition(s) and 43 deletion(s). Raw diff Collapse all Expand all
188188 void initializeLoopUnswitchPass(PassRegistry&);
189189 void initializeLoopVersioningLICMPass(PassRegistry&);
190190 void initializeLoopIdiomRecognizePass(PassRegistry&);
191 void initializeLowerAtomicPass(PassRegistry&);
191 void initializeLowerAtomicLegacyPassPass(PassRegistry &);
192192 void initializeLowerBitSetsPass(PassRegistry&);
193193 void initializeLowerExpectIntrinsicPass(PassRegistry&);
194194 void initializeLowerGuardIntrinsicPass(PassRegistry&);
0 //===- LowerAtomic.cpp - Lower atomic intrinsics ----------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
9 // This pass lowers atomic intrinsics to non-atomic form for use in a known
10 // non-preemptible environment.
11 ///
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_TRANSFORMS_SCALAR_LOWERATOMIC_H
15 #define LLVM_TRANSFORMS_SCALAR_LOWERATOMIC_H
16
17 #include "llvm/IR/PassManager.h"
18
19 namespace llvm {
20
21 /// A pass that lowers atomic intrinsic into non-atomic intrinsics.
22 class LowerAtomicPass : public PassInfoMixin {
23 public:
24 PreservedAnalyses run(Function &F);
25 };
26 }
27
28 #endif // LLVM_TRANSFORMS_SCALAR_LOWERATOMIC_H
6767 #include "llvm/Transforms/Scalar/GVN.h"
6868 #include "llvm/Transforms/Scalar/LoopRotation.h"
6969 #include "llvm/Transforms/Scalar/LoopSimplifyCFG.h"
70 #include "llvm/Transforms/Scalar/LowerAtomic.h"
7071 #include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
7172 #include "llvm/Transforms/Scalar/Reassociate.h"
7273 #include "llvm/Transforms/Scalar/SROA.h"
113113 FUNCTION_PASS("instcombine", InstCombinePass())
114114 FUNCTION_PASS("invalidate", InvalidateAllAnalysesPass())
115115 FUNCTION_PASS("no-op-function", NoOpFunctionPass())
116 FUNCTION_PASS("loweratomic", LowerAtomicPass())
116117 FUNCTION_PASS("lower-expect", LowerExpectIntrinsicPass())
117118 FUNCTION_PASS("gvn", GVN())
118119 FUNCTION_PASS("print", PrintFunctionPass(dbgs()))
1111 //
1212 //===----------------------------------------------------------------------===//
1313
14 #include "llvm/Transforms/Scalar.h"
14 #include "llvm/Transforms/Scalar/LowerAtomic.h"
1515 #include "llvm/IR/Function.h"
1616 #include "llvm/IR/IRBuilder.h"
1717 #include "llvm/IR/IntrinsicInst.h"
1818 #include "llvm/Pass.h"
19 #include "llvm/Transforms/Scalar.h"
1920 using namespace llvm;
2021
2122 #define DEBUG_TYPE "loweratomic"
108109 return true;
109110 }
110111
112 static bool runOnBasicBlock(BasicBlock &BB) {
113 bool Changed = false;
114 for (BasicBlock::iterator DI = BB.begin(), DE = BB.end(); DI != DE;) {
115 Instruction *Inst = &*DI++;
116 if (FenceInst *FI = dyn_cast(Inst))
117 Changed |= LowerFenceInst(FI);
118 else if (AtomicCmpXchgInst *CXI = dyn_cast(Inst))
119 Changed |= LowerAtomicCmpXchgInst(CXI);
120 else if (AtomicRMWInst *RMWI = dyn_cast(Inst))
121 Changed |= LowerAtomicRMWInst(RMWI);
122 else if (LoadInst *LI = dyn_cast(Inst)) {
123 if (LI->isAtomic())
124 LowerLoadInst(LI);
125 } else if (StoreInst *SI = dyn_cast(Inst)) {
126 if (SI->isAtomic())
127 LowerStoreInst(SI);
128 }
129 }
130 return Changed;
131 }
132
133 static bool lowerAtomics(Function &F) {
134 bool Changed = false;
135 for (BasicBlock &BB : F) {
136 Changed |= runOnBasicBlock(BB);
137 }
138 return Changed;
139 }
140
141 PreservedAnalyses LowerAtomicPass::run(Function &F) {
142 if (lowerAtomics(F))
143 return PreservedAnalyses::none();
144 return PreservedAnalyses::all();
145 }
146
111147 namespace {
112 struct LowerAtomic : public FunctionPass {
113 static char ID;
148 class LowerAtomicLegacyPass : public FunctionPass {
149 public:
150 static char ID;
114151
115 LowerAtomic() : FunctionPass(ID) {
116 initializeLowerAtomicPass(*PassRegistry::getPassRegistry());
117 }
152 LowerAtomicLegacyPass() : FunctionPass(ID) {
153 initializeLowerAtomicLegacyPassPass(*PassRegistry::getPassRegistry());
154 }
118155
119 bool runOnFunction(Function &F) override {
120 if (skipFunction(F))
121 return false;
122 bool Changed = false;
123 for (BasicBlock &BB: F) {
124 Changed |= runOnBasicBlock(BB);
125 }
126 return Changed;
127 }
156 bool runOnFunction(Function &F) override {
157 if (skipFunction(F))
158 return false;
159 auto PA = Impl.run(F);
160 return !PA.areAllPreserved();
161 }
128162
129 private:
130 bool runOnBasicBlock(BasicBlock &BB) {
131 bool Changed = false;
132 for (BasicBlock::iterator DI = BB.begin(), DE = BB.end(); DI != DE;) {
133 Instruction *Inst = &*DI++;
134 if (FenceInst *FI = dyn_cast(Inst))
135 Changed |= LowerFenceInst(FI);
136 else if (AtomicCmpXchgInst *CXI = dyn_cast(Inst))
137 Changed |= LowerAtomicCmpXchgInst(CXI);
138 else if (AtomicRMWInst *RMWI = dyn_cast(Inst))
139 Changed |= LowerAtomicRMWInst(RMWI);
140 else if (LoadInst *LI = dyn_cast(Inst)) {
141 if (LI->isAtomic())
142 LowerLoadInst(LI);
143 } else if (StoreInst *SI = dyn_cast(Inst)) {
144 if (SI->isAtomic())
145 LowerStoreInst(SI);
146 }
147 }
148 return Changed;
149 }
163 private:
164 LowerAtomicPass Impl;
150165 };
151166 }
152167
153 char LowerAtomic::ID = 0;
154 INITIALIZE_PASS(LowerAtomic, "loweratomic",
155 "Lower atomic intrinsics to non-atomic form",
156 false, false)
168 char LowerAtomicLegacyPass::ID = 0;
169 INITIALIZE_PASS(LowerAtomicLegacyPass, "loweratomic",
170 "Lower atomic intrinsics to non-atomic form", false, false)
157171
158 Pass *llvm::createLowerAtomicPass() { return new LowerAtomic(); }
172 Pass *llvm::createLowerAtomicPass() { return new LowerAtomicLegacyPass(); }
5959 initializeLoopUnswitchPass(Registry);
6060 initializeLoopVersioningLICMPass(Registry);
6161 initializeLoopIdiomRecognizePass(Registry);
62 initializeLowerAtomicPass(Registry);
62 initializeLowerAtomicLegacyPassPass(Registry);
6363 initializeLowerExpectIntrinsicPass(Registry);
6464 initializeLowerGuardIntrinsicPass(Registry);
6565 initializeMemCpyOptPass(Registry);
0 ; RUN: opt < %s -loweratomic -S | FileCheck %s
1 ; RUN: opt < %s -passes=loweratomic -S | FileCheck %s
12
23 define i8 @add() {
34 ; CHECK-LABEL: @add(