RISCVInstructionSelector.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //===-- RISCVInstructionSelector.cpp -----------------------------*- C++ -*-==//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. /// \file
  9. /// This file implements the targeting of the InstructionSelector class for
  10. /// RISCV.
  11. /// \todo This should be generated by TableGen.
  12. //===----------------------------------------------------------------------===//
  13. #include "RISCVRegisterBankInfo.h"
  14. #include "RISCVSubtarget.h"
  15. #include "RISCVTargetMachine.h"
  16. #include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
  17. #include "llvm/CodeGen/GlobalISel/InstructionSelectorImpl.h"
  18. #include "llvm/IR/IntrinsicsRISCV.h"
  19. #include "llvm/Support/Debug.h"
  20. #define DEBUG_TYPE "riscv-isel"
  21. using namespace llvm;
  22. #define GET_GLOBALISEL_PREDICATE_BITSET
  23. #include "RISCVGenGlobalISel.inc"
  24. #undef GET_GLOBALISEL_PREDICATE_BITSET
  25. namespace {
  26. class RISCVInstructionSelector : public InstructionSelector {
  27. public:
  28. RISCVInstructionSelector(const RISCVTargetMachine &TM,
  29. const RISCVSubtarget &STI,
  30. const RISCVRegisterBankInfo &RBI);
  31. bool select(MachineInstr &I) override;
  32. static const char *getName() { return DEBUG_TYPE; }
  33. private:
  34. bool selectImpl(MachineInstr &I, CodeGenCoverage &CoverageInfo) const;
  35. const RISCVSubtarget &STI;
  36. const RISCVInstrInfo &TII;
  37. const RISCVRegisterInfo &TRI;
  38. const RISCVRegisterBankInfo &RBI;
  39. // FIXME: This is necessary because DAGISel uses "Subtarget->" and GlobalISel
  40. // uses "STI." in the code generated by TableGen. We need to unify the name of
  41. // Subtarget variable.
  42. const RISCVSubtarget *Subtarget = &STI;
  43. #define GET_GLOBALISEL_PREDICATES_DECL
  44. #include "RISCVGenGlobalISel.inc"
  45. #undef GET_GLOBALISEL_PREDICATES_DECL
  46. #define GET_GLOBALISEL_TEMPORARIES_DECL
  47. #include "RISCVGenGlobalISel.inc"
  48. #undef GET_GLOBALISEL_TEMPORARIES_DECL
  49. };
  50. } // end anonymous namespace
  51. #define GET_GLOBALISEL_IMPL
  52. #include "RISCVGenGlobalISel.inc"
  53. #undef GET_GLOBALISEL_IMPL
  54. RISCVInstructionSelector::RISCVInstructionSelector(
  55. const RISCVTargetMachine &TM, const RISCVSubtarget &STI,
  56. const RISCVRegisterBankInfo &RBI)
  57. : STI(STI), TII(*STI.getInstrInfo()), TRI(*STI.getRegisterInfo()), RBI(RBI),
  58. #define GET_GLOBALISEL_PREDICATES_INIT
  59. #include "RISCVGenGlobalISel.inc"
  60. #undef GET_GLOBALISEL_PREDICATES_INIT
  61. #define GET_GLOBALISEL_TEMPORARIES_INIT
  62. #include "RISCVGenGlobalISel.inc"
  63. #undef GET_GLOBALISEL_TEMPORARIES_INIT
  64. {
  65. }
  66. bool RISCVInstructionSelector::select(MachineInstr &I) {
  67. if (!isPreISelGenericOpcode(I.getOpcode())) {
  68. // Certain non-generic instructions also need some special handling.
  69. return true;
  70. }
  71. if (selectImpl(I, *CoverageInfo))
  72. return true;
  73. return false;
  74. }
  75. namespace llvm {
  76. InstructionSelector *
  77. createRISCVInstructionSelector(const RISCVTargetMachine &TM,
  78. RISCVSubtarget &Subtarget,
  79. RISCVRegisterBankInfo &RBI) {
  80. return new RISCVInstructionSelector(TM, Subtarget, RBI);
  81. }
  82. } // end namespace llvm