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