forked from OSchip/llvm-project
[PM] Port LowerAtomic to the new pass manager.
llvm-svn: 269511
This commit is contained in:
parent
542a628907
commit
9922344178
|
@ -189,7 +189,7 @@ void initializeLoopUnrollPass(PassRegistry&);
|
|||
void initializeLoopUnswitchPass(PassRegistry&);
|
||||
void initializeLoopVersioningLICMPass(PassRegistry&);
|
||||
void initializeLoopIdiomRecognizePass(PassRegistry&);
|
||||
void initializeLowerAtomicPass(PassRegistry&);
|
||||
void initializeLowerAtomicLegacyPassPass(PassRegistry &);
|
||||
void initializeLowerBitSetsPass(PassRegistry&);
|
||||
void initializeLowerExpectIntrinsicPass(PassRegistry&);
|
||||
void initializeLowerGuardIntrinsicPass(PassRegistry&);
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
//===- LowerAtomic.cpp - Lower atomic intrinsics ----------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
/// \file
|
||||
// This pass lowers atomic intrinsics to non-atomic form for use in a known
|
||||
// non-preemptible environment.
|
||||
///
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_TRANSFORMS_SCALAR_LOWERATOMIC_H
|
||||
#define LLVM_TRANSFORMS_SCALAR_LOWERATOMIC_H
|
||||
|
||||
#include "llvm/IR/PassManager.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
/// A pass that lowers atomic intrinsic into non-atomic intrinsics.
|
||||
class LowerAtomicPass : public PassInfoMixin<LowerAtomicPass> {
|
||||
public:
|
||||
PreservedAnalyses run(Function &F);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // LLVM_TRANSFORMS_SCALAR_LOWERATOMIC_H
|
|
@ -68,6 +68,7 @@
|
|||
#include "llvm/Transforms/Scalar/GVN.h"
|
||||
#include "llvm/Transforms/Scalar/LoopRotation.h"
|
||||
#include "llvm/Transforms/Scalar/LoopSimplifyCFG.h"
|
||||
#include "llvm/Transforms/Scalar/LowerAtomic.h"
|
||||
#include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
|
||||
#include "llvm/Transforms/Scalar/Reassociate.h"
|
||||
#include "llvm/Transforms/Scalar/SROA.h"
|
||||
|
|
|
@ -114,6 +114,7 @@ FUNCTION_PASS("early-cse", EarlyCSEPass())
|
|||
FUNCTION_PASS("instcombine", InstCombinePass())
|
||||
FUNCTION_PASS("invalidate<all>", InvalidateAllAnalysesPass())
|
||||
FUNCTION_PASS("no-op-function", NoOpFunctionPass())
|
||||
FUNCTION_PASS("loweratomic", LowerAtomicPass())
|
||||
FUNCTION_PASS("lower-expect", LowerExpectIntrinsicPass())
|
||||
FUNCTION_PASS("gvn", GVN())
|
||||
FUNCTION_PASS("print", PrintFunctionPass(dbgs()))
|
||||
|
|
|
@ -12,11 +12,12 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Transforms/Scalar.h"
|
||||
#include "llvm/Transforms/Scalar/LowerAtomic.h"
|
||||
#include "llvm/IR/Function.h"
|
||||
#include "llvm/IR/IRBuilder.h"
|
||||
#include "llvm/IR/IntrinsicInst.h"
|
||||
#include "llvm/Pass.h"
|
||||
#include "llvm/Transforms/Scalar.h"
|
||||
using namespace llvm;
|
||||
|
||||
#define DEBUG_TYPE "loweratomic"
|
||||
|
@ -109,51 +110,64 @@ static bool LowerStoreInst(StoreInst *SI) {
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool runOnBasicBlock(BasicBlock &BB) {
|
||||
bool Changed = false;
|
||||
for (BasicBlock::iterator DI = BB.begin(), DE = BB.end(); DI != DE;) {
|
||||
Instruction *Inst = &*DI++;
|
||||
if (FenceInst *FI = dyn_cast<FenceInst>(Inst))
|
||||
Changed |= LowerFenceInst(FI);
|
||||
else if (AtomicCmpXchgInst *CXI = dyn_cast<AtomicCmpXchgInst>(Inst))
|
||||
Changed |= LowerAtomicCmpXchgInst(CXI);
|
||||
else if (AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(Inst))
|
||||
Changed |= LowerAtomicRMWInst(RMWI);
|
||||
else if (LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
|
||||
if (LI->isAtomic())
|
||||
LowerLoadInst(LI);
|
||||
} else if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) {
|
||||
if (SI->isAtomic())
|
||||
LowerStoreInst(SI);
|
||||
}
|
||||
}
|
||||
return Changed;
|
||||
}
|
||||
|
||||
static bool lowerAtomics(Function &F) {
|
||||
bool Changed = false;
|
||||
for (BasicBlock &BB : F) {
|
||||
Changed |= runOnBasicBlock(BB);
|
||||
}
|
||||
return Changed;
|
||||
}
|
||||
|
||||
PreservedAnalyses LowerAtomicPass::run(Function &F) {
|
||||
if (lowerAtomics(F))
|
||||
return PreservedAnalyses::none();
|
||||
return PreservedAnalyses::all();
|
||||
}
|
||||
|
||||
namespace {
|
||||
struct LowerAtomic : public FunctionPass {
|
||||
static char ID;
|
||||
class LowerAtomicLegacyPass : public FunctionPass {
|
||||
public:
|
||||
static char ID;
|
||||
|
||||
LowerAtomic() : FunctionPass(ID) {
|
||||
initializeLowerAtomicPass(*PassRegistry::getPassRegistry());
|
||||
}
|
||||
LowerAtomicLegacyPass() : FunctionPass(ID) {
|
||||
initializeLowerAtomicLegacyPassPass(*PassRegistry::getPassRegistry());
|
||||
}
|
||||
|
||||
bool runOnFunction(Function &F) override {
|
||||
if (skipFunction(F))
|
||||
return false;
|
||||
bool Changed = false;
|
||||
for (BasicBlock &BB: F) {
|
||||
Changed |= runOnBasicBlock(BB);
|
||||
}
|
||||
return Changed;
|
||||
}
|
||||
bool runOnFunction(Function &F) override {
|
||||
if (skipFunction(F))
|
||||
return false;
|
||||
auto PA = Impl.run(F);
|
||||
return !PA.areAllPreserved();
|
||||
}
|
||||
|
||||
private:
|
||||
bool runOnBasicBlock(BasicBlock &BB) {
|
||||
bool Changed = false;
|
||||
for (BasicBlock::iterator DI = BB.begin(), DE = BB.end(); DI != DE;) {
|
||||
Instruction *Inst = &*DI++;
|
||||
if (FenceInst *FI = dyn_cast<FenceInst>(Inst))
|
||||
Changed |= LowerFenceInst(FI);
|
||||
else if (AtomicCmpXchgInst *CXI = dyn_cast<AtomicCmpXchgInst>(Inst))
|
||||
Changed |= LowerAtomicCmpXchgInst(CXI);
|
||||
else if (AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(Inst))
|
||||
Changed |= LowerAtomicRMWInst(RMWI);
|
||||
else if (LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
|
||||
if (LI->isAtomic())
|
||||
LowerLoadInst(LI);
|
||||
} else if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) {
|
||||
if (SI->isAtomic())
|
||||
LowerStoreInst(SI);
|
||||
}
|
||||
}
|
||||
return Changed;
|
||||
}
|
||||
private:
|
||||
LowerAtomicPass Impl;
|
||||
};
|
||||
}
|
||||
|
||||
char LowerAtomic::ID = 0;
|
||||
INITIALIZE_PASS(LowerAtomic, "loweratomic",
|
||||
"Lower atomic intrinsics to non-atomic form",
|
||||
false, false)
|
||||
char LowerAtomicLegacyPass::ID = 0;
|
||||
INITIALIZE_PASS(LowerAtomicLegacyPass, "loweratomic",
|
||||
"Lower atomic intrinsics to non-atomic form", false, false)
|
||||
|
||||
Pass *llvm::createLowerAtomicPass() { return new LowerAtomic(); }
|
||||
Pass *llvm::createLowerAtomicPass() { return new LowerAtomicLegacyPass(); }
|
||||
|
|
|
@ -60,7 +60,7 @@ void llvm::initializeScalarOpts(PassRegistry &Registry) {
|
|||
initializeLoopUnswitchPass(Registry);
|
||||
initializeLoopVersioningLICMPass(Registry);
|
||||
initializeLoopIdiomRecognizePass(Registry);
|
||||
initializeLowerAtomicPass(Registry);
|
||||
initializeLowerAtomicLegacyPassPass(Registry);
|
||||
initializeLowerExpectIntrinsicPass(Registry);
|
||||
initializeLowerGuardIntrinsicPass(Registry);
|
||||
initializeMemCpyOptPass(Registry);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -loweratomic -S | FileCheck %s
|
||||
; RUN: opt < %s -passes=loweratomic -S | FileCheck %s
|
||||
|
||||
define i8 @add() {
|
||||
; CHECK-LABEL: @add(
|
||||
|
|
Loading…
Reference in New Issue