LLVM 23.0.0git
X86InsertVZeroUpper.cpp File Reference

This file defines the pass which inserts x86 AVX vzeroupper instructions before calls to SSE encoded functions. More...

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "x86-insert-vzeroupper"

Functions

 STATISTIC (NumVZU, "Number of vzeroupper instructions inserted")
static const chargetBlockExitStateName (BlockExitState ST)
static bool isYmmOrZmmReg (MCRegister Reg)
 VZEROUPPER cleans state that is related to Y/ZMM0-15 only.
static bool checkFnHasLiveInYmmOrZmm (MachineRegisterInfo &MRI)
static bool clobbersAllYmmAndZmmRegs (const MachineOperand &MO)
static bool hasYmmOrZmmReg (MachineInstr &MI)
static bool callHasRegMask (MachineInstr &MI)
 Check if given call instruction has a RegMask operand.
static bool insertVZeroUpper (MachineBasicBlock::iterator I, MachineBasicBlock &MBB, const TargetInstrInfo *TII)
 Insert a vzeroupper instruction before I.
static void addDirtySuccessor (MachineBasicBlock &MBB, BlockStateMap &BlockStates, DirtySuccessorsWorkList &DirtySuccessors)
 Add MBB to the DirtySuccessors list if it hasn't already been added.
static bool processBasicBlock (MachineBasicBlock &MBB, BlockStateMap &BlockStates, DirtySuccessorsWorkList &DirtySuccessors, bool IsX86INTR, const TargetInstrInfo *TII)
 Loop over all of the instructions in the basic block, inserting vzeroupper instructions before function calls.
static bool insertVZeroUpper (MachineFunction &MF)
 Loop over all of the basic blocks, inserting vzeroupper instructions before function calls.

Variables

static cl::opt< boolUseVZeroUpper ("x86-use-vzeroupper", cl::Hidden, cl::desc("Minimize AVX to SSE transition penalty"), cl::init(true))

Detailed Description

This file defines the pass which inserts x86 AVX vzeroupper instructions before calls to SSE encoded functions.

This avoids transition latency penalty when transferring control between AVX encoded instructions and old SSE encoding mode.

Definition in file X86InsertVZeroUpper.cpp.

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "x86-insert-vzeroupper"

Definition at line 43 of file X86InsertVZeroUpper.cpp.

Function Documentation

◆ addDirtySuccessor()

void addDirtySuccessor ( MachineBasicBlock & MBB,
BlockStateMap & BlockStates,
DirtySuccessorsWorkList & DirtySuccessors )
static

Add MBB to the DirtySuccessors list if it hasn't already been added.

Definition at line 181 of file X86InsertVZeroUpper.cpp.

References MBB.

Referenced by insertVZeroUpper(), and processBasicBlock().

◆ callHasRegMask()

bool callHasRegMask ( MachineInstr & MI)
static

Check if given call instruction has a RegMask operand.

Definition at line 162 of file X86InsertVZeroUpper.cpp.

References assert(), and MI.

Referenced by processBasicBlock().

◆ checkFnHasLiveInYmmOrZmm()

bool checkFnHasLiveInYmmOrZmm ( MachineRegisterInfo & MRI)
static

Definition at line 127 of file X86InsertVZeroUpper.cpp.

References isYmmOrZmmReg(), and llvm::MachineRegisterInfo::liveins().

Referenced by insertVZeroUpper().

◆ clobbersAllYmmAndZmmRegs()

bool clobbersAllYmmAndZmmRegs ( const MachineOperand & MO)
static

Definition at line 135 of file X86InsertVZeroUpper.cpp.

References llvm::MachineOperand::clobbersPhysReg().

Referenced by hasYmmOrZmmReg().

◆ getBlockExitStateName()

const char * getBlockExitStateName ( BlockExitState ST)
static

Definition at line 107 of file X86InsertVZeroUpper.cpp.

References llvm_unreachable.

Referenced by processBasicBlock().

◆ hasYmmOrZmmReg()

bool hasYmmOrZmmReg ( MachineInstr & MI)
static

Definition at line 147 of file X86InsertVZeroUpper.cpp.

References clobbersAllYmmAndZmmRegs(), isYmmOrZmmReg(), and MI.

Referenced by processBasicBlock().

◆ insertVZeroUpper() [1/2]

bool insertVZeroUpper ( MachineBasicBlock::iterator I,
MachineBasicBlock & MBB,
const TargetInstrInfo * TII )
static

Insert a vzeroupper instruction before I.

Definition at line 172 of file X86InsertVZeroUpper.cpp.

References llvm::BuildMI(), I, MBB, and TII.

Referenced by insertVZeroUpper(), processBasicBlock(), and llvm::X86InsertVZeroUpperPass::run().

◆ insertVZeroUpper() [2/2]

◆ isYmmOrZmmReg()

bool isYmmOrZmmReg ( MCRegister Reg)
static

VZEROUPPER cleans state that is related to Y/ZMM0-15 only.

Thus, there is no need to check for Y/ZMM16 and above.

Definition at line 122 of file X86InsertVZeroUpper.cpp.

References Reg.

Referenced by checkFnHasLiveInYmmOrZmm(), and hasYmmOrZmmReg().

◆ processBasicBlock()

bool processBasicBlock ( MachineBasicBlock & MBB,
BlockStateMap & BlockStates,
DirtySuccessorsWorkList & DirtySuccessors,
bool IsX86INTR,
const TargetInstrInfo * TII )
static

Loop over all of the instructions in the basic block, inserting vzeroupper instructions before function calls.

Definition at line 192 of file X86InsertVZeroUpper.cpp.

References addDirtySuccessor(), callHasRegMask(), llvm::dbgs(), getBlockExitStateName(), hasYmmOrZmmReg(), insertVZeroUpper(), LLVM_DEBUG, MBB, MI, and TII.

Referenced by insertVZeroUpper().

◆ STATISTIC()

STATISTIC ( NumVZU ,
"Number of vzeroupper instructions inserted"  )

Variable Documentation

◆ UseVZeroUpper

cl::opt< bool > UseVZeroUpper("x86-use-vzeroupper", cl::Hidden, cl::desc("Minimize AVX to SSE transition penalty"), cl::init(true)) ( "x86-use-vzeroupper" ,
cl::Hidden ,
cl::desc("Minimize AVX to SSE transition penalty") ,
cl::init(true)  )
static

Referenced by insertVZeroUpper().