LLVM 19.0.0git
X86MCTargetDesc.h
Go to the documentation of this file.
1//===-- X86MCTargetDesc.h - X86 Target Descriptions -------------*- 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 provides X86 specific target descriptions.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_X86_MCTARGETDESC_X86MCTARGETDESC_H
14#define LLVM_LIB_TARGET_X86_MCTARGETDESC_X86MCTARGETDESC_H
15
17#include <memory>
18#include <string>
19
20namespace llvm {
21class formatted_raw_ostream;
22class MCAsmBackend;
23class MCCodeEmitter;
24class MCContext;
25class MCInst;
26class MCInstPrinter;
27class MCInstrInfo;
28class MCObjectStreamer;
29class MCObjectTargetWriter;
30class MCObjectWriter;
31class MCRegister;
32class MCRegisterInfo;
33class MCStreamer;
34class MCSubtargetInfo;
35class MCTargetOptions;
36class MCTargetStreamer;
37class Target;
38class Triple;
39class StringRef;
40
41/// Flavour of dwarf regnumbers
42///
43namespace DWARFFlavour {
44 enum {
46 };
47}
48
49/// Native X86 register numbers
50///
51namespace N86 {
52 enum {
53 EAX = 0, ECX = 1, EDX = 2, EBX = 3, ESP = 4, EBP = 5, ESI = 6, EDI = 7
54 };
55}
56
57namespace X86_MC {
58std::string ParseX86Triple(const Triple &TT);
59
60unsigned getDwarfRegFlavour(const Triple &TT, bool isEH);
61
62void initLLVMToSEHAndCVRegMapping(MCRegisterInfo *MRI);
63
64
65/// Returns true if this instruction has a LOCK prefix.
66bool hasLockPrefix(const MCInst &MI);
67
68/// \param Op operand # of the memory operand.
69///
70/// \returns true if the specified instruction has a 16-bit memory operand.
71bool is16BitMemOperand(const MCInst &MI, unsigned Op,
72 const MCSubtargetInfo &STI);
73
74/// \param Op operand # of the memory operand.
75///
76/// \returns true if the specified instruction has a 32-bit memory operand.
77bool is32BitMemOperand(const MCInst &MI, unsigned Op);
78
79/// \param Op operand # of the memory operand.
80///
81/// \returns true if the specified instruction has a 64-bit memory operand.
82#ifndef NDEBUG
83bool is64BitMemOperand(const MCInst &MI, unsigned Op);
84#endif
85
86/// Returns true if this instruction needs an Address-Size override prefix.
87bool needsAddressSizeOverride(const MCInst &MI, const MCSubtargetInfo &STI,
88 int MemoryOperand, uint64_t TSFlags);
89
90/// Create a X86 MCSubtargetInfo instance. This is exposed so Asm parser, etc.
91/// do not need to go through TargetRegistry.
92MCSubtargetInfo *createX86MCSubtargetInfo(const Triple &TT, StringRef CPU,
93 StringRef FS);
94
95void emitInstruction(MCObjectStreamer &, const MCInst &Inst,
96 const MCSubtargetInfo &STI);
97
98void emitPrefix(MCCodeEmitter &MCE, const MCInst &MI, SmallVectorImpl<char> &CB,
99 const MCSubtargetInfo &STI);
100}
101
102MCCodeEmitter *createX86MCCodeEmitter(const MCInstrInfo &MCII,
103 MCContext &Ctx);
104
105MCAsmBackend *createX86_32AsmBackend(const Target &T,
106 const MCSubtargetInfo &STI,
107 const MCRegisterInfo &MRI,
108 const MCTargetOptions &Options);
109MCAsmBackend *createX86_64AsmBackend(const Target &T,
110 const MCSubtargetInfo &STI,
111 const MCRegisterInfo &MRI,
112 const MCTargetOptions &Options);
113
114/// Implements X86-only directives for assembly emission.
115MCTargetStreamer *createX86AsmTargetStreamer(MCStreamer &S,
116 formatted_raw_ostream &OS,
117 MCInstPrinter *InstPrinter,
118 bool IsVerboseAsm);
119
120/// Implements X86-only directives for object files.
121MCTargetStreamer *createX86ObjectTargetStreamer(MCStreamer &S,
122 const MCSubtargetInfo &STI);
123
124/// Construct an X86 Windows COFF machine code streamer which will generate
125/// PE/COFF format object files.
126///
127/// Takes ownership of \p AB and \p CE.
128MCStreamer *createX86WinCOFFStreamer(MCContext &C,
129 std::unique_ptr<MCAsmBackend> &&AB,
130 std::unique_ptr<MCObjectWriter> &&OW,
131 std::unique_ptr<MCCodeEmitter> &&CE,
132 bool IncrementalLinkerCompatible);
133
134MCStreamer *createX86ELFStreamer(const Triple &T, MCContext &Context,
135 std::unique_ptr<MCAsmBackend> &&MAB,
136 std::unique_ptr<MCObjectWriter> &&MOW,
137 std::unique_ptr<MCCodeEmitter> &&MCE);
138
139/// Construct an X86 Mach-O object writer.
140std::unique_ptr<MCObjectTargetWriter>
141createX86MachObjectWriter(bool Is64Bit, uint32_t CPUType, uint32_t CPUSubtype);
142
143/// Construct an X86 ELF object writer.
144std::unique_ptr<MCObjectTargetWriter>
145createX86ELFObjectWriter(bool IsELF64, uint8_t OSABI, uint16_t EMachine);
146/// Construct an X86 Win COFF object writer.
147std::unique_ptr<MCObjectTargetWriter>
148createX86WinCOFFObjectWriter(bool Is64Bit);
149
150/// \param Reg speicifed register.
151/// \param Size the bit size of returned register.
152/// \param High requires the high register.
153///
154/// \returns the sub or super register of a specific X86 register.
155MCRegister getX86SubSuperRegister(MCRegister Reg, unsigned Size,
156 bool High = false);
157} // End llvm namespace
158
159
160// Defines symbolic names for X86 registers. This defines a mapping from
161// register name to register number.
162//
163#define GET_REGINFO_ENUM
164#include "X86GenRegisterInfo.inc"
165
166// Defines symbolic names for the X86 instructions.
167//
168#define GET_INSTRINFO_ENUM
169#define GET_INSTRINFO_MC_HELPER_DECLS
170#include "X86GenInstrInfo.inc"
171
172#define GET_SUBTARGETINFO_ENUM
173#include "X86GenSubtargetInfo.inc"
174
175#define GET_X86_MNEMONIC_TABLES_H
176#include "X86GenMnemonicTables.inc"
177
178#endif
unsigned const MachineRegisterInfo * MRI
uint64_t Size
IRTranslator LLVM IR MI
static LVOptions Options
Definition: LVOptions.cpp:25
unsigned Reg
uint64_t High
raw_pwrite_stream & OS
This file defines the SmallVector class.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
bool is32BitMemOperand(const MCInst &MI, unsigned Op)
bool is16BitMemOperand(const MCInst &MI, unsigned Op, const MCSubtargetInfo &STI)
bool hasLockPrefix(const MCInst &MI)
Returns true if this instruction has a LOCK prefix.
void initLLVMToSEHAndCVRegMapping(MCRegisterInfo *MRI)
bool needsAddressSizeOverride(const MCInst &MI, const MCSubtargetInfo &STI, int MemoryOperand, uint64_t TSFlags)
Returns true if this instruction needs an Address-Size override prefix.
void emitPrefix(MCCodeEmitter &MCE, const MCInst &MI, SmallVectorImpl< char > &CB, const MCSubtargetInfo &STI)
std::string ParseX86Triple(const Triple &TT)
void emitInstruction(MCObjectStreamer &, const MCInst &Inst, const MCSubtargetInfo &STI)
MCSubtargetInfo * createX86MCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS)
Create a X86 MCSubtargetInfo instance.
bool is64BitMemOperand(const MCInst &MI, unsigned Op)
unsigned getDwarfRegFlavour(const Triple &TT, bool isEH)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
MCTargetStreamer * createX86ObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
Implements X86-only directives for object files.
MCStreamer * createX86WinCOFFStreamer(MCContext &C, std::unique_ptr< MCAsmBackend > &&AB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE, bool IncrementalLinkerCompatible)
Construct an X86 Windows COFF machine code streamer which will generate PE/COFF format object files.
MCRegister getX86SubSuperRegister(MCRegister Reg, unsigned Size, bool High=false)
MCAsmBackend * createX86_64AsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
std::unique_ptr< MCObjectTargetWriter > createX86WinCOFFObjectWriter(bool Is64Bit)
Construct an X86 Win COFF object writer.
MCCodeEmitter * createX86MCCodeEmitter(const MCInstrInfo &MCII, MCContext &Ctx)
MCStreamer * createX86ELFStreamer(const Triple &T, MCContext &Context, std::unique_ptr< MCAsmBackend > &&MAB, std::unique_ptr< MCObjectWriter > &&MOW, std::unique_ptr< MCCodeEmitter > &&MCE)
std::unique_ptr< MCObjectTargetWriter > createX86MachObjectWriter(bool Is64Bit, uint32_t CPUType, uint32_t CPUSubtype)
Construct an X86 Mach-O object writer.
DWARFExpression::Operation Op
MCTargetStreamer * createX86AsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrinter, bool IsVerboseAsm)
Implements X86-only directives for assembly emission.
std::unique_ptr< MCObjectTargetWriter > createX86ELFObjectWriter(bool IsELF64, uint8_t OSABI, uint16_t EMachine)
Construct an X86 ELF object writer.
MCAsmBackend * createX86_32AsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)