xref: /freebsd-src/contrib/llvm-project/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCCodeEmitter.h (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
10b57cec5SDimitry Andric //===-- PPCMCCodeEmitter.h - Convert PPC code to machine code -------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file implements the PPCMCCodeEmitter class.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #ifndef LLVM_LIB_TARGET_PPC_MCCODEEMITTER_PPCCODEEMITTER_H
140b57cec5SDimitry Andric #define LLVM_LIB_TARGET_PPC_MCCODEEMITTER_PPCCODEEMITTER_H
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric #include "llvm/MC/MCAsmInfo.h"
170b57cec5SDimitry Andric #include "llvm/MC/MCCodeEmitter.h"
180b57cec5SDimitry Andric #include "llvm/MC/MCSubtargetInfo.h"
190b57cec5SDimitry Andric #include "llvm/MC/MCInstrInfo.h"
200b57cec5SDimitry Andric #include "llvm/MC/MCContext.h"
210b57cec5SDimitry Andric #include "llvm/MC/MCInst.h"
220b57cec5SDimitry Andric 
230b57cec5SDimitry Andric namespace llvm {
240b57cec5SDimitry Andric 
250b57cec5SDimitry Andric class PPCMCCodeEmitter : public MCCodeEmitter {
260b57cec5SDimitry Andric   const MCInstrInfo &MCII;
270b57cec5SDimitry Andric   const MCContext &CTX;
280b57cec5SDimitry Andric   bool IsLittleEndian;
290b57cec5SDimitry Andric 
300b57cec5SDimitry Andric public:
PPCMCCodeEmitter(const MCInstrInfo & mcii,MCContext & ctx)310b57cec5SDimitry Andric   PPCMCCodeEmitter(const MCInstrInfo &mcii, MCContext &ctx)
320b57cec5SDimitry Andric       : MCII(mcii), CTX(ctx),
330b57cec5SDimitry Andric         IsLittleEndian(ctx.getAsmInfo()->isLittleEndian()) {}
340b57cec5SDimitry Andric   PPCMCCodeEmitter(const PPCMCCodeEmitter &) = delete;
350b57cec5SDimitry Andric   void operator=(const PPCMCCodeEmitter &) = delete;
360b57cec5SDimitry Andric   ~PPCMCCodeEmitter() override = default;
370b57cec5SDimitry Andric 
380b57cec5SDimitry Andric   unsigned getDirectBrEncoding(const MCInst &MI, unsigned OpNo,
390b57cec5SDimitry Andric                                SmallVectorImpl<MCFixup> &Fixups,
400b57cec5SDimitry Andric                                const MCSubtargetInfo &STI) const;
410b57cec5SDimitry Andric   unsigned getCondBrEncoding(const MCInst &MI, unsigned OpNo,
420b57cec5SDimitry Andric                              SmallVectorImpl<MCFixup> &Fixups,
430b57cec5SDimitry Andric                              const MCSubtargetInfo &STI) const;
440b57cec5SDimitry Andric   unsigned getAbsDirectBrEncoding(const MCInst &MI, unsigned OpNo,
450b57cec5SDimitry Andric                                   SmallVectorImpl<MCFixup> &Fixups,
460b57cec5SDimitry Andric                                   const MCSubtargetInfo &STI) const;
470b57cec5SDimitry Andric   unsigned getAbsCondBrEncoding(const MCInst &MI, unsigned OpNo,
480b57cec5SDimitry Andric                                 SmallVectorImpl<MCFixup> &Fixups,
490b57cec5SDimitry Andric                                 const MCSubtargetInfo &STI) const;
500b57cec5SDimitry Andric   unsigned getImm16Encoding(const MCInst &MI, unsigned OpNo,
510b57cec5SDimitry Andric                             SmallVectorImpl<MCFixup> &Fixups,
520b57cec5SDimitry Andric                             const MCSubtargetInfo &STI) const;
535ffd83dbSDimitry Andric   uint64_t getImm34Encoding(const MCInst &MI, unsigned OpNo,
545ffd83dbSDimitry Andric                             SmallVectorImpl<MCFixup> &Fixups,
55e8d8bef9SDimitry Andric                             const MCSubtargetInfo &STI,
56e8d8bef9SDimitry Andric                             MCFixupKind Fixup) const;
57e8d8bef9SDimitry Andric   uint64_t getImm34EncodingNoPCRel(const MCInst &MI, unsigned OpNo,
58e8d8bef9SDimitry Andric                                    SmallVectorImpl<MCFixup> &Fixups,
59e8d8bef9SDimitry Andric                                    const MCSubtargetInfo &STI) const;
60e8d8bef9SDimitry Andric   uint64_t getImm34EncodingPCRel(const MCInst &MI, unsigned OpNo,
61e8d8bef9SDimitry Andric                                  SmallVectorImpl<MCFixup> &Fixups,
625ffd83dbSDimitry Andric                                  const MCSubtargetInfo &STI) const;
6306c3fb27SDimitry Andric   unsigned getDispRIEncoding(const MCInst &MI, unsigned OpNo,
640b57cec5SDimitry Andric                              SmallVectorImpl<MCFixup> &Fixups,
650b57cec5SDimitry Andric                              const MCSubtargetInfo &STI) const;
6606c3fb27SDimitry Andric   unsigned getDispRIXEncoding(const MCInst &MI, unsigned OpNo,
670b57cec5SDimitry Andric                               SmallVectorImpl<MCFixup> &Fixups,
680b57cec5SDimitry Andric                               const MCSubtargetInfo &STI) const;
6906c3fb27SDimitry Andric   unsigned getDispRIX16Encoding(const MCInst &MI, unsigned OpNo,
700b57cec5SDimitry Andric                                 SmallVectorImpl<MCFixup> &Fixups,
710b57cec5SDimitry Andric                                 const MCSubtargetInfo &STI) const;
7206c3fb27SDimitry Andric   unsigned getDispRIHashEncoding(const MCInst &MI, unsigned OpNo,
73fe6060f1SDimitry Andric                                  SmallVectorImpl<MCFixup> &Fixups,
74fe6060f1SDimitry Andric                                  const MCSubtargetInfo &STI) const;
7506c3fb27SDimitry Andric   uint64_t getDispRI34PCRelEncoding(const MCInst &MI, unsigned OpNo,
765ffd83dbSDimitry Andric                                     SmallVectorImpl<MCFixup> &Fixups,
775ffd83dbSDimitry Andric                                     const MCSubtargetInfo &STI) const;
7806c3fb27SDimitry Andric   uint64_t getDispRI34Encoding(const MCInst &MI, unsigned OpNo,
795ffd83dbSDimitry Andric                                SmallVectorImpl<MCFixup> &Fixups,
805ffd83dbSDimitry Andric                                const MCSubtargetInfo &STI) const;
8106c3fb27SDimitry Andric   unsigned getDispSPE8Encoding(const MCInst &MI, unsigned OpNo,
820b57cec5SDimitry Andric                                SmallVectorImpl<MCFixup> &Fixups,
830b57cec5SDimitry Andric                                const MCSubtargetInfo &STI) const;
8406c3fb27SDimitry Andric   unsigned getDispSPE4Encoding(const MCInst &MI, unsigned OpNo,
850b57cec5SDimitry Andric                                SmallVectorImpl<MCFixup> &Fixups,
860b57cec5SDimitry Andric                                const MCSubtargetInfo &STI) const;
8706c3fb27SDimitry Andric   unsigned getDispSPE2Encoding(const MCInst &MI, unsigned OpNo,
880b57cec5SDimitry Andric                                SmallVectorImpl<MCFixup> &Fixups,
890b57cec5SDimitry Andric                                const MCSubtargetInfo &STI) const;
900b57cec5SDimitry Andric   unsigned getTLSRegEncoding(const MCInst &MI, unsigned OpNo,
910b57cec5SDimitry Andric                              SmallVectorImpl<MCFixup> &Fixups,
920b57cec5SDimitry Andric                              const MCSubtargetInfo &STI) const;
930b57cec5SDimitry Andric   unsigned getTLSCallEncoding(const MCInst &MI, unsigned OpNo,
940b57cec5SDimitry Andric                               SmallVectorImpl<MCFixup> &Fixups,
950b57cec5SDimitry Andric                               const MCSubtargetInfo &STI) const;
960b57cec5SDimitry Andric   unsigned get_crbitm_encoding(const MCInst &MI, unsigned OpNo,
970b57cec5SDimitry Andric                                SmallVectorImpl<MCFixup> &Fixups,
980b57cec5SDimitry Andric                                const MCSubtargetInfo &STI) const;
99e8d8bef9SDimitry Andric   unsigned getVSRpEvenEncoding(const MCInst &MI, unsigned OpNo,
100e8d8bef9SDimitry Andric                                SmallVectorImpl<MCFixup> &Fixups,
101e8d8bef9SDimitry Andric                                const MCSubtargetInfo &STI) const;
1020b57cec5SDimitry Andric 
1030b57cec5SDimitry Andric   /// getMachineOpValue - Return binary encoding of operand. If the machine
1040b57cec5SDimitry Andric   /// operand requires relocation, record the relocation and return zero.
1055ffd83dbSDimitry Andric   uint64_t getMachineOpValue(const MCInst &MI, const MCOperand &MO,
1060b57cec5SDimitry Andric                              SmallVectorImpl<MCFixup> &Fixups,
1070b57cec5SDimitry Andric                              const MCSubtargetInfo &STI) const;
1080b57cec5SDimitry Andric 
1090b57cec5SDimitry Andric   // getBinaryCodeForInstr - TableGen'erated function for getting the
1100b57cec5SDimitry Andric   // binary encoding for an instruction.
1110b57cec5SDimitry Andric   uint64_t getBinaryCodeForInstr(const MCInst &MI,
1120b57cec5SDimitry Andric                                  SmallVectorImpl<MCFixup> &Fixups,
1130b57cec5SDimitry Andric                                  const MCSubtargetInfo &STI) const;
1140b57cec5SDimitry Andric 
11506c3fb27SDimitry Andric   void encodeInstruction(const MCInst &MI, SmallVectorImpl<char> &CB,
1160b57cec5SDimitry Andric                          SmallVectorImpl<MCFixup> &Fixups,
1170b57cec5SDimitry Andric                          const MCSubtargetInfo &STI) const override;
1180b57cec5SDimitry Andric 
1190b57cec5SDimitry Andric   // Get the number of bytes used to encode the given MCInst.
1200b57cec5SDimitry Andric   unsigned getInstSizeInBytes(const MCInst &MI) const;
1210b57cec5SDimitry Andric 
1225ffd83dbSDimitry Andric   // Is this instruction a prefixed instruction.
1235ffd83dbSDimitry Andric   bool isPrefixedInstruction(const MCInst &MI) const;
124*5f757f3fSDimitry Andric 
125*5f757f3fSDimitry Andric   /// Check if Opcode corresponds to a call instruction that should be marked
126*5f757f3fSDimitry Andric   /// with the NOTOC relocation.
127*5f757f3fSDimitry Andric   bool isNoTOCCallInstr(const MCInst &MI) const;
1280b57cec5SDimitry Andric };
1290b57cec5SDimitry Andric 
1300b57cec5SDimitry Andric } // namespace llvm
1310b57cec5SDimitry Andric 
1320b57cec5SDimitry Andric #endif // LLVM_LIB_TARGET_PPC_MCCODEEMITTER_PPCCODEEMITTER_H
133