65#define FIXUPBW_DESC "X86 Byte/Word Instruction Fixup"
66#define FIXUPBW_NAME "x86-fixup-bw-insts"
68#define DEBUG_TYPE FIXUPBW_NAME
71class X86FixupBWInstImpl {
74 : PSI(PSI), MBFI(MBFI) {}
116 bool OptForSize =
false;
149char X86FixupBWInstLegacy::ID = 0;
156 return new X86FixupBWInstLegacy();
161 if (!ST.getCLOpts().fixup_byte_word_insts)
165 TII = ST.getInstrInfo();
167 LiveUnits.
init(
TII->getRegisterInfo());
185Register X86FixupBWInstImpl::getSuperRegDestIfDead(MachineInstr *OrigMI)
const {
191 const auto SubRegIdx =
TRI->getSubRegIndex(SuperDestReg, OrigDestReg);
197 if (SubRegIdx == X86::sub_8bit_hi)
203 bool SuperIsLive =
false;
204 auto Range =
TRI->regunits(OrigDestReg);
206 for (MCRegUnit S :
TRI->regunits(SuperDestReg)) {
207 I = std::lower_bound(
I,
E, S);
208 if ((
I ==
E || *
I > S) &&
251 if (
Opc != X86::MOV8rm &&
Opc != X86::MOV16rm &&
Opc != X86::MOV8rr &&
255 bool IsDefined =
false;
260 if (MO.isDef() &&
TRI->isSuperRegisterEq(OrigDestReg, MO.getReg()))
267 if (MO.isUse() && !
TRI->isSubRegisterEq(OrigDestReg, MO.getReg()) &&
268 TRI->regsOverlap(SuperDestReg, MO.getReg()))
280MachineInstr *X86FixupBWInstImpl::tryReplaceLoad(
unsigned New32BitOpcode,
281 MachineInstr *
MI)
const {
286 Register NewDestReg = getSuperRegDestIfDead(
MI);
291 MachineInstrBuilder MIB =
292 BuildMI(*MF, MIMetadata(*
MI),
TII->get(New32BitOpcode), NewDestReg);
294 unsigned NumArgs =
MI->getNumOperands();
295 for (
unsigned i = 1; i < NumArgs; ++i)
296 MIB.
add(
MI->getOperand(i));
301 if (
unsigned OldInstrNum =
MI->peekDebugInstrNum()) {
303 MI->getOperand(0).getReg());
305 MF->makeDebugValueSubstitution({OldInstrNum, 0}, {NewInstrNum, 0}, Subreg);
311MachineInstr *X86FixupBWInstImpl::tryReplaceCopy(MachineInstr *
MI)
const {
312 assert(
MI->getNumExplicitOperands() == 2);
313 auto &OldDest =
MI->getOperand(0);
314 auto &OldSrc =
MI->getOperand(1);
316 Register NewDestReg = getSuperRegDestIfDead(
MI);
326 if (
TRI->getSubRegIndex(NewSrcReg, OldSrc.getReg()) !=
327 TRI->getSubRegIndex(NewDestReg, OldDest.getReg()))
335 MachineInstrBuilder MIB =
336 BuildMI(*MF, MIMetadata(*
MI),
TII->get(X86::MOV32rr), NewDestReg)
337 .
addReg(NewSrcReg, RegState::Undef)
338 .
addReg(OldSrc.getReg(), RegState::Implicit);
341 for (
auto &
Op :
MI->implicit_operands())
342 if (
Op.getReg() != (
Op.isDef() ? NewDestReg : NewSrcReg))
348MachineInstr *X86FixupBWInstImpl::tryReplaceExtend(
unsigned New32BitOpcode,
349 MachineInstr *
MI)
const {
350 Register NewDestReg = getSuperRegDestIfDead(
MI);
357 if (
MI->getOpcode() == X86::MOVSX16rr8 &&
358 MI->getOperand(0).getReg() == X86::AX &&
359 MI->getOperand(1).getReg() == X86::AL)
363 MachineInstrBuilder MIB =
364 BuildMI(*MF, MIMetadata(*
MI),
TII->get(New32BitOpcode), NewDestReg);
366 unsigned NumArgs =
MI->getNumOperands();
367 for (
unsigned i = 1; i < NumArgs; ++i)
368 MIB.
add(
MI->getOperand(i));
372 if (
unsigned OldInstrNum =
MI->peekDebugInstrNum()) {
374 MI->getOperand(0).getReg());
376 MF->makeDebugValueSubstitution({OldInstrNum, 0}, {NewInstrNum, 0}, Subreg);
383X86FixupBWInstImpl::tryReplaceInstr(MachineInstr *
MI,
384 MachineBasicBlock &
MBB)
const {
386 switch (
MI->getOpcode()) {
394 return tryReplaceLoad(X86::MOVZX32rm8,
MI);
402 return tryReplaceLoad(X86::MOVZX32rm16,
MI);
410 return tryReplaceCopy(
MI);
412 case X86::MOVSX16rr8:
413 return tryReplaceExtend(X86::MOVSX32rr8,
MI);
414 case X86::MOVSX16rm8:
415 return tryReplaceExtend(X86::MOVSX32rm8,
MI);
416 case X86::MOVZX16rr8:
417 return tryReplaceExtend(X86::MOVZX32rr8,
MI);
418 case X86::MOVZX16rm8:
419 return tryReplaceExtend(X86::MOVZX32rm8,
MI);
430 MachineBasicBlock &
MBB) {
453 if (MachineInstr *NewMI = tryReplaceInstr(&
MI,
MBB))
454 MIReplacements.
push_back(std::make_pair(&
MI, NewMI));
457 if (!
MI.isDebugInstr())
461 while (!MIReplacements.
empty()) {
462 MachineInstr *
MI = MIReplacements.
back().first;
463 MachineInstr *NewMI = MIReplacements.
back().second;
473 ProfileSummaryInfo *PSI =
474 &getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
475 MachineBlockFrequencyInfo *MBFI =
477 ? &getAnalysis<LazyMachineBlockFrequencyInfoPass>().getBFI()
479 X86FixupBWInstImpl Impl(PSI, MBFI);
480 return Impl.runOnMachineFunction(MF);
488 .getCachedResult<ProfileSummaryAnalysis>(
493 X86FixupBWInstImpl Impl(PSI, MBFI);
494 bool Changed = Impl.runOnMachineFunction(MF);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const HexagonInstrInfo * TII
===- LazyMachineBlockFrequencyInfo.h - Lazy Block Frequency -*- C++ -*–===//
Register const TargetRegisterInfo * TRI
Promote Memory to Register
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
#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...
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 functi...
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
bool test(unsigned Idx) const
Returns true if bit Idx is set.
Represents analyses that only rely on functions' control flow.
FunctionPass class - This class is used to implement most global optimizations.
Module * getParent()
Get the module that this global value is contained inside of...
const HexagonRegisterInfo & getRegisterInfo() const
This is an alternative analysis pass to MachineBlockFrequencyInfo.
A set of register units used to track register liveness.
const BitVector & getBitVector() const
Return the internal bitvector representation of the set.
void init(const TargetRegisterInfo &TRI)
Initialize and clear the set.
LLVM_ABI void stepBackward(const MachineInstr &MI)
Updates liveness when stepping backwards over the instruction MI.
LLVM_ABI void addLiveOuts(const MachineBasicBlock &MBB)
Adds registers living out of block MBB.
void clear()
Clears the set.
LLVM_ABI instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
LLVM_ABI instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Properties which a MachineFunction may have at a given point in time.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineInstrBuilder & setMemRefs(ArrayRef< MachineMemOperand * > MMOs) const
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & add(const MachineOperand &MO) const
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
mop_range implicit_operands()
LLVM_ABI unsigned getDebugInstrNum()
Fetch the instruction number of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
Register getReg() const
getReg - Returns the register number.
const TargetRegisterInfo * getTargetRegisterInfo() const
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
An analysis pass based on legacy pass manager to deliver ProfileSummaryInfo.
Analysis providing profile information.
bool hasProfileSummary() const
Returns true if profile summary is available.
Wrapper class representing virtual and physical registers.
constexpr bool isValid() const
void push_back(const T &Elt)
Represent a constant reference to a string, i.e.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
This is an optimization pass for GlobalISel generic memory operations.
OuterAnalysisManagerProxy< ModuleAnalysisManager, MachineFunction > ModuleAnalysisManagerMachineFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
MCRegister getX86SubSuperRegister(MCRegister Reg, unsigned Size, bool High=false)
LLVM_ABI bool shouldOptimizeForSize(const MachineFunction *MF, ProfileSummaryInfo *PSI, const MachineBlockFrequencyInfo *BFI, PGSOQueryType QueryType=PGSOQueryType::Other)
Returns true if machine function MF is suggested to be size-optimized based on the profile.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
auto reverse(ContainerTy &&C)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
FunctionPass * createX86FixupBWInstsLegacyPass()
DWARFExpression::Operation Op