1 //===-- X86InstrInfo.h - X86 Instruction Information ------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the X86 implementation of the TargetInstrInfo class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_X86_X86INSTRINFO_H
15 #define LLVM_LIB_TARGET_X86_X86INSTRINFO_H
17 #include "MCTargetDesc/X86BaseInfo.h"
18 #include "X86InstrFMA3Info.h"
19 #include "X86RegisterInfo.h"
20 #include "llvm/CodeGen/ISDOpcodes.h"
21 #include "llvm/CodeGen/TargetInstrInfo.h"
24 #define GET_INSTRINFO_HEADER
25 #include "X86GenInstrInfo.inc"
28 class MachineInstrBuilder
;
29 class X86RegisterInfo
;
35 // For instr that was compressed from EVEX to VEX.
36 AC_EVEX_2_VEX
= MachineInstr::TAsmComments
39 // X86 specific condition code. These correspond to X86_*_COND in
40 // X86InstrInfo.td. They must be kept in synch.
58 LAST_VALID_COND
= COND_S
,
60 // Artificial condition codes. These are used by AnalyzeBranch
61 // to indicate a block terminated with two conditional branches that together
62 // form a compound condition. They occur in code using FCMP_OEQ or FCMP_UNE,
63 // which can't be represented on x86 with a single condition. These
64 // are never used in MachineInstrs and are inverses of one another.
71 // Turn condition code into conditional branch opcode.
72 unsigned GetCondBranchFromCond(CondCode CC
);
74 /// Return a pair of condition code for the given predicate and whether
75 /// the instruction operands should be swaped to match the condition code.
76 std::pair
<CondCode
, bool> getX86ConditionCode(CmpInst::Predicate Predicate
);
78 /// Return a set opcode for the given condition and whether it has
80 unsigned getSETFromCond(CondCode CC
, bool HasMemoryOperand
= false);
82 /// Return a cmov opcode for the given condition, register size in
83 /// bytes, and operand type.
84 unsigned getCMovFromCond(CondCode CC
, unsigned RegBytes
,
85 bool HasMemoryOperand
= false);
87 // Turn jCC opcode into condition code.
88 CondCode
getCondFromBranchOpc(unsigned Opc
);
90 // Turn setCC opcode into condition code.
91 CondCode
getCondFromSETOpc(unsigned Opc
);
93 // Turn CMov opcode into condition code.
94 CondCode
getCondFromCMovOpc(unsigned Opc
);
96 /// GetOppositeBranchCondition - Return the inverse of the specified cond,
97 /// e.g. turning COND_E to COND_NE.
98 CondCode
GetOppositeBranchCondition(CondCode CC
);
100 /// Get the VPCMP immediate for the given condition.
101 unsigned getVPCMPImmForCond(ISD::CondCode CC
);
103 /// Get the VPCMP immediate if the opcodes are swapped.
104 unsigned getSwappedVPCMPImm(unsigned Imm
);
106 /// Get the VPCOM immediate if the opcodes are swapped.
107 unsigned getSwappedVPCOMImm(unsigned Imm
);
111 /// isGlobalStubReference - Return true if the specified TargetFlag operand is
112 /// a reference to a stub for a global, not the global itself.
113 inline static bool isGlobalStubReference(unsigned char TargetFlag
) {
114 switch (TargetFlag
) {
115 case X86II::MO_DLLIMPORT
: // dllimport stub.
116 case X86II::MO_GOTPCREL
: // rip-relative GOT reference.
117 case X86II::MO_GOT
: // normal GOT reference.
118 case X86II::MO_DARWIN_NONLAZY_PIC_BASE
: // Normal $non_lazy_ptr ref.
119 case X86II::MO_DARWIN_NONLAZY
: // Normal $non_lazy_ptr ref.
120 case X86II::MO_COFFSTUB
: // COFF .refptr stub.
127 /// isGlobalRelativeToPICBase - Return true if the specified global value
128 /// reference is relative to a 32-bit PIC base (X86ISD::GlobalBaseReg). If this
129 /// is true, the addressing mode has the PIC base register added in (e.g. EBX).
130 inline static bool isGlobalRelativeToPICBase(unsigned char TargetFlag
) {
131 switch (TargetFlag
) {
132 case X86II::MO_GOTOFF
: // isPICStyleGOT: local global.
133 case X86II::MO_GOT
: // isPICStyleGOT: other global.
134 case X86II::MO_PIC_BASE_OFFSET
: // Darwin local global.
135 case X86II::MO_DARWIN_NONLAZY_PIC_BASE
: // Darwin/32 external global.
136 case X86II::MO_TLVP
: // ??? Pretty sure..
143 inline static bool isScale(const MachineOperand
&MO
) {
144 return MO
.isImm() && (MO
.getImm() == 1 || MO
.getImm() == 2 ||
145 MO
.getImm() == 4 || MO
.getImm() == 8);
148 inline static bool isLeaMem(const MachineInstr
&MI
, unsigned Op
) {
149 if (MI
.getOperand(Op
).isFI())
151 return Op
+ X86::AddrSegmentReg
<= MI
.getNumOperands() &&
152 MI
.getOperand(Op
+ X86::AddrBaseReg
).isReg() &&
153 isScale(MI
.getOperand(Op
+ X86::AddrScaleAmt
)) &&
154 MI
.getOperand(Op
+ X86::AddrIndexReg
).isReg() &&
155 (MI
.getOperand(Op
+ X86::AddrDisp
).isImm() ||
156 MI
.getOperand(Op
+ X86::AddrDisp
).isGlobal() ||
157 MI
.getOperand(Op
+ X86::AddrDisp
).isCPI() ||
158 MI
.getOperand(Op
+ X86::AddrDisp
).isJTI());
161 inline static bool isMem(const MachineInstr
&MI
, unsigned Op
) {
162 if (MI
.getOperand(Op
).isFI())
164 return Op
+ X86::AddrNumOperands
<= MI
.getNumOperands() &&
165 MI
.getOperand(Op
+ X86::AddrSegmentReg
).isReg() && isLeaMem(MI
, Op
);
168 class X86InstrInfo final
: public X86GenInstrInfo
{
169 X86Subtarget
&Subtarget
;
170 const X86RegisterInfo RI
;
172 virtual void anchor();
174 bool AnalyzeBranchImpl(MachineBasicBlock
&MBB
, MachineBasicBlock
*&TBB
,
175 MachineBasicBlock
*&FBB
,
176 SmallVectorImpl
<MachineOperand
> &Cond
,
177 SmallVectorImpl
<MachineInstr
*> &CondBranches
,
178 bool AllowModify
) const;
181 explicit X86InstrInfo(X86Subtarget
&STI
);
183 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
184 /// such, whenever a client has an instance of instruction info, it should
185 /// always be able to get register info as well (through this method).
187 const X86RegisterInfo
&getRegisterInfo() const { return RI
; }
189 /// Returns the stack pointer adjustment that happens inside the frame
190 /// setup..destroy sequence (e.g. by pushes, or inside the callee).
191 int64_t getFrameAdjustment(const MachineInstr
&I
) const {
192 assert(isFrameInstr(I
));
194 return I
.getOperand(2).getImm();
195 return I
.getOperand(1).getImm();
198 /// Sets the stack pointer adjustment made inside the frame made up by this
200 void setFrameAdjustment(MachineInstr
&I
, int64_t V
) const {
201 assert(isFrameInstr(I
));
203 I
.getOperand(2).setImm(V
);
205 I
.getOperand(1).setImm(V
);
208 /// getSPAdjust - This returns the stack pointer adjustment made by
209 /// this instruction. For x86, we need to handle more complex call
210 /// sequences involving PUSHes.
211 int getSPAdjust(const MachineInstr
&MI
) const override
;
213 /// isCoalescableExtInstr - Return true if the instruction is a "coalescable"
214 /// extension instruction. That is, it's like a copy where it's legal for the
215 /// source to overlap the destination. e.g. X86::MOVSX64rr32. If this returns
216 /// true, then it's expected the pre-extension value is available as a subreg
217 /// of the result register. This also returns the sub-register index in
219 bool isCoalescableExtInstr(const MachineInstr
&MI
, unsigned &SrcReg
,
220 unsigned &DstReg
, unsigned &SubIdx
) const override
;
222 unsigned isLoadFromStackSlot(const MachineInstr
&MI
,
223 int &FrameIndex
) const override
;
224 unsigned isLoadFromStackSlot(const MachineInstr
&MI
,
226 unsigned &MemBytes
) const override
;
227 /// isLoadFromStackSlotPostFE - Check for post-frame ptr elimination
228 /// stack locations as well. This uses a heuristic so it isn't
229 /// reliable for correctness.
230 unsigned isLoadFromStackSlotPostFE(const MachineInstr
&MI
,
231 int &FrameIndex
) const override
;
233 unsigned isStoreToStackSlot(const MachineInstr
&MI
,
234 int &FrameIndex
) const override
;
235 unsigned isStoreToStackSlot(const MachineInstr
&MI
,
237 unsigned &MemBytes
) const override
;
238 /// isStoreToStackSlotPostFE - Check for post-frame ptr elimination
239 /// stack locations as well. This uses a heuristic so it isn't
240 /// reliable for correctness.
241 unsigned isStoreToStackSlotPostFE(const MachineInstr
&MI
,
242 int &FrameIndex
) const override
;
244 bool isReallyTriviallyReMaterializable(const MachineInstr
&MI
,
245 AliasAnalysis
*AA
) const override
;
246 void reMaterialize(MachineBasicBlock
&MBB
, MachineBasicBlock::iterator MI
,
247 unsigned DestReg
, unsigned SubIdx
,
248 const MachineInstr
&Orig
,
249 const TargetRegisterInfo
&TRI
) const override
;
251 /// Given an operand within a MachineInstr, insert preceding code to put it
252 /// into the right format for a particular kind of LEA instruction. This may
253 /// involve using an appropriate super-register instead (with an implicit use
254 /// of the original) or creating a new virtual register and inserting COPY
255 /// instructions to get the data into the right class.
257 /// Reference parameters are set to indicate how caller should add this
258 /// operand to the LEA instruction.
259 bool classifyLEAReg(MachineInstr
&MI
, const MachineOperand
&Src
,
260 unsigned LEAOpcode
, bool AllowSP
, unsigned &NewSrc
,
261 bool &isKill
, bool &isUndef
, MachineOperand
&ImplicitOp
,
262 LiveVariables
*LV
) const;
264 /// convertToThreeAddress - This method must be implemented by targets that
265 /// set the M_CONVERTIBLE_TO_3_ADDR flag. When this flag is set, the target
266 /// may be able to convert a two-address instruction into a true
267 /// three-address instruction on demand. This allows the X86 target (for
268 /// example) to convert ADD and SHL instructions into LEA instructions if they
269 /// would require register copies due to two-addressness.
271 /// This method returns a null pointer if the transformation cannot be
272 /// performed, otherwise it returns the new instruction.
274 MachineInstr
*convertToThreeAddress(MachineFunction::iterator
&MFI
,
276 LiveVariables
*LV
) const override
;
278 /// Returns true iff the routine could find two commutable operands in the
279 /// given machine instruction.
280 /// The 'SrcOpIdx1' and 'SrcOpIdx2' are INPUT and OUTPUT arguments. Their
281 /// input values can be re-defined in this method only if the input values
282 /// are not pre-defined, which is designated by the special value
283 /// 'CommuteAnyOperandIndex' assigned to it.
284 /// If both of indices are pre-defined and refer to some operands, then the
285 /// method simply returns true if the corresponding operands are commutable
286 /// and returns false otherwise.
288 /// For example, calling this method this way:
289 /// unsigned Op1 = 1, Op2 = CommuteAnyOperandIndex;
290 /// findCommutedOpIndices(MI, Op1, Op2);
291 /// can be interpreted as a query asking to find an operand that would be
292 /// commutable with the operand#1.
293 bool findCommutedOpIndices(MachineInstr
&MI
, unsigned &SrcOpIdx1
,
294 unsigned &SrcOpIdx2
) const override
;
296 /// Returns an adjusted FMA opcode that must be used in FMA instruction that
297 /// performs the same computations as the given \p MI but which has the
298 /// operands \p SrcOpIdx1 and \p SrcOpIdx2 commuted.
299 /// It may return 0 if it is unsafe to commute the operands.
300 /// Note that a machine instruction (instead of its opcode) is passed as the
301 /// first parameter to make it possible to analyze the instruction's uses and
302 /// commute the first operand of FMA even when it seems unsafe when you look
303 /// at the opcode. For example, it is Ok to commute the first operand of
304 /// VFMADD*SD_Int, if ONLY the lowest 64-bit element of the result is used.
306 /// The returned FMA opcode may differ from the opcode in the given \p MI.
307 /// For example, commuting the operands #1 and #3 in the following FMA
308 /// FMA213 #1, #2, #3
309 /// results into instruction with adjusted opcode:
310 /// FMA231 #3, #2, #1
312 getFMA3OpcodeToCommuteOperands(const MachineInstr
&MI
, unsigned SrcOpIdx1
,
314 const X86InstrFMA3Group
&FMA3Group
) const;
317 bool isUnpredicatedTerminator(const MachineInstr
&MI
) const override
;
318 bool isUnconditionalTailCall(const MachineInstr
&MI
) const override
;
319 bool canMakeTailCallConditional(SmallVectorImpl
<MachineOperand
> &Cond
,
320 const MachineInstr
&TailCall
) const override
;
321 void replaceBranchWithTailCall(MachineBasicBlock
&MBB
,
322 SmallVectorImpl
<MachineOperand
> &Cond
,
323 const MachineInstr
&TailCall
) const override
;
325 bool analyzeBranch(MachineBasicBlock
&MBB
, MachineBasicBlock
*&TBB
,
326 MachineBasicBlock
*&FBB
,
327 SmallVectorImpl
<MachineOperand
> &Cond
,
328 bool AllowModify
) const override
;
330 bool getMemOpBaseRegImmOfs(MachineInstr
&LdSt
, unsigned &BaseReg
,
332 const TargetRegisterInfo
*TRI
) const override
;
333 bool analyzeBranchPredicate(MachineBasicBlock
&MBB
,
334 TargetInstrInfo::MachineBranchPredicate
&MBP
,
335 bool AllowModify
= false) const override
;
337 unsigned removeBranch(MachineBasicBlock
&MBB
,
338 int *BytesRemoved
= nullptr) const override
;
339 unsigned insertBranch(MachineBasicBlock
&MBB
, MachineBasicBlock
*TBB
,
340 MachineBasicBlock
*FBB
, ArrayRef
<MachineOperand
> Cond
,
342 int *BytesAdded
= nullptr) const override
;
343 bool canInsertSelect(const MachineBasicBlock
&, ArrayRef
<MachineOperand
> Cond
,
344 unsigned, unsigned, int &, int &, int &) const override
;
345 void insertSelect(MachineBasicBlock
&MBB
, MachineBasicBlock::iterator MI
,
346 const DebugLoc
&DL
, unsigned DstReg
,
347 ArrayRef
<MachineOperand
> Cond
, unsigned TrueReg
,
348 unsigned FalseReg
) const override
;
349 void copyPhysReg(MachineBasicBlock
&MBB
, MachineBasicBlock::iterator MI
,
350 const DebugLoc
&DL
, unsigned DestReg
, unsigned SrcReg
,
351 bool KillSrc
) const override
;
352 void storeRegToStackSlot(MachineBasicBlock
&MBB
,
353 MachineBasicBlock::iterator MI
, unsigned SrcReg
,
354 bool isKill
, int FrameIndex
,
355 const TargetRegisterClass
*RC
,
356 const TargetRegisterInfo
*TRI
) const override
;
358 void storeRegToAddr(MachineFunction
&MF
, unsigned SrcReg
, bool isKill
,
359 SmallVectorImpl
<MachineOperand
> &Addr
,
360 const TargetRegisterClass
*RC
,
361 ArrayRef
<MachineMemOperand
*> MMOs
,
362 SmallVectorImpl
<MachineInstr
*> &NewMIs
) const;
364 void loadRegFromStackSlot(MachineBasicBlock
&MBB
,
365 MachineBasicBlock::iterator MI
, unsigned DestReg
,
366 int FrameIndex
, const TargetRegisterClass
*RC
,
367 const TargetRegisterInfo
*TRI
) const override
;
369 void loadRegFromAddr(MachineFunction
&MF
, unsigned DestReg
,
370 SmallVectorImpl
<MachineOperand
> &Addr
,
371 const TargetRegisterClass
*RC
,
372 ArrayRef
<MachineMemOperand
*> MMOs
,
373 SmallVectorImpl
<MachineInstr
*> &NewMIs
) const;
375 bool expandPostRAPseudo(MachineInstr
&MI
) const override
;
377 /// Check whether the target can fold a load that feeds a subreg operand
378 /// (or a subreg operand that feeds a store).
379 bool isSubregFoldable() const override
{ return true; }
381 /// foldMemoryOperand - If this target supports it, fold a load or store of
382 /// the specified stack slot into the specified machine instruction for the
383 /// specified operand(s). If this is possible, the target should perform the
384 /// folding and return true, otherwise it should return false. If it folds
385 /// the instruction, it is likely that the MachineInstruction the iterator
386 /// references has been changed.
388 foldMemoryOperandImpl(MachineFunction
&MF
, MachineInstr
&MI
,
389 ArrayRef
<unsigned> Ops
,
390 MachineBasicBlock::iterator InsertPt
, int FrameIndex
,
391 LiveIntervals
*LIS
= nullptr) const override
;
393 /// foldMemoryOperand - Same as the previous version except it allows folding
394 /// of any load and store from / to any address, not just from a specific
396 MachineInstr
*foldMemoryOperandImpl(
397 MachineFunction
&MF
, MachineInstr
&MI
, ArrayRef
<unsigned> Ops
,
398 MachineBasicBlock::iterator InsertPt
, MachineInstr
&LoadMI
,
399 LiveIntervals
*LIS
= nullptr) const override
;
401 /// unfoldMemoryOperand - Separate a single instruction which folded a load or
402 /// a store or a load and a store into two or more instruction. If this is
403 /// possible, returns true as well as the new instructions by reference.
405 unfoldMemoryOperand(MachineFunction
&MF
, MachineInstr
&MI
, unsigned Reg
,
406 bool UnfoldLoad
, bool UnfoldStore
,
407 SmallVectorImpl
<MachineInstr
*> &NewMIs
) const override
;
409 bool unfoldMemoryOperand(SelectionDAG
&DAG
, SDNode
*N
,
410 SmallVectorImpl
<SDNode
*> &NewNodes
) const override
;
412 /// getOpcodeAfterMemoryUnfold - Returns the opcode of the would be new
413 /// instruction after load / store are unfolded from an instruction of the
414 /// specified opcode. It returns zero if the specified unfolding is not
415 /// possible. If LoadRegIndex is non-null, it is filled in with the operand
416 /// index of the operand which will hold the register holding the loaded
419 getOpcodeAfterMemoryUnfold(unsigned Opc
, bool UnfoldLoad
, bool UnfoldStore
,
420 unsigned *LoadRegIndex
= nullptr) const override
;
422 /// areLoadsFromSameBasePtr - This is used by the pre-regalloc scheduler
423 /// to determine if two loads are loading from the same base address. It
424 /// should only return true if the base pointers are the same and the
425 /// only differences between the two addresses are the offset. It also returns
426 /// the offsets by reference.
427 bool areLoadsFromSameBasePtr(SDNode
*Load1
, SDNode
*Load2
, int64_t &Offset1
,
428 int64_t &Offset2
) const override
;
430 /// shouldScheduleLoadsNear - This is a used by the pre-regalloc scheduler to
431 /// determine (in conjunction with areLoadsFromSameBasePtr) if two loads
432 /// should be scheduled togther. On some targets if two loads are loading from
433 /// addresses in the same cache line, it's better if they are scheduled
434 /// together. This function takes two integers that represent the load offsets
435 /// from the common base address. It returns true if it decides it's desirable
436 /// to schedule the two loads together. "NumLoads" is the number of loads that
437 /// have already been scheduled after Load1.
438 bool shouldScheduleLoadsNear(SDNode
*Load1
, SDNode
*Load2
, int64_t Offset1
,
440 unsigned NumLoads
) const override
;
442 void getNoop(MCInst
&NopInst
) const override
;
445 reverseBranchCondition(SmallVectorImpl
<MachineOperand
> &Cond
) const override
;
447 /// isSafeToMoveRegClassDefs - Return true if it's safe to move a machine
448 /// instruction that defines the specified register class.
449 bool isSafeToMoveRegClassDefs(const TargetRegisterClass
*RC
) const override
;
451 /// isSafeToClobberEFLAGS - Return true if it's safe insert an instruction tha
452 /// would clobber the EFLAGS condition register. Note the result may be
453 /// conservative. If it cannot definitely determine the safety after visiting
454 /// a few instructions in each direction it assumes it's not safe.
455 bool isSafeToClobberEFLAGS(MachineBasicBlock
&MBB
,
456 MachineBasicBlock::iterator I
) const;
458 /// True if MI has a condition code def, e.g. EFLAGS, that is
460 bool hasLiveCondCodeDef(MachineInstr
&MI
) const;
462 /// getGlobalBaseReg - Return a virtual register initialized with the
463 /// the global base register value. Output instructions required to
464 /// initialize the register in the function entry block, if necessary.
466 unsigned getGlobalBaseReg(MachineFunction
*MF
) const;
468 std::pair
<uint16_t, uint16_t>
469 getExecutionDomain(const MachineInstr
&MI
) const override
;
471 uint16_t getExecutionDomainCustom(const MachineInstr
&MI
) const;
473 void setExecutionDomain(MachineInstr
&MI
, unsigned Domain
) const override
;
475 bool setExecutionDomainCustom(MachineInstr
&MI
, unsigned Domain
) const;
478 getPartialRegUpdateClearance(const MachineInstr
&MI
, unsigned OpNum
,
479 const TargetRegisterInfo
*TRI
) const override
;
480 unsigned getUndefRegClearance(const MachineInstr
&MI
, unsigned &OpNum
,
481 const TargetRegisterInfo
*TRI
) const override
;
482 void breakPartialRegDependency(MachineInstr
&MI
, unsigned OpNum
,
483 const TargetRegisterInfo
*TRI
) const override
;
485 MachineInstr
*foldMemoryOperandImpl(MachineFunction
&MF
, MachineInstr
&MI
,
487 ArrayRef
<MachineOperand
> MOs
,
488 MachineBasicBlock::iterator InsertPt
,
489 unsigned Size
, unsigned Alignment
,
490 bool AllowCommute
) const;
492 bool isHighLatencyDef(int opc
) const override
;
494 bool hasHighOperandLatency(const TargetSchedModel
&SchedModel
,
495 const MachineRegisterInfo
*MRI
,
496 const MachineInstr
&DefMI
, unsigned DefIdx
,
497 const MachineInstr
&UseMI
,
498 unsigned UseIdx
) const override
;
500 bool useMachineCombiner() const override
{ return true; }
502 bool isAssociativeAndCommutative(const MachineInstr
&Inst
) const override
;
504 bool hasReassociableOperands(const MachineInstr
&Inst
,
505 const MachineBasicBlock
*MBB
) const override
;
507 void setSpecialOperandAttr(MachineInstr
&OldMI1
, MachineInstr
&OldMI2
,
508 MachineInstr
&NewMI1
,
509 MachineInstr
&NewMI2
) const override
;
511 /// analyzeCompare - For a comparison instruction, return the source registers
512 /// in SrcReg and SrcReg2 if having two register operands, and the value it
513 /// compares against in CmpValue. Return true if the comparison instruction
515 bool analyzeCompare(const MachineInstr
&MI
, unsigned &SrcReg
,
516 unsigned &SrcReg2
, int &CmpMask
,
517 int &CmpValue
) const override
;
519 /// optimizeCompareInstr - Check if there exists an earlier instruction that
520 /// operates on the same source operands and sets flags in the same way as
521 /// Compare; remove Compare if possible.
522 bool optimizeCompareInstr(MachineInstr
&CmpInstr
, unsigned SrcReg
,
523 unsigned SrcReg2
, int CmpMask
, int CmpValue
,
524 const MachineRegisterInfo
*MRI
) const override
;
526 /// optimizeLoadInstr - Try to remove the load by folding it to a register
527 /// operand at the use. We fold the load instructions if and only if the
528 /// def and use are in the same BB. We only look at one load and see
529 /// whether it can be folded into MI. FoldAsLoadDefReg is the virtual register
530 /// defined by the load we are trying to fold. DefMI returns the machine
531 /// instruction that defines FoldAsLoadDefReg, and the function returns
532 /// the machine instruction generated due to folding.
533 MachineInstr
*optimizeLoadInstr(MachineInstr
&MI
,
534 const MachineRegisterInfo
*MRI
,
535 unsigned &FoldAsLoadDefReg
,
536 MachineInstr
*&DefMI
) const override
;
538 std::pair
<unsigned, unsigned>
539 decomposeMachineOperandsTargetFlags(unsigned TF
) const override
;
541 ArrayRef
<std::pair
<unsigned, const char *>>
542 getSerializableDirectMachineOperandTargetFlags() const override
;
544 virtual outliner::OutlinedFunction
getOutliningCandidateInfo(
545 std::vector
<outliner::Candidate
> &RepeatedSequenceLocs
) const override
;
547 bool isFunctionSafeToOutlineFrom(MachineFunction
&MF
,
548 bool OutlineFromLinkOnceODRs
) const override
;
551 getOutliningType(MachineBasicBlock::iterator
&MIT
, unsigned Flags
) const override
;
553 void buildOutlinedFrame(MachineBasicBlock
&MBB
, MachineFunction
&MF
,
554 const outliner::OutlinedFunction
&OF
) const override
;
556 MachineBasicBlock::iterator
557 insertOutlinedCall(Module
&M
, MachineBasicBlock
&MBB
,
558 MachineBasicBlock::iterator
&It
, MachineFunction
&MF
,
559 const outliner::Candidate
&C
) const override
;
562 /// Commutes the operands in the given instruction by changing the operands
563 /// order and/or changing the instruction's opcode and/or the immediate value
566 /// The arguments 'CommuteOpIdx1' and 'CommuteOpIdx2' specify the operands
569 /// Do not call this method for a non-commutable instruction or
570 /// non-commutable operands.
571 /// Even though the instruction is commutable, the method may still
572 /// fail to commute the operands, null pointer is returned in such cases.
573 MachineInstr
*commuteInstructionImpl(MachineInstr
&MI
, bool NewMI
,
574 unsigned CommuteOpIdx1
,
575 unsigned CommuteOpIdx2
) const override
;
577 /// If the specific machine instruction is a instruction that moves/copies
578 /// value from one register to another register return true along with
579 /// @Source machine operand and @Destination machine operand.
580 bool isCopyInstrImpl(const MachineInstr
&MI
, const MachineOperand
*&Source
,
581 const MachineOperand
*&Destination
) const override
;
584 MachineInstr
*convertToThreeAddressWithLEA(unsigned MIOpc
,
585 MachineFunction::iterator
&MFI
,
587 LiveVariables
*LV
) const;
589 /// Handles memory folding for special case instructions, for instance those
590 /// requiring custom manipulation of the address.
591 MachineInstr
*foldMemoryOperandCustom(MachineFunction
&MF
, MachineInstr
&MI
,
593 ArrayRef
<MachineOperand
> MOs
,
594 MachineBasicBlock::iterator InsertPt
,
595 unsigned Size
, unsigned Align
) const;
597 /// isFrameOperand - Return true and the FrameIndex if the specified
598 /// operand and follow operands form a reference to the stack frame.
599 bool isFrameOperand(const MachineInstr
&MI
, unsigned int Op
,
600 int &FrameIndex
) const;
602 /// Returns true iff the routine could find two commutable operands in the
603 /// given machine instruction with 3 vector inputs.
604 /// The 'SrcOpIdx1' and 'SrcOpIdx2' are INPUT and OUTPUT arguments. Their
605 /// input values can be re-defined in this method only if the input values
606 /// are not pre-defined, which is designated by the special value
607 /// 'CommuteAnyOperandIndex' assigned to it.
608 /// If both of indices are pre-defined and refer to some operands, then the
609 /// method simply returns true if the corresponding operands are commutable
610 /// and returns false otherwise.
612 /// For example, calling this method this way:
613 /// unsigned Op1 = 1, Op2 = CommuteAnyOperandIndex;
614 /// findThreeSrcCommutedOpIndices(MI, Op1, Op2);
615 /// can be interpreted as a query asking to find an operand that would be
616 /// commutable with the operand#1.
618 /// If IsIntrinsic is set, operand 1 will be ignored for commuting.
619 bool findThreeSrcCommutedOpIndices(const MachineInstr
&MI
,
622 bool IsIntrinsic
= false) const;