Go to the documentation of this file.
28 #define DEBUG_TYPE "x86-seses"
30 STATISTIC(NumLFENCEsInserted,
"Number of lfence instructions inserted");
33 "x86-seses-enable-without-lvi-cfi",
34 cl::desc(
"Force enable speculative execution side effect suppression. "
35 "(Note: User must pass -mlvi-cfi in order to mitigate indirect "
36 "branches and returns.)"),
40 "x86-seses-one-lfence-per-bb",
42 "Omit all lfences other than the first to be placed in a basic block."),
46 "x86-seses-only-lfence-non-const",
47 cl::desc(
"Only lfence before groups of terminators where at least one "
48 "branch instruction has an input to the addressing mode that is a "
49 "register other than %rip."),
54 cl::desc(
"Omit all lfences before branch instructions."),
59 class X86SpeculativeExecutionSideEffectSuppression
66 return "X86 Speculative Execution Side Effect Suppression";
83 if (MO.isReg() && X86::RIP != MO.getReg())
88 bool X86SpeculativeExecutionSideEffectSuppression::runOnMachineFunction(
99 !Subtarget.useSpeculativeExecutionSideEffectSuppression())
110 bool PrevInstIsLFENCE =
false;
111 for (
auto &
MI :
MBB) {
113 if (
MI.getOpcode() == X86::LFENCE) {
114 PrevInstIsLFENCE =
true;
122 if (
MI.mayLoadOrStore() && !
MI.isTerminator()) {
123 if (!PrevInstIsLFENCE) {
125 NumLFENCEsInserted++;
144 if (
MI.isTerminator() && FirstTerminator ==
nullptr)
145 FirstTerminator = &
MI;
151 PrevInstIsLFENCE =
false;
158 PrevInstIsLFENCE =
false;
163 if (!PrevInstIsLFENCE) {
164 assert(FirstTerminator &&
"Unknown terminator instruction");
166 NumLFENCEsInserted++;
177 return new X86SpeculativeExecutionSideEffectSuppression();
180 INITIALIZE_PASS(X86SpeculativeExecutionSideEffectSuppression,
"x86-seses",
181 "X86 Speculative Execution Side Effect Suppression",
false,
CodeGenOpt::Level getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
This is an optimization pass for GlobalISel generic memory operations.
const X86InstrInfo * getInstrInfo() const override
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
static cl::opt< bool > OnlyLFENCENonConst("x86-seses-only-lfence-non-const", cl::desc("Only lfence before groups of terminators where at least one " "branch instruction has an input to the addressing mode that is a " "register other than %rip."), cl::init(false), cl::Hidden)
static bool hasConstantAddressingMode(const MachineInstr &MI)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
const HexagonInstrInfo * TII
MachineOperand class - Representation of each machine instruction operand.
STATISTIC(NumFunctions, "Total number of functions")
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
FunctionPass * createX86SpeculativeExecutionSideEffectSuppression()
Representation of each machine instruction.
initializer< Ty > init(const Ty &Val)
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static cl::opt< bool > OneLFENCEPerBasicBlock("x86-seses-one-lfence-per-bb", cl::desc("Omit all lfences other than the first to be placed in a basic block."), cl::init(false), cl::Hidden)
static cl::opt< bool > OmitBranchLFENCEs("x86-seses-omit-branch-lfences", cl::desc("Omit all lfences before branch instructions."), cl::init(false), cl::Hidden)
StringRef - Represent a constant reference to a string, i.e.
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
static cl::opt< bool > EnableSpeculativeExecutionSideEffectSuppression("x86-seses-enable-without-lvi-cfi", cl::desc("Force enable speculative execution side effect suppression. " "(Note: User must pass -mlvi-cfi in order to mitigate indirect " "branches and returns.)"), cl::init(false), cl::Hidden)
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
FunctionPass class - This class is used to implement most global optimizations.