InstructionSelector.h 20 KB

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