1 //===-- PPC.h - Top-level interface for PowerPC Target ----------*- 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 //
9 // This file contains the entry points for global functions defined in the LLVM
10 // PowerPC back-end.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_LIB_TARGET_POWERPC_PPC_H
15 #define LLVM_LIB_TARGET_POWERPC_PPC_H
16 
17 #include "llvm/Support/CodeGen.h"
18 
19 // GCC #defines PPC on Linux but we use it as our namespace name
20 #undef PPC
21 
22 namespace llvm {
23 class PPCRegisterBankInfo;
24 class PPCSubtarget;
25 class PPCTargetMachine;
26 class PassRegistry;
27 class FunctionPass;
28 class InstructionSelector;
29 class MachineInstr;
30 class MachineOperand;
31 class AsmPrinter;
32 class MCInst;
33 class MCOperand;
34 class ModulePass;
35 
36 FunctionPass *createPPCCTRLoops();
37 #ifndef NDEBUG
38   FunctionPass *createPPCCTRLoopsVerify();
39 #endif
40   FunctionPass *createPPCLoopInstrFormPrepPass(PPCTargetMachine &TM);
41   FunctionPass *createPPCTOCRegDepsPass();
42   FunctionPass *createPPCEarlyReturnPass();
43   FunctionPass *createPPCVSXCopyPass();
44   FunctionPass *createPPCVSXFMAMutatePass();
45   FunctionPass *createPPCVSXSwapRemovalPass();
46   FunctionPass *createPPCReduceCRLogicalsPass();
47   FunctionPass *createPPCMIPeepholePass();
48   FunctionPass *createPPCBranchSelectionPass();
49   FunctionPass *createPPCBranchCoalescingPass();
50   FunctionPass *createPPCISelDag(PPCTargetMachine &TM, CodeGenOpt::Level OL);
51   FunctionPass *createPPCTLSDynamicCallPass();
52   FunctionPass *createPPCBoolRetToIntPass();
53   FunctionPass *createPPCExpandISELPass();
54   FunctionPass *createPPCPreEmitPeepholePass();
55   void LowerPPCMachineInstrToMCInst(const MachineInstr *MI, MCInst &OutMI,
56                                     AsmPrinter &AP);
57   bool LowerPPCMachineOperandToMCOperand(const MachineOperand &MO,
58                                          MCOperand &OutMO, AsmPrinter &AP);
59 
60   void initializePPCCTRLoopsPass(PassRegistry&);
61 #ifndef NDEBUG
62   void initializePPCCTRLoopsVerifyPass(PassRegistry&);
63 #endif
64   void initializePPCLoopInstrFormPrepPass(PassRegistry&);
65   void initializePPCTOCRegDepsPass(PassRegistry&);
66   void initializePPCEarlyReturnPass(PassRegistry&);
67   void initializePPCVSXCopyPass(PassRegistry&);
68   void initializePPCVSXFMAMutatePass(PassRegistry&);
69   void initializePPCVSXSwapRemovalPass(PassRegistry&);
70   void initializePPCReduceCRLogicalsPass(PassRegistry&);
71   void initializePPCBSelPass(PassRegistry&);
72   void initializePPCBranchCoalescingPass(PassRegistry&);
73   void initializePPCBoolRetToIntPass(PassRegistry&);
74   void initializePPCExpandISELPass(PassRegistry &);
75   void initializePPCPreEmitPeepholePass(PassRegistry &);
76   void initializePPCTLSDynamicCallPass(PassRegistry &);
77   void initializePPCMIPeepholePass(PassRegistry&);
78 
79   extern char &PPCVSXFMAMutateID;
80 
81   ModulePass *createPPCLowerMASSVEntriesPass();
82   void initializePPCLowerMASSVEntriesPass(PassRegistry &);
83   extern char &PPCLowerMASSVEntriesID;
84 
85   InstructionSelector *
86   createPPCInstructionSelector(const PPCTargetMachine &, const PPCSubtarget &,
87                                const PPCRegisterBankInfo &);
88   namespace PPCII {
89 
90   /// Target Operand Flag enum.
91   enum TOF {
92     //===------------------------------------------------------------------===//
93     // PPC Specific MachineOperand flags.
94     MO_NO_FLAG,
95 
96     /// On a symbol operand "FOO", this indicates that the reference is actually
97     /// to "FOO@plt".  This is used for calls and jumps to external functions
98     /// and for PIC calls on 32-bit ELF systems.
99     MO_PLT = 1,
100 
101     /// MO_PIC_FLAG - If this bit is set, the symbol reference is relative to
102     /// the function's picbase, e.g. lo16(symbol-picbase).
103     MO_PIC_FLAG = 2,
104 
105     /// MO_PCREL_FLAG - If this bit is set, the symbol reference is relative to
106     /// the current instruction address(pc), e.g., var@pcrel. Fixup is VK_PCREL.
107     MO_PCREL_FLAG = 4,
108 
109     /// MO_GOT_FLAG - If this bit is set the symbol reference is to be computed
110     /// via the GOT. For example when combined with the MO_PCREL_FLAG it should
111     /// produce the relocation @got@pcrel. Fixup is VK_PPC_GOT_PCREL.
112     MO_GOT_FLAG = 8,
113 
114     // MO_PCREL_OPT_FLAG - If this bit is set the operand is part of a
115     // PC Relative linker optimization.
116     MO_PCREL_OPT_FLAG = 16,
117 
118     /// MO_TLSGD_FLAG - If this bit is set the symbol reference is relative to
119     /// TLS General Dynamic model.
120     MO_TLSGD_FLAG = 32,
121 
122     /// MO_TPREL_FLAG - If this bit is set the symbol reference is relative to
123     /// TLS Initial Exec model.
124     MO_TPREL_FLAG = 64,
125 
126     /// MO_TLSLD_FLAG - If this bit is set the symbol reference is relative to
127     /// TLS Local Dynamic model.
128     MO_TLSLD_FLAG = 128,
129 
130     /// MO_GOT_TLSGD_PCREL_FLAG - A combintaion of flags, if these bits are set
131     /// they should produce the relocation @got@tlsgd@pcrel.
132     /// Fix up is VK_PPC_GOT_TLSGD_PCREL
133     MO_GOT_TLSGD_PCREL_FLAG = MO_PCREL_FLAG | MO_GOT_FLAG | MO_TLSGD_FLAG,
134 
135     /// MO_GOT_TLSLD_PCREL_FLAG - A combintaion of flags, if these bits are set
136     /// they should produce the relocation @got@tlsld@pcrel.
137     /// Fix up is VK_PPC_GOT_TLSLD_PCREL
138     MO_GOT_TLSLD_PCREL_FLAG = MO_PCREL_FLAG | MO_GOT_FLAG | MO_TLSLD_FLAG,
139 
140     /// MO_GOT_TPREL_PCREL_FLAG - A combintaion of flags, if these bits are set
141     /// they should produce the relocation @got@tprel@pcrel.
142     /// Fix up is VK_PPC_GOT_TPREL_PCREL
143     MO_GOT_TPREL_PCREL_FLAG = MO_GOT_FLAG | MO_TPREL_FLAG | MO_PCREL_FLAG,
144 
145     /// The next are not flags but distinct values.
146     MO_ACCESS_MASK = 0xf00,
147 
148     /// MO_LO, MO_HA - lo16(symbol) and ha16(symbol)
149     MO_LO = 1 << 8,
150     MO_HA = 2 << 8,
151 
152     MO_TPREL_LO = 4 << 8,
153     MO_TPREL_HA = 3 << 8,
154 
155     /// These values identify relocations on immediates folded
156     /// into memory operations.
157     MO_DTPREL_LO = 5 << 8,
158     MO_TLSLD_LO = 6 << 8,
159     MO_TOC_LO = 7 << 8,
160 
161     // Symbol for VK_PPC_TLS fixup attached to an ADD instruction
162     MO_TLS = 8 << 8
163   };
164   } // end namespace PPCII
165 
166 } // end namespace llvm;
167 
168 #endif
169