45#include "llvm/IR/IntrinsicsX86.h"
52#define DEBUG_TYPE "x86-fence-nontemporal-stores"
55 return I.hasMetadata(LLVMContext::MD_nontemporal) &&
I.mayWriteToMemory();
67 if (
auto Intrin = CB->getIntrinsicID()) {
68 return Intrin == Intrinsic::x86_sse_sfence ||
69 Intrin == Intrinsic::x86_sse2_mfence;
83 I.maySynchronize() ||
I.mayThrow();
100 if (ST && !ST->hasSSE1())
129 int Flag = Passthrough;
139 if ((Flag & DirtyOut)) {
148 while (!Worklist.
empty()) {
151 bool NewDirtyIn =
false;
153 if (Flags[Pred] & DirtyOut) {
158 if (NewDirtyIn && !(Flags[BB] & DirtyIn)) {
159 Flags[BB] |= DirtyIn;
160 if (Flags[BB] & Passthrough) {
161 Flags[BB] |= DirtyOut;
174 bool CurrentDirty = Flags[&BB] & DirtyIn;
179 CurrentDirty =
false;
182 Builder.SetInsertPoint(&
I);
183 Builder.SetCurrentDebugLocation(
I.getDebugLoc());
184 Builder.CreateIntrinsic(Intrinsic::x86_sse_sfence, {});
185 CurrentDirty =
false;
197class X86FenceNonTemporalStoresLegacy :
public FunctionPass {
201 X86FenceNonTemporalStoresLegacy() : FunctionPass(ID) {}
204 auto *TPC = getAnalysisIfAvailable<TargetPassConfig>();
205 const X86Subtarget *
ST =
206 TPC ? &TPC->getTM<X86TargetMachine>().getSubtarget<X86Subtarget>(
F)
211 void getAnalysisUsage(AnalysisUsage &AU)
const override {
215 StringRef getPassName()
const override {
216 return "X86 Fence Non-Temporal Stores";
222char X86FenceNonTemporalStoresLegacy::ID = 0;
225 "X86 Fence Non-Temporal Stores",
false,
false)
228 return new X86FenceNonTemporalStoresLegacy();
233 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 SmallPtrSet class.
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.