28#define DEBUG_TYPE "x86-seses"
30STATISTIC(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."),
59class X86SpeculativeExecutionSideEffectSuppression
66 return "X86 Speculative Execution Side Effect Suppression";
73char X86SpeculativeExecutionSideEffectSuppression::ID = 0;
83 if (MO.isReg() && X86::RIP != MO.getReg())
88bool X86SpeculativeExecutionSideEffectSuppression::runOnMachineFunction(
98 !(Subtarget.useLVILoadHardening() && OptLevel == CodeGenOptLevel::None) &&
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();
180INITIALIZE_PASS(X86SpeculativeExecutionSideEffectSuppression,
"x86-seses",
181 "X86 Speculative Execution Side Effect Suppression",
false,
const HexagonInstrInfo * TII
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
static cl::opt< bool > OmitBranchLFENCEs("x86-seses-omit-branch-lfences", cl::desc("Omit all lfences before branch instructions."), cl::init(false), cl::Hidden)
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 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 > 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)
static bool hasConstantAddressingMode(const MachineInstr &MI)
FunctionPass class - This class is used to implement most global optimizations.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
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.
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
StringRef - Represent a constant reference to a string, i.e.
CodeGenOptLevel getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
const X86InstrInfo * getInstrInfo() const override
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
initializer< Ty > init(const Ty &Val)
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.
FunctionPass * createX86SpeculativeExecutionSideEffectSuppression()
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.