InstructionSelector.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/CodeGen/GlobalISel/InstructionSelector.h ------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. /// \file This file declares the API for the instruction selector.
  15. /// This class is responsible for selecting machine instructions.
  16. /// It's implemented by the target. It's used by the InstructionSelect pass.
  17. //
  18. //===----------------------------------------------------------------------===//
  19. #ifndef LLVM_CODEGEN_GLOBALISEL_INSTRUCTIONSELECTOR_H
  20. #define LLVM_CODEGEN_GLOBALISEL_INSTRUCTIONSELECTOR_H
  21. #include "llvm/ADT/DenseMap.h"
  22. #include "llvm/ADT/SmallVector.h"
  23. #include "llvm/CodeGen/GlobalISel/Utils.h"
  24. #include "llvm/CodeGen/MachineFunction.h"
  25. #include "llvm/IR/Function.h"
  26. #include "llvm/Support/LowLevelTypeImpl.h"
  27. #include <bitset>
  28. #include <cstddef>
  29. #include <cstdint>
  30. #include <functional>
  31. #include <initializer_list>
  32. #include <optional>
  33. #include <vector>
  34. namespace llvm {
  35. class BlockFrequencyInfo;
  36. class CodeGenCoverage;
  37. class MachineBasicBlock;
  38. class ProfileSummaryInfo;
  39. class APInt;
  40. class APFloat;
  41. class GISelKnownBits;
  42. class MachineInstr;
  43. class MachineInstrBuilder;
  44. class MachineFunction;
  45. class MachineOperand;
  46. class MachineRegisterInfo;
  47. class RegisterBankInfo;
  48. class TargetInstrInfo;
  49. class TargetRegisterInfo;
  50. /// Container class for CodeGen predicate results.
  51. /// This is convenient because std::bitset does not have a constructor
  52. /// with an initializer list of set bits.
  53. ///
  54. /// Each InstructionSelector subclass should define a PredicateBitset class
  55. /// with:
  56. /// const unsigned MAX_SUBTARGET_PREDICATES = 192;
  57. /// using PredicateBitset = PredicateBitsetImpl<MAX_SUBTARGET_PREDICATES>;
  58. /// and updating the constant to suit the target. Tablegen provides a suitable
  59. /// definition for the predicates in use in <Target>GenGlobalISel.inc when
  60. /// GET_GLOBALISEL_PREDICATE_BITSET is defined.
  61. template <std::size_t MaxPredicates>
  62. class PredicateBitsetImpl : public std::bitset<MaxPredicates> {
  63. public:
  64. // Cannot inherit constructors because it's not supported by VC++..
  65. PredicateBitsetImpl() = default;
  66. PredicateBitsetImpl(const std::bitset<MaxPredicates> &B)
  67. : std::bitset<MaxPredicates>(B) {}
  68. PredicateBitsetImpl(std::initializer_list<unsigned> Init) {
  69. for (auto I : Init)
  70. std::bitset<MaxPredicates>::set(I);
  71. }
  72. };
  73. enum {
  74. /// Begin a try-block to attempt a match and jump to OnFail if it is
  75. /// unsuccessful.
  76. /// - OnFail - The MatchTable entry at which to resume if the match fails.
  77. ///
  78. /// FIXME: This ought to take an argument indicating the number of try-blocks
  79. /// to exit on failure. It's usually one but the last match attempt of
  80. /// a block will need more. The (implemented) alternative is to tack a
  81. /// GIM_Reject on the end of each try-block which is simpler but
  82. /// requires an extra opcode and iteration in the interpreter on each
  83. /// failed match.
  84. GIM_Try,
  85. /// Switch over the opcode on the specified instruction
  86. /// - InsnID - Instruction ID
  87. /// - LowerBound - numerically minimum opcode supported
  88. /// - UpperBound - numerically maximum + 1 opcode supported
  89. /// - Default - failure jump target
  90. /// - JumpTable... - (UpperBound - LowerBound) (at least 2) jump targets
  91. GIM_SwitchOpcode,
  92. /// Switch over the LLT on the specified instruction operand
  93. /// - InsnID - Instruction ID
  94. /// - OpIdx - Operand index
  95. /// - LowerBound - numerically minimum Type ID supported
  96. /// - UpperBound - numerically maximum + 1 Type ID supported
  97. /// - Default - failure jump target
  98. /// - JumpTable... - (UpperBound - LowerBound) (at least 2) jump targets
  99. GIM_SwitchType,
  100. /// Record the specified instruction
  101. /// - NewInsnID - Instruction ID to define
  102. /// - InsnID - Instruction ID
  103. /// - OpIdx - Operand index
  104. GIM_RecordInsn,
  105. /// Check the feature bits
  106. /// - Expected features
  107. GIM_CheckFeatures,
  108. /// Check the opcode on the specified instruction
  109. /// - InsnID - Instruction ID
  110. /// - Expected opcode
  111. GIM_CheckOpcode,
  112. /// Check the opcode on the specified instruction, checking 2 acceptable
  113. /// alternatives.
  114. /// - InsnID - Instruction ID
  115. /// - Expected opcode
  116. /// - Alternative expected opcode
  117. GIM_CheckOpcodeIsEither,
  118. /// Check the instruction has the right number of operands
  119. /// - InsnID - Instruction ID
  120. /// - Expected number of operands
  121. GIM_CheckNumOperands,
  122. /// Check an immediate predicate on the specified instruction
  123. /// - InsnID - Instruction ID
  124. /// - The predicate to test
  125. GIM_CheckI64ImmPredicate,
  126. /// Check an immediate predicate on the specified instruction via an APInt.
  127. /// - InsnID - Instruction ID
  128. /// - The predicate to test
  129. GIM_CheckAPIntImmPredicate,
  130. /// Check a floating point immediate predicate on the specified instruction.
  131. /// - InsnID - Instruction ID
  132. /// - The predicate to test
  133. GIM_CheckAPFloatImmPredicate,
  134. /// Check an immediate predicate on the specified instruction
  135. /// - InsnID - Instruction ID
  136. /// - OpIdx - Operand index
  137. /// - The predicate to test
  138. GIM_CheckImmOperandPredicate,
  139. /// Check a memory operation has the specified atomic ordering.
  140. /// - InsnID - Instruction ID
  141. /// - Ordering - The AtomicOrdering value
  142. GIM_CheckAtomicOrdering,
  143. GIM_CheckAtomicOrderingOrStrongerThan,
  144. GIM_CheckAtomicOrderingWeakerThan,
  145. /// Check the size of the memory access for the given machine memory operand.
  146. /// - InsnID - Instruction ID
  147. /// - MMOIdx - MMO index
  148. /// - Size - The size in bytes of the memory access
  149. GIM_CheckMemorySizeEqualTo,
  150. /// Check the address space of the memory access for the given machine memory
  151. /// operand.
  152. /// - InsnID - Instruction ID
  153. /// - MMOIdx - MMO index
  154. /// - NumAddrSpace - Number of valid address spaces
  155. /// - AddrSpaceN - An allowed space of the memory access
  156. /// - AddrSpaceN+1 ...
  157. GIM_CheckMemoryAddressSpace,
  158. /// Check the minimum alignment of the memory access for the given machine
  159. /// memory operand.
  160. /// - InsnID - Instruction ID
  161. /// - MMOIdx - MMO index
  162. /// - MinAlign - Minimum acceptable alignment
  163. GIM_CheckMemoryAlignment,
  164. /// Check the size of the memory access for the given machine memory operand
  165. /// against the size of an operand.
  166. /// - InsnID - Instruction ID
  167. /// - MMOIdx - MMO index
  168. /// - OpIdx - The operand index to compare the MMO against
  169. GIM_CheckMemorySizeEqualToLLT,
  170. GIM_CheckMemorySizeLessThanLLT,
  171. GIM_CheckMemorySizeGreaterThanLLT,
  172. /// Check if this is a vector that can be treated as a vector splat
  173. /// constant. This is valid for both G_BUILD_VECTOR as well as
  174. /// G_BUILD_VECTOR_TRUNC. For AllOnes refers to individual bits, so a -1
  175. /// element.
  176. /// - InsnID - Instruction ID
  177. GIM_CheckIsBuildVectorAllOnes,
  178. GIM_CheckIsBuildVectorAllZeros,
  179. /// Check a generic C++ instruction predicate
  180. /// - InsnID - Instruction ID
  181. /// - PredicateID - The ID of the predicate function to call
  182. GIM_CheckCxxInsnPredicate,
  183. /// Check if there's no use of the first result.
  184. /// - InsnID - Instruction ID
  185. GIM_CheckHasNoUse,
  186. /// Check the type for the specified operand
  187. /// - InsnID - Instruction ID
  188. /// - OpIdx - Operand index
  189. /// - Expected type
  190. GIM_CheckType,
  191. /// Check the type of a pointer to any address space.
  192. /// - InsnID - Instruction ID
  193. /// - OpIdx - Operand index
  194. /// - SizeInBits - The size of the pointer value in bits.
  195. GIM_CheckPointerToAny,
  196. /// Check the register bank for the specified operand
  197. /// - InsnID - Instruction ID
  198. /// - OpIdx - Operand index
  199. /// - Expected register bank (specified as a register class)
  200. GIM_CheckRegBankForClass,
  201. /// Check the operand matches a complex predicate
  202. /// - InsnID - Instruction ID
  203. /// - OpIdx - Operand index
  204. /// - RendererID - The renderer to hold the result
  205. /// - Complex predicate ID
  206. GIM_CheckComplexPattern,
  207. /// Check the operand is a specific integer
  208. /// - InsnID - Instruction ID
  209. /// - OpIdx - Operand index
  210. /// - Expected integer
  211. GIM_CheckConstantInt,
  212. /// Check the operand is a specific literal integer (i.e. MO.isImm() or
  213. /// MO.isCImm() is true).
  214. /// - InsnID - Instruction ID
  215. /// - OpIdx - Operand index
  216. /// - Expected integer
  217. GIM_CheckLiteralInt,
  218. /// Check the operand is a specific intrinsic ID
  219. /// - InsnID - Instruction ID
  220. /// - OpIdx - Operand index
  221. /// - Expected Intrinsic ID
  222. GIM_CheckIntrinsicID,
  223. /// Check the operand is a specific predicate
  224. /// - InsnID - Instruction ID
  225. /// - OpIdx - Operand index
  226. /// - Expected predicate
  227. GIM_CheckCmpPredicate,
  228. /// Check the specified operand is an MBB
  229. /// - InsnID - Instruction ID
  230. /// - OpIdx - Operand index
  231. GIM_CheckIsMBB,
  232. /// Check the specified operand is an Imm
  233. /// - InsnID - Instruction ID
  234. /// - OpIdx - Operand index
  235. GIM_CheckIsImm,
  236. /// Check if the specified operand is safe to fold into the current
  237. /// instruction.
  238. /// - InsnID - Instruction ID
  239. GIM_CheckIsSafeToFold,
  240. /// Check the specified operands are identical.
  241. /// - InsnID - Instruction ID
  242. /// - OpIdx - Operand index
  243. /// - OtherInsnID - Other instruction ID
  244. /// - OtherOpIdx - Other operand index
  245. GIM_CheckIsSameOperand,
  246. /// Predicates with 'let PredicateCodeUsesOperands = 1' need to examine some
  247. /// named operands that will be recorded in RecordedOperands. Names of these
  248. /// operands are referenced in predicate argument list. Emitter determines
  249. /// StoreIdx(corresponds to the order in which names appear in argument list).
  250. /// - InsnID - Instruction ID
  251. /// - OpIdx - Operand index
  252. /// - StoreIdx - Store location in RecordedOperands.
  253. GIM_RecordNamedOperand,
  254. /// Fail the current try-block, or completely fail to match if there is no
  255. /// current try-block.
  256. GIM_Reject,
  257. //=== Renderers ===
  258. /// Mutate an instruction
  259. /// - NewInsnID - Instruction ID to define
  260. /// - OldInsnID - Instruction ID to mutate
  261. /// - NewOpcode - The new opcode to use
  262. GIR_MutateOpcode,
  263. /// Build a new instruction
  264. /// - InsnID - Instruction ID to define
  265. /// - Opcode - The new opcode to use
  266. GIR_BuildMI,
  267. /// Copy an operand to the specified instruction
  268. /// - NewInsnID - Instruction ID to modify
  269. /// - OldInsnID - Instruction ID to copy from
  270. /// - OpIdx - The operand to copy
  271. GIR_Copy,
  272. /// Copy an operand to the specified instruction or add a zero register if the
  273. /// operand is a zero immediate.
  274. /// - NewInsnID - Instruction ID to modify
  275. /// - OldInsnID - Instruction ID to copy from
  276. /// - OpIdx - The operand to copy
  277. /// - ZeroReg - The zero register to use
  278. GIR_CopyOrAddZeroReg,
  279. /// Copy an operand to the specified instruction
  280. /// - NewInsnID - Instruction ID to modify
  281. /// - OldInsnID - Instruction ID to copy from
  282. /// - OpIdx - The operand to copy
  283. /// - SubRegIdx - The subregister to copy
  284. GIR_CopySubReg,
  285. /// Add an implicit register def to the specified instruction
  286. /// - InsnID - Instruction ID to modify
  287. /// - RegNum - The register to add
  288. GIR_AddImplicitDef,
  289. /// Add an implicit register use to the specified instruction
  290. /// - InsnID - Instruction ID to modify
  291. /// - RegNum - The register to add
  292. GIR_AddImplicitUse,
  293. /// Add an register to the specified instruction
  294. /// - InsnID - Instruction ID to modify
  295. /// - RegNum - The register to add
  296. GIR_AddRegister,
  297. /// Add a temporary register to the specified instruction
  298. /// - InsnID - Instruction ID to modify
  299. /// - TempRegID - The temporary register ID to add
  300. /// - TempRegFlags - The register flags to set
  301. GIR_AddTempRegister,
  302. /// Add a temporary register to the specified instruction
  303. /// - InsnID - Instruction ID to modify
  304. /// - TempRegID - The temporary register ID to add
  305. /// - TempRegFlags - The register flags to set
  306. /// - SubRegIndex - The subregister index to set
  307. GIR_AddTempSubRegister,
  308. /// Add an immediate to the specified instruction
  309. /// - InsnID - Instruction ID to modify
  310. /// - Imm - The immediate to add
  311. GIR_AddImm,
  312. /// Render complex operands to the specified instruction
  313. /// - InsnID - Instruction ID to modify
  314. /// - RendererID - The renderer to call
  315. GIR_ComplexRenderer,
  316. /// Render sub-operands of complex operands to the specified instruction
  317. /// - InsnID - Instruction ID to modify
  318. /// - RendererID - The renderer to call
  319. /// - RenderOpID - The suboperand to render.
  320. GIR_ComplexSubOperandRenderer,
  321. /// Render operands to the specified instruction using a custom function
  322. /// - InsnID - Instruction ID to modify
  323. /// - OldInsnID - Instruction ID to get the matched operand from
  324. /// - RendererFnID - Custom renderer function to call
  325. GIR_CustomRenderer,
  326. /// Render operands to the specified instruction using a custom function,
  327. /// reading from a specific operand.
  328. /// - InsnID - Instruction ID to modify
  329. /// - OldInsnID - Instruction ID to get the matched operand from
  330. /// - OpIdx - Operand index in OldInsnID the render function should read from..
  331. /// - RendererFnID - Custom renderer function to call
  332. GIR_CustomOperandRenderer,
  333. /// Render a G_CONSTANT operator as a sign-extended immediate.
  334. /// - NewInsnID - Instruction ID to modify
  335. /// - OldInsnID - Instruction ID to copy from
  336. /// The operand index is implicitly 1.
  337. GIR_CopyConstantAsSImm,
  338. /// Render a G_FCONSTANT operator as a sign-extended immediate.
  339. /// - NewInsnID - Instruction ID to modify
  340. /// - OldInsnID - Instruction ID to copy from
  341. /// The operand index is implicitly 1.
  342. GIR_CopyFConstantAsFPImm,
  343. /// Constrain an instruction operand to a register class.
  344. /// - InsnID - Instruction ID to modify
  345. /// - OpIdx - Operand index
  346. /// - RCEnum - Register class enumeration value
  347. GIR_ConstrainOperandRC,
  348. /// Constrain an instructions operands according to the instruction
  349. /// description.
  350. /// - InsnID - Instruction ID to modify
  351. GIR_ConstrainSelectedInstOperands,
  352. /// Merge all memory operands into instruction.
  353. /// - InsnID - Instruction ID to modify
  354. /// - MergeInsnID... - One or more Instruction ID to merge into the result.
  355. /// - GIU_MergeMemOperands_EndOfList - Terminates the list of instructions to
  356. /// merge.
  357. GIR_MergeMemOperands,
  358. /// Erase from parent.
  359. /// - InsnID - Instruction ID to erase
  360. GIR_EraseFromParent,
  361. /// Create a new temporary register that's not constrained.
  362. /// - TempRegID - The temporary register ID to initialize.
  363. /// - Expected type
  364. GIR_MakeTempReg,
  365. /// A successful emission
  366. GIR_Done,
  367. /// Increment the rule coverage counter.
  368. /// - RuleID - The ID of the rule that was covered.
  369. GIR_Coverage,
  370. /// Keeping track of the number of the GI opcodes. Must be the last entry.
  371. GIU_NumOpcodes,
  372. };
  373. enum {
  374. /// Indicates the end of the variable-length MergeInsnID list in a
  375. /// GIR_MergeMemOperands opcode.
  376. GIU_MergeMemOperands_EndOfList = -1,
  377. };
  378. /// Provides the logic to select generic machine instructions.
  379. class InstructionSelector {
  380. public:
  381. virtual ~InstructionSelector() = default;
  382. /// Select the (possibly generic) instruction \p I to only use target-specific
  383. /// opcodes. It is OK to insert multiple instructions, but they cannot be
  384. /// generic pre-isel instructions.
  385. ///
  386. /// \returns whether selection succeeded.
  387. /// \pre I.getParent() && I.getParent()->getParent()
  388. /// \post
  389. /// if returns true:
  390. /// for I in all mutated/inserted instructions:
  391. /// !isPreISelGenericOpcode(I.getOpcode())
  392. virtual bool select(MachineInstr &I) = 0;
  393. CodeGenCoverage *CoverageInfo = nullptr;
  394. GISelKnownBits *KnownBits = nullptr;
  395. MachineFunction *MF = nullptr;
  396. ProfileSummaryInfo *PSI = nullptr;
  397. BlockFrequencyInfo *BFI = nullptr;
  398. // For some predicates, we need to track the current MBB.
  399. MachineBasicBlock *CurMBB = nullptr;
  400. virtual void setupGeneratedPerFunctionState(MachineFunction &MF) {
  401. llvm_unreachable("TableGen should have emitted implementation");
  402. }
  403. /// Setup per-MF selector state.
  404. virtual void setupMF(MachineFunction &mf, GISelKnownBits *KB,
  405. CodeGenCoverage &covinfo, ProfileSummaryInfo *psi,
  406. BlockFrequencyInfo *bfi) {
  407. CoverageInfo = &covinfo;
  408. KnownBits = KB;
  409. MF = &mf;
  410. PSI = psi;
  411. BFI = bfi;
  412. CurMBB = nullptr;
  413. setupGeneratedPerFunctionState(mf);
  414. }
  415. protected:
  416. using ComplexRendererFns =
  417. std::optional<SmallVector<std::function<void(MachineInstrBuilder &)>, 4>>;
  418. using RecordedMIVector = SmallVector<MachineInstr *, 4>;
  419. using NewMIVector = SmallVector<MachineInstrBuilder, 4>;
  420. struct MatcherState {
  421. std::vector<ComplexRendererFns::value_type> Renderers;
  422. RecordedMIVector MIs;
  423. DenseMap<unsigned, unsigned> TempRegisters;
  424. /// Named operands that predicate with 'let PredicateCodeUsesOperands = 1'
  425. /// referenced in its argument list. Operands are inserted at index set by
  426. /// emitter, it corresponds to the order in which names appear in argument
  427. /// list. Currently such predicates don't have more then 3 arguments.
  428. std::array<const MachineOperand *, 3> RecordedOperands;
  429. MatcherState(unsigned MaxRenderers);
  430. };
  431. bool shouldOptForSize(const MachineFunction *MF) const {
  432. const auto &F = MF->getFunction();
  433. return F.hasOptSize() || F.hasMinSize() ||
  434. (PSI && BFI && CurMBB && llvm::shouldOptForSize(*CurMBB, PSI, BFI));
  435. }
  436. public:
  437. template <class PredicateBitset, class ComplexMatcherMemFn,
  438. class CustomRendererFn>
  439. struct ISelInfoTy {
  440. ISelInfoTy(const LLT *TypeObjects, size_t NumTypeObjects,
  441. const PredicateBitset *FeatureBitsets,
  442. const ComplexMatcherMemFn *ComplexPredicates,
  443. const CustomRendererFn *CustomRenderers)
  444. : TypeObjects(TypeObjects),
  445. FeatureBitsets(FeatureBitsets),
  446. ComplexPredicates(ComplexPredicates),
  447. CustomRenderers(CustomRenderers) {
  448. for (size_t I = 0; I < NumTypeObjects; ++I)
  449. TypeIDMap[TypeObjects[I]] = I;
  450. }
  451. const LLT *TypeObjects;
  452. const PredicateBitset *FeatureBitsets;
  453. const ComplexMatcherMemFn *ComplexPredicates;
  454. const CustomRendererFn *CustomRenderers;
  455. SmallDenseMap<LLT, unsigned, 64> TypeIDMap;
  456. };
  457. protected:
  458. InstructionSelector();
  459. /// Execute a given matcher table and return true if the match was successful
  460. /// and false otherwise.
  461. template <class TgtInstructionSelector, class PredicateBitset,
  462. class ComplexMatcherMemFn, class CustomRendererFn>
  463. bool executeMatchTable(
  464. TgtInstructionSelector &ISel, NewMIVector &OutMIs, MatcherState &State,
  465. const ISelInfoTy<PredicateBitset, ComplexMatcherMemFn, CustomRendererFn>
  466. &ISelInfo,
  467. const int64_t *MatchTable, const TargetInstrInfo &TII,
  468. MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI,
  469. const RegisterBankInfo &RBI, const PredicateBitset &AvailableFeatures,
  470. CodeGenCoverage &CoverageInfo) const;
  471. virtual const int64_t *getMatchTable() const {
  472. llvm_unreachable("Should have been overridden by tablegen if used");
  473. }
  474. virtual bool testImmPredicate_I64(unsigned, int64_t) const {
  475. llvm_unreachable(
  476. "Subclasses must override this with a tablegen-erated function");
  477. }
  478. virtual bool testImmPredicate_APInt(unsigned, const APInt &) const {
  479. llvm_unreachable(
  480. "Subclasses must override this with a tablegen-erated function");
  481. }
  482. virtual bool testImmPredicate_APFloat(unsigned, const APFloat &) const {
  483. llvm_unreachable(
  484. "Subclasses must override this with a tablegen-erated function");
  485. }
  486. virtual bool testMIPredicate_MI(
  487. unsigned, const MachineInstr &,
  488. const std::array<const MachineOperand *, 3> &Operands) const {
  489. llvm_unreachable(
  490. "Subclasses must override this with a tablegen-erated function");
  491. }
  492. bool isOperandImmEqual(const MachineOperand &MO, int64_t Value,
  493. const MachineRegisterInfo &MRI) const;
  494. /// Return true if the specified operand is a G_PTR_ADD with a G_CONSTANT on the
  495. /// right-hand side. GlobalISel's separation of pointer and integer types
  496. /// means that we don't need to worry about G_OR with equivalent semantics.
  497. bool isBaseWithConstantOffset(const MachineOperand &Root,
  498. const MachineRegisterInfo &MRI) const;
  499. /// Return true if MI can obviously be folded into IntoMI.
  500. /// MI and IntoMI do not need to be in the same basic blocks, but MI must
  501. /// preceed IntoMI.
  502. bool isObviouslySafeToFold(MachineInstr &MI, MachineInstr &IntoMI) const;
  503. };
  504. } // end namespace llvm
  505. #endif // LLVM_CODEGEN_GLOBALISEL_INSTRUCTIONSELECTOR_H
  506. #ifdef __GNUC__
  507. #pragma GCC diagnostic pop
  508. #endif