28#define DEBUG_TYPE "x86-seses"
30STATISTIC(NumLFENCEsInserted,
"Number of lfence instructions inserted");
35 "X86 Speculative Execution Side Effect Suppression";
37class X86SpeculativeExecutionSideEffectSuppressionLegacy
40 X86SpeculativeExecutionSideEffectSuppressionLegacy()
44 StringRef getPassName()
const override {
return X86SESESPassName; }
50char X86SpeculativeExecutionSideEffectSuppressionLegacy::ID = 0;
60 if (MO.isReg() && X86::RIP != MO.getReg())
70 const X86Options &CLOpts = Subtarget.
getCLOpts();
75 if (!CLOpts.seses_enable_without_lvi_cfi &&
77 !Subtarget.useSpeculativeExecutionSideEffectSuppression())
81 << MF.
getName() <<
" **********\n");
88 bool PrevInstIsLFENCE =
false;
89 for (
auto &
MI :
MBB) {
91 if (
MI.getOpcode() == X86::LFENCE) {
92 PrevInstIsLFENCE =
true;
100 if (
MI.mayLoadOrStore() && !
MI.isTerminator()) {
101 if (!PrevInstIsLFENCE) {
103 NumLFENCEsInserted++;
106 if (CLOpts.seses_one_lfence_per_bb)
122 if (
MI.isTerminator() && FirstTerminator ==
nullptr)
123 FirstTerminator = &
MI;
127 if (!
MI.isBranch() || CLOpts.seses_omit_branch_lfences) {
129 PrevInstIsLFENCE =
false;
136 PrevInstIsLFENCE =
false;
141 if (!PrevInstIsLFENCE) {
142 assert(FirstTerminator &&
"Unknown terminator instruction");
144 NumLFENCEsInserted++;
154bool X86SpeculativeExecutionSideEffectSuppressionLegacy::runOnMachineFunction(
169 return new X86SpeculativeExecutionSideEffectSuppressionLegacy();
172INITIALIZE_PASS(X86SpeculativeExecutionSideEffectSuppressionLegacy,
"x86-seses",
173 "X86 Speculative Execution Side Effect Suppression",
false,
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const HexagonInstrInfo * TII
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
static bool runX86SpeculativeExecutionSideEffectSuppression(MachineFunction &MF)
static bool hasConstantAddressingMode(const MachineInstr &MI)
Represents analyses that only rely on functions' control flow.
FunctionPass class - This class is used to implement most global optimizations.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
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.
Represent a constant reference to a string, i.e.
CodeGenOptLevel getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
const X86InstrInfo * getInstrInfo() const override
const X86Options & getCLOpts() const
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
FunctionPass * createX86SpeculativeExecutionSideEffectSuppressionLegacyPass()
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.