LLVM  14.0.0git
Macros | Enumerations | Functions
X86MCCodeEmitter.cpp File Reference
#include "MCTargetDesc/X86BaseInfo.h"
#include "MCTargetDesc/X86FixupKinds.h"
#include "MCTargetDesc/X86MCTargetDesc.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/MC/MCCodeEmitter.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCFixup.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCInstrDesc.h"
#include "llvm/MC/MCInstrInfo.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <cstdint>
#include <cstdlib>
Include dependency graph for X86MCCodeEmitter.cpp:

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "mccodeemitter"
 

Enumerations

enum  GlobalOffsetTableExprKind { GOT_None, GOT_Normal, GOT_SymDiff }
 

Functions

static uint8_t modRMByte (unsigned Mod, unsigned RegOpcode, unsigned RM)
 
static void emitByte (uint8_t C, raw_ostream &OS)
 
static void emitConstant (uint64_t Val, unsigned Size, raw_ostream &OS)
 
static bool isDispOrCDisp8 (uint64_t TSFlags, int Value, int &ImmOffset)
 Determine if this immediate can fit in a disp8 or a compressed disp8 for EVEX instructions. More...
 
static MCFixupKind getImmFixupKind (uint64_t TSFlags)
 
static bool is16BitMemOperand (const MCInst &MI, unsigned Op, const MCSubtargetInfo &STI)
 
static bool is32BitMemOperand (const MCInst &MI, unsigned Op)
 
static bool is64BitMemOperand (const MCInst &MI, unsigned Op)
 
static GlobalOffsetTableExprKind startsWithGlobalOffsetTable (const MCExpr *Expr)
 Check if this expression starts with GLOBAL_OFFSET_TABLE and if it is of the form GLOBAL_OFFSET_TABLE-symbol. More...
 
static bool hasSecRelSymbolRef (const MCExpr *Expr)
 
static bool isPCRel32Branch (const MCInst &MI, const MCInstrInfo &MCII)
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "mccodeemitter"

Definition at line 35 of file X86MCCodeEmitter.cpp.

Enumeration Type Documentation

◆ GlobalOffsetTableExprKind

Enumerator
GOT_None 
GOT_Normal 
GOT_SymDiff 

Definition at line 217 of file X86MCCodeEmitter.cpp.

Function Documentation

◆ emitByte()

static void emitByte ( uint8_t  C,
raw_ostream OS 
)
static

Definition at line 107 of file X86MCCodeEmitter.cpp.

Referenced by emitConstant().

◆ emitConstant()

static void emitConstant ( uint64_t  Val,
unsigned  Size,
raw_ostream OS 
)
static

Definition at line 109 of file X86MCCodeEmitter.cpp.

References emitByte(), i, and llvm::Check::Size.

◆ getImmFixupKind()

static MCFixupKind getImmFixupKind ( uint64_t  TSFlags)
static
Returns
the appropriate fixup kind to use for an immediate in an instruction with the specified TSFlags.

Definition at line 143 of file X86MCCodeEmitter.cpp.

References llvm::MCFixup::getKindForSize(), llvm::X86II::getSizeOfImm(), llvm::X86II::isImmPCRel(), llvm::X86II::isImmSigned(), isPCRel(), llvm_unreachable, llvm::X86::reloc_signed_4byte, and llvm::Check::Size.

Referenced by isPCRel32Branch().

◆ hasSecRelSymbolRef()

static bool hasSecRelSymbolRef ( const MCExpr Expr)
static

◆ is16BitMemOperand()

static bool is16BitMemOperand ( const MCInst MI,
unsigned  Op,
const MCSubtargetInfo STI 
)
static
Parameters
Opoperand # of the memory operand.
Returns
true if the specified instruction has a 16-bit memory operand.

Definition at line 161 of file X86MCCodeEmitter.cpp.

References llvm::X86::AddrBaseReg, llvm::X86::AddrIndexReg, llvm::sampleprof::Base, contains(), llvm::MCSubtargetInfo::hasFeature(), Index, and MI.

◆ is32BitMemOperand()

static bool is32BitMemOperand ( const MCInst MI,
unsigned  Op 
)
static
Parameters
Opoperand # of the memory operand.
Returns
true if the specified instruction has a 32-bit memory operand.

Definition at line 182 of file X86MCCodeEmitter.cpp.

References llvm::X86::AddrBaseReg, llvm::X86::AddrIndexReg, assert(), llvm::MCOperand::getReg(), and MI.

◆ is64BitMemOperand()

static bool is64BitMemOperand ( const MCInst MI,
unsigned  Op 
)
static
Parameters
Opoperand # of the memory operand.
Returns
true if the specified instruction has a 64-bit memory operand.

Definition at line 204 of file X86MCCodeEmitter.cpp.

References llvm::X86::AddrBaseReg, llvm::X86::AddrIndexReg, llvm::MCOperand::getReg(), and MI.

◆ isDispOrCDisp8()

static bool isDispOrCDisp8 ( uint64_t  TSFlags,
int  Value,
int ImmOffset 
)
static

Determine if this immediate can fit in a disp8 or a compressed disp8 for EVEX instructions.

will be set to the value to pass to the ImmOffset parameter of emitImmediate.

Definition at line 120 of file X86MCCodeEmitter.cpp.

References assert(), llvm::X86II::CD8_Scale_Mask, llvm::X86II::CD8_Scale_Shift, llvm::X86II::EncodingMask, llvm::X86II::EVEX, llvm::isInt< 8 >(), and llvm::isPowerOf2_32().

◆ isPCRel32Branch()

static bool isPCRel32Branch ( const MCInst MI,
const MCInstrInfo MCII 
)
static

◆ modRMByte()

static uint8_t modRMByte ( unsigned  Mod,
unsigned  RegOpcode,
unsigned  RM 
)
static

Definition at line 102 of file X86MCCodeEmitter.cpp.

References assert(), Mod, and llvm::AArch64::RM.

◆ startsWithGlobalOffsetTable()

static GlobalOffsetTableExprKind startsWithGlobalOffsetTable ( const MCExpr Expr)
static

Check if this expression starts with GLOBAL_OFFSET_TABLE and if it is of the form GLOBAL_OFFSET_TABLE-symbol.

This is needed to support PIC on ELF i386 as GLOBAL_OFFSET_TABLE is magical. We check only simple case that are know to be used: GLOBAL_OFFSET_TABLE by itself or at the start of a binary expression.

Definition at line 225 of file X86MCCodeEmitter.cpp.

References llvm::MCExpr::Binary, llvm::MCExpr::getKind(), llvm::MCBinaryExpr::getLHS(), llvm::MCBinaryExpr::getRHS(), GOT_None, GOT_Normal, GOT_SymDiff, llvm::Ref, S, and llvm::MCExpr::SymbolRef.