63 #define FIXUPBW_DESC "X86 Byte/Word Instruction Fixup" 64 #define FIXUPBW_NAME "x86-fixup-bw-insts" 66 #define DEBUG_TYPE FIXUPBW_NAME 71 cl::desc(
"Change byte and word instructions to larger sizes"),
84 unsigned &SuperDestReg)
const;
155 MLI = &getAnalysis<MachineLoopInfo>();
156 LiveRegs.init(
TII->getRegisterInfo());
162 processBasicBlock(MF, MBB);
174 bool FixupBWInstPass::getSuperRegDestIfDead(
MachineInstr *OrigMI,
175 unsigned &SuperDestReg)
const {
176 auto *
TRI = &
TII->getRegisterInfo();
181 const auto SubRegIdx =
TRI->getSubRegIndex(SuperDestReg, OrigDestReg);
187 if (SubRegIdx == X86::sub_8bit_hi)
192 if (!LiveRegs.contains(SuperDestReg)) {
195 if (SubRegIdx != X86::sub_8bit)
237 unsigned Opc = OrigMI->
getOpcode(); (void)Opc;
241 assert((Opc == X86::MOV8rm || Opc == X86::MOV16rm || Opc == X86::MOV8rr ||
242 Opc == X86::MOV16rr) &&
243 "Unexpected opcode.");
245 bool IsDefined =
false;
250 assert((MO.isDef() || MO.isUse()) &&
"Expected Def or Use only!");
252 if (MO.isDef() &&
TRI->isSuperRegisterEq(OrigDestReg, MO.getReg()))
259 if (MO.isUse() && !
TRI->isSubRegisterEq(OrigDestReg, MO.getReg()) &&
260 TRI->regsOverlap(SuperDestReg, MO.getReg()))
272 MachineInstr *FixupBWInstPass::tryReplaceLoad(
unsigned New32BitOpcode,
280 if (!getSuperRegDestIfDead(MI, NewDestReg))
288 for (
unsigned i = 1; i < NumArgs; ++i)
302 if (!getSuperRegDestIfDead(MI, NewDestReg))
309 auto *
TRI = &
TII->getRegisterInfo();
310 if (TRI->getSubRegIndex(NewSrcReg, OldSrc.getReg()) !=
311 TRI->getSubRegIndex(NewDestReg, OldDest.getReg()))
326 if (
Op.getReg() != (
Op.isDef() ? NewDestReg : NewSrcReg))
342 if (ML->begin() == ML->end() && !OptForSize)
343 return tryReplaceLoad(X86::MOVZX32rm8, MI);
351 return tryReplaceLoad(X86::MOVZX32rm16, MI);
359 return tryReplaceCopy(MI);
388 LiveRegs.addLiveOuts(MBB);
394 MIReplacements.
push_back(std::make_pair(MI, NewMI));
397 LiveRegs.stepBackward(*MI);
400 while (!MIReplacements.
empty()) {
const MachineInstrBuilder & setMemRefs(ArrayRef< MachineMemOperand *> MMOs) const
const MachineInstrBuilder & add(const MachineOperand &MO) const
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
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.
void initializeFixupBWInstPassPass(PassRegistry &)
void push_back(const T &Elt)
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
unsigned getReg() const
getReg - Returns the register number.
unsigned const TargetRegisterInfo * TRI
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
unsigned getNumOperands() const
Retuns the total number of operands.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
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.
Represent the analysis usage information of a pass.
bool optForSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
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.
unsigned getX86SubSuperRegister(unsigned, unsigned, bool High=false)
Returns the sub or super register of a specific X86 register.
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
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef - Represent a constant reference to a string, i.e.
const MachineOperand & getOperand(unsigned i) const
Properties which a MachineFunction may have at a given point in time.