65 #define FIXUPBW_DESC "X86 Byte/Word Instruction Fixup" 66 #define FIXUPBW_NAME "x86-fixup-bw-insts" 68 #define DEBUG_TYPE FIXUPBW_NAME 73 cl::desc(
"Change byte and word instructions to larger sizes"),
141 bool OptForSize =
false;
165 MLI = &getAnalysis<MachineLoopInfo>();
166 PSI = &getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
167 MBFI = (PSI && PSI->hasProfileSummary()) ?
168 &getAnalysis<LazyMachineBlockFrequencyInfoPass>().getBFI() :
170 LiveRegs.init(
TII->getRegisterInfo());
176 processBasicBlock(MF, MBB);
188 bool FixupBWInstPass::getSuperRegDestIfDead(
MachineInstr *OrigMI,
190 auto *
TRI = &
TII->getRegisterInfo();
195 const auto SubRegIdx =
TRI->getSubRegIndex(SuperDestReg, OrigDestReg);
201 if (SubRegIdx == X86::sub_8bit_hi)
206 if (!LiveRegs.contains(SuperDestReg)) {
209 if (SubRegIdx != X86::sub_8bit)
251 unsigned Opc = OrigMI->
getOpcode(); (void)Opc;
255 if (Opc != X86::MOV8rm && Opc != X86::MOV16rm && Opc != X86::MOV8rr &&
259 bool IsDefined =
false;
264 assert((MO.isDef() || MO.isUse()) &&
"Expected Def or Use only!");
266 if (MO.isDef() &&
TRI->isSuperRegisterEq(OrigDestReg, MO.getReg()))
273 if (MO.isUse() && !
TRI->isSubRegisterEq(OrigDestReg, MO.getReg()) &&
274 TRI->regsOverlap(SuperDestReg, MO.getReg()))
286 MachineInstr *FixupBWInstPass::tryReplaceLoad(
unsigned New32BitOpcode,
294 if (!getSuperRegDestIfDead(MI, NewDestReg))
302 for (
unsigned i = 1; i < NumArgs; ++i)
316 if (!getSuperRegDestIfDead(MI, NewDestReg))
323 auto *
TRI = &
TII->getRegisterInfo();
324 if (TRI->getSubRegIndex(NewSrcReg, OldSrc.getReg()) !=
325 TRI->getSubRegIndex(NewDestReg, OldDest.getReg()))
340 if (
Op.getReg() != (
Op.isDef() ? NewDestReg : NewSrcReg))
346 MachineInstr *FixupBWInstPass::tryReplaceExtend(
unsigned New32BitOpcode,
349 if (!getSuperRegDestIfDead(MI, NewDestReg))
355 if (MI->
getOpcode() == X86::MOVSX16rr8 &&
365 for (
unsigned i = 1; i < NumArgs; ++i)
383 if (ML->begin() == ML->end() && !OptForSize)
384 return tryReplaceLoad(X86::MOVZX32rm8, MI);
392 return tryReplaceLoad(X86::MOVZX32rm16, MI);
400 return tryReplaceCopy(MI);
402 case X86::MOVSX16rr8:
403 return tryReplaceExtend(X86::MOVSX32rr8, MI);
404 case X86::MOVSX16rm8:
405 return tryReplaceExtend(X86::MOVSX32rm8, MI);
406 case X86::MOVZX16rr8:
407 return tryReplaceExtend(X86::MOVZX32rr8, MI);
408 case X86::MOVZX16rm8:
409 return tryReplaceExtend(X86::MOVZX32rm8, MI);
438 LiveRegs.addLiveOuts(MBB);
447 MIReplacements.
push_back(std::make_pair(MI, NewMI));
450 LiveRegs.stepBackward(*MI);
453 while (!MIReplacements.
empty()) {
const MachineInstrBuilder & setMemRefs(ArrayRef< MachineMemOperand *> MMOs) const
const MachineInstrBuilder & add(const MachineOperand &MO) const
FunctionPass * createX86FixupBWInsts()
Return a Machine IR pass that selectively replaces certain byte and word instructions by equivalent 3...
This class represents lattice values for constants.
bool hasOptSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
void push_back(const T &Elt)
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
Analysis providing profile information.
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
unsigned const TargetRegisterInfo * TRI
MCRegister getX86SubSuperRegister(MCRegister, unsigned, bool High=false)
Returns the sub or super register of a specific X86 register.
AnalysisUsage & addRequired()
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
An analysis pass based on legacy pass manager to deliver ProfileSummaryInfo.
unsigned getNumOperands() const
Retuns the total number of operands.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
===- LazyMachineBlockFrequencyInfo.h - Lazy Block Frequency -*- C++ -*–===//
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
reverse_iterator rbegin()
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
initializer< Ty > init(const Ty &Val)
ArrayRef< MachineMemOperand * > memoperands() const
Access to memory operands of the instruction.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
This is an alternative analysis pass to MachineBlockFrequencyInfo.
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
unsigned getNumExplicitOperands() const
Returns the number of non-implicit operands.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
static cl::opt< bool > FixupBWInsts("fixup-byte-word-insts", cl::desc("Change byte and word instructions to larger sizes"), cl::init(true), cl::Hidden)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
const Function & getFunction() const
Return the LLVM function that this machine code represents.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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...
iterator_range< mop_iterator > implicit_operands()
MachineFunctionProperties & set(Property P)
Representation of each machine instruction.
A set of physical registers with utility functions to track liveness when walking backward/forward th...
LLVM_NODISCARD bool empty() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef - Represent a constant reference to a string, i.e.
Register getReg() const
getReg - Returns the register number.
const MachineOperand & getOperand(unsigned i) const
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Properties which a MachineFunction may have at a given point in time.
Wrapper class representing virtual and physical registers.