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"),
130 MachineFunctionProperties::Property::NoVRegs);
142 bool OptForSize =
false;
153char FixupBWInstPass::ID = 0;
167 MLI = &getAnalysis<MachineLoopInfo>();
168 PSI = &getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
169 MBFI = (PSI && PSI->hasProfileSummary()) ?
170 &getAnalysis<LazyMachineBlockFrequencyInfoPass>().getBFI() :
172 LiveUnits.init(
TII->getRegisterInfo());
178 processBasicBlock(MF,
MBB);
196 const auto SubRegIdx =
TRI->getSubRegIndex(SuperDestReg, OrigDestReg);
202 if (SubRegIdx == X86::sub_8bit_hi)
208 bool SuperIsLive =
false;
209 auto Range =
TRI->regunits(OrigDestReg);
212 I = std::lower_bound(
I,
E, S);
213 if ((
I ==
E || *
I > S) && LiveUnits.getBitVector().test(S)) {
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()))
286MachineInstr *FixupBWInstPass::tryReplaceLoad(
unsigned New32BitOpcode,
292 Register NewDestReg = getSuperRegDestIfDead(
MI);
300 unsigned NumArgs =
MI->getNumOperands();
301 for (
unsigned i = 1; i < NumArgs; ++i)
302 MIB.
add(
MI->getOperand(i));
307 if (
unsigned OldInstrNum =
MI->peekDebugInstrNum()) {
309 MI->getOperand(0).getReg());
311 MF->makeDebugValueSubstitution({OldInstrNum, 0}, {NewInstrNum, 0}, Subreg);
318 assert(
MI->getNumExplicitOperands() == 2);
319 auto &OldDest =
MI->getOperand(0);
320 auto &OldSrc =
MI->getOperand(1);
322 Register NewDestReg = getSuperRegDestIfDead(
MI);
332 if (
TRI->getSubRegIndex(NewSrcReg, OldSrc.getReg()) !=
333 TRI->getSubRegIndex(NewDestReg, OldDest.getReg()))
347 for (
auto &
Op :
MI->implicit_operands())
348 if (
Op.getReg() != (
Op.isDef() ? NewDestReg : NewSrcReg))
354MachineInstr *FixupBWInstPass::tryReplaceExtend(
unsigned New32BitOpcode,
356 Register NewDestReg = getSuperRegDestIfDead(
MI);
363 if (
MI->getOpcode() == X86::MOVSX16rr8 &&
364 MI->getOperand(0).getReg() == X86::AX &&
365 MI->getOperand(1).getReg() == X86::AL)
372 unsigned NumArgs =
MI->getNumOperands();
373 for (
unsigned i = 1; i < NumArgs; ++i)
374 MIB.
add(
MI->getOperand(i));
378 if (
unsigned OldInstrNum =
MI->peekDebugInstrNum()) {
380 MI->getOperand(0).getReg());
382 MF->makeDebugValueSubstitution({OldInstrNum, 0}, {NewInstrNum, 0}, Subreg);
391 switch (
MI->getOpcode()) {
399 return tryReplaceLoad(X86::MOVZX32rm8,
MI);
407 return tryReplaceLoad(X86::MOVZX32rm16,
MI);
415 return tryReplaceCopy(
MI);
417 case X86::MOVSX16rr8:
418 return tryReplaceExtend(X86::MOVSX32rr8,
MI);
419 case X86::MOVSX16rm8:
420 return tryReplaceExtend(X86::MOVSX32rm8,
MI);
421 case X86::MOVZX16rr8:
422 return tryReplaceExtend(X86::MOVZX32rr8,
MI);
423 case X86::MOVZX16rm8:
424 return tryReplaceExtend(X86::MOVZX32rm8,
MI);
453 LiveUnits.addLiveOuts(
MBB);
460 MIReplacements.
push_back(std::make_pair(&
MI, NewMI));
463 LiveUnits.stepBackward(
MI);
466 while (!MIReplacements.
empty()) {
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const HexagonInstrInfo * TII
===- LazyMachineBlockFrequencyInfo.h - Lazy Block Frequency -*- C++ -*–===//
unsigned const TargetRegisterInfo * TRI
#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...
static cl::opt< bool > FixupBWInsts("fixup-byte-word-insts", cl::desc("Change byte and word instructions to larger sizes"), cl::init(true), cl::Hidden)
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
This class represents an Operation in the Expression.
FunctionPass class - This class is used to implement most global optimizations.
bool hasOptSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
This is an alternative analysis pass to MachineBlockFrequencyInfo.
A set of register units used to track register liveness.
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
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.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
virtual MachineFunctionProperties getRequiredProperties() const
Properties which a MachineFunction may have at a given point in time.
MachineFunctionProperties & set(Property P)
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 & add(const MachineOperand &MO) const
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
iterator_range< mop_iterator > implicit_operands()
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
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
An analysis pass based on legacy pass manager to deliver ProfileSummaryInfo.
Analysis providing profile information.
Wrapper class representing virtual and physical registers.
constexpr bool isValid() const
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ Implicit
Not emitted register (e.g. carry, or temporary result).
@ Undef
Value of the register doesn't matter.
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.
MCRegister getX86SubSuperRegister(MCRegister Reg, unsigned Size, bool High=false)
FunctionPass * createX86FixupBWInsts()
Return a Machine IR pass that selectively replaces certain byte and word instructions by equivalent 3...
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.
auto reverse(ContainerTy &&C)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.