xref: /freebsd/contrib/llvm-project/llvm/lib/Target/PowerPC/GISel/PPCInstructionSelector.cpp (revision 77013d11e6483b970af25e13c9b892075742f7e5)
1 //===- PPCInstructionSelector.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 /// PowerPC.
11 //===----------------------------------------------------------------------===//
12 
13 #include "PPCInstrInfo.h"
14 #include "PPCRegisterBankInfo.h"
15 #include "PPCSubtarget.h"
16 #include "PPCTargetMachine.h"
17 #include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
18 #include "llvm/CodeGen/GlobalISel/InstructionSelectorImpl.h"
19 #include "llvm/CodeGen/MachineFunction.h"
20 #include "llvm/IR/IntrinsicsPowerPC.h"
21 #include "llvm/Support/Debug.h"
22 
23 #define DEBUG_TYPE "ppc-gisel"
24 
25 using namespace llvm;
26 
27 namespace {
28 
29 #define GET_GLOBALISEL_PREDICATE_BITSET
30 #include "PPCGenGlobalISel.inc"
31 #undef GET_GLOBALISEL_PREDICATE_BITSET
32 
33 class PPCInstructionSelector : public InstructionSelector {
34 public:
35   PPCInstructionSelector(const PPCTargetMachine &TM, const PPCSubtarget &STI,
36                          const PPCRegisterBankInfo &RBI);
37 
38   bool select(MachineInstr &I) override;
39   static const char *getName() { return DEBUG_TYPE; }
40 
41 private:
42   /// tblgen generated 'select' implementation that is used as the initial
43   /// selector for the patterns that do not require complex C++.
44   bool selectImpl(MachineInstr &I, CodeGenCoverage &CoverageInfo) const;
45 
46   const PPCInstrInfo &TII;
47   const PPCRegisterInfo &TRI;
48   const PPCRegisterBankInfo &RBI;
49 
50 #define GET_GLOBALISEL_PREDICATES_DECL
51 #include "PPCGenGlobalISel.inc"
52 #undef GET_GLOBALISEL_PREDICATES_DECL
53 
54 #define GET_GLOBALISEL_TEMPORARIES_DECL
55 #include "PPCGenGlobalISel.inc"
56 #undef GET_GLOBALISEL_TEMPORARIES_DECL
57 };
58 
59 } // end anonymous namespace
60 
61 #define GET_GLOBALISEL_IMPL
62 #include "PPCGenGlobalISel.inc"
63 #undef GET_GLOBALISEL_IMPL
64 
65 PPCInstructionSelector::PPCInstructionSelector(const PPCTargetMachine &TM,
66                                                const PPCSubtarget &STI,
67                                                const PPCRegisterBankInfo &RBI)
68     : InstructionSelector(), TII(*STI.getInstrInfo()),
69       TRI(*STI.getRegisterInfo()), RBI(RBI),
70 #define GET_GLOBALISEL_PREDICATES_INIT
71 #include "PPCGenGlobalISel.inc"
72 #undef GET_GLOBALISEL_PREDICATES_INIT
73 #define GET_GLOBALISEL_TEMPORARIES_INIT
74 #include "PPCGenGlobalISel.inc"
75 #undef GET_GLOBALISEL_TEMPORARIES_INIT
76 {
77 }
78 
79 bool PPCInstructionSelector::select(MachineInstr &I) {
80   if (selectImpl(I, *CoverageInfo))
81     return true;
82   return false;
83 }
84 
85 namespace llvm {
86 InstructionSelector *
87 createPPCInstructionSelector(const PPCTargetMachine &TM,
88                              const PPCSubtarget &Subtarget,
89                              const PPCRegisterBankInfo &RBI) {
90   return new PPCInstructionSelector(TM, Subtarget, RBI);
91 }
92 } // end namespace llvm
93