xref: /freebsd/contrib/llvm-project/llvm/lib/Target/M68k/GISel/M68kInstructionSelector.cpp (revision f126890ac5386406dadf7c4cfa9566cbb56537c5)
1 //===-- M68kInstructionSelector.cpp -----------------------------*- C++ -*-===//
2 //===----------------------------------------------------------------------===//
3 /// \file
4 /// This file implements the targeting of the InstructionSelector class for
5 /// M68k.
6 /// \todo This should be generated by TableGen.
7 //===----------------------------------------------------------------------===//
8 
9 #include "M68kRegisterBankInfo.h"
10 #include "M68kSubtarget.h"
11 #include "M68kTargetMachine.h"
12 #include "llvm/CodeGen/GlobalISel/GIMatchTableExecutorImpl.h"
13 #include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
14 #include "llvm/Support/Debug.h"
15 
16 #define DEBUG_TYPE "m68k-isel"
17 
18 using namespace llvm;
19 
20 #define GET_GLOBALISEL_PREDICATE_BITSET
21 #include "M68kGenGlobalISel.inc"
22 #undef GET_GLOBALISEL_PREDICATE_BITSET
23 
24 namespace {
25 
26 class M68kInstructionSelector : public InstructionSelector {
27 public:
28   M68kInstructionSelector(const M68kTargetMachine &TM, const M68kSubtarget &STI,
29                           const M68kRegisterBankInfo &RBI);
30 
31   bool select(MachineInstr &I) override;
32   static const char *getName() { return DEBUG_TYPE; }
33 
34 private:
35   bool selectImpl(MachineInstr &I, CodeGenCoverage &CoverageInfo) const;
36 
37   const M68kTargetMachine &TM;
38   const M68kInstrInfo &TII;
39   const M68kRegisterInfo &TRI;
40   const M68kRegisterBankInfo &RBI;
41 
42 #define GET_GLOBALISEL_PREDICATES_DECL
43 #include "M68kGenGlobalISel.inc"
44 #undef GET_GLOBALISEL_PREDICATES_DECL
45 
46 #define GET_GLOBALISEL_TEMPORARIES_DECL
47 #include "M68kGenGlobalISel.inc"
48 #undef GET_GLOBALISEL_TEMPORARIES_DECL
49 };
50 
51 } // end anonymous namespace
52 
53 #define GET_GLOBALISEL_IMPL
54 #include "M68kGenGlobalISel.inc"
55 #undef GET_GLOBALISEL_IMPL
56 
57 M68kInstructionSelector::M68kInstructionSelector(
58     const M68kTargetMachine &TM, const M68kSubtarget &STI,
59     const M68kRegisterBankInfo &RBI)
60     : InstructionSelector(), TM(TM), TII(*STI.getInstrInfo()),
61       TRI(*STI.getRegisterInfo()), RBI(RBI),
62 
63 #define GET_GLOBALISEL_PREDICATES_INIT
64 #include "M68kGenGlobalISel.inc"
65 #undef GET_GLOBALISEL_PREDICATES_INIT
66 #define GET_GLOBALISEL_TEMPORARIES_INIT
67 #include "M68kGenGlobalISel.inc"
68 #undef GET_GLOBALISEL_TEMPORARIES_INIT
69 {
70 }
71 
72 bool M68kInstructionSelector::select(MachineInstr &I) {
73   // Certain non-generic instructions also need some special handling.
74   if (!isPreISelGenericOpcode(I.getOpcode()))
75     return true;
76 
77   if (selectImpl(I, *CoverageInfo))
78     return true;
79 
80   return false;
81 }
82 
83 namespace llvm {
84 InstructionSelector *
85 createM68kInstructionSelector(const M68kTargetMachine &TM,
86                               const M68kSubtarget &Subtarget,
87                               const M68kRegisterBankInfo &RBI) {
88   return new M68kInstructionSelector(TM, Subtarget, RBI);
89 }
90 } // end namespace llvm
91