1c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//===- llvm/Target/TargetInstrInfo.h - Instruction Info ---------*- C++ -*-===//
2c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//
3c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//                     The LLVM Compiler Infrastructure
4c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//
5c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// This file is distributed under the University of Illinois Open Source
6c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// License. See LICENSE.TXT for details.
7c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//
8c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//===----------------------------------------------------------------------===//
9c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//
10c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// This file describes the target machine instruction set to the code generator.
11c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//
12c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//===----------------------------------------------------------------------===//
13c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
14c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#ifndef LLVM_TARGET_TARGETINSTRINFO_H
15c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#define LLVM_TARGET_TARGETINSTRINFO_H
16c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
17c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/ArrayRef.h"
18c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/DenseMap.h"
19c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/DenseMapInfo.h"
20c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/None.h"
21c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/CodeGen/LiveIntervalAnalysis.h"
22c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/CodeGen/MachineBasicBlock.h"
23c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/CodeGen/MachineCombinerPattern.h"
24c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/CodeGen/MachineFunction.h"
25c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/CodeGen/MachineInstr.h"
26c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/CodeGen/MachineLoopInfo.h"
27c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/CodeGen/MachineOperand.h"
28c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/CodeGen/PseudoSourceValue.h"
29c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/MC/MCInstrInfo.h"
30c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/Support/BranchProbability.h"
31c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/Support/ErrorHandling.h"
32c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include <cassert>
33c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include <cstddef>
34c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include <cstdint>
35c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include <utility>
36c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include <vector>
37c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
38c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotnamespace llvm {
39c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
40c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass DFAPacketizer;
41c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass InstrItineraryData;
42c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass LiveVariables;
43c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass MachineMemOperand;
44c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass MachineRegisterInfo;
45c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass MCAsmInfo;
46c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass MCInst;
47c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotstruct MCSchedModel;
48c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass Module;
49c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass ScheduleDAG;
50c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass ScheduleHazardRecognizer;
51c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass SDNode;
52c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass SelectionDAG;
53c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass RegScavenger;
54c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass TargetRegisterClass;
55c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass TargetRegisterInfo;
56c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass TargetSchedModel;
57c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass TargetSubtargetInfo;
58c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
59c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <class T> class SmallVectorImpl;
60c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
61c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//---------------------------------------------------------------------------
62c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///
63c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// TargetInstrInfo - Interface to description of machine instruction set
64c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///
65c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass TargetInstrInfo : public MCInstrInfo {
66c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic:
67c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  TargetInstrInfo(unsigned CFSetupOpcode = ~0u, unsigned CFDestroyOpcode = ~0u,
68c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                  unsigned CatchRetOpcode = ~0u, unsigned ReturnOpcode = ~0u)
69c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      : CallFrameSetupOpcode(CFSetupOpcode),
70c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        CallFrameDestroyOpcode(CFDestroyOpcode), CatchRetOpcode(CatchRetOpcode),
71c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        ReturnOpcode(ReturnOpcode) {}
72c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  TargetInstrInfo(const TargetInstrInfo &) = delete;
73c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  TargetInstrInfo &operator=(const TargetInstrInfo &) = delete;
74c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual ~TargetInstrInfo();
75c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
76c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static bool isGenericOpcode(unsigned Opc) {
77c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return Opc <= TargetOpcode::GENERIC_OP_END;
78c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
79c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
80c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Given a machine instruction descriptor, returns the register
81c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// class constraint for OpNum, or NULL.
82c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const TargetRegisterClass *getRegClass(const MCInstrDesc &TID, unsigned OpNum,
83c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                         const TargetRegisterInfo *TRI,
84c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                         const MachineFunction &MF) const;
85c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
86c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return true if the instruction is trivially rematerializable, meaning it
87c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// has no side effects and requires no operands that aren't always available.
88c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// This means the only allowed uses are constants and unallocatable physical
89c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// registers so that the instructions result is independent of the place
90c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// in the function.
91c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isTriviallyReMaterializable(const MachineInstr &MI,
92c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                   AliasAnalysis *AA = nullptr) const {
93c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return MI.getOpcode() == TargetOpcode::IMPLICIT_DEF ||
94c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot           (MI.getDesc().isRematerializable() &&
95c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot            (isReallyTriviallyReMaterializable(MI, AA) ||
96c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot             isReallyTriviallyReMaterializableGeneric(MI, AA)));
97c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
98c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
99c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotprotected:
100c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// For instructions with opcodes for which the M_REMATERIALIZABLE flag is
101c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// set, this hook lets the target specify whether the instruction is actually
102c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// trivially rematerializable, taking into consideration its operands. This
103c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// predicate must return false if the instruction has any side effects other
104c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// than producing a value, or if it requres any address registers that are
105c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// not always available.
106c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Requirements must be check as stated in isTriviallyReMaterializable() .
107c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool isReallyTriviallyReMaterializable(const MachineInstr &MI,
108c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                                 AliasAnalysis *AA) const {
109c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return false;
110c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
111c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
112c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// This method commutes the operands of the given machine instruction MI.
113c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// The operands to be commuted are specified by their indices OpIdx1 and
114c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// OpIdx2.
115c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
116c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// If a target has any instructions that are commutable but require
117c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// converting to different instructions or making non-trivial changes
118c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// to commute them, this method can be overloaded to do that.
119c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// The default implementation simply swaps the commutable operands.
120c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
121c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// If NewMI is false, MI is modified in place and returned; otherwise, a
122c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// new machine instruction is created and returned.
123c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
124c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Do not call this method for a non-commutable instruction.
125c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Even though the instruction is commutable, the method may still
126c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// fail to commute the operands, null pointer is returned in such cases.
127c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual MachineInstr *commuteInstructionImpl(MachineInstr &MI, bool NewMI,
128c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                               unsigned OpIdx1,
129c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                               unsigned OpIdx2) const;
130c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
131c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Assigns the (CommutableOpIdx1, CommutableOpIdx2) pair of commutable
132c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// operand indices to (ResultIdx1, ResultIdx2).
133c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// One or both input values of the pair: (ResultIdx1, ResultIdx2) may be
134c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// predefined to some indices or be undefined (designated by the special
135c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// value 'CommuteAnyOperandIndex').
136c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// The predefined result indices cannot be re-defined.
137c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// The function returns true iff after the result pair redefinition
138c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// the fixed result pair is equal to or equivalent to the source pair of
139c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// indices: (CommutableOpIdx1, CommutableOpIdx2). It is assumed here that
140c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// the pairs (x,y) and (y,x) are equivalent.
141c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static bool fixCommutedOpIndices(unsigned &ResultIdx1, unsigned &ResultIdx2,
142c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                   unsigned CommutableOpIdx1,
143c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                   unsigned CommutableOpIdx2);
144c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
145c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotprivate:
146c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// For instructions with opcodes for which the M_REMATERIALIZABLE flag is
147c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// set and the target hook isReallyTriviallyReMaterializable returns false,
148c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// this function does target-independent tests to determine if the
149c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// instruction is really trivially rematerializable.
150c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isReallyTriviallyReMaterializableGeneric(const MachineInstr &MI,
151c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                                AliasAnalysis *AA) const;
152c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
153c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic:
154c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// These methods return the opcode of the frame setup/destroy instructions
155c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// if they exist (-1 otherwise).  Some targets use pseudo instructions in
156c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// order to abstract away the difference between operating with a frame
157c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// pointer and operating without, through the use of these two instructions.
158c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
159c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  unsigned getCallFrameSetupOpcode() const { return CallFrameSetupOpcode; }
160c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  unsigned getCallFrameDestroyOpcode() const { return CallFrameDestroyOpcode; }
161c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
162c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns true if the argument is a frame pseudo instruction.
163c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isFrameInstr(const MachineInstr &I) const {
164c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return I.getOpcode() == getCallFrameSetupOpcode() ||
165c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot           I.getOpcode() == getCallFrameDestroyOpcode();
166c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
167c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
168c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns true if the argument is a frame setup pseudo instruction.
169c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isFrameSetup(const MachineInstr &I) const {
170c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return I.getOpcode() == getCallFrameSetupOpcode();
171c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
172c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
173c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns size of the frame associated with the given frame instruction.
174c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// For frame setup instruction this is frame that is set up space set up
175c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// after the instruction. For frame destroy instruction this is the frame
176c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// freed by the caller.
177c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Note, in some cases a call frame (or a part of it) may be prepared prior
178c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// to the frame setup instruction. It occurs in the calls that involve
179c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// inalloca arguments. This function reports only the size of the frame part
180c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// that is set up between the frame setup and destroy pseudo instructions.
181c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  int64_t getFrameSize(const MachineInstr &I) const {
182c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    assert(isFrameInstr(I) && "Not a frame instruction");
183c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    assert(I.getOperand(0).getImm() >= 0);
184c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return I.getOperand(0).getImm();
185c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
186c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
187c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns the total frame size, which is made up of the space set up inside
188c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// the pair of frame start-stop instructions and the space that is set up
189c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// prior to the pair.
190c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  int64_t getFrameTotalSize(const MachineInstr &I) const {
191c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (isFrameSetup(I)) {
192c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      assert(I.getOperand(1).getImm() >= 0 &&
193c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot             "Frame size must not be negative");
194c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return getFrameSize(I) + I.getOperand(1).getImm();
195c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    }
196c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return getFrameSize(I);
197c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
198c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
199c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  unsigned getCatchReturnOpcode() const { return CatchRetOpcode; }
200c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  unsigned getReturnOpcode() const { return ReturnOpcode; }
201c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
202c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns the actual stack pointer adjustment made by an instruction
203c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// as part of a call sequence. By default, only call frame setup/destroy
204c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// instructions adjust the stack, but targets may want to override this
205c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// to enable more fine-grained adjustment, or adjust by a different value.
206c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual int getSPAdjust(const MachineInstr &MI) const;
207c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
208c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return true if the instruction is a "coalescable" extension instruction.
209c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// That is, it's like a copy where it's legal for the source to overlap the
210c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// destination. e.g. X86::MOVSX64rr32. If this returns true, then it's
211c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// expected the pre-extension value is available as a subreg of the result
212c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// register. This also returns the sub-register index in SubIdx.
213c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool isCoalescableExtInstr(const MachineInstr &MI, unsigned &SrcReg,
214c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                     unsigned &DstReg, unsigned &SubIdx) const {
215c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return false;
216c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
217c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
218c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// If the specified machine instruction is a direct
219c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// load from a stack slot, return the virtual or physical register number of
220c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// the destination along with the FrameIndex of the loaded stack slot.  If
221c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// not, return 0.  This predicate must return 0 if the instruction has
222c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// any side effects other than loading from the stack slot.
223c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual unsigned isLoadFromStackSlot(const MachineInstr &MI,
224c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                       int &FrameIndex) const {
225c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return 0;
226c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
227c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
228c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Check for post-frame ptr elimination stack locations as well.
229c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// This uses a heuristic so it isn't reliable for correctness.
230c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual unsigned isLoadFromStackSlotPostFE(const MachineInstr &MI,
231c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                             int &FrameIndex) const {
232c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return 0;
233c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
234c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
235c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// If the specified machine instruction has a load from a stack slot,
236c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// return true along with the FrameIndex of the loaded stack slot and the
237c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// machine mem operand containing the reference.
238c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// If not, return false.  Unlike isLoadFromStackSlot, this returns true for
239c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// any instructions that loads from the stack.  This is just a hint, as some
240c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// cases may be missed.
241c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool hasLoadFromStackSlot(const MachineInstr &MI,
242c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                    const MachineMemOperand *&MMO,
243c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                    int &FrameIndex) const;
244c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
245c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// If the specified machine instruction is a direct
246c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// store to a stack slot, return the virtual or physical register number of
247c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// the source reg along with the FrameIndex of the loaded stack slot.  If
248c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// not, return 0.  This predicate must return 0 if the instruction has
249c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// any side effects other than storing to the stack slot.
250c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual unsigned isStoreToStackSlot(const MachineInstr &MI,
251c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                      int &FrameIndex) const {
252c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return 0;
253c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
254c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
255c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Check for post-frame ptr elimination stack locations as well.
256c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// This uses a heuristic, so it isn't reliable for correctness.
257c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual unsigned isStoreToStackSlotPostFE(const MachineInstr &MI,
258c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                            int &FrameIndex) const {
259c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return 0;
260c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
261c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
262c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// If the specified machine instruction has a store to a stack slot,
263c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// return true along with the FrameIndex of the loaded stack slot and the
264c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// machine mem operand containing the reference.
265c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// If not, return false.  Unlike isStoreToStackSlot,
266c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// this returns true for any instructions that stores to the
267c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// stack.  This is just a hint, as some cases may be missed.
268c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool hasStoreToStackSlot(const MachineInstr &MI,
269c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                   const MachineMemOperand *&MMO,
270c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                   int &FrameIndex) const;
271c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
272c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return true if the specified machine instruction
273c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// is a copy of one stack slot to another and has no other effect.
274c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Provide the identity of the two frame indices.
275c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool isStackSlotCopy(const MachineInstr &MI, int &DestFrameIndex,
276c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                               int &SrcFrameIndex) const {
277c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return false;
278c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
279c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
280c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Compute the size in bytes and offset within a stack slot of a spilled
281c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// register or subregister.
282c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
283c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \param [out] Size in bytes of the spilled value.
284c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \param [out] Offset in bytes within the stack slot.
285c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \returns true if both Size and Offset are successfully computed.
286c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
287c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Not all subregisters have computable spill slots. For example,
288c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// subregisters registers may not be byte-sized, and a pair of discontiguous
289c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// subregisters has no single offset.
290c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
291c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Targets with nontrivial bigendian implementations may need to override
292c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// this, particularly to support spilled vector registers.
293c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool getStackSlotRange(const TargetRegisterClass *RC, unsigned SubIdx,
294c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                 unsigned &Size, unsigned &Offset,
295c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                 const MachineFunction &MF) const;
296c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
297c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns the size in bytes of the specified MachineInstr, or ~0U
298c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// when this function is not implemented by a target.
299c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual unsigned getInstSizeInBytes(const MachineInstr &MI) const {
300c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return ~0U;
301c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
302c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
303c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return true if the instruction is as cheap as a move instruction.
304c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
305c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Targets for different archs need to override this, and different
306c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// micro-architectures can also be finely tuned inside.
307c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool isAsCheapAsAMove(const MachineInstr &MI) const {
308c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return MI.isAsCheapAsAMove();
309c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
310c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
311c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return true if the instruction should be sunk by MachineSink.
312c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
313c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// MachineSink determines on its own whether the instruction is safe to sink;
314c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// this gives the target a hook to override the default behavior with regards
315c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// to which instructions should be sunk.
316c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool shouldSink(const MachineInstr &MI) const { return true; }
317c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
318c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Re-issue the specified 'original' instruction at the
319c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// specific location targeting a new destination register.
320c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// The register in Orig->getOperand(0).getReg() will be substituted by
321c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// DestReg:SubIdx. Any existing subreg index is preserved or composed with
322c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// SubIdx.
323c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual void reMaterialize(MachineBasicBlock &MBB,
324c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                             MachineBasicBlock::iterator MI, unsigned DestReg,
325c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                             unsigned SubIdx, const MachineInstr &Orig,
326c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                             const TargetRegisterInfo &TRI) const;
327c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
328c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \brief Clones instruction or the whole instruction bundle \p Orig and
329c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// insert into \p MBB before \p InsertBefore. The target may update operands
330c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// that are required to be unique.
331c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
332c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \p Orig must not return true for MachineInstr::isNotDuplicable().
333c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual MachineInstr &duplicate(MachineBasicBlock &MBB,
334c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                  MachineBasicBlock::iterator InsertBefore,
335c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                  const MachineInstr &Orig) const;
336c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
337c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// This method must be implemented by targets that
338c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// set the M_CONVERTIBLE_TO_3_ADDR flag.  When this flag is set, the target
339c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// may be able to convert a two-address instruction into one or more true
340c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// three-address instructions on demand.  This allows the X86 target (for
341c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// example) to convert ADD and SHL instructions into LEA instructions if they
342c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// would require register copies due to two-addressness.
343c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
344c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// This method returns a null pointer if the transformation cannot be
345c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// performed, otherwise it returns the last new instruction.
346c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
347c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
348c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                              MachineInstr &MI,
349c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                              LiveVariables *LV) const {
350c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return nullptr;
351c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
352c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
353c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  // This constant can be used as an input value of operand index passed to
354c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  // the method findCommutedOpIndices() to tell the method that the
355c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  // corresponding operand index is not pre-defined and that the method
356c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  // can pick any commutable operand.
357c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static const unsigned CommuteAnyOperandIndex = ~0U;
358c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
359c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// This method commutes the operands of the given machine instruction MI.
360c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
361c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// The operands to be commuted are specified by their indices OpIdx1 and
362c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// OpIdx2. OpIdx1 and OpIdx2 arguments may be set to a special value
363c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// 'CommuteAnyOperandIndex', which means that the method is free to choose
364c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// any arbitrarily chosen commutable operand. If both arguments are set to
365c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// 'CommuteAnyOperandIndex' then the method looks for 2 different commutable
366c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// operands; then commutes them if such operands could be found.
367c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
368c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// If NewMI is false, MI is modified in place and returned; otherwise, a
369c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// new machine instruction is created and returned.
370c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
371c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Do not call this method for a non-commutable instruction or
372c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// for non-commuable operands.
373c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Even though the instruction is commutable, the method may still
374c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// fail to commute the operands, null pointer is returned in such cases.
375c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachineInstr *
376c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  commuteInstruction(MachineInstr &MI, bool NewMI = false,
377c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                     unsigned OpIdx1 = CommuteAnyOperandIndex,
378c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                     unsigned OpIdx2 = CommuteAnyOperandIndex) const;
379c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
380c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns true iff the routine could find two commutable operands in the
381c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// given machine instruction.
382c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// The 'SrcOpIdx1' and 'SrcOpIdx2' are INPUT and OUTPUT arguments.
383c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// If any of the INPUT values is set to the special value
384c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// 'CommuteAnyOperandIndex' then the method arbitrarily picks a commutable
385c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// operand, then returns its index in the corresponding argument.
386c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// If both of INPUT values are set to 'CommuteAnyOperandIndex' then method
387c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// looks for 2 commutable operands.
388c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// If INPUT values refer to some operands of MI, then the method simply
389c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// returns true if the corresponding operands are commutable and returns
390c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// false otherwise.
391c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
392c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// For example, calling this method this way:
393c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///     unsigned Op1 = 1, Op2 = CommuteAnyOperandIndex;
394c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///     findCommutedOpIndices(MI, Op1, Op2);
395c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// can be interpreted as a query asking to find an operand that would be
396c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// commutable with the operand#1.
397c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool findCommutedOpIndices(MachineInstr &MI, unsigned &SrcOpIdx1,
398c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                     unsigned &SrcOpIdx2) const;
399c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
400c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// A pair composed of a register and a sub-register index.
401c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Used to give some type checking when modeling Reg:SubReg.
402c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  struct RegSubRegPair {
403c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    unsigned Reg;
404c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    unsigned SubReg;
405c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
406c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    RegSubRegPair(unsigned Reg = 0, unsigned SubReg = 0)
407c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        : Reg(Reg), SubReg(SubReg) {}
408c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  };
409c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
410c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// A pair composed of a pair of a register and a sub-register index,
411c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// and another sub-register index.
412c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Used to give some type checking when modeling Reg:SubReg1, SubReg2.
413c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  struct RegSubRegPairAndIdx : RegSubRegPair {
414c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    unsigned SubIdx;
415c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
416c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    RegSubRegPairAndIdx(unsigned Reg = 0, unsigned SubReg = 0,
417c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                        unsigned SubIdx = 0)
418c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        : RegSubRegPair(Reg, SubReg), SubIdx(SubIdx) {}
419c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  };
420c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
421c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Build the equivalent inputs of a REG_SEQUENCE for the given \p MI
422c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// and \p DefIdx.
423c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \p [out] InputRegs of the equivalent REG_SEQUENCE. Each element of
424c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// the list is modeled as <Reg:SubReg, SubIdx>.
425c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// E.g., REG_SEQUENCE vreg1:sub1, sub0, vreg2, sub1 would produce
426c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// two elements:
427c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// - vreg1:sub1, sub0
428c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// - vreg2<:0>, sub1
429c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
430c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \returns true if it is possible to build such an input sequence
431c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// with the pair \p MI, \p DefIdx. False otherwise.
432c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
433c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \pre MI.isRegSequence() or MI.isRegSequenceLike().
434c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
435c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \note The generic implementation does not provide any support for
436c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// MI.isRegSequenceLike(). In other words, one has to override
437c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// getRegSequenceLikeInputs for target specific instructions.
438c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool
439c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getRegSequenceInputs(const MachineInstr &MI, unsigned DefIdx,
440c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                       SmallVectorImpl<RegSubRegPairAndIdx> &InputRegs) const;
441c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
442c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Build the equivalent inputs of a EXTRACT_SUBREG for the given \p MI
443c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// and \p DefIdx.
444c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \p [out] InputReg of the equivalent EXTRACT_SUBREG.
445c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// E.g., EXTRACT_SUBREG vreg1:sub1, sub0, sub1 would produce:
446c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// - vreg1:sub1, sub0
447c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
448c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \returns true if it is possible to build such an input sequence
449c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// with the pair \p MI, \p DefIdx. False otherwise.
450c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
451c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \pre MI.isExtractSubreg() or MI.isExtractSubregLike().
452c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
453c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \note The generic implementation does not provide any support for
454c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// MI.isExtractSubregLike(). In other words, one has to override
455c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// getExtractSubregLikeInputs for target specific instructions.
456c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool getExtractSubregInputs(const MachineInstr &MI, unsigned DefIdx,
457c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                              RegSubRegPairAndIdx &InputReg) const;
458c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
459c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Build the equivalent inputs of a INSERT_SUBREG for the given \p MI
460c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// and \p DefIdx.
461c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \p [out] BaseReg and \p [out] InsertedReg contain
462c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// the equivalent inputs of INSERT_SUBREG.
463c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// E.g., INSERT_SUBREG vreg0:sub0, vreg1:sub1, sub3 would produce:
464c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// - BaseReg: vreg0:sub0
465c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// - InsertedReg: vreg1:sub1, sub3
466c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
467c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \returns true if it is possible to build such an input sequence
468c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// with the pair \p MI, \p DefIdx. False otherwise.
469c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
470c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \pre MI.isInsertSubreg() or MI.isInsertSubregLike().
471c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
472c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \note The generic implementation does not provide any support for
473c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// MI.isInsertSubregLike(). In other words, one has to override
474c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// getInsertSubregLikeInputs for target specific instructions.
475c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool getInsertSubregInputs(const MachineInstr &MI, unsigned DefIdx,
476c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                             RegSubRegPair &BaseReg,
477c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                             RegSubRegPairAndIdx &InsertedReg) const;
478c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
479c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return true if two machine instructions would produce identical values.
480c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// By default, this is only true when the two instructions
481c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// are deemed identical except for defs. If this function is called when the
482c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// IR is still in SSA form, the caller can pass the MachineRegisterInfo for
483c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// aggressive checks.
484c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool produceSameValue(const MachineInstr &MI0,
485c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                const MachineInstr &MI1,
486c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                const MachineRegisterInfo *MRI = nullptr) const;
487c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
488c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \returns true if a branch from an instruction with opcode \p BranchOpc
489c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///  bytes is capable of jumping to a position \p BrOffset bytes away.
490c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool isBranchOffsetInRange(unsigned BranchOpc,
491c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                     int64_t BrOffset) const {
492c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable("target did not implement");
493c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
494c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
495c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \returns The block that branch instruction \p MI jumps to.
496c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual MachineBasicBlock *getBranchDestBlock(const MachineInstr &MI) const {
497c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable("target did not implement");
498c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
499c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
500c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Insert an unconditional indirect branch at the end of \p MBB to \p
501c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// NewDestBB.  \p BrOffset indicates the offset of \p NewDestBB relative to
502c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// the offset of the position to insert the new branch.
503c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
504c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \returns The number of bytes added to the block.
505c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual unsigned insertIndirectBranch(MachineBasicBlock &MBB,
506c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                        MachineBasicBlock &NewDestBB,
507c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                        const DebugLoc &DL,
508c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                        int64_t BrOffset = 0,
509c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                        RegScavenger *RS = nullptr) const {
510c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable("target did not implement");
511c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
512c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
513c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Analyze the branching code at the end of MBB, returning
514c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// true if it cannot be understood (e.g. it's a switch dispatch or isn't
515c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// implemented for a target).  Upon success, this returns false and returns
516c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// with the following information in various cases:
517c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
518c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// 1. If this block ends with no branches (it just falls through to its succ)
519c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///    just return false, leaving TBB/FBB null.
520c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// 2. If this block ends with only an unconditional branch, it sets TBB to be
521c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///    the destination block.
522c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// 3. If this block ends with a conditional branch and it falls through to a
523c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///    successor block, it sets TBB to be the branch destination block and a
524c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///    list of operands that evaluate the condition. These operands can be
525c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///    passed to other TargetInstrInfo methods to create new branches.
526c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// 4. If this block ends with a conditional branch followed by an
527c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///    unconditional branch, it returns the 'true' destination in TBB, the
528c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///    'false' destination in FBB, and a list of operands that evaluate the
529c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///    condition.  These operands can be passed to other TargetInstrInfo
530c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///    methods to create new branches.
531c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
532c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Note that removeBranch and insertBranch must be implemented to support
533c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// cases where this method returns success.
534c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
535c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// If AllowModify is true, then this routine is allowed to modify the basic
536c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// block (e.g. delete instructions after the unconditional branch).
537c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
538c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// The CFG information in MBB.Predecessors and MBB.Successors must be valid
539c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// before calling this function.
540c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
541c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                             MachineBasicBlock *&FBB,
542c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                             SmallVectorImpl<MachineOperand> &Cond,
543c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                             bool AllowModify = false) const {
544c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return true;
545c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
546c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
547c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Represents a predicate at the MachineFunction level.  The control flow a
548c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// MachineBranchPredicate represents is:
549c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
550c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///  Reg <def>= LHS `Predicate` RHS         == ConditionDef
551c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///  if Reg then goto TrueDest else goto FalseDest
552c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
553c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  struct MachineBranchPredicate {
554c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    enum ComparePredicate {
555c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      PRED_EQ,     // True if two values are equal
556c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      PRED_NE,     // True if two values are not equal
557c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      PRED_INVALID // Sentinel value
558c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    };
559c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
560c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    ComparePredicate Predicate = PRED_INVALID;
561c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    MachineOperand LHS = MachineOperand::CreateImm(0);
562c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    MachineOperand RHS = MachineOperand::CreateImm(0);
563c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    MachineBasicBlock *TrueDest = nullptr;
564c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    MachineBasicBlock *FalseDest = nullptr;
565c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    MachineInstr *ConditionDef = nullptr;
566c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
567c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    /// SingleUseCondition is true if ConditionDef is dead except for the
568c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    /// branch(es) at the end of the basic block.
569c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    ///
570c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    bool SingleUseCondition = false;
571c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
572c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    explicit MachineBranchPredicate() = default;
573c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  };
574c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
575c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Analyze the branching code at the end of MBB and parse it into the
576c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// MachineBranchPredicate structure if possible.  Returns false on success
577c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// and true on failure.
578c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
579c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// If AllowModify is true, then this routine is allowed to modify the basic
580c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// block (e.g. delete instructions after the unconditional branch).
581c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
582c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool analyzeBranchPredicate(MachineBasicBlock &MBB,
583c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                      MachineBranchPredicate &MBP,
584c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                      bool AllowModify = false) const {
585c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return true;
586c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
587c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
588c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Remove the branching code at the end of the specific MBB.
589c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// This is only invoked in cases where AnalyzeBranch returns success. It
590c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// returns the number of instructions that were removed.
591c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// If \p BytesRemoved is non-null, report the change in code size from the
592c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// removed instructions.
593c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual unsigned removeBranch(MachineBasicBlock &MBB,
594c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                int *BytesRemoved = nullptr) const {
595c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable("Target didn't implement TargetInstrInfo::removeBranch!");
596c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
597c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
598c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Insert branch code into the end of the specified MachineBasicBlock. The
599c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// operands to this method are the same as those returned by AnalyzeBranch.
600c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// This is only invoked in cases where AnalyzeBranch returns success. It
601c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// returns the number of instructions inserted. If \p BytesAdded is non-null,
602c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// report the change in code size from the added instructions.
603c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
604c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// It is also invoked by tail merging to add unconditional branches in
605c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// cases where AnalyzeBranch doesn't apply because there was no original
606c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// branch to analyze.  At least this much must be implemented, else tail
607c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// merging needs to be disabled.
608c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
609c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// The CFG information in MBB.Predecessors and MBB.Successors must be valid
610c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// before calling this function.
611c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
612c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                MachineBasicBlock *FBB,
613c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                ArrayRef<MachineOperand> Cond,
614c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                const DebugLoc &DL,
615c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                int *BytesAdded = nullptr) const {
616c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable("Target didn't implement TargetInstrInfo::insertBranch!");
617c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
618c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
619c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  unsigned insertUnconditionalBranch(MachineBasicBlock &MBB,
620c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                     MachineBasicBlock *DestBB,
621c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                     const DebugLoc &DL,
622c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                     int *BytesAdded = nullptr) const {
623c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return insertBranch(MBB, DestBB, nullptr, ArrayRef<MachineOperand>(), DL,
624c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                        BytesAdded);
625c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
626c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
627c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Analyze the loop code, return true if it cannot be understoo. Upon
628c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// success, this function returns false and returns information about the
629c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// induction variable and compare instruction used at the end.
630c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool analyzeLoop(MachineLoop &L, MachineInstr *&IndVarInst,
631c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                           MachineInstr *&CmpInst) const {
632c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return true;
633c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
634c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
635c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Generate code to reduce the loop iteration by one and check if the loop is
636c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// finished.  Return the value/register of the the new loop count.  We need
637c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// this function when peeling off one or more iterations of a loop. This
638c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// function assumes the nth iteration is peeled first.
639c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual unsigned reduceLoopCount(MachineBasicBlock &MBB, MachineInstr *IndVar,
640c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                   MachineInstr &Cmp,
641c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                   SmallVectorImpl<MachineOperand> &Cond,
642c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                   SmallVectorImpl<MachineInstr *> &PrevInsts,
643c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                   unsigned Iter, unsigned MaxIter) const {
644c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable("Target didn't implement ReduceLoopCount");
645c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
646c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
647c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Delete the instruction OldInst and everything after it, replacing it with
648c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// an unconditional branch to NewDest. This is used by the tail merging pass.
649c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual void ReplaceTailWithBranchTo(MachineBasicBlock::iterator Tail,
650c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                       MachineBasicBlock *NewDest) const;
651c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
652c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return true if it's legal to split the given basic
653c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// block at the specified instruction (i.e. instruction would be the start
654c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// of a new basic block).
655c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool isLegalToSplitMBBAt(MachineBasicBlock &MBB,
656c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                   MachineBasicBlock::iterator MBBI) const {
657c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return true;
658c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
659c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
660c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return true if it's profitable to predicate
661c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// instructions with accumulated instruction latency of "NumCycles"
662c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// of the specified basic block, where the probability of the instructions
663c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// being executed is given by Probability, and Confidence is a measure
664c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// of our confidence that it will be properly predicted.
665c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool isProfitableToIfCvt(MachineBasicBlock &MBB, unsigned NumCycles,
666c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                   unsigned ExtraPredCycles,
667c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                   BranchProbability Probability) const {
668c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return false;
669c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
670c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
671c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Second variant of isProfitableToIfCvt. This one
672c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// checks for the case where two basic blocks from true and false path
673c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// of a if-then-else (diamond) are predicated on mutally exclusive
674c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// predicates, where the probability of the true path being taken is given
675c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// by Probability, and Confidence is a measure of our confidence that it
676c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// will be properly predicted.
677c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool isProfitableToIfCvt(MachineBasicBlock &TMBB, unsigned NumTCycles,
678c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                   unsigned ExtraTCycles,
679c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                   MachineBasicBlock &FMBB, unsigned NumFCycles,
680c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                   unsigned ExtraFCycles,
681c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                   BranchProbability Probability) const {
682c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return false;
683c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
684c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
685c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return true if it's profitable for if-converter to duplicate instructions
686c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// of specified accumulated instruction latencies in the specified MBB to
687c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// enable if-conversion.
688c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// The probability of the instructions being executed is given by
689c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Probability, and Confidence is a measure of our confidence that it
690c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// will be properly predicted.
691c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB,
692c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                         unsigned NumCycles,
693c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                         BranchProbability Probability) const {
694c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return false;
695c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
696c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
697c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return true if it's profitable to unpredicate
698c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// one side of a 'diamond', i.e. two sides of if-else predicated on mutually
699c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// exclusive predicates.
700c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// e.g.
701c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///   subeq  r0, r1, #1
702c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///   addne  r0, r1, #1
703c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// =>
704c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///   sub    r0, r1, #1
705c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///   addne  r0, r1, #1
706c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
707c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// This may be profitable is conditional instructions are always executed.
708c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool isProfitableToUnpredicate(MachineBasicBlock &TMBB,
709c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                         MachineBasicBlock &FMBB) const {
710c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return false;
711c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
712c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
713c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return true if it is possible to insert a select
714c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// instruction that chooses between TrueReg and FalseReg based on the
715c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// condition code in Cond.
716c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
717c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// When successful, also return the latency in cycles from TrueReg,
718c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// FalseReg, and Cond to the destination register. In most cases, a select
719c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// instruction will be 1 cycle, so CondCycles = TrueCycles = FalseCycles = 1
720c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
721c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Some x86 implementations have 2-cycle cmov instructions.
722c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
723c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @param MBB         Block where select instruction would be inserted.
724c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @param Cond        Condition returned by AnalyzeBranch.
725c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @param TrueReg     Virtual register to select when Cond is true.
726c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @param FalseReg    Virtual register to select when Cond is false.
727c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @param CondCycles  Latency from Cond+Branch to select output.
728c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @param TrueCycles  Latency from TrueReg to select output.
729c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @param FalseCycles Latency from FalseReg to select output.
730c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool canInsertSelect(const MachineBasicBlock &MBB,
731c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                               ArrayRef<MachineOperand> Cond, unsigned TrueReg,
732c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                               unsigned FalseReg, int &CondCycles,
733c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                               int &TrueCycles, int &FalseCycles) const {
734c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return false;
735c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
736c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
737c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Insert a select instruction into MBB before I that will copy TrueReg to
738c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// DstReg when Cond is true, and FalseReg to DstReg when Cond is false.
739c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
740c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// This function can only be called after canInsertSelect() returned true.
741c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// The condition in Cond comes from AnalyzeBranch, and it can be assumed
742c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// that the same flags or registers required by Cond are available at the
743c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// insertion point.
744c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
745c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @param MBB      Block where select instruction should be inserted.
746c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @param I        Insertion point.
747c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @param DL       Source location for debugging.
748c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @param DstReg   Virtual register to be defined by select instruction.
749c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @param Cond     Condition as computed by AnalyzeBranch.
750c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @param TrueReg  Virtual register to copy when Cond is true.
751c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @param FalseReg Virtual register to copy when Cons is false.
752c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual void insertSelect(MachineBasicBlock &MBB,
753c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                            MachineBasicBlock::iterator I, const DebugLoc &DL,
754c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                            unsigned DstReg, ArrayRef<MachineOperand> Cond,
755c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                            unsigned TrueReg, unsigned FalseReg) const {
756c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable("Target didn't implement TargetInstrInfo::insertSelect!");
757c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
758c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
759c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Analyze the given select instruction, returning true if
760c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// it cannot be understood. It is assumed that MI->isSelect() is true.
761c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
762c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// When successful, return the controlling condition and the operands that
763c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// determine the true and false result values.
764c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
765c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///   Result = SELECT Cond, TrueOp, FalseOp
766c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
767c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Some targets can optimize select instructions, for example by predicating
768c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// the instruction defining one of the operands. Such targets should set
769c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Optimizable.
770c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
771c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @param         MI Select instruction to analyze.
772c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @param Cond    Condition controlling the select.
773c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @param TrueOp  Operand number of the value selected when Cond is true.
774c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @param FalseOp Operand number of the value selected when Cond is false.
775c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @param Optimizable Returned as true if MI is optimizable.
776c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @returns False on success.
777c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool analyzeSelect(const MachineInstr &MI,
778c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                             SmallVectorImpl<MachineOperand> &Cond,
779c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                             unsigned &TrueOp, unsigned &FalseOp,
780c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                             bool &Optimizable) const {
781c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    assert(MI.getDesc().isSelect() && "MI must be a select instruction");
782c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return true;
783c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
784c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
785c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Given a select instruction that was understood by
786c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// analyzeSelect and returned Optimizable = true, attempt to optimize MI by
787c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// merging it with one of its operands. Returns NULL on failure.
788c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
789c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// When successful, returns the new select instruction. The client is
790c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// responsible for deleting MI.
791c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
792c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// If both sides of the select can be optimized, PreferFalse is used to pick
793c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// a side.
794c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
795c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @param MI          Optimizable select instruction.
796c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @param NewMIs     Set that record all MIs in the basic block up to \p
797c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// MI. Has to be updated with any newly created MI or deleted ones.
798c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @param PreferFalse Try to optimize FalseOp instead of TrueOp.
799c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// @returns Optimized instruction or NULL.
800c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual MachineInstr *optimizeSelect(MachineInstr &MI,
801c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                       SmallPtrSetImpl<MachineInstr *> &NewMIs,
802c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                       bool PreferFalse = false) const {
803c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    // This function must be implemented if Optimizable is ever set.
804c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable("Target must implement TargetInstrInfo::optimizeSelect!");
805c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
806c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
807c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Emit instructions to copy a pair of physical registers.
808c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
809c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// This function should support copies within any legal register class as
810c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// well as any cross-class copies created during instruction selection.
811c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
812c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// The source and destination registers may overlap, which may require a
813c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// careful implementation when multiple copy instructions are required for
814c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// large registers. See for example the ARM target.
815c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual void copyPhysReg(MachineBasicBlock &MBB,
816c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                           MachineBasicBlock::iterator MI, const DebugLoc &DL,
817c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                           unsigned DestReg, unsigned SrcReg,
818c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                           bool KillSrc) const {
819c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable("Target didn't implement TargetInstrInfo::copyPhysReg!");
820c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
821c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
822c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Store the specified register of the given register class to the specified
823c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// stack frame index. The store instruction is to be added to the given
824c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// machine basic block before the specified machine instruction. If isKill
825c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// is true, the register operand is the last use and must be marked kill.
826c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
827c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                   MachineBasicBlock::iterator MI,
828c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                   unsigned SrcReg, bool isKill, int FrameIndex,
829c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                   const TargetRegisterClass *RC,
830c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                   const TargetRegisterInfo *TRI) const {
831c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable("Target didn't implement "
832c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                     "TargetInstrInfo::storeRegToStackSlot!");
833c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
834c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
835c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Load the specified register of the given register class from the specified
836c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// stack frame index. The load instruction is to be added to the given
837c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// machine basic block before the specified machine instruction.
838c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
839c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                    MachineBasicBlock::iterator MI,
840c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                    unsigned DestReg, int FrameIndex,
841c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                    const TargetRegisterClass *RC,
842c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                    const TargetRegisterInfo *TRI) const {
843c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable("Target didn't implement "
844c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                     "TargetInstrInfo::loadRegFromStackSlot!");
845c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
846c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
847c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// This function is called for all pseudo instructions
848c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// that remain after register allocation. Many pseudo instructions are
849c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// created to help register allocation. This is the place to convert them
850c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// into real instructions. The target can edit MI in place, or it can insert
851c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// new instructions and erase MI. The function should return true if
852c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// anything was changed.
853c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool expandPostRAPseudo(MachineInstr &MI) const { return false; }
854c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
855c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Check whether the target can fold a load that feeds a subreg operand
856c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// (or a subreg operand that feeds a store).
857c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// For example, X86 may want to return true if it can fold
858c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// movl (%esp), %eax
859c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// subb, %al, ...
860c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Into:
861c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// subb (%esp), ...
862c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
863c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Ideally, we'd like the target implementation of foldMemoryOperand() to
864c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// reject subregs - but since this behavior used to be enforced in the
865c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// target-independent code, moving this responsibility to the targets
866c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// has the potential of causing nasty silent breakage in out-of-tree targets.
867c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool isSubregFoldable() const { return false; }
868c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
869c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Attempt to fold a load or store of the specified stack
870c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// slot into the specified machine instruction for the specified operand(s).
871c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// If this is possible, a new instruction is returned with the specified
872c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// operand folded, otherwise NULL is returned.
873c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// The new instruction is inserted before MI, and the client is responsible
874c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// for removing the old instruction.
875c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachineInstr *foldMemoryOperand(MachineInstr &MI, ArrayRef<unsigned> Ops,
876c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                  int FrameIndex,
877c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                  LiveIntervals *LIS = nullptr) const;
878c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
879c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Same as the previous version except it allows folding of any load and
880c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// store from / to any address, not just from a specific stack slot.
881c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachineInstr *foldMemoryOperand(MachineInstr &MI, ArrayRef<unsigned> Ops,
882c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                  MachineInstr &LoadMI,
883c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                  LiveIntervals *LIS = nullptr) const;
884c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
885c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return true when there is potentially a faster code sequence
886c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// for an instruction chain ending in \p Root. All potential patterns are
887c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// returned in the \p Pattern vector. Pattern should be sorted in priority
888c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// order since the pattern evaluator stops checking as soon as it finds a
889c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// faster sequence.
890c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \param Root - Instruction that could be combined with one of its operands
891c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \param Patterns - Vector of possible combination patterns
892c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool getMachineCombinerPatterns(
893c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      MachineInstr &Root,
894c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      SmallVectorImpl<MachineCombinerPattern> &Patterns) const;
895c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
896c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return true when a code sequence can improve throughput. It
897c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// should be called only for instructions in loops.
898c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \param Pattern - combiner pattern
899c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool isThroughputPattern(MachineCombinerPattern Pattern) const;
900c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
901c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return true if the input \P Inst is part of a chain of dependent ops
902c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// that are suitable for reassociation, otherwise return false.
903c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// If the instruction's operands must be commuted to have a previous
904c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// instruction of the same type define the first source operand, \P Commuted
905c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// will be set to true.
906c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isReassociationCandidate(const MachineInstr &Inst, bool &Commuted) const;
907c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
908c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return true when \P Inst is both associative and commutative.
909c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool isAssociativeAndCommutative(const MachineInstr &Inst) const {
910c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return false;
911c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
912c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
913c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return true when \P Inst has reassociable operands in the same \P MBB.
914c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool hasReassociableOperands(const MachineInstr &Inst,
915c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                       const MachineBasicBlock *MBB) const;
916c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
917c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return true when \P Inst has reassociable sibling.
918c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool hasReassociableSibling(const MachineInstr &Inst, bool &Commuted) const;
919c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
920c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// When getMachineCombinerPatterns() finds patterns, this function generates
921c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// the instructions that could replace the original code sequence. The client
922c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// has to decide whether the actual replacement is beneficial or not.
923c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \param Root - Instruction that could be combined with one of its operands
924c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \param Pattern - Combination pattern for Root
925c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \param InsInstrs - Vector of new instructions that implement P
926c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \param DelInstrs - Old instructions, including Root, that could be
927c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// replaced by InsInstr
928c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \param InstrIdxForVirtReg - map of virtual register to instruction in
929c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// InsInstr that defines it
930c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual void genAlternativeCodeSequence(
931c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      MachineInstr &Root, MachineCombinerPattern Pattern,
932c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      SmallVectorImpl<MachineInstr *> &InsInstrs,
933c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      SmallVectorImpl<MachineInstr *> &DelInstrs,
934c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      DenseMap<unsigned, unsigned> &InstrIdxForVirtReg) const;
935c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
936c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Attempt to reassociate \P Root and \P Prev according to \P Pattern to
937c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// reduce critical path length.
938c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void reassociateOps(MachineInstr &Root, MachineInstr &Prev,
939c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                      MachineCombinerPattern Pattern,
940c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                      SmallVectorImpl<MachineInstr *> &InsInstrs,
941c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                      SmallVectorImpl<MachineInstr *> &DelInstrs,
942c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                      DenseMap<unsigned, unsigned> &InstrIdxForVirtReg) const;
943c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
944c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// This is an architecture-specific helper function of reassociateOps.
945c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Set special operand attributes for new instructions after reassociation.
946c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual void setSpecialOperandAttr(MachineInstr &OldMI1, MachineInstr &OldMI2,
947c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                     MachineInstr &NewMI1,
948c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                     MachineInstr &NewMI2) const {}
949c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
950c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return true when a target supports MachineCombiner.
951c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool useMachineCombiner() const { return false; }
952c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
953c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotprotected:
954c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Target-dependent implementation for foldMemoryOperand.
955c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Target-independent code in foldMemoryOperand will
956c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// take care of adding a MachineMemOperand to the newly created instruction.
957c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// The instruction and any auxiliary instructions necessary will be inserted
958c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// at InsertPt.
959c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual MachineInstr *
960c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  foldMemoryOperandImpl(MachineFunction &MF, MachineInstr &MI,
961c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                        ArrayRef<unsigned> Ops,
962c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                        MachineBasicBlock::iterator InsertPt, int FrameIndex,
963c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                        LiveIntervals *LIS = nullptr) const {
964c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return nullptr;
965c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
966c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
967c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Target-dependent implementation for foldMemoryOperand.
968c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Target-independent code in foldMemoryOperand will
969c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// take care of adding a MachineMemOperand to the newly created instruction.
970c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// The instruction and any auxiliary instructions necessary will be inserted
971c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// at InsertPt.
972c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual MachineInstr *foldMemoryOperandImpl(
973c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      MachineFunction &MF, MachineInstr &MI, ArrayRef<unsigned> Ops,
974c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      MachineBasicBlock::iterator InsertPt, MachineInstr &LoadMI,
975c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      LiveIntervals *LIS = nullptr) const {
976c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return nullptr;
977c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
978c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
979c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \brief Target-dependent implementation of getRegSequenceInputs.
980c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
981c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \returns true if it is possible to build the equivalent
982c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// REG_SEQUENCE inputs with the pair \p MI, \p DefIdx. False otherwise.
983c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
984c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \pre MI.isRegSequenceLike().
985c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
986c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \see TargetInstrInfo::getRegSequenceInputs.
987c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool getRegSequenceLikeInputs(
988c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      const MachineInstr &MI, unsigned DefIdx,
989c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      SmallVectorImpl<RegSubRegPairAndIdx> &InputRegs) const {
990c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return false;
991c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
992c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
993c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \brief Target-dependent implementation of getExtractSubregInputs.
994c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
995c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \returns true if it is possible to build the equivalent
996c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// EXTRACT_SUBREG inputs with the pair \p MI, \p DefIdx. False otherwise.
997c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
998c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \pre MI.isExtractSubregLike().
999c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1000c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \see TargetInstrInfo::getExtractSubregInputs.
1001c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool getExtractSubregLikeInputs(const MachineInstr &MI,
1002c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                          unsigned DefIdx,
1003c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                          RegSubRegPairAndIdx &InputReg) const {
1004c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return false;
1005c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1006c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1007c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \brief Target-dependent implementation of getInsertSubregInputs.
1008c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1009c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \returns true if it is possible to build the equivalent
1010c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// INSERT_SUBREG inputs with the pair \p MI, \p DefIdx. False otherwise.
1011c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1012c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \pre MI.isInsertSubregLike().
1013c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1014c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \see TargetInstrInfo::getInsertSubregInputs.
1015c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool
1016c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getInsertSubregLikeInputs(const MachineInstr &MI, unsigned DefIdx,
1017c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                            RegSubRegPair &BaseReg,
1018c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                            RegSubRegPairAndIdx &InsertedReg) const {
1019c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return false;
1020c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1021c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1022c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic:
1023c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// getAddressSpaceForPseudoSourceKind - Given the kind of memory
1024c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// (e.g. stack) the target returns the corresponding address space.
1025c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual unsigned
1026c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getAddressSpaceForPseudoSourceKind(PseudoSourceValue::PSVKind Kind) const {
1027c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return 0;
1028c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1029c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1030c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// unfoldMemoryOperand - Separate a single instruction which folded a load or
1031c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// a store or a load and a store into two or more instruction. If this is
1032c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// possible, returns true as well as the new instructions by reference.
1033c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool
1034c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  unfoldMemoryOperand(MachineFunction &MF, MachineInstr &MI, unsigned Reg,
1035c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                      bool UnfoldLoad, bool UnfoldStore,
1036c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                      SmallVectorImpl<MachineInstr *> &NewMIs) const {
1037c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return false;
1038c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1039c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1040c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool unfoldMemoryOperand(SelectionDAG &DAG, SDNode *N,
1041c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                   SmallVectorImpl<SDNode *> &NewNodes) const {
1042c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return false;
1043c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1044c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1045c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns the opcode of the would be new
1046c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// instruction after load / store are unfolded from an instruction of the
1047c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// specified opcode. It returns zero if the specified unfolding is not
1048c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// possible. If LoadRegIndex is non-null, it is filled in with the operand
1049c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// index of the operand which will hold the register holding the loaded
1050c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// value.
1051c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual unsigned
1052c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getOpcodeAfterMemoryUnfold(unsigned Opc, bool UnfoldLoad, bool UnfoldStore,
1053c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                             unsigned *LoadRegIndex = nullptr) const {
1054c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return 0;
1055c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1056c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1057c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// This is used by the pre-regalloc scheduler to determine if two loads are
1058c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// loading from the same base address. It should only return true if the base
1059c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// pointers are the same and the only differences between the two addresses
1060c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// are the offset. It also returns the offsets by reference.
1061c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2,
1062c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                       int64_t &Offset1,
1063c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                       int64_t &Offset2) const {
1064c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return false;
1065c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1066c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1067c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// This is a used by the pre-regalloc scheduler to determine (in conjunction
1068c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// with areLoadsFromSameBasePtr) if two loads should be scheduled together.
1069c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// On some targets if two loads are loading from
1070c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// addresses in the same cache line, it's better if they are scheduled
1071c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// together. This function takes two integers that represent the load offsets
1072c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// from the common base address. It returns true if it decides it's desirable
1073c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// to schedule the two loads together. "NumLoads" is the number of loads that
1074c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// have already been scheduled after Load1.
1075c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2,
1076c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                       int64_t Offset1, int64_t Offset2,
1077c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                       unsigned NumLoads) const {
1078c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return false;
1079c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1080c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1081c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Get the base register and byte offset of an instruction that reads/writes
1082c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// memory.
1083c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool getMemOpBaseRegImmOfs(MachineInstr &MemOp, unsigned &BaseReg,
1084c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                     int64_t &Offset,
1085c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                     const TargetRegisterInfo *TRI) const {
1086c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return false;
1087c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1088c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1089c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return true if the instruction contains a base register and offset. If
1090c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// true, the function also sets the operand position in the instruction
1091c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// for the base register and offset.
1092c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool getBaseAndOffsetPosition(const MachineInstr &MI,
1093c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                        unsigned &BasePos,
1094c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                        unsigned &OffsetPos) const {
1095c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return false;
1096c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1097c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1098c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// If the instruction is an increment of a constant value, return the amount.
1099c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool getIncrementValue(const MachineInstr &MI, int &Value) const {
1100c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return false;
1101c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1102c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1103c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns true if the two given memory operations should be scheduled
1104c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// adjacent. Note that you have to add:
1105c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///   DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
1106c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// or
1107c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///   DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
1108c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// to TargetPassConfig::createMachineScheduler() to have an effect.
1109c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool shouldClusterMemOps(MachineInstr &FirstLdSt, unsigned BaseReg1,
1110c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                   MachineInstr &SecondLdSt, unsigned BaseReg2,
1111c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                   unsigned NumLoads) const {
1112c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable("target did not implement shouldClusterMemOps()");
1113c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1114c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1115c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Reverses the branch condition of the specified condition list,
1116c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// returning false on success and true if it cannot be reversed.
1117c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool
1118c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  reverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const {
1119c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return true;
1120c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1121c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1122c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Insert a noop into the instruction stream at the specified point.
1123c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual void insertNoop(MachineBasicBlock &MBB,
1124c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                          MachineBasicBlock::iterator MI) const;
1125c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1126c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return the noop instruction to use for a noop.
1127c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual void getNoop(MCInst &NopInst) const;
1128c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1129c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return true for post-incremented instructions.
1130c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool isPostIncrement(const MachineInstr &MI) const { return false; }
1131c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1132c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns true if the instruction is already predicated.
1133c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool isPredicated(const MachineInstr &MI) const { return false; }
1134c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1135c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns true if the instruction is a
1136c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// terminator instruction that has not been predicated.
1137c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool isUnpredicatedTerminator(const MachineInstr &MI) const;
1138c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1139c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns true if MI is an unconditional tail call.
1140c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool isUnconditionalTailCall(const MachineInstr &MI) const {
1141c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return false;
1142c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1143c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1144c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns true if the tail call can be made conditional on BranchCond.
1145c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool canMakeTailCallConditional(SmallVectorImpl<MachineOperand> &Cond,
1146c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                          const MachineInstr &TailCall) const {
1147c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return false;
1148c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1149c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1150c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Replace the conditional branch in MBB with a conditional tail call.
1151c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual void replaceBranchWithTailCall(MachineBasicBlock &MBB,
1152c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                         SmallVectorImpl<MachineOperand> &Cond,
1153c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                         const MachineInstr &TailCall) const {
1154c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable("Target didn't implement replaceBranchWithTailCall!");
1155c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1156c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1157c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Convert the instruction into a predicated instruction.
1158c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// It returns true if the operation was successful.
1159c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool PredicateInstruction(MachineInstr &MI,
1160c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                    ArrayRef<MachineOperand> Pred) const;
1161c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1162c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns true if the first specified predicate
1163c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// subsumes the second, e.g. GE subsumes GT.
1164c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool SubsumesPredicate(ArrayRef<MachineOperand> Pred1,
1165c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                 ArrayRef<MachineOperand> Pred2) const {
1166c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return false;
1167c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1168c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1169c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// If the specified instruction defines any predicate
1170c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// or condition code register(s) used for predication, returns true as well
1171c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// as the definition predicate(s) by reference.
1172c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool DefinesPredicate(MachineInstr &MI,
1173c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                std::vector<MachineOperand> &Pred) const {
1174c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return false;
1175c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1176c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1177c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return true if the specified instruction can be predicated.
1178c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// By default, this returns true for every instruction with a
1179c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// PredicateOperand.
1180c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool isPredicable(const MachineInstr &MI) const {
1181c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return MI.getDesc().isPredicable();
1182c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1183c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1184c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return true if it's safe to move a machine
1185c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// instruction that defines the specified register class.
1186c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool isSafeToMoveRegClassDefs(const TargetRegisterClass *RC) const {
1187c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return true;
1188c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1189c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1190c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Test if the given instruction should be considered a scheduling boundary.
1191c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// This primarily includes labels and terminators.
1192c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool isSchedulingBoundary(const MachineInstr &MI,
1193c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                    const MachineBasicBlock *MBB,
1194c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                    const MachineFunction &MF) const;
1195c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1196c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Measure the specified inline asm to determine an approximation of its
1197c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// length.
1198c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual unsigned getInlineAsmLength(const char *Str,
1199c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                      const MCAsmInfo &MAI) const;
1200c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1201c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Allocate and return a hazard recognizer to use for this target when
1202c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// scheduling the machine instructions before register allocation.
1203c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual ScheduleHazardRecognizer *
1204c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  CreateTargetHazardRecognizer(const TargetSubtargetInfo *STI,
1205c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                               const ScheduleDAG *DAG) const;
1206c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1207c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Allocate and return a hazard recognizer to use for this target when
1208c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// scheduling the machine instructions before register allocation.
1209c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual ScheduleHazardRecognizer *
1210c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  CreateTargetMIHazardRecognizer(const InstrItineraryData *,
1211c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                 const ScheduleDAG *DAG) const;
1212c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1213c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Allocate and return a hazard recognizer to use for this target when
1214c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// scheduling the machine instructions after register allocation.
1215c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual ScheduleHazardRecognizer *
1216c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  CreateTargetPostRAHazardRecognizer(const InstrItineraryData *,
1217c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                     const ScheduleDAG *DAG) const;
1218c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1219c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Allocate and return a hazard recognizer to use for by non-scheduling
1220c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// passes.
1221c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual ScheduleHazardRecognizer *
1222c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  CreateTargetPostRAHazardRecognizer(const MachineFunction &MF) const {
1223c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return nullptr;
1224c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1225c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1226c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Provide a global flag for disabling the PreRA hazard recognizer that
1227c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// targets may choose to honor.
1228c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool usePreRAHazardRecognizer() const;
1229c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1230c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// For a comparison instruction, return the source registers
1231c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// in SrcReg and SrcReg2 if having two register operands, and the value it
1232c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// compares against in CmpValue. Return true if the comparison instruction
1233c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// can be analyzed.
1234c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool analyzeCompare(const MachineInstr &MI, unsigned &SrcReg,
1235c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                              unsigned &SrcReg2, int &Mask, int &Value) const {
1236c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return false;
1237c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1238c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1239c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// See if the comparison instruction can be converted
1240c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// into something more efficient. E.g., on ARM most instructions can set the
1241c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// flags register, obviating the need for a separate CMP.
1242c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool optimizeCompareInstr(MachineInstr &CmpInstr, unsigned SrcReg,
1243c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                    unsigned SrcReg2, int Mask, int Value,
1244c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                    const MachineRegisterInfo *MRI) const {
1245c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return false;
1246c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1247c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool optimizeCondBranch(MachineInstr &MI) const { return false; }
1248c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1249c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Try to remove the load by folding it to a register operand at the use.
1250c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// We fold the load instructions if and only if the
1251c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// def and use are in the same BB. We only look at one load and see
1252c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// whether it can be folded into MI. FoldAsLoadDefReg is the virtual register
1253c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// defined by the load we are trying to fold. DefMI returns the machine
1254c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// instruction that defines FoldAsLoadDefReg, and the function returns
1255c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// the machine instruction generated due to folding.
1256c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual MachineInstr *optimizeLoadInstr(MachineInstr &MI,
1257c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                          const MachineRegisterInfo *MRI,
1258c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                          unsigned &FoldAsLoadDefReg,
1259c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                          MachineInstr *&DefMI) const {
1260c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return nullptr;
1261c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1262c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1263c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// 'Reg' is known to be defined by a move immediate instruction,
1264c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// try to fold the immediate into the use instruction.
1265c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// If MRI->hasOneNonDBGUse(Reg) is true, and this function returns true,
1266c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// then the caller may assume that DefMI has been erased from its parent
1267c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// block. The caller may assume that it will not be erased by this
1268c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// function otherwise.
1269c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool FoldImmediate(MachineInstr &UseMI, MachineInstr &DefMI,
1270c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                             unsigned Reg, MachineRegisterInfo *MRI) const {
1271c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return false;
1272c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1273c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1274c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return the number of u-operations the given machine
1275c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// instruction will be decoded to on the target cpu. The itinerary's
1276c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// IssueWidth is the number of microops that can be dispatched each
1277c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// cycle. An instruction with zero microops takes no dispatch resources.
1278c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual unsigned getNumMicroOps(const InstrItineraryData *ItinData,
1279c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                  const MachineInstr &MI) const;
1280c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1281c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return true for pseudo instructions that don't consume any
1282c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// machine resources in their current form. These are common cases that the
1283c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// scheduler should consider free, rather than conservatively handling them
1284c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// as instructions with no itinerary.
1285c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isZeroCost(unsigned Opcode) const {
1286c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return Opcode <= TargetOpcode::COPY;
1287c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1288c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1289c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual int getOperandLatency(const InstrItineraryData *ItinData,
1290c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                SDNode *DefNode, unsigned DefIdx,
1291c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                SDNode *UseNode, unsigned UseIdx) const;
1292c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1293c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Compute and return the use operand latency of a given pair of def and use.
1294c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// In most cases, the static scheduling itinerary was enough to determine the
1295c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// operand latency. But it may not be possible for instructions with variable
1296c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// number of defs / uses.
1297c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1298c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// This is a raw interface to the itinerary that may be directly overridden
1299c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// by a target. Use computeOperandLatency to get the best estimate of
1300c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// latency.
1301c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual int getOperandLatency(const InstrItineraryData *ItinData,
1302c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                const MachineInstr &DefMI, unsigned DefIdx,
1303c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                const MachineInstr &UseMI,
1304c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                unsigned UseIdx) const;
1305c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1306c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Compute the instruction latency of a given instruction.
1307c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// If the instruction has higher cost when predicated, it's returned via
1308c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// PredCost.
1309c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual unsigned getInstrLatency(const InstrItineraryData *ItinData,
1310c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                   const MachineInstr &MI,
1311c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                   unsigned *PredCost = nullptr) const;
1312c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1313c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual unsigned getPredicationCost(const MachineInstr &MI) const;
1314c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1315c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual int getInstrLatency(const InstrItineraryData *ItinData,
1316c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                              SDNode *Node) const;
1317c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1318c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return the default expected latency for a def based on its opcode.
1319c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  unsigned defaultDefLatency(const MCSchedModel &SchedModel,
1320c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                             const MachineInstr &DefMI) const;
1321c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1322c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  int computeDefOperandLatency(const InstrItineraryData *ItinData,
1323c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                               const MachineInstr &DefMI) const;
1324c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1325c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return true if this opcode has high latency to its result.
1326c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool isHighLatencyDef(int opc) const { return false; }
1327c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1328c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Compute operand latency between a def of 'Reg'
1329c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// and a use in the current loop. Return true if the target considered
1330c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// it 'high'. This is used by optimization passes such as machine LICM to
1331c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// determine whether it makes sense to hoist an instruction out even in a
1332c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// high register pressure situation.
1333c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool hasHighOperandLatency(const TargetSchedModel &SchedModel,
1334c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                     const MachineRegisterInfo *MRI,
1335c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                     const MachineInstr &DefMI, unsigned DefIdx,
1336c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                     const MachineInstr &UseMI,
1337c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                     unsigned UseIdx) const {
1338c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return false;
1339c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1340c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1341c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Compute operand latency of a def of 'Reg'. Return true
1342c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// if the target considered it 'low'.
1343c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool hasLowDefLatency(const TargetSchedModel &SchedModel,
1344c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                const MachineInstr &DefMI,
1345c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                unsigned DefIdx) const;
1346c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1347c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Perform target-specific instruction verification.
1348c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool verifyInstruction(const MachineInstr &MI,
1349c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                 StringRef &ErrInfo) const {
1350c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return true;
1351c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1352c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1353c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return the current execution domain and bit mask of
1354c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// possible domains for instruction.
1355c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1356c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Some micro-architectures have multiple execution domains, and multiple
1357c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// opcodes that perform the same operation in different domains.  For
1358c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// example, the x86 architecture provides the por, orps, and orpd
1359c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// instructions that all do the same thing.  There is a latency penalty if a
1360c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// register is written in one domain and read in another.
1361c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1362c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// This function returns a pair (domain, mask) containing the execution
1363c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// domain of MI, and a bit mask of possible domains.  The setExecutionDomain
1364c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// function can be used to change the opcode to one of the domains in the
1365c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// bit mask.  Instructions whose execution domain can't be changed should
1366c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// return a 0 mask.
1367c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1368c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// The execution domain numbers don't have any special meaning except domain
1369c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// 0 is used for instructions that are not associated with any interesting
1370c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// execution domain.
1371c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1372c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual std::pair<uint16_t, uint16_t>
1373c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getExecutionDomain(const MachineInstr &MI) const {
1374c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return std::make_pair(0, 0);
1375c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1376c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1377c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Change the opcode of MI to execute in Domain.
1378c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1379c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// The bit (1 << Domain) must be set in the mask returned from
1380c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// getExecutionDomain(MI).
1381c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual void setExecutionDomain(MachineInstr &MI, unsigned Domain) const {}
1382c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1383c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns the preferred minimum clearance
1384c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// before an instruction with an unwanted partial register update.
1385c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1386c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Some instructions only write part of a register, and implicitly need to
1387c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// read the other parts of the register.  This may cause unwanted stalls
1388c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// preventing otherwise unrelated instructions from executing in parallel in
1389c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// an out-of-order CPU.
1390c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1391c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// For example, the x86 instruction cvtsi2ss writes its result to bits
1392c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// [31:0] of the destination xmm register. Bits [127:32] are unaffected, so
1393c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// the instruction needs to wait for the old value of the register to become
1394c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// available:
1395c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1396c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///   addps %xmm1, %xmm0
1397c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///   movaps %xmm0, (%rax)
1398c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///   cvtsi2ss %rbx, %xmm0
1399c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1400c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// In the code above, the cvtsi2ss instruction needs to wait for the addps
1401c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// instruction before it can issue, even though the high bits of %xmm0
1402c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// probably aren't needed.
1403c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1404c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// This hook returns the preferred clearance before MI, measured in
1405c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// instructions.  Other defs of MI's operand OpNum are avoided in the last N
1406c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// instructions before MI.  It should only return a positive value for
1407c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// unwanted dependencies.  If the old bits of the defined register have
1408c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// useful values, or if MI is determined to otherwise read the dependency,
1409c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// the hook should return 0.
1410c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1411c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// The unwanted dependency may be handled by:
1412c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1413c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// 1. Allocating the same register for an MI def and use.  That makes the
1414c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///    unwanted dependency identical to a required dependency.
1415c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1416c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// 2. Allocating a register for the def that has no defs in the previous N
1417c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///    instructions.
1418c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1419c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// 3. Calling breakPartialRegDependency() with the same arguments.  This
1420c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///    allows the target to insert a dependency breaking instruction.
1421c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1422c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual unsigned
1423c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getPartialRegUpdateClearance(const MachineInstr &MI, unsigned OpNum,
1424c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                               const TargetRegisterInfo *TRI) const {
1425c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    // The default implementation returns 0 for no partial register dependency.
1426c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return 0;
1427c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1428c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1429c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \brief Return the minimum clearance before an instruction that reads an
1430c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// unused register.
1431c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1432c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// For example, AVX instructions may copy part of a register operand into
1433c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// the unused high bits of the destination register.
1434c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1435c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// vcvtsi2sdq %rax, %xmm0<undef>, %xmm14
1436c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1437c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// In the code above, vcvtsi2sdq copies %xmm0[127:64] into %xmm14 creating a
1438c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// false dependence on any previous write to %xmm0.
1439c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1440c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// This hook works similarly to getPartialRegUpdateClearance, except that it
1441c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// does not take an operand index. Instead sets \p OpNum to the index of the
1442c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// unused register.
1443c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual unsigned getUndefRegClearance(const MachineInstr &MI, unsigned &OpNum,
1444c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                        const TargetRegisterInfo *TRI) const {
1445c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    // The default implementation returns 0 for no undef register dependency.
1446c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return 0;
1447c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1448c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1449c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Insert a dependency-breaking instruction
1450c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// before MI to eliminate an unwanted dependency on OpNum.
1451c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1452c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// If it wasn't possible to avoid a def in the last N instructions before MI
1453c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// (see getPartialRegUpdateClearance), this hook will be called to break the
1454c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// unwanted dependency.
1455c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1456c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// On x86, an xorps instruction can be used as a dependency breaker:
1457c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1458c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///   addps %xmm1, %xmm0
1459c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///   movaps %xmm0, (%rax)
1460c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///   xorps %xmm0, %xmm0
1461c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///   cvtsi2ss %rbx, %xmm0
1462c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1463c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// An <imp-kill> operand should be added to MI if an instruction was
1464c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// inserted.  This ties the instructions together in the post-ra scheduler.
1465c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1466c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual void breakPartialRegDependency(MachineInstr &MI, unsigned OpNum,
1467c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                         const TargetRegisterInfo *TRI) const {}
1468c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1469c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Create machine specific model for scheduling.
1470c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual DFAPacketizer *
1471c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  CreateTargetScheduleState(const TargetSubtargetInfo &) const {
1472c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return nullptr;
1473c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1474c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1475c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Sometimes, it is possible for the target
1476c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// to tell, even without aliasing information, that two MIs access different
1477c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// memory addresses. This function returns true if two MIs access different
1478c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// memory addresses and false otherwise.
1479c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1480c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Assumes any physical registers used to compute addresses have the same
1481c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// value for both instructions. (This is the most useful assumption for
1482c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// post-RA scheduling.)
1483c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1484c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// See also MachineInstr::mayAlias, which is implemented on top of this
1485c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// function.
1486c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool
1487c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  areMemAccessesTriviallyDisjoint(MachineInstr &MIa, MachineInstr &MIb,
1488c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                  AliasAnalysis *AA = nullptr) const {
1489c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    assert((MIa.mayLoad() || MIa.mayStore()) &&
1490c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot           "MIa must load from or modify a memory location");
1491c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    assert((MIb.mayLoad() || MIb.mayStore()) &&
1492c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot           "MIb must load from or modify a memory location");
1493c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return false;
1494c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1495c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1496c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \brief Return the value to use for the MachineCSE's LookAheadLimit,
1497c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// which is a heuristic used for CSE'ing phys reg defs.
1498c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual unsigned getMachineCSELookAheadLimit() const {
1499c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    // The default lookahead is small to prevent unprofitable quadratic
1500c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    // behavior.
1501c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return 5;
1502c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1503c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1504c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return an array that contains the ids of the target indices (used for the
1505c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// TargetIndex machine operand) and their names.
1506c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1507c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// MIR Serialization is able to serialize only the target indices that are
1508c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// defined by this method.
1509c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual ArrayRef<std::pair<int, const char *>>
1510c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getSerializableTargetIndices() const {
1511c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return None;
1512c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1513c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1514c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Decompose the machine operand's target flags into two values - the direct
1515c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// target flag value and any of bit flags that are applied.
1516c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual std::pair<unsigned, unsigned>
1517c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  decomposeMachineOperandsTargetFlags(unsigned /*TF*/) const {
1518c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return std::make_pair(0u, 0u);
1519c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1520c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1521c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return an array that contains the direct target flag values and their
1522c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// names.
1523c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1524c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// MIR Serialization is able to serialize only the target flags that are
1525c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// defined by this method.
1526c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual ArrayRef<std::pair<unsigned, const char *>>
1527c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getSerializableDirectMachineOperandTargetFlags() const {
1528c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return None;
1529c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1530c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1531c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return an array that contains the bitmask target flag values and their
1532c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// names.
1533c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1534c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// MIR Serialization is able to serialize only the target flags that are
1535c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// defined by this method.
1536c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual ArrayRef<std::pair<unsigned, const char *>>
1537c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getSerializableBitmaskMachineOperandTargetFlags() const {
1538c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return None;
1539c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1540c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1541c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return an array that contains the MMO target flag values and their
1542c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// names.
1543c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
1544c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// MIR Serialization is able to serialize only the MMO target flags that are
1545c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// defined by this method.
1546c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual ArrayRef<std::pair<MachineMemOperand::Flags, const char *>>
1547c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getSerializableMachineMemOperandTargetFlags() const {
1548c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return None;
1549c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1550c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1551c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Determines whether \p Inst is a tail call instruction. Override this
1552c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// method on targets that do not properly set MCID::Return and MCID::Call on
1553c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// tail call instructions."
1554c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool isTailCall(const MachineInstr &Inst) const {
1555c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return Inst.isReturn() && Inst.isCall();
1556c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1557c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1558c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// True if the instruction is bound to the top of its basic block and no
1559c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// other instructions shall be inserted before it. This can be implemented
1560c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// to prevent register allocator to insert spills before such instructions.
1561c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool isBasicBlockPrologue(const MachineInstr &MI) const {
1562c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return false;
1563c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1564c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1565c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \brief Describes the number of instructions that it will take to call and
1566c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// construct a frame for a given outlining candidate.
1567c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  struct MachineOutlinerInfo {
1568c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    /// Number of instructions to call an outlined function for this candidate.
1569c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    unsigned CallOverhead;
1570c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1571c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    /// \brief Number of instructions to construct an outlined function frame
1572c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    /// for this candidate.
1573c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    unsigned FrameOverhead;
1574c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1575c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    /// \brief Represents the specific instructions that must be emitted to
1576c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    /// construct a call to this candidate.
1577c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    unsigned CallConstructionID;
1578c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1579c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    /// \brief Represents the specific instructions that must be emitted to
1580c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    /// construct a frame for this candidate's outlined function.
1581c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    unsigned FrameConstructionID;
1582c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1583c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    MachineOutlinerInfo() {}
1584c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    MachineOutlinerInfo(unsigned CallOverhead, unsigned FrameOverhead,
1585c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                        unsigned CallConstructionID,
1586c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                        unsigned FrameConstructionID)
1587c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        : CallOverhead(CallOverhead), FrameOverhead(FrameOverhead),
1588c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot          CallConstructionID(CallConstructionID),
1589c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot          FrameConstructionID(FrameConstructionID) {}
1590c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  };
1591c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1592c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \brief Returns a \p MachineOutlinerInfo struct containing target-specific
1593c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// information for a set of outlining candidates.
1594c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual MachineOutlinerInfo getOutlininingCandidateInfo(
1595c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      std::vector<
1596c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot          std::pair<MachineBasicBlock::iterator, MachineBasicBlock::iterator>>
1597c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot          &RepeatedSequenceLocs) const {
1598c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable(
1599c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        "Target didn't implement TargetInstrInfo::getOutliningOverhead!");
1600c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1601c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1602c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Represents how an instruction should be mapped by the outliner.
1603c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \p Legal instructions are those which are safe to outline.
1604c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \p Illegal instructions are those which cannot be outlined.
1605c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \p Invisible instructions are instructions which can be outlined, but
1606c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// shouldn't actually impact the outlining result.
1607c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  enum MachineOutlinerInstrType { Legal, Illegal, Invisible };
1608c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1609c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns how or if \p MI should be outlined.
1610c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual MachineOutlinerInstrType getOutliningType(MachineInstr &MI) const {
1611c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable(
1612c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        "Target didn't implement TargetInstrInfo::getOutliningType!");
1613c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1614c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1615c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Insert a custom epilogue for outlined functions.
1616c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// This may be empty, in which case no epilogue or return statement will be
1617c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// emitted.
1618c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual void insertOutlinerEpilogue(MachineBasicBlock &MBB,
1619c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                      MachineFunction &MF,
1620c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                      const MachineOutlinerInfo &MInfo) const {
1621c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable(
1622c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        "Target didn't implement TargetInstrInfo::insertOutlinerEpilogue!");
1623c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1624c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1625c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Insert a call to an outlined function into the program.
1626c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Returns an iterator to the spot where we inserted the call. This must be
1627c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// implemented by the target.
1628c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual MachineBasicBlock::iterator
1629c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  insertOutlinedCall(Module &M, MachineBasicBlock &MBB,
1630c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                     MachineBasicBlock::iterator &It, MachineFunction &MF,
1631c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                     const MachineOutlinerInfo &MInfo) const {
1632c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable(
1633c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        "Target didn't implement TargetInstrInfo::insertOutlinedCall!");
1634c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1635c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1636c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Insert a custom prologue for outlined functions.
1637c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// This may be empty, in which case no prologue will be emitted.
1638c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual void insertOutlinerPrologue(MachineBasicBlock &MBB,
1639c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                      MachineFunction &MF,
1640c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                      const MachineOutlinerInfo &MInfo) const {
1641c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable(
1642c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot        "Target didn't implement TargetInstrInfo::insertOutlinerPrologue!");
1643c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1644c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1645c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Return true if the function can safely be outlined from.
1646c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// A function \p MF is considered safe for outlining if an outlined function
1647c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// produced from instructions in F will produce a program which produces the
1648c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// same output for any set of given inputs.
1649c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  virtual bool isFunctionSafeToOutlineFrom(MachineFunction &MF,
1650c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                           bool OutlineFromLinkOnceODRs) const {
1651c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    llvm_unreachable("Target didn't implement "
1652c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                     "TargetInstrInfo::isFunctionSafeToOutlineFrom!");
1653c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1654c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1655c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotprivate:
1656c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  unsigned CallFrameSetupOpcode, CallFrameDestroyOpcode;
1657c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  unsigned CatchRetOpcode;
1658c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  unsigned ReturnOpcode;
1659c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot};
1660c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1661c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// \brief Provide DenseMapInfo for TargetInstrInfo::RegSubRegPair.
1662c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <> struct DenseMapInfo<TargetInstrInfo::RegSubRegPair> {
1663c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  using RegInfo = DenseMapInfo<unsigned>;
1664c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1665c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static inline TargetInstrInfo::RegSubRegPair getEmptyKey() {
1666c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return TargetInstrInfo::RegSubRegPair(RegInfo::getEmptyKey(),
1667c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                          RegInfo::getEmptyKey());
1668c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1669c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1670c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static inline TargetInstrInfo::RegSubRegPair getTombstoneKey() {
1671c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return TargetInstrInfo::RegSubRegPair(RegInfo::getTombstoneKey(),
1672c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                          RegInfo::getTombstoneKey());
1673c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1674c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1675c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// \brief Reuse getHashValue implementation from
1676c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// std::pair<unsigned, unsigned>.
1677c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static unsigned getHashValue(const TargetInstrInfo::RegSubRegPair &Val) {
1678c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    std::pair<unsigned, unsigned> PairVal = std::make_pair(Val.Reg, Val.SubReg);
1679c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return DenseMapInfo<std::pair<unsigned, unsigned>>::getHashValue(PairVal);
1680c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1681c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1682c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static bool isEqual(const TargetInstrInfo::RegSubRegPair &LHS,
1683c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                      const TargetInstrInfo::RegSubRegPair &RHS) {
1684c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return RegInfo::isEqual(LHS.Reg, RHS.Reg) &&
1685c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot           RegInfo::isEqual(LHS.SubReg, RHS.SubReg);
1686c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
1687c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot};
1688c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1689c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} // end namespace llvm
1690c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
1691c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#endif // LLVM_TARGET_TARGETINSTRINFO_H
1692