]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCCodeEmitter.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / PowerPC / MCTargetDesc / PPCMCCodeEmitter.h
1 //===-- PPCMCCodeEmitter.h - Convert PPC code to machine code -------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the PPCMCCodeEmitter class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_LIB_TARGET_PPC_MCCODEEMITTER_PPCCODEEMITTER_H
15 #define LLVM_LIB_TARGET_PPC_MCCODEEMITTER_PPCCODEEMITTER_H
16
17 #include "llvm/MC/MCAsmInfo.h"
18 #include "llvm/MC/MCCodeEmitter.h"
19 #include "llvm/MC/MCSubtargetInfo.h"
20 #include "llvm/MC/MCInstrInfo.h"
21 #include "llvm/MC/MCContext.h"
22 #include "llvm/MC/MCInst.h"
23
24 namespace llvm {
25
26 class PPCMCCodeEmitter : public MCCodeEmitter {
27   const MCInstrInfo &MCII;
28   const MCContext &CTX;
29   bool IsLittleEndian;
30
31 public:
32   PPCMCCodeEmitter(const MCInstrInfo &mcii, MCContext &ctx)
33       : MCII(mcii), CTX(ctx),
34         IsLittleEndian(ctx.getAsmInfo()->isLittleEndian()) {}
35   PPCMCCodeEmitter(const PPCMCCodeEmitter &) = delete;
36   void operator=(const PPCMCCodeEmitter &) = delete;
37   ~PPCMCCodeEmitter() override = default;
38
39   unsigned getDirectBrEncoding(const MCInst &MI, unsigned OpNo,
40                                SmallVectorImpl<MCFixup> &Fixups,
41                                const MCSubtargetInfo &STI) const;
42   unsigned getCondBrEncoding(const MCInst &MI, unsigned OpNo,
43                              SmallVectorImpl<MCFixup> &Fixups,
44                              const MCSubtargetInfo &STI) const;
45   unsigned getAbsDirectBrEncoding(const MCInst &MI, unsigned OpNo,
46                                   SmallVectorImpl<MCFixup> &Fixups,
47                                   const MCSubtargetInfo &STI) const;
48   unsigned getAbsCondBrEncoding(const MCInst &MI, unsigned OpNo,
49                                 SmallVectorImpl<MCFixup> &Fixups,
50                                 const MCSubtargetInfo &STI) const;
51   unsigned getImm16Encoding(const MCInst &MI, unsigned OpNo,
52                             SmallVectorImpl<MCFixup> &Fixups,
53                             const MCSubtargetInfo &STI) const;
54   unsigned getMemRIEncoding(const MCInst &MI, unsigned OpNo,
55                             SmallVectorImpl<MCFixup> &Fixups,
56                             const MCSubtargetInfo &STI) const;
57   unsigned getMemRIXEncoding(const MCInst &MI, unsigned OpNo,
58                              SmallVectorImpl<MCFixup> &Fixups,
59                              const MCSubtargetInfo &STI) const;
60   unsigned getMemRIX16Encoding(const MCInst &MI, unsigned OpNo,
61                                SmallVectorImpl<MCFixup> &Fixups,
62                                const MCSubtargetInfo &STI) const;
63   unsigned getSPE8DisEncoding(const MCInst &MI, unsigned OpNo,
64                               SmallVectorImpl<MCFixup> &Fixups,
65                               const MCSubtargetInfo &STI) const;
66   unsigned getSPE4DisEncoding(const MCInst &MI, unsigned OpNo,
67                               SmallVectorImpl<MCFixup> &Fixups,
68                               const MCSubtargetInfo &STI) const;
69   unsigned getSPE2DisEncoding(const MCInst &MI, unsigned OpNo,
70                               SmallVectorImpl<MCFixup> &Fixups,
71                               const MCSubtargetInfo &STI) const;
72   unsigned getTLSRegEncoding(const MCInst &MI, unsigned OpNo,
73                              SmallVectorImpl<MCFixup> &Fixups,
74                              const MCSubtargetInfo &STI) const;
75   unsigned getTLSCallEncoding(const MCInst &MI, unsigned OpNo,
76                               SmallVectorImpl<MCFixup> &Fixups,
77                               const MCSubtargetInfo &STI) const;
78   unsigned get_crbitm_encoding(const MCInst &MI, unsigned OpNo,
79                                SmallVectorImpl<MCFixup> &Fixups,
80                                const MCSubtargetInfo &STI) const;
81
82   /// getMachineOpValue - Return binary encoding of operand. If the machine
83   /// operand requires relocation, record the relocation and return zero.
84   unsigned getMachineOpValue(const MCInst &MI, const MCOperand &MO,
85                              SmallVectorImpl<MCFixup> &Fixups,
86                              const MCSubtargetInfo &STI) const;
87
88   // getBinaryCodeForInstr - TableGen'erated function for getting the
89   // binary encoding for an instruction.
90   uint64_t getBinaryCodeForInstr(const MCInst &MI,
91                                  SmallVectorImpl<MCFixup> &Fixups,
92                                  const MCSubtargetInfo &STI) const;
93
94   void encodeInstruction(const MCInst &MI, raw_ostream &OS,
95                          SmallVectorImpl<MCFixup> &Fixups,
96                          const MCSubtargetInfo &STI) const override;
97
98   // Get the number of bytes used to encode the given MCInst.
99   unsigned getInstSizeInBytes(const MCInst &MI) const;
100
101 private:
102   uint64_t computeAvailableFeatures(const FeatureBitset &FB) const;
103   void verifyInstructionPredicates(const MCInst &MI,
104                                    uint64_t AvailableFeatures) const;
105 };
106
107 } // namespace llvm
108
109 #endif // LLVM_LIB_TARGET_PPC_MCCODEEMITTER_PPCCODEEMITTER_H