diff options
Diffstat (limited to 'lib/Target/X86/X86VZeroUpper.cpp')
| -rw-r--r-- | lib/Target/X86/X86VZeroUpper.cpp | 51 |
1 files changed, 33 insertions, 18 deletions
diff --git a/lib/Target/X86/X86VZeroUpper.cpp b/lib/Target/X86/X86VZeroUpper.cpp index d17dfac6a997..224262830b12 100644 --- a/lib/Target/X86/X86VZeroUpper.cpp +++ b/lib/Target/X86/X86VZeroUpper.cpp @@ -1,4 +1,4 @@ -//===-- X86VZeroUpper.cpp - AVX vzeroupper instruction inserter -----------===// +//===- X86VZeroUpper.cpp - AVX vzeroupper instruction inserter ------------===// // // The LLVM Compiler Infrastructure // @@ -17,14 +17,25 @@ #include "X86.h" #include "X86InstrInfo.h" #include "X86Subtarget.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" +#include "llvm/CodeGen/MachineBasicBlock.h" +#include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineFunctionPass.h" +#include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/MachineInstrBuilder.h" +#include "llvm/CodeGen/MachineOperand.h" #include "llvm/CodeGen/MachineRegisterInfo.h" -#include "llvm/CodeGen/Passes.h" +#include "llvm/CodeGen/TargetInstrInfo.h" +#include "llvm/CodeGen/TargetRegisterInfo.h" +#include "llvm/IR/CallingConv.h" +#include "llvm/IR/DebugLoc.h" +#include "llvm/IR/Function.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/Target/TargetInstrInfo.h" +#include <cassert> + using namespace llvm; #define DEBUG_TYPE "x86-vzeroupper" @@ -35,23 +46,25 @@ namespace { class VZeroUpperInserter : public MachineFunctionPass { public: - VZeroUpperInserter() : MachineFunctionPass(ID) {} + bool runOnMachineFunction(MachineFunction &MF) override; + MachineFunctionProperties getRequiredProperties() const override { return MachineFunctionProperties().set( MachineFunctionProperties::Property::NoVRegs); } + StringRef getPassName() const override { return "X86 vzeroupper inserter"; } private: - void processBasicBlock(MachineBasicBlock &MBB); void insertVZeroUpper(MachineBasicBlock::iterator I, MachineBasicBlock &MBB); void addDirtySuccessor(MachineBasicBlock &MBB); - typedef enum { PASS_THROUGH, EXITS_CLEAN, EXITS_DIRTY } BlockExitState; + using BlockExitState = enum { PASS_THROUGH, EXITS_CLEAN, EXITS_DIRTY }; + static const char* getBlockExitStateName(BlockExitState ST); // Core algorithm state: @@ -73,13 +86,15 @@ namespace { // to be guarded until we discover a predecessor that // is DIRTY_OUT. struct BlockState { - BlockState() : ExitState(PASS_THROUGH), AddedToDirtySuccessors(false) {} - BlockExitState ExitState; - bool AddedToDirtySuccessors; + BlockExitState ExitState = PASS_THROUGH; + bool AddedToDirtySuccessors = false; MachineBasicBlock::iterator FirstUnguardedCall; + + BlockState() = default; }; - typedef SmallVector<BlockState, 8> BlockStateMap; - typedef SmallVector<MachineBasicBlock*, 8> DirtySuccessorsWorkList; + + using BlockStateMap = SmallVector<BlockState, 8>; + using DirtySuccessorsWorkList = SmallVector<MachineBasicBlock *, 8>; BlockStateMap BlockStates; DirtySuccessorsWorkList DirtySuccessors; @@ -90,8 +105,9 @@ namespace { static char ID; }; - char VZeroUpperInserter::ID = 0; -} +} // end anonymous namespace + +char VZeroUpperInserter::ID = 0; FunctionPass *llvm::createX86IssueVZeroUpperPass() { return new VZeroUpperInserter(); @@ -116,9 +132,8 @@ static bool isYmmOrZmmReg(unsigned Reg) { } static bool checkFnHasLiveInYmmOrZmm(MachineRegisterInfo &MRI) { - for (MachineRegisterInfo::livein_iterator I = MRI.livein_begin(), - E = MRI.livein_end(); I != E; ++I) - if (isYmmOrZmmReg(I->first)) + for (std::pair<unsigned, unsigned> LI : MRI.liveins()) + if (isYmmOrZmmReg(LI.first)) return true; return false; @@ -220,7 +235,7 @@ void VZeroUpperInserter::processBasicBlock(MachineBasicBlock &MBB) { // If the call has no RegMask, skip it as well. It usually happens on // helper function calls (such as '_chkstk', '_ftol2') where standard // calling convention is not used (RegMask is not used to mark register - // clobbered and register usage (def/imp-def/use) is well-defined and + // clobbered and register usage (def/implicit-def/use) is well-defined and // explicitly specified. if (IsCall && !callHasRegMask(MI)) continue; @@ -270,7 +285,7 @@ bool VZeroUpperInserter::runOnMachineFunction(MachineFunction &MF) { TII = ST.getInstrInfo(); MachineRegisterInfo &MRI = MF.getRegInfo(); EverMadeChange = false; - IsX86INTR = MF.getFunction()->getCallingConv() == CallingConv::X86_INTR; + IsX86INTR = MF.getFunction().getCallingConv() == CallingConv::X86_INTR; bool FnHasLiveInYmmOrZmm = checkFnHasLiveInYmmOrZmm(MRI); |
