LLVM  13.0.0git
PPCMCCodeEmitter.h
Go to the documentation of this file.
1 //===-- PPCMCCodeEmitter.h - Convert PPC code to machine code -------------===//
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 implements the PPCMCCodeEmitter class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_LIB_TARGET_PPC_MCCODEEMITTER_PPCCODEEMITTER_H
14 #define LLVM_LIB_TARGET_PPC_MCCODEEMITTER_PPCCODEEMITTER_H
15 
16 #include "llvm/MC/MCAsmInfo.h"
17 #include "llvm/MC/MCCodeEmitter.h"
19 #include "llvm/MC/MCInstrInfo.h"
20 #include "llvm/MC/MCContext.h"
21 #include "llvm/MC/MCInst.h"
22 
23 namespace llvm {
24 
26  const MCInstrInfo &MCII;
27  const MCContext &CTX;
28  bool IsLittleEndian;
29 
30 public:
32  : MCII(mcii), CTX(ctx),
33  IsLittleEndian(ctx.getAsmInfo()->isLittleEndian()) {}
34  PPCMCCodeEmitter(const PPCMCCodeEmitter &) = delete;
35  void operator=(const PPCMCCodeEmitter &) = delete;
36  ~PPCMCCodeEmitter() override = default;
37 
38  unsigned getDirectBrEncoding(const MCInst &MI, unsigned OpNo,
40  const MCSubtargetInfo &STI) const;
41  unsigned getCondBrEncoding(const MCInst &MI, unsigned OpNo,
43  const MCSubtargetInfo &STI) const;
44  unsigned getAbsDirectBrEncoding(const MCInst &MI, unsigned OpNo,
46  const MCSubtargetInfo &STI) const;
47  unsigned getAbsCondBrEncoding(const MCInst &MI, unsigned OpNo,
49  const MCSubtargetInfo &STI) const;
50  unsigned getImm16Encoding(const MCInst &MI, unsigned OpNo,
52  const MCSubtargetInfo &STI) const;
53  uint64_t getImm34Encoding(const MCInst &MI, unsigned OpNo,
55  const MCSubtargetInfo &STI,
56  MCFixupKind Fixup) const;
57  uint64_t getImm34EncodingNoPCRel(const MCInst &MI, unsigned OpNo,
59  const MCSubtargetInfo &STI) const;
60  uint64_t getImm34EncodingPCRel(const MCInst &MI, unsigned OpNo,
62  const MCSubtargetInfo &STI) const;
63  unsigned getMemRIEncoding(const MCInst &MI, unsigned OpNo,
65  const MCSubtargetInfo &STI) const;
66  unsigned getMemRIXEncoding(const MCInst &MI, unsigned OpNo,
68  const MCSubtargetInfo &STI) const;
69  unsigned getMemRIX16Encoding(const MCInst &MI, unsigned OpNo,
71  const MCSubtargetInfo &STI) const;
72  unsigned getMemRIHashEncoding(const MCInst &MI, unsigned OpNo,
74  const MCSubtargetInfo &STI) const;
75  uint64_t getMemRI34PCRelEncoding(const MCInst &MI, unsigned OpNo,
77  const MCSubtargetInfo &STI) const;
78  uint64_t getMemRI34Encoding(const MCInst &MI, unsigned OpNo,
80  const MCSubtargetInfo &STI) const;
81  unsigned getSPE8DisEncoding(const MCInst &MI, unsigned OpNo,
83  const MCSubtargetInfo &STI) const;
84  unsigned getSPE4DisEncoding(const MCInst &MI, unsigned OpNo,
86  const MCSubtargetInfo &STI) const;
87  unsigned getSPE2DisEncoding(const MCInst &MI, unsigned OpNo,
89  const MCSubtargetInfo &STI) const;
90  unsigned getTLSRegEncoding(const MCInst &MI, unsigned OpNo,
92  const MCSubtargetInfo &STI) const;
93  unsigned getTLSCallEncoding(const MCInst &MI, unsigned OpNo,
95  const MCSubtargetInfo &STI) const;
96  unsigned get_crbitm_encoding(const MCInst &MI, unsigned OpNo,
98  const MCSubtargetInfo &STI) const;
99  unsigned getVSRpEvenEncoding(const MCInst &MI, unsigned OpNo,
101  const MCSubtargetInfo &STI) const;
102 
103  /// getMachineOpValue - Return binary encoding of operand. If the machine
104  /// operand requires relocation, record the relocation and return zero.
105  uint64_t getMachineOpValue(const MCInst &MI, const MCOperand &MO,
107  const MCSubtargetInfo &STI) const;
108 
109  // getBinaryCodeForInstr - TableGen'erated function for getting the
110  // binary encoding for an instruction.
111  uint64_t getBinaryCodeForInstr(const MCInst &MI,
113  const MCSubtargetInfo &STI) const;
114 
115  void encodeInstruction(const MCInst &MI, raw_ostream &OS,
117  const MCSubtargetInfo &STI) const override;
118 
119  // Get the number of bytes used to encode the given MCInst.
120  unsigned getInstSizeInBytes(const MCInst &MI) const;
121 
122  // Is this instruction a prefixed instruction.
123  bool isPrefixedInstruction(const MCInst &MI) const;
124 
125 private:
126  FeatureBitset computeAvailableFeatures(const FeatureBitset &FB) const;
127  void
128  verifyInstructionPredicates(const MCInst &MI,
129  const FeatureBitset &AvailableFeatures) const;
130 };
131 
132 } // namespace llvm
133 
134 #endif // LLVM_LIB_TARGET_PPC_MCCODEEMITTER_PPCCODEEMITTER_H
llvm::PPCMCCodeEmitter::getInstSizeInBytes
unsigned getInstSizeInBytes(const MCInst &MI) const
Definition: PPCMCCodeEmitter.cpp:482
llvm::PPCMCCodeEmitter::isPrefixedInstruction
bool isPrefixedInstruction(const MCInst &MI) const
Definition: PPCMCCodeEmitter.cpp:488
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:102
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::PPCMCCodeEmitter::getBinaryCodeForInstr
uint64_t getBinaryCodeForInstr(const MCInst &MI, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
llvm::PPCMCCodeEmitter::getMemRI34PCRelEncoding
uint64_t getMemRI34PCRelEncoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
Definition: PPCMCCodeEmitter.cpp:225
llvm::PPCMCCodeEmitter::getAbsDirectBrEncoding
unsigned getAbsDirectBrEncoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
Definition: PPCMCCodeEmitter.cpp:72
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:71
MCCodeEmitter.h
llvm::PPCMCCodeEmitter::getVSRpEvenEncoding
unsigned getVSRpEvenEncoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
Definition: PPCMCCodeEmitter.cpp:98
llvm::PPCMCCodeEmitter::getSPE4DisEncoding
unsigned getSPE4DisEncoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
Definition: PPCMCCodeEmitter.cpp:342
llvm::PPCMCCodeEmitter
Definition: PPCMCCodeEmitter.h:25
llvm::FeatureBitset
Container class for subtarget features.
Definition: SubtargetFeature.h:40
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
llvm::PPCMCCodeEmitter::operator=
void operator=(const PPCMCCodeEmitter &)=delete
llvm::PPCMCCodeEmitter::getAbsCondBrEncoding
unsigned getAbsCondBrEncoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
Definition: PPCMCCodeEmitter.cpp:85
llvm::PPCMCCodeEmitter::get_crbitm_encoding
unsigned get_crbitm_encoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
Definition: PPCMCCodeEmitter.cpp:405
llvm::PPCMCCodeEmitter::getMemRIX16Encoding
unsigned getMemRIX16Encoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
Definition: PPCMCCodeEmitter.cpp:185
llvm::PPCMCCodeEmitter::getImm34EncodingPCRel
uint64_t getImm34EncodingPCRel(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
Definition: PPCMCCodeEmitter.cpp:142
llvm::PPCMCCodeEmitter::getSPE8DisEncoding
unsigned getSPE8DisEncoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
Definition: PPCMCCodeEmitter.cpp:327
MCContext.h
MCInstrInfo.h
MCInst.h
llvm::AArch64::Fixups
Fixups
Definition: AArch64FixupKinds.h:17
MCSubtargetInfo.h
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::PPCMCCodeEmitter::getMachineOpValue
uint64_t getMachineOpValue(const MCInst &MI, const MCOperand &MO, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getMachineOpValue - Return binary encoding of operand.
Definition: PPCMCCodeEmitter.cpp:430
llvm::PPCMCCodeEmitter::getCondBrEncoding
unsigned getCondBrEncoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
Definition: PPCMCCodeEmitter.cpp:59
llvm::PPCMCCodeEmitter::getMemRIEncoding
unsigned getMemRIEncoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
Definition: PPCMCCodeEmitter.cpp:149
llvm::PPCMCCodeEmitter::getImm34EncodingNoPCRel
uint64_t getImm34EncodingNoPCRel(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
Definition: PPCMCCodeEmitter.cpp:134
llvm::PPCMCCodeEmitter::getMemRIXEncoding
unsigned getMemRIXEncoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
Definition: PPCMCCodeEmitter.cpp:167
llvm::PPCMCCodeEmitter::getTLSRegEncoding
unsigned getTLSRegEncoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
Definition: PPCMCCodeEmitter.cpp:372
MCAsmInfo.h
llvm::PPCMCCodeEmitter::PPCMCCodeEmitter
PPCMCCodeEmitter(const MCInstrInfo &mcii, MCContext &ctx)
Definition: PPCMCCodeEmitter.h:31
llvm::PPCMCCodeEmitter::encodeInstruction
void encodeInstruction(const MCInst &MI, raw_ostream &OS, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const override
EncodeInstruction - Encode the given Inst to bytes on the output stream OS.
Definition: PPCMCCodeEmitter.cpp:451
llvm::PPCMCCodeEmitter::getDirectBrEncoding
unsigned getDirectBrEncoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
Definition: PPCMCCodeEmitter.cpp:43
llvm::PPCMCCodeEmitter::getMemRI34Encoding
uint64_t getMemRI34Encoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
Definition: PPCMCCodeEmitter.cpp:315
llvm::MCInstrInfo
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:25
llvm::MCCodeEmitter
MCCodeEmitter - Generic instruction encoding interface.
Definition: MCCodeEmitter.h:21
llvm::PPCMCCodeEmitter::getMemRIHashEncoding
unsigned getMemRIHashEncoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
Definition: PPCMCCodeEmitter.cpp:207
llvm::PPCMCCodeEmitter::getImm34Encoding
uint64_t getImm34Encoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI, MCFixupKind Fixup) const
Definition: PPCMCCodeEmitter.cpp:119
llvm::MCFixupKind
MCFixupKind
Extensible enumeration to represent the type of a fixup.
Definition: MCFixup.h:21
llvm::PPCMCCodeEmitter::getTLSCallEncoding
unsigned getTLSCallEncoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
Definition: PPCMCCodeEmitter.cpp:392
llvm::PPCMCCodeEmitter::~PPCMCCodeEmitter
~PPCMCCodeEmitter() override=default
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:43
llvm::MCOperand
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:36
llvm::PPCMCCodeEmitter::getSPE2DisEncoding
unsigned getSPE2DisEncoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
Definition: PPCMCCodeEmitter.cpp:357
llvm::PPCMCCodeEmitter::getImm16Encoding
unsigned getImm16Encoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
Definition: PPCMCCodeEmitter.cpp:107
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:75