LLVM 22.0.0git
llvm::MCExpr Class Reference

Base class for the full range of assembler expressions which are needed for parsing. More...

#include "llvm/MC/MCExpr.h"

Inheritance diagram for llvm::MCExpr:
[legend]

Public Types

enum  ExprKind : uint8_t {
  Binary , Constant , SymbolRef , Unary ,
  Specifier , Target
}

Public Member Functions

 MCExpr (const MCExpr &)=delete
MCExproperator= (const MCExpr &)=delete
Accessors
ExprKind getKind () const
SMLoc getLoc () const
Utility Methods
LLVM_ABI void dump () const
Expression Evaluation
LLVM_ABI bool evaluateAsAbsolute (int64_t &Res) const
 Try to evaluate the expression to an absolute value.
LLVM_ABI bool evaluateAsAbsolute (int64_t &Res, const MCAssembler &Asm) const
LLVM_ABI bool evaluateAsAbsolute (int64_t &Res, const MCAssembler *Asm) const
LLVM_ABI bool evaluateKnownAbsolute (int64_t &Res, const MCAssembler &Asm) const
 Aggressive variant of evaluateAsRelocatable when relocations are unavailable (e.g.
LLVM_ABI bool evaluateAsRelocatable (MCValue &Res, const MCAssembler *Asm) const
 Try to evaluate the expression to a relocatable value, i.e.
LLVM_ABI bool evaluateAsValue (MCValue &Res, const MCAssembler &Asm) const
 Try to evaluate the expression to the form (a - b + constant) where neither a nor b are variables.
LLVM_ABI MCFragmentfindAssociatedFragment () const
 Find the "associated section" for this expression, which is currently defined as the absolute section for constants, or otherwise the section associated with the first defined symbol in the expression.

Static Public Member Functions

static LLVM_ABI bool evaluateSymbolicAdd (const MCAssembler *, bool, const MCValue &, const MCValue &, MCValue &)

Protected Types

using Spec = uint16_t

Protected Member Functions

 MCExpr (ExprKind Kind, SMLoc Loc, unsigned SubclassData=0)
LLVM_ABI bool evaluateAsRelocatableImpl (MCValue &Res, const MCAssembler *Asm, bool InSet) const
unsigned getSubclassData () const

Friends

class MCAsmInfo
class MCFragment
class MCOperand

Detailed Description

Base class for the full range of assembler expressions which are needed for parsing.

Definition at line 34 of file MCExpr.h.

Member Typedef Documentation

◆ Spec

using llvm::MCExpr::Spec = uint16_t
protected

Definition at line 66 of file MCExpr.h.

Member Enumeration Documentation

◆ ExprKind

Enumerator
Binary 

Binary expressions.

Constant 

Constant expressions.

SymbolRef 

References to labels and assigned expressions.

Unary 

Unary expressions.

Specifier 

Expression with a relocation specifier.

Target 

Target specific expression.

Definition at line 40 of file MCExpr.h.

Constructor & Destructor Documentation

◆ MCExpr() [1/2]

◆ MCExpr() [2/2]

llvm::MCExpr::MCExpr ( const MCExpr & )
delete

References MCExpr().

Member Function Documentation

◆ dump()

LLVM_DUMP_METHOD void MCExpr::dump ( ) const

Definition at line 193 of file MCExpr.cpp.

References llvm::dbgs(), and LLVM_DUMP_METHOD.

◆ evaluateAsAbsolute() [1/3]

bool MCExpr::evaluateAsAbsolute ( int64_t & Res) const

Try to evaluate the expression to an absolute value.

Parameters
Res- The absolute value, if evaluation succeeds.
Returns
- True on success.

Definition at line 238 of file MCExpr.cpp.

Referenced by printImpl(), and targetOpKnownBitsMapHelper().

◆ evaluateAsAbsolute() [2/3]

bool MCExpr::evaluateAsAbsolute ( int64_t & Res,
const MCAssembler & Asm ) const

Definition at line 242 of file MCExpr.cpp.

◆ evaluateAsAbsolute() [3/3]

bool MCExpr::evaluateAsAbsolute ( int64_t & Res,
const MCAssembler * Asm ) const

Definition at line 246 of file MCExpr.cpp.

◆ evaluateAsRelocatable()

bool MCExpr::evaluateAsRelocatable ( MCValue & Res,
const MCAssembler * Asm ) const

Try to evaluate the expression to a relocatable value, i.e.

an expression of the fixed form (a - b + constant).

Parameters
Res- The relocatable value, if evaluation succeeds.
Asm- The assembler object to use for evaluating values.
Returns
- True on success.

Definition at line 450 of file MCExpr.cpp.

References evaluateAsRelocatableImpl().

Referenced by llvm::DelayedMCExprs::assignDocNode(), evaluate(), evaluate(), llvm::AVRMCExpr::evaluateAsConstant(), llvm::PPC::evaluateAsConstant(), evaluateAsRelocatable(), llvm::AMDGPUMCExpr::evaluateAsRelocatableImpl(), llvm::SystemZMCAsmInfoGOFF::evaluateAsRelocatableImpl(), llvm::VEELFMCAsmInfo::evaluateAsRelocatableImpl(), llvm::RISCVAsmBackend::evaluateFixup(), getPCRelHiFixup(), llvm::MachObjectWriter::getSymbolAddress(), llvm::MCAssembler::isThumbFunc(), and llvm::DelayedMCExprs::resolveDelayedExpressions().

◆ evaluateAsRelocatableImpl()

bool MCExpr::evaluateAsRelocatableImpl ( MCValue & Res,
const MCAssembler * Asm,
bool InSet ) const
protected

-(a - b + const) ==> (b - a - const)

Definition at line 457 of file MCExpr.cpp.

References _, A(), llvm::MCBinaryExpr::Add, llvm::MCBinaryExpr::And, llvm::MCBinaryExpr::AShr, B(), Binary, llvm::cast(), Constant, llvm::MCConstantExpr::create(), llvm::MCBinaryExpr::Div, llvm::dyn_cast(), llvm::MCBinaryExpr::EQ, evaluateAsRelocatableImpl(), evaluateSymbolicAdd(), llvm::MCValue::get(), llvm::MCValue::getAddSym(), llvm::MCValue::getConstant(), getKind(), llvm::MCSymbolRefExpr::getKind(), llvm::MCBinaryExpr::getLHS(), getLoc(), llvm::MCSymbol::getName(), llvm::MCBinaryExpr::getOpcode(), llvm::MCUnaryExpr::getOpcode(), llvm::MCBinaryExpr::getRHS(), llvm::MCValue::getSpecifier(), llvm::MCUnaryExpr::getSubExpr(), llvm::MCValue::getSubSym(), llvm::MCSymbolRefExpr::getSymbol(), llvm::MCSymbol::getVariableValue(), llvm::MCBinaryExpr::GT, llvm::MCBinaryExpr::GTE, llvm::MCValue::isAbsolute(), llvm::MCSymbol::isResolving(), llvm::MCSymbol::isVariable(), llvm::MCSymbol::isWeakExternal(), llvm::MCBinaryExpr::LAnd, llvm_unreachable, llvm::MCUnaryExpr::LNot, llvm::MCBinaryExpr::LOr, llvm::MCBinaryExpr::LShr, llvm::MCBinaryExpr::LT, llvm::MCBinaryExpr::LTE, llvm::make_scope_exit(), llvm::MCUnaryExpr::Minus, llvm::MCBinaryExpr::Mod, llvm::MCBinaryExpr::Mul, llvm::MCBinaryExpr::NE, llvm::MCUnaryExpr::Not, llvm::MCBinaryExpr::Or, llvm::MCBinaryExpr::OrNot, llvm::MCUnaryExpr::Plus, llvm::MCSymbol::setIsResolving(), llvm::MCSymbol::setVariableValue(), llvm::MCBinaryExpr::Shl, Specifier, llvm::MCBinaryExpr::Sub, std::swap(), SymbolRef, Target, Unary, and llvm::MCBinaryExpr::Xor.

Referenced by evaluateAsRelocatable(), evaluateAsRelocatableImpl(), and evaluateAsValue().

◆ evaluateAsValue()

bool MCExpr::evaluateAsValue ( MCValue & Res,
const MCAssembler & Asm ) const

Try to evaluate the expression to the form (a - b + constant) where neither a nor b are variables.

This is a more aggressive variant of evaluateAsRelocatable. The intended use is for when relocations are not available, like the .size directive.

Definition at line 453 of file MCExpr.cpp.

References evaluateAsRelocatableImpl().

Referenced by llvm::MCAssembler::getBaseSymbol(), and getSymbolOffsetImpl().

◆ evaluateKnownAbsolute()

bool MCExpr::evaluateKnownAbsolute ( int64_t & Res,
const MCAssembler & Asm ) const

Aggressive variant of evaluateAsRelocatable when relocations are unavailable (e.g.

.fill). Expects callers to handle errors when true is returned.

Definition at line 250 of file MCExpr.cpp.

Referenced by computeLabelDiff(), llvm::LoongArchAsmBackend::relaxDwarfCFA(), llvm::RISCVAsmBackend::relaxDwarfCFA(), llvm::LoongArchAsmBackend::relaxDwarfLineAddr(), llvm::RISCVAsmBackend::relaxDwarfLineAddr(), llvm::LoongArchAsmBackend::relaxLEB128(), and llvm::RISCVAsmBackend::relaxLEB128().

◆ evaluateSymbolicAdd()

bool MCExpr::evaluateSymbolicAdd ( const MCAssembler * Asm,
bool InSet,
const MCValue & LHS,
const MCValue & RHS,
MCValue & Res )
static

Definition at line 407 of file MCExpr.cpp.

References A(), attemptToFoldSymbolOffsetDifference(), B(), and llvm::MCValue::get().

Referenced by evaluateAsRelocatableImpl().

◆ findAssociatedFragment()

MCFragment * MCExpr::findAssociatedFragment ( ) const

◆ getKind()

◆ getLoc()

◆ getSubclassData()

◆ operator=()

MCExpr & llvm::MCExpr::operator= ( const MCExpr & )
delete

References MCExpr().

◆ MCAsmInfo

friend class MCAsmInfo
friend

Definition at line 37 of file MCExpr.h.

References MCAsmInfo.

Referenced by MCAsmInfo, and llvm::MCTargetExpr::printImpl().

◆ MCFragment

friend class MCFragment
friend

Definition at line 38 of file MCExpr.h.

References MCFragment.

Referenced by findAssociatedFragment(), llvm::MCTargetExpr::findAssociatedFragment(), and MCFragment.

◆ MCOperand

friend class MCOperand
friend

Definition at line 39 of file MCExpr.h.

References MCOperand.

Referenced by MCOperand.


The documentation for this class was generated from the following files: