43#include "llvm/IR/IntrinsicsX86.h"
49#define DEBUG_TYPE "x86-fence-nontemporal-stores"
52 return I.hasMetadata(LLVMContext::MD_nontemporal) &&
I.mayWriteToMemory();
64 if (
auto Intrin = CB->getIntrinsicID()) {
65 return Intrin == Intrinsic::x86_sse_sfence ||
66 Intrin == Intrinsic::x86_sse2_mfence;
80 I.maySynchronize() ||
I.mayThrow();
97 if (ST && !ST->hasSSE1())
126 int Flag = Passthrough;
136 if ((Flag & DirtyOut)) {
145 while (!Worklist.
empty()) {
148 bool NewDirtyIn =
false;
150 if (Flags[
Pred] & DirtyOut) {
155 if (NewDirtyIn && !(Flags[BB] & DirtyIn)) {
156 Flags[BB] |= DirtyIn;
157 if (Flags[BB] & Passthrough) {
158 Flags[BB] |= DirtyOut;
171 bool CurrentDirty = Flags[&BB] & DirtyIn;
176 CurrentDirty =
false;
179 Builder.SetInsertPoint(&
I);
180 Builder.SetCurrentDebugLocation(
I.getDebugLoc());
181 Builder.CreateIntrinsic(Intrinsic::x86_sse_sfence, {});
182 CurrentDirty =
false;
194class X86FenceNonTemporalStoresLegacy :
public FunctionPass {
198 X86FenceNonTemporalStoresLegacy() : FunctionPass(ID) {}
201 auto *TPC = getAnalysisIfAvailable<TargetPassConfig>();
202 const X86Subtarget *
ST =
203 TPC ? &TPC->getTM<X86TargetMachine>().getSubtarget<X86Subtarget>(
F)
208 void getAnalysisUsage(AnalysisUsage &AU)
const override {
212 StringRef getPassName()
const override {
213 return "X86 Fence Non-Temporal Stores";
219char X86FenceNonTemporalStoresLegacy::ID = 0;
222 "X86 Fence Non-Temporal Stores",
false,
false)
225 return new X86FenceNonTemporalStoresLegacy();
230 const X86Subtarget *ST = TM ? TM->getSubtargetImpl(
F) :
nullptr;
static bool runImpl(MachineFunction &MF)
This file defines the DenseMap class.
static bool runOnFunction(Function &F, bool PostInlining)
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
This header defines various interfaces for pass management in LLVM.
FunctionAnalysisManager FAM
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file defines the SmallVector class.
Target-Independent Code Generator Pass Configuration Options pass.
static bool runImpl(Function &F, const X86Subtarget *ST)
static bool isNonTemporalFence(const Instruction &I)
Returns true if I is a hardware fence that serializes write-combining stores:
static bool isNonTemporalStore(const Instruction &I)
static bool containsNonTemporalStores(Function &F)
static bool isSyncOrReturnPoint(const Instruction &I)
Returns true if I is a potential cross-thread synchronization point, or which might return to a calle...
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
LLVM Basic Block Representation.
Represents analyses that only rely on functions' control flow.
FunctionPass class - This class is used to implement most global optimizations.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
bool empty() const
Determine if the SetVector is empty or not.
bool insert(const value_type &X)
Insert a new element into the SetVector.
value_type pop_back_val()
A SetVector that performs no allocations if smaller than a certain size.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM)
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
auto successors(const MachineBasicBlock *BB)
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
FunctionPass * createX86FenceNonTemporalStoresLegacyPass()
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
auto predecessors(const MachineBasicBlock *BB)
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.