Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

984 lines
46 KiB

  1. //===-- llvm/Target/TargetInstrInfo.h - Instruction Info --------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file describes the target machine instruction set to the code generator.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_TARGET_TARGETINSTRINFO_H
  14. #define LLVM_TARGET_TARGETINSTRINFO_H
  15. #include "llvm/ADT/SmallSet.h"
  16. #include "llvm/CodeGen/DFAPacketizer.h"
  17. #include "llvm/CodeGen/MachineFunction.h"
  18. #include "llvm/MC/MCInstrInfo.h"
  19. namespace llvm {
  20. class InstrItineraryData;
  21. class LiveVariables;
  22. class MCAsmInfo;
  23. class MachineMemOperand;
  24. class MachineRegisterInfo;
  25. class MDNode;
  26. class MCInst;
  27. class MCSchedModel;
  28. class SDNode;
  29. class ScheduleHazardRecognizer;
  30. class SelectionDAG;
  31. class ScheduleDAG;
  32. class TargetRegisterClass;
  33. class TargetRegisterInfo;
  34. class BranchProbability;
  35. template<class T> class SmallVectorImpl;
  36. //---------------------------------------------------------------------------
  37. ///
  38. /// TargetInstrInfo - Interface to description of machine instruction set
  39. ///
  40. class TargetInstrInfo : public MCInstrInfo {
  41. TargetInstrInfo(const TargetInstrInfo &) LLVM_DELETED_FUNCTION;
  42. void operator=(const TargetInstrInfo &) LLVM_DELETED_FUNCTION;
  43. public:
  44. TargetInstrInfo(int CFSetupOpcode = -1, int CFDestroyOpcode = -1)
  45. : CallFrameSetupOpcode(CFSetupOpcode),
  46. CallFrameDestroyOpcode(CFDestroyOpcode) {
  47. }
  48. virtual ~TargetInstrInfo();
  49. /// getRegClass - Givem a machine instruction descriptor, returns the register
  50. /// class constraint for OpNum, or NULL.
  51. const TargetRegisterClass *getRegClass(const MCInstrDesc &TID,
  52. unsigned OpNum,
  53. const TargetRegisterInfo *TRI,
  54. const MachineFunction &MF) const;
  55. /// isTriviallyReMaterializable - Return true if the instruction is trivially
  56. /// rematerializable, meaning it has no side effects and requires no operands
  57. /// that aren't always available.
  58. bool isTriviallyReMaterializable(const MachineInstr *MI,
  59. AliasAnalysis *AA = 0) const {
  60. return MI->getOpcode() == TargetOpcode::IMPLICIT_DEF ||
  61. (MI->getDesc().isRematerializable() &&
  62. (isReallyTriviallyReMaterializable(MI, AA) ||
  63. isReallyTriviallyReMaterializableGeneric(MI, AA)));
  64. }
  65. protected:
  66. /// isReallyTriviallyReMaterializable - For instructions with opcodes for
  67. /// which the M_REMATERIALIZABLE flag is set, this hook lets the target
  68. /// specify whether the instruction is actually trivially rematerializable,
  69. /// taking into consideration its operands. This predicate must return false
  70. /// if the instruction has any side effects other than producing a value, or
  71. /// if it requres any address registers that are not always available.
  72. virtual bool isReallyTriviallyReMaterializable(const MachineInstr *MI,
  73. AliasAnalysis *AA) const {
  74. return false;
  75. }
  76. private:
  77. /// isReallyTriviallyReMaterializableGeneric - For instructions with opcodes
  78. /// for which the M_REMATERIALIZABLE flag is set and the target hook
  79. /// isReallyTriviallyReMaterializable returns false, this function does
  80. /// target-independent tests to determine if the instruction is really
  81. /// trivially rematerializable.
  82. bool isReallyTriviallyReMaterializableGeneric(const MachineInstr *MI,
  83. AliasAnalysis *AA) const;
  84. public:
  85. /// getCallFrameSetup/DestroyOpcode - These methods return the opcode of the
  86. /// frame setup/destroy instructions if they exist (-1 otherwise). Some
  87. /// targets use pseudo instructions in order to abstract away the difference
  88. /// between operating with a frame pointer and operating without, through the
  89. /// use of these two instructions.
  90. ///
  91. int getCallFrameSetupOpcode() const { return CallFrameSetupOpcode; }
  92. int getCallFrameDestroyOpcode() const { return CallFrameDestroyOpcode; }
  93. /// isCoalescableExtInstr - Return true if the instruction is a "coalescable"
  94. /// extension instruction. That is, it's like a copy where it's legal for the
  95. /// source to overlap the destination. e.g. X86::MOVSX64rr32. If this returns
  96. /// true, then it's expected the pre-extension value is available as a subreg
  97. /// of the result register. This also returns the sub-register index in
  98. /// SubIdx.
  99. virtual bool isCoalescableExtInstr(const MachineInstr &MI,
  100. unsigned &SrcReg, unsigned &DstReg,
  101. unsigned &SubIdx) const {
  102. return false;
  103. }
  104. /// isLoadFromStackSlot - If the specified machine instruction is a direct
  105. /// load from a stack slot, return the virtual or physical register number of
  106. /// the destination along with the FrameIndex of the loaded stack slot. If
  107. /// not, return 0. This predicate must return 0 if the instruction has
  108. /// any side effects other than loading from the stack slot.
  109. virtual unsigned isLoadFromStackSlot(const MachineInstr *MI,
  110. int &FrameIndex) const {
  111. return 0;
  112. }
  113. /// isLoadFromStackSlotPostFE - Check for post-frame ptr elimination
  114. /// stack locations as well. This uses a heuristic so it isn't
  115. /// reliable for correctness.
  116. virtual unsigned isLoadFromStackSlotPostFE(const MachineInstr *MI,
  117. int &FrameIndex) const {
  118. return 0;
  119. }
  120. /// hasLoadFromStackSlot - If the specified machine instruction has
  121. /// a load from a stack slot, return true along with the FrameIndex
  122. /// of the loaded stack slot and the machine mem operand containing
  123. /// the reference. If not, return false. Unlike
  124. /// isLoadFromStackSlot, this returns true for any instructions that
  125. /// loads from the stack. This is just a hint, as some cases may be
  126. /// missed.
  127. virtual bool hasLoadFromStackSlot(const MachineInstr *MI,
  128. const MachineMemOperand *&MMO,
  129. int &FrameIndex) const;
  130. /// isStoreToStackSlot - If the specified machine instruction is a direct
  131. /// store to a stack slot, return the virtual or physical register number of
  132. /// the source reg along with the FrameIndex of the loaded stack slot. If
  133. /// not, return 0. This predicate must return 0 if the instruction has
  134. /// any side effects other than storing to the stack slot.
  135. virtual unsigned isStoreToStackSlot(const MachineInstr *MI,
  136. int &FrameIndex) const {
  137. return 0;
  138. }
  139. /// isStoreToStackSlotPostFE - Check for post-frame ptr elimination
  140. /// stack locations as well. This uses a heuristic so it isn't
  141. /// reliable for correctness.
  142. virtual unsigned isStoreToStackSlotPostFE(const MachineInstr *MI,
  143. int &FrameIndex) const {
  144. return 0;
  145. }
  146. /// hasStoreToStackSlot - If the specified machine instruction has a
  147. /// store to a stack slot, return true along with the FrameIndex of
  148. /// the loaded stack slot and the machine mem operand containing the
  149. /// reference. If not, return false. Unlike isStoreToStackSlot,
  150. /// this returns true for any instructions that stores to the
  151. /// stack. This is just a hint, as some cases may be missed.
  152. virtual bool hasStoreToStackSlot(const MachineInstr *MI,
  153. const MachineMemOperand *&MMO,
  154. int &FrameIndex) const;
  155. /// reMaterialize - Re-issue the specified 'original' instruction at the
  156. /// specific location targeting a new destination register.
  157. /// The register in Orig->getOperand(0).getReg() will be substituted by
  158. /// DestReg:SubIdx. Any existing subreg index is preserved or composed with
  159. /// SubIdx.
  160. virtual void reMaterialize(MachineBasicBlock &MBB,
  161. MachineBasicBlock::iterator MI,
  162. unsigned DestReg, unsigned SubIdx,
  163. const MachineInstr *Orig,
  164. const TargetRegisterInfo &TRI) const;
  165. /// duplicate - Create a duplicate of the Orig instruction in MF. This is like
  166. /// MachineFunction::CloneMachineInstr(), but the target may update operands
  167. /// that are required to be unique.
  168. ///
  169. /// The instruction must be duplicable as indicated by isNotDuplicable().
  170. virtual MachineInstr *duplicate(MachineInstr *Orig,
  171. MachineFunction &MF) const;
  172. /// convertToThreeAddress - This method must be implemented by targets that
  173. /// set the M_CONVERTIBLE_TO_3_ADDR flag. When this flag is set, the target
  174. /// may be able to convert a two-address instruction into one or more true
  175. /// three-address instructions on demand. This allows the X86 target (for
  176. /// example) to convert ADD and SHL instructions into LEA instructions if they
  177. /// would require register copies due to two-addressness.
  178. ///
  179. /// This method returns a null pointer if the transformation cannot be
  180. /// performed, otherwise it returns the last new instruction.
  181. ///
  182. virtual MachineInstr *
  183. convertToThreeAddress(MachineFunction::iterator &MFI,
  184. MachineBasicBlock::iterator &MBBI, LiveVariables *LV) const {
  185. return 0;
  186. }
  187. /// commuteInstruction - If a target has any instructions that are
  188. /// commutable but require converting to different instructions or making
  189. /// non-trivial changes to commute them, this method can overloaded to do
  190. /// that. The default implementation simply swaps the commutable operands.
  191. /// If NewMI is false, MI is modified in place and returned; otherwise, a
  192. /// new machine instruction is created and returned. Do not call this
  193. /// method for a non-commutable instruction, but there may be some cases
  194. /// where this method fails and returns null.
  195. virtual MachineInstr *commuteInstruction(MachineInstr *MI,
  196. bool NewMI = false) const;
  197. /// findCommutedOpIndices - If specified MI is commutable, return the two
  198. /// operand indices that would swap value. Return false if the instruction
  199. /// is not in a form which this routine understands.
  200. virtual bool findCommutedOpIndices(MachineInstr *MI, unsigned &SrcOpIdx1,
  201. unsigned &SrcOpIdx2) const;
  202. /// produceSameValue - Return true if two machine instructions would produce
  203. /// identical values. By default, this is only true when the two instructions
  204. /// are deemed identical except for defs. If this function is called when the
  205. /// IR is still in SSA form, the caller can pass the MachineRegisterInfo for
  206. /// aggressive checks.
  207. virtual bool produceSameValue(const MachineInstr *MI0,
  208. const MachineInstr *MI1,
  209. const MachineRegisterInfo *MRI = 0) const;
  210. /// AnalyzeBranch - Analyze the branching code at the end of MBB, returning
  211. /// true if it cannot be understood (e.g. it's a switch dispatch or isn't
  212. /// implemented for a target). Upon success, this returns false and returns
  213. /// with the following information in various cases:
  214. ///
  215. /// 1. If this block ends with no branches (it just falls through to its succ)
  216. /// just return false, leaving TBB/FBB null.
  217. /// 2. If this block ends with only an unconditional branch, it sets TBB to be
  218. /// the destination block.
  219. /// 3. If this block ends with a conditional branch and it falls through to a
  220. /// successor block, it sets TBB to be the branch destination block and a
  221. /// list of operands that evaluate the condition. These operands can be
  222. /// passed to other TargetInstrInfo methods to create new branches.
  223. /// 4. If this block ends with a conditional branch followed by an
  224. /// unconditional branch, it returns the 'true' destination in TBB, the
  225. /// 'false' destination in FBB, and a list of operands that evaluate the
  226. /// condition. These operands can be passed to other TargetInstrInfo
  227. /// methods to create new branches.
  228. ///
  229. /// Note that RemoveBranch and InsertBranch must be implemented to support
  230. /// cases where this method returns success.
  231. ///
  232. /// If AllowModify is true, then this routine is allowed to modify the basic
  233. /// block (e.g. delete instructions after the unconditional branch).
  234. ///
  235. virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
  236. MachineBasicBlock *&FBB,
  237. SmallVectorImpl<MachineOperand> &Cond,
  238. bool AllowModify = false) const {
  239. return true;
  240. }
  241. /// RemoveBranch - Remove the branching code at the end of the specific MBB.
  242. /// This is only invoked in cases where AnalyzeBranch returns success. It
  243. /// returns the number of instructions that were removed.
  244. virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const {
  245. llvm_unreachable("Target didn't implement TargetInstrInfo::RemoveBranch!");
  246. }
  247. /// InsertBranch - Insert branch code into the end of the specified
  248. /// MachineBasicBlock. The operands to this method are the same as those
  249. /// returned by AnalyzeBranch. This is only invoked in cases where
  250. /// AnalyzeBranch returns success. It returns the number of instructions
  251. /// inserted.
  252. ///
  253. /// It is also invoked by tail merging to add unconditional branches in
  254. /// cases where AnalyzeBranch doesn't apply because there was no original
  255. /// branch to analyze. At least this much must be implemented, else tail
  256. /// merging needs to be disabled.
  257. virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
  258. MachineBasicBlock *FBB,
  259. const SmallVectorImpl<MachineOperand> &Cond,
  260. DebugLoc DL) const {
  261. llvm_unreachable("Target didn't implement TargetInstrInfo::InsertBranch!");
  262. }
  263. /// ReplaceTailWithBranchTo - Delete the instruction OldInst and everything
  264. /// after it, replacing it with an unconditional branch to NewDest. This is
  265. /// used by the tail merging pass.
  266. virtual void ReplaceTailWithBranchTo(MachineBasicBlock::iterator Tail,
  267. MachineBasicBlock *NewDest) const;
  268. /// isLegalToSplitMBBAt - Return true if it's legal to split the given basic
  269. /// block at the specified instruction (i.e. instruction would be the start
  270. /// of a new basic block).
  271. virtual bool isLegalToSplitMBBAt(MachineBasicBlock &MBB,
  272. MachineBasicBlock::iterator MBBI) const {
  273. return true;
  274. }
  275. /// isProfitableToIfCvt - Return true if it's profitable to predicate
  276. /// instructions with accumulated instruction latency of "NumCycles"
  277. /// of the specified basic block, where the probability of the instructions
  278. /// being executed is given by Probability, and Confidence is a measure
  279. /// of our confidence that it will be properly predicted.
  280. virtual
  281. bool isProfitableToIfCvt(MachineBasicBlock &MBB, unsigned NumCycles,
  282. unsigned ExtraPredCycles,
  283. const BranchProbability &Probability) const {
  284. return false;
  285. }
  286. /// isProfitableToIfCvt - Second variant of isProfitableToIfCvt, this one
  287. /// checks for the case where two basic blocks from true and false path
  288. /// of a if-then-else (diamond) are predicated on mutally exclusive
  289. /// predicates, where the probability of the true path being taken is given
  290. /// by Probability, and Confidence is a measure of our confidence that it
  291. /// will be properly predicted.
  292. virtual bool
  293. isProfitableToIfCvt(MachineBasicBlock &TMBB,
  294. unsigned NumTCycles, unsigned ExtraTCycles,
  295. MachineBasicBlock &FMBB,
  296. unsigned NumFCycles, unsigned ExtraFCycles,
  297. const BranchProbability &Probability) const {
  298. return false;
  299. }
  300. /// isProfitableToDupForIfCvt - Return true if it's profitable for
  301. /// if-converter to duplicate instructions of specified accumulated
  302. /// instruction latencies in the specified MBB to enable if-conversion.
  303. /// The probability of the instructions being executed is given by
  304. /// Probability, and Confidence is a measure of our confidence that it
  305. /// will be properly predicted.
  306. virtual bool
  307. isProfitableToDupForIfCvt(MachineBasicBlock &MBB, unsigned NumCycles,
  308. const BranchProbability &Probability) const {
  309. return false;
  310. }
  311. /// isProfitableToUnpredicate - Return true if it's profitable to unpredicate
  312. /// one side of a 'diamond', i.e. two sides of if-else predicated on mutually
  313. /// exclusive predicates.
  314. /// e.g.
  315. /// subeq r0, r1, #1
  316. /// addne r0, r1, #1
  317. /// =>
  318. /// sub r0, r1, #1
  319. /// addne r0, r1, #1
  320. ///
  321. /// This may be profitable is conditional instructions are always executed.
  322. virtual bool isProfitableToUnpredicate(MachineBasicBlock &TMBB,
  323. MachineBasicBlock &FMBB) const {
  324. return false;
  325. }
  326. /// canInsertSelect - Return true if it is possible to insert a select
  327. /// instruction that chooses between TrueReg and FalseReg based on the
  328. /// condition code in Cond.
  329. ///
  330. /// When successful, also return the latency in cycles from TrueReg,
  331. /// FalseReg, and Cond to the destination register. In most cases, a select
  332. /// instruction will be 1 cycle, so CondCycles = TrueCycles = FalseCycles = 1
  333. ///
  334. /// Some x86 implementations have 2-cycle cmov instructions.
  335. ///
  336. /// @param MBB Block where select instruction would be inserted.
  337. /// @param Cond Condition returned by AnalyzeBranch.
  338. /// @param TrueReg Virtual register to select when Cond is true.
  339. /// @param FalseReg Virtual register to select when Cond is false.
  340. /// @param CondCycles Latency from Cond+Branch to select output.
  341. /// @param TrueCycles Latency from TrueReg to select output.
  342. /// @param FalseCycles Latency from FalseReg to select output.
  343. virtual bool canInsertSelect(const MachineBasicBlock &MBB,
  344. const SmallVectorImpl<MachineOperand> &Cond,
  345. unsigned TrueReg, unsigned FalseReg,
  346. int &CondCycles,
  347. int &TrueCycles, int &FalseCycles) const {
  348. return false;
  349. }
  350. /// insertSelect - Insert a select instruction into MBB before I that will
  351. /// copy TrueReg to DstReg when Cond is true, and FalseReg to DstReg when
  352. /// Cond is false.
  353. ///
  354. /// This function can only be called after canInsertSelect() returned true.
  355. /// The condition in Cond comes from AnalyzeBranch, and it can be assumed
  356. /// that the same flags or registers required by Cond are available at the
  357. /// insertion point.
  358. ///
  359. /// @param MBB Block where select instruction should be inserted.
  360. /// @param I Insertion point.
  361. /// @param DL Source location for debugging.
  362. /// @param DstReg Virtual register to be defined by select instruction.
  363. /// @param Cond Condition as computed by AnalyzeBranch.
  364. /// @param TrueReg Virtual register to copy when Cond is true.
  365. /// @param FalseReg Virtual register to copy when Cons is false.
  366. virtual void insertSelect(MachineBasicBlock &MBB,
  367. MachineBasicBlock::iterator I, DebugLoc DL,
  368. unsigned DstReg,
  369. const SmallVectorImpl<MachineOperand> &Cond,
  370. unsigned TrueReg, unsigned FalseReg) const {
  371. llvm_unreachable("Target didn't implement TargetInstrInfo::insertSelect!");
  372. }
  373. /// analyzeSelect - Analyze the given select instruction, returning true if
  374. /// it cannot be understood. It is assumed that MI->isSelect() is true.
  375. ///
  376. /// When successful, return the controlling condition and the operands that
  377. /// determine the true and false result values.
  378. ///
  379. /// Result = SELECT Cond, TrueOp, FalseOp
  380. ///
  381. /// Some targets can optimize select instructions, for example by predicating
  382. /// the instruction defining one of the operands. Such targets should set
  383. /// Optimizable.
  384. ///
  385. /// @param MI Select instruction to analyze.
  386. /// @param Cond Condition controlling the select.
  387. /// @param TrueOp Operand number of the value selected when Cond is true.
  388. /// @param FalseOp Operand number of the value selected when Cond is false.
  389. /// @param Optimizable Returned as true if MI is optimizable.
  390. /// @returns False on success.
  391. virtual bool analyzeSelect(const MachineInstr *MI,
  392. SmallVectorImpl<MachineOperand> &Cond,
  393. unsigned &TrueOp, unsigned &FalseOp,
  394. bool &Optimizable) const {
  395. assert(MI && MI->getDesc().isSelect() && "MI must be a select instruction");
  396. return true;
  397. }
  398. /// optimizeSelect - Given a select instruction that was understood by
  399. /// analyzeSelect and returned Optimizable = true, attempt to optimize MI by
  400. /// merging it with one of its operands. Returns NULL on failure.
  401. ///
  402. /// When successful, returns the new select instruction. The client is
  403. /// responsible for deleting MI.
  404. ///
  405. /// If both sides of the select can be optimized, PreferFalse is used to pick
  406. /// a side.
  407. ///
  408. /// @param MI Optimizable select instruction.
  409. /// @param PreferFalse Try to optimize FalseOp instead of TrueOp.
  410. /// @returns Optimized instruction or NULL.
  411. virtual MachineInstr *optimizeSelect(MachineInstr *MI,
  412. bool PreferFalse = false) const {
  413. // This function must be implemented if Optimizable is ever set.
  414. llvm_unreachable("Target must implement TargetInstrInfo::optimizeSelect!");
  415. }
  416. /// copyPhysReg - Emit instructions to copy a pair of physical registers.
  417. ///
  418. /// This function should support copies within any legal register class as
  419. /// well as any cross-class copies created during instruction selection.
  420. ///
  421. /// The source and destination registers may overlap, which may require a
  422. /// careful implementation when multiple copy instructions are required for
  423. /// large registers. See for example the ARM target.
  424. virtual void copyPhysReg(MachineBasicBlock &MBB,
  425. MachineBasicBlock::iterator MI, DebugLoc DL,
  426. unsigned DestReg, unsigned SrcReg,
  427. bool KillSrc) const {
  428. llvm_unreachable("Target didn't implement TargetInstrInfo::copyPhysReg!");
  429. }
  430. /// storeRegToStackSlot - Store the specified register of the given register
  431. /// class to the specified stack frame index. The store instruction is to be
  432. /// added to the given machine basic block before the specified machine
  433. /// instruction. If isKill is true, the register operand is the last use and
  434. /// must be marked kill.
  435. virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
  436. MachineBasicBlock::iterator MI,
  437. unsigned SrcReg, bool isKill, int FrameIndex,
  438. const TargetRegisterClass *RC,
  439. const TargetRegisterInfo *TRI) const {
  440. llvm_unreachable("Target didn't implement "
  441. "TargetInstrInfo::storeRegToStackSlot!");
  442. }
  443. /// loadRegFromStackSlot - Load the specified register of the given register
  444. /// class from the specified stack frame index. The load instruction is to be
  445. /// added to the given machine basic block before the specified machine
  446. /// instruction.
  447. virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
  448. MachineBasicBlock::iterator MI,
  449. unsigned DestReg, int FrameIndex,
  450. const TargetRegisterClass *RC,
  451. const TargetRegisterInfo *TRI) const {
  452. llvm_unreachable("Target didn't implement "
  453. "TargetInstrInfo::loadRegFromStackSlot!");
  454. }
  455. /// expandPostRAPseudo - This function is called for all pseudo instructions
  456. /// that remain after register allocation. Many pseudo instructions are
  457. /// created to help register allocation. This is the place to convert them
  458. /// into real instructions. The target can edit MI in place, or it can insert
  459. /// new instructions and erase MI. The function should return true if
  460. /// anything was changed.
  461. virtual bool expandPostRAPseudo(MachineBasicBlock::iterator MI) const {
  462. return false;
  463. }
  464. /// emitFrameIndexDebugValue - Emit a target-dependent form of
  465. /// DBG_VALUE encoding the address of a frame index. Addresses would
  466. /// normally be lowered the same way as other addresses on the target,
  467. /// e.g. in load instructions. For targets that do not support this
  468. /// the debug info is simply lost.
  469. /// If you add this for a target you should handle this DBG_VALUE in the
  470. /// target-specific AsmPrinter code as well; you will probably get invalid
  471. /// assembly output if you don't.
  472. virtual MachineInstr *emitFrameIndexDebugValue(MachineFunction &MF,
  473. int FrameIx,
  474. uint64_t Offset,
  475. const MDNode *MDPtr,
  476. DebugLoc dl) const {
  477. return 0;
  478. }
  479. /// foldMemoryOperand - Attempt to fold a load or store of the specified stack
  480. /// slot into the specified machine instruction for the specified operand(s).
  481. /// If this is possible, a new instruction is returned with the specified
  482. /// operand folded, otherwise NULL is returned.
  483. /// The new instruction is inserted before MI, and the client is responsible
  484. /// for removing the old instruction.
  485. MachineInstr* foldMemoryOperand(MachineBasicBlock::iterator MI,
  486. const SmallVectorImpl<unsigned> &Ops,
  487. int FrameIndex) const;
  488. /// foldMemoryOperand - Same as the previous version except it allows folding
  489. /// of any load and store from / to any address, not just from a specific
  490. /// stack slot.
  491. MachineInstr* foldMemoryOperand(MachineBasicBlock::iterator MI,
  492. const SmallVectorImpl<unsigned> &Ops,
  493. MachineInstr* LoadMI) const;
  494. protected:
  495. /// foldMemoryOperandImpl - Target-dependent implementation for
  496. /// foldMemoryOperand. Target-independent code in foldMemoryOperand will
  497. /// take care of adding a MachineMemOperand to the newly created instruction.
  498. virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
  499. MachineInstr* MI,
  500. const SmallVectorImpl<unsigned> &Ops,
  501. int FrameIndex) const {
  502. return 0;
  503. }
  504. /// foldMemoryOperandImpl - Target-dependent implementation for
  505. /// foldMemoryOperand. Target-independent code in foldMemoryOperand will
  506. /// take care of adding a MachineMemOperand to the newly created instruction.
  507. virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
  508. MachineInstr* MI,
  509. const SmallVectorImpl<unsigned> &Ops,
  510. MachineInstr* LoadMI) const {
  511. return 0;
  512. }
  513. public:
  514. /// canFoldMemoryOperand - Returns true for the specified load / store if
  515. /// folding is possible.
  516. virtual
  517. bool canFoldMemoryOperand(const MachineInstr *MI,
  518. const SmallVectorImpl<unsigned> &Ops) const;
  519. /// unfoldMemoryOperand - Separate a single instruction which folded a load or
  520. /// a store or a load and a store into two or more instruction. If this is
  521. /// possible, returns true as well as the new instructions by reference.
  522. virtual bool unfoldMemoryOperand(MachineFunction &MF, MachineInstr *MI,
  523. unsigned Reg, bool UnfoldLoad, bool UnfoldStore,
  524. SmallVectorImpl<MachineInstr*> &NewMIs) const{
  525. return false;
  526. }
  527. virtual bool unfoldMemoryOperand(SelectionDAG &DAG, SDNode *N,
  528. SmallVectorImpl<SDNode*> &NewNodes) const {
  529. return false;
  530. }
  531. /// getOpcodeAfterMemoryUnfold - Returns the opcode of the would be new
  532. /// instruction after load / store are unfolded from an instruction of the
  533. /// specified opcode. It returns zero if the specified unfolding is not
  534. /// possible. If LoadRegIndex is non-null, it is filled in with the operand
  535. /// index of the operand which will hold the register holding the loaded
  536. /// value.
  537. virtual unsigned getOpcodeAfterMemoryUnfold(unsigned Opc,
  538. bool UnfoldLoad, bool UnfoldStore,
  539. unsigned *LoadRegIndex = 0) const {
  540. return 0;
  541. }
  542. /// areLoadsFromSameBasePtr - This is used by the pre-regalloc scheduler
  543. /// to determine if two loads are loading from the same base address. It
  544. /// should only return true if the base pointers are the same and the
  545. /// only differences between the two addresses are the offset. It also returns
  546. /// the offsets by reference.
  547. virtual bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2,
  548. int64_t &Offset1, int64_t &Offset2) const {
  549. return false;
  550. }
  551. /// shouldScheduleLoadsNear - This is a used by the pre-regalloc scheduler to
  552. /// determine (in conjunction with areLoadsFromSameBasePtr) if two loads should
  553. /// be scheduled togther. On some targets if two loads are loading from
  554. /// addresses in the same cache line, it's better if they are scheduled
  555. /// together. This function takes two integers that represent the load offsets
  556. /// from the common base address. It returns true if it decides it's desirable
  557. /// to schedule the two loads together. "NumLoads" is the number of loads that
  558. /// have already been scheduled after Load1.
  559. virtual bool shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2,
  560. int64_t Offset1, int64_t Offset2,
  561. unsigned NumLoads) const {
  562. return false;
  563. }
  564. /// \brief Get the base register and byte offset of a load/store instr.
  565. virtual bool getLdStBaseRegImmOfs(MachineInstr *LdSt,
  566. unsigned &BaseReg, unsigned &Offset,
  567. const TargetRegisterInfo *TRI) const {
  568. return false;
  569. }
  570. virtual bool shouldClusterLoads(MachineInstr *FirstLdSt,
  571. MachineInstr *SecondLdSt,
  572. unsigned NumLoads) const {
  573. return false;
  574. }
  575. /// \brief Can this target fuse the given instructions if they are scheduled
  576. /// adjacent.
  577. virtual bool shouldScheduleAdjacent(MachineInstr* First,
  578. MachineInstr *Second) const {
  579. return false;
  580. }
  581. /// ReverseBranchCondition - Reverses the branch condition of the specified
  582. /// condition list, returning false on success and true if it cannot be
  583. /// reversed.
  584. virtual
  585. bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const {
  586. return true;
  587. }
  588. /// insertNoop - Insert a noop into the instruction stream at the specified
  589. /// point.
  590. virtual void insertNoop(MachineBasicBlock &MBB,
  591. MachineBasicBlock::iterator MI) const;
  592. /// getNoopForMachoTarget - Return the noop instruction to use for a noop.
  593. virtual void getNoopForMachoTarget(MCInst &NopInst) const {
  594. // Default to just using 'nop' string.
  595. }
  596. /// isPredicated - Returns true if the instruction is already predicated.
  597. ///
  598. virtual bool isPredicated(const MachineInstr *MI) const {
  599. return false;
  600. }
  601. /// isUnpredicatedTerminator - Returns true if the instruction is a
  602. /// terminator instruction that has not been predicated.
  603. virtual bool isUnpredicatedTerminator(const MachineInstr *MI) const;
  604. /// PredicateInstruction - Convert the instruction into a predicated
  605. /// instruction. It returns true if the operation was successful.
  606. virtual
  607. bool PredicateInstruction(MachineInstr *MI,
  608. const SmallVectorImpl<MachineOperand> &Pred) const;
  609. /// SubsumesPredicate - Returns true if the first specified predicate
  610. /// subsumes the second, e.g. GE subsumes GT.
  611. virtual
  612. bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
  613. const SmallVectorImpl<MachineOperand> &Pred2) const {
  614. return false;
  615. }
  616. /// DefinesPredicate - If the specified instruction defines any predicate
  617. /// or condition code register(s) used for predication, returns true as well
  618. /// as the definition predicate(s) by reference.
  619. virtual bool DefinesPredicate(MachineInstr *MI,
  620. std::vector<MachineOperand> &Pred) const {
  621. return false;
  622. }
  623. /// isPredicable - Return true if the specified instruction can be predicated.
  624. /// By default, this returns true for every instruction with a
  625. /// PredicateOperand.
  626. virtual bool isPredicable(MachineInstr *MI) const {
  627. return MI->getDesc().isPredicable();
  628. }
  629. /// isSafeToMoveRegClassDefs - Return true if it's safe to move a machine
  630. /// instruction that defines the specified register class.
  631. virtual bool isSafeToMoveRegClassDefs(const TargetRegisterClass *RC) const {
  632. return true;
  633. }
  634. /// isSchedulingBoundary - Test if the given instruction should be
  635. /// considered a scheduling boundary. This primarily includes labels and
  636. /// terminators.
  637. virtual bool isSchedulingBoundary(const MachineInstr *MI,
  638. const MachineBasicBlock *MBB,
  639. const MachineFunction &MF) const;
  640. /// Measure the specified inline asm to determine an approximation of its
  641. /// length.
  642. virtual unsigned getInlineAsmLength(const char *Str,
  643. const MCAsmInfo &MAI) const;
  644. /// CreateTargetHazardRecognizer - Allocate and return a hazard recognizer to
  645. /// use for this target when scheduling the machine instructions before
  646. /// register allocation.
  647. virtual ScheduleHazardRecognizer*
  648. CreateTargetHazardRecognizer(const TargetMachine *TM,
  649. const ScheduleDAG *DAG) const;
  650. /// CreateTargetMIHazardRecognizer - Allocate and return a hazard recognizer
  651. /// to use for this target when scheduling the machine instructions before
  652. /// register allocation.
  653. virtual ScheduleHazardRecognizer*
  654. CreateTargetMIHazardRecognizer(const InstrItineraryData*,
  655. const ScheduleDAG *DAG) const;
  656. /// CreateTargetPostRAHazardRecognizer - Allocate and return a hazard
  657. /// recognizer to use for this target when scheduling the machine instructions
  658. /// after register allocation.
  659. virtual ScheduleHazardRecognizer*
  660. CreateTargetPostRAHazardRecognizer(const InstrItineraryData*,
  661. const ScheduleDAG *DAG) const;
  662. /// Provide a global flag for disabling the PreRA hazard recognizer that
  663. /// targets may choose to honor.
  664. bool usePreRAHazardRecognizer() const;
  665. /// analyzeCompare - For a comparison instruction, return the source registers
  666. /// in SrcReg and SrcReg2 if having two register operands, and the value it
  667. /// compares against in CmpValue. Return true if the comparison instruction
  668. /// can be analyzed.
  669. virtual bool analyzeCompare(const MachineInstr *MI,
  670. unsigned &SrcReg, unsigned &SrcReg2,
  671. int &Mask, int &Value) const {
  672. return false;
  673. }
  674. /// optimizeCompareInstr - See if the comparison instruction can be converted
  675. /// into something more efficient. E.g., on ARM most instructions can set the
  676. /// flags register, obviating the need for a separate CMP.
  677. virtual bool optimizeCompareInstr(MachineInstr *CmpInstr,
  678. unsigned SrcReg, unsigned SrcReg2,
  679. int Mask, int Value,
  680. const MachineRegisterInfo *MRI) const {
  681. return false;
  682. }
  683. /// optimizeLoadInstr - Try to remove the load by folding it to a register
  684. /// operand at the use. We fold the load instructions if and only if the
  685. /// def and use are in the same BB. We only look at one load and see
  686. /// whether it can be folded into MI. FoldAsLoadDefReg is the virtual register
  687. /// defined by the load we are trying to fold. DefMI returns the machine
  688. /// instruction that defines FoldAsLoadDefReg, and the function returns
  689. /// the machine instruction generated due to folding.
  690. virtual MachineInstr* optimizeLoadInstr(MachineInstr *MI,
  691. const MachineRegisterInfo *MRI,
  692. unsigned &FoldAsLoadDefReg,
  693. MachineInstr *&DefMI) const {
  694. return 0;
  695. }
  696. /// FoldImmediate - 'Reg' is known to be defined by a move immediate
  697. /// instruction, try to fold the immediate into the use instruction.
  698. /// If MRI->hasOneNonDBGUse(Reg) is true, and this function returns true,
  699. /// then the caller may assume that DefMI has been erased from its parent
  700. /// block. The caller may assume that it will not be erased by this
  701. /// function otherwise.
  702. virtual bool FoldImmediate(MachineInstr *UseMI, MachineInstr *DefMI,
  703. unsigned Reg, MachineRegisterInfo *MRI) const {
  704. return false;
  705. }
  706. /// getNumMicroOps - Return the number of u-operations the given machine
  707. /// instruction will be decoded to on the target cpu. The itinerary's
  708. /// IssueWidth is the number of microops that can be dispatched each
  709. /// cycle. An instruction with zero microops takes no dispatch resources.
  710. virtual unsigned getNumMicroOps(const InstrItineraryData *ItinData,
  711. const MachineInstr *MI) const;
  712. /// isZeroCost - Return true for pseudo instructions that don't consume any
  713. /// machine resources in their current form. These are common cases that the
  714. /// scheduler should consider free, rather than conservatively handling them
  715. /// as instructions with no itinerary.
  716. bool isZeroCost(unsigned Opcode) const {
  717. return Opcode <= TargetOpcode::COPY;
  718. }
  719. virtual int getOperandLatency(const InstrItineraryData *ItinData,
  720. SDNode *DefNode, unsigned DefIdx,
  721. SDNode *UseNode, unsigned UseIdx) const;
  722. /// getOperandLatency - Compute and return the use operand latency of a given
  723. /// pair of def and use.
  724. /// In most cases, the static scheduling itinerary was enough to determine the
  725. /// operand latency. But it may not be possible for instructions with variable
  726. /// number of defs / uses.
  727. ///
  728. /// This is a raw interface to the itinerary that may be directly overriden by
  729. /// a target. Use computeOperandLatency to get the best estimate of latency.
  730. virtual int getOperandLatency(const InstrItineraryData *ItinData,
  731. const MachineInstr *DefMI, unsigned DefIdx,
  732. const MachineInstr *UseMI,
  733. unsigned UseIdx) const;
  734. /// computeOperandLatency - Compute and return the latency of the given data
  735. /// dependent def and use when the operand indices are already known.
  736. ///
  737. /// FindMin may be set to get the minimum vs. expected latency.
  738. unsigned computeOperandLatency(const InstrItineraryData *ItinData,
  739. const MachineInstr *DefMI, unsigned DefIdx,
  740. const MachineInstr *UseMI, unsigned UseIdx,
  741. bool FindMin = false) const;
  742. /// getInstrLatency - Compute the instruction latency of a given instruction.
  743. /// If the instruction has higher cost when predicated, it's returned via
  744. /// PredCost.
  745. virtual unsigned getInstrLatency(const InstrItineraryData *ItinData,
  746. const MachineInstr *MI,
  747. unsigned *PredCost = 0) const;
  748. virtual int getInstrLatency(const InstrItineraryData *ItinData,
  749. SDNode *Node) const;
  750. /// Return the default expected latency for a def based on it's opcode.
  751. unsigned defaultDefLatency(const MCSchedModel *SchedModel,
  752. const MachineInstr *DefMI) const;
  753. int computeDefOperandLatency(const InstrItineraryData *ItinData,
  754. const MachineInstr *DefMI, bool FindMin) const;
  755. /// isHighLatencyDef - Return true if this opcode has high latency to its
  756. /// result.
  757. virtual bool isHighLatencyDef(int opc) const { return false; }
  758. /// hasHighOperandLatency - Compute operand latency between a def of 'Reg'
  759. /// and an use in the current loop, return true if the target considered
  760. /// it 'high'. This is used by optimization passes such as machine LICM to
  761. /// determine whether it makes sense to hoist an instruction out even in
  762. /// high register pressure situation.
  763. virtual
  764. bool hasHighOperandLatency(const InstrItineraryData *ItinData,
  765. const MachineRegisterInfo *MRI,
  766. const MachineInstr *DefMI, unsigned DefIdx,
  767. const MachineInstr *UseMI, unsigned UseIdx) const {
  768. return false;
  769. }
  770. /// hasLowDefLatency - Compute operand latency of a def of 'Reg', return true
  771. /// if the target considered it 'low'.
  772. virtual
  773. bool hasLowDefLatency(const InstrItineraryData *ItinData,
  774. const MachineInstr *DefMI, unsigned DefIdx) const;
  775. /// verifyInstruction - Perform target specific instruction verification.
  776. virtual
  777. bool verifyInstruction(const MachineInstr *MI, StringRef &ErrInfo) const {
  778. return true;
  779. }
  780. /// getExecutionDomain - Return the current execution domain and bit mask of
  781. /// possible domains for instruction.
  782. ///
  783. /// Some micro-architectures have multiple execution domains, and multiple
  784. /// opcodes that perform the same operation in different domains. For
  785. /// example, the x86 architecture provides the por, orps, and orpd
  786. /// instructions that all do the same thing. There is a latency penalty if a
  787. /// register is written in one domain and read in another.
  788. ///
  789. /// This function returns a pair (domain, mask) containing the execution
  790. /// domain of MI, and a bit mask of possible domains. The setExecutionDomain
  791. /// function can be used to change the opcode to one of the domains in the
  792. /// bit mask. Instructions whose execution domain can't be changed should
  793. /// return a 0 mask.
  794. ///
  795. /// The execution domain numbers don't have any special meaning except domain
  796. /// 0 is used for instructions that are not associated with any interesting
  797. /// execution domain.
  798. ///
  799. virtual std::pair<uint16_t, uint16_t>
  800. getExecutionDomain(const MachineInstr *MI) const {
  801. return std::make_pair(0, 0);
  802. }
  803. /// setExecutionDomain - Change the opcode of MI to execute in Domain.
  804. ///
  805. /// The bit (1 << Domain) must be set in the mask returned from
  806. /// getExecutionDomain(MI).
  807. ///
  808. virtual void setExecutionDomain(MachineInstr *MI, unsigned Domain) const {}
  809. /// getPartialRegUpdateClearance - Returns the preferred minimum clearance
  810. /// before an instruction with an unwanted partial register update.
  811. ///
  812. /// Some instructions only write part of a register, and implicitly need to
  813. /// read the other parts of the register. This may cause unwanted stalls
  814. /// preventing otherwise unrelated instructions from executing in parallel in
  815. /// an out-of-order CPU.
  816. ///
  817. /// For example, the x86 instruction cvtsi2ss writes its result to bits
  818. /// [31:0] of the destination xmm register. Bits [127:32] are unaffected, so
  819. /// the instruction needs to wait for the old value of the register to become
  820. /// available:
  821. ///
  822. /// addps %xmm1, %xmm0
  823. /// movaps %xmm0, (%rax)
  824. /// cvtsi2ss %rbx, %xmm0
  825. ///
  826. /// In the code above, the cvtsi2ss instruction needs to wait for the addps
  827. /// instruction before it can issue, even though the high bits of %xmm0
  828. /// probably aren't needed.
  829. ///
  830. /// This hook returns the preferred clearance before MI, measured in
  831. /// instructions. Other defs of MI's operand OpNum are avoided in the last N
  832. /// instructions before MI. It should only return a positive value for
  833. /// unwanted dependencies. If the old bits of the defined register have
  834. /// useful values, or if MI is determined to otherwise read the dependency,
  835. /// the hook should return 0.
  836. ///
  837. /// The unwanted dependency may be handled by:
  838. ///
  839. /// 1. Allocating the same register for an MI def and use. That makes the
  840. /// unwanted dependency identical to a required dependency.
  841. ///
  842. /// 2. Allocating a register for the def that has no defs in the previous N
  843. /// instructions.
  844. ///
  845. /// 3. Calling breakPartialRegDependency() with the same arguments. This
  846. /// allows the target to insert a dependency breaking instruction.
  847. ///
  848. virtual unsigned
  849. getPartialRegUpdateClearance(const MachineInstr *MI, unsigned OpNum,
  850. const TargetRegisterInfo *TRI) const {
  851. // The default implementation returns 0 for no partial register dependency.
  852. return 0;
  853. }
  854. /// breakPartialRegDependency - Insert a dependency-breaking instruction
  855. /// before MI to eliminate an unwanted dependency on OpNum.
  856. ///
  857. /// If it wasn't possible to avoid a def in the last N instructions before MI
  858. /// (see getPartialRegUpdateClearance), this hook will be called to break the
  859. /// unwanted dependency.
  860. ///
  861. /// On x86, an xorps instruction can be used as a dependency breaker:
  862. ///
  863. /// addps %xmm1, %xmm0
  864. /// movaps %xmm0, (%rax)
  865. /// xorps %xmm0, %xmm0
  866. /// cvtsi2ss %rbx, %xmm0
  867. ///
  868. /// An <imp-kill> operand should be added to MI if an instruction was
  869. /// inserted. This ties the instructions together in the post-ra scheduler.
  870. ///
  871. virtual void
  872. breakPartialRegDependency(MachineBasicBlock::iterator MI, unsigned OpNum,
  873. const TargetRegisterInfo *TRI) const {}
  874. /// Create machine specific model for scheduling.
  875. virtual DFAPacketizer*
  876. CreateTargetScheduleState(const TargetMachine*, const ScheduleDAG*) const {
  877. return NULL;
  878. }
  879. private:
  880. int CallFrameSetupOpcode, CallFrameDestroyOpcode;
  881. };
  882. } // End llvm namespace
  883. #endif