ARMMCExpr: Migrate to MCSpecifierExpr

This commit is contained in:
Fangrui Song
2025-06-07 23:32:18 -07:00
parent 49a706d8ef
commit 532facc78e
5 changed files with 8 additions and 38 deletions

View File

@@ -619,7 +619,7 @@ unsigned ARMAsmBackend::adjustFixupValue(const MCAssembler &Asm,
// Offset by 8 just as above.
if (const MCSymbolRefExpr *SRE =
dyn_cast<MCSymbolRefExpr>(Fixup.getValue()))
if (getSpecifier(SRE) == ARMMCExpr::VK_TLSCALL)
if (SRE->getSpecifier() == ARMMCExpr::VK_TLSCALL)
return 0;
return 0xffffff & (Value >> 2);
case ARM::fixup_t2_uncondbranch: {
@@ -746,7 +746,7 @@ unsigned ARMAsmBackend::adjustFixupValue(const MCAssembler &Asm,
uint32_t offset = (Value - 4) >> 2;
if (const MCSymbolRefExpr *SRE =
dyn_cast<MCSymbolRefExpr>(Fixup.getValue()))
if (getSpecifier(SRE) == ARMMCExpr::VK_TLSCALL)
if (SRE->getSpecifier() == ARMMCExpr::VK_TLSCALL)
offset = 0;
uint32_t signBit = (offset & 0x400000) >> 22;
uint32_t I1Bit = (offset & 0x200000) >> 21;

View File

@@ -590,7 +590,7 @@ public:
/// necessary.
void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) override {
if (const MCSymbolRefExpr *SRE = dyn_cast_or_null<MCSymbolRefExpr>(Value)) {
if (getSpecifier(SRE) == ARMMCExpr::VK_SBREL && !(Size == 4)) {
if (SRE->getSpecifier() == ARMMCExpr::VK_SBREL && !(Size == 4)) {
getContext().reportError(Loc, "relocated expression must be 32-bit");
return;
}

View File

@@ -1191,7 +1191,7 @@ uint32_t ARMMCCodeEmitter::getHiLoImmOpValue(const MCInst &MI, unsigned OpIdx,
// :lower0_7: assembly prefixes.
const MCExpr *E = MO.getExpr();
MCFixupKind Kind;
if (E->getKind() == MCExpr::Target) {
if (E->getKind() == MCExpr::Specifier) {
const ARMMCExpr *ARM16Expr = cast<ARMMCExpr>(E);
E = ARM16Expr->getSubExpr();

View File

@@ -48,7 +48,3 @@ void ARMMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
if (Expr->getKind() != MCExpr::SymbolRef)
OS << ')';
}
void ARMMCExpr::visitUsedExpr(MCStreamer &Streamer) const {
Streamer.visitUsedExpr(*getSubExpr());
}

View File

@@ -13,9 +13,10 @@
namespace llvm {
class ARMMCExpr : public MCTargetExpr {
class ARMMCExpr : public MCSpecifierExpr {
public:
enum Specifier {
using Specifier = uint16_t;
enum {
VK_None,
VK_HI16 =
MCSymbolRefExpr::FirstTargetSpecifier, // The R_ARM_MOVT_ABS relocation
@@ -57,16 +58,10 @@ public:
};
private:
const Specifier specifier;
const MCExpr *Expr;
explicit ARMMCExpr(Specifier S, const MCExpr *Expr)
: specifier(S), Expr(Expr) {}
: MCSpecifierExpr(Expr, S) {}
public:
/// @name Construction
/// @{
static const ARMMCExpr *create(Specifier S, const MCExpr *Expr,
MCContext &Ctx);
@@ -94,33 +89,12 @@ public:
return create(VK_LO_0_7, Expr, Ctx);
}
/// @}
/// @name Accessors
/// @{
Specifier getSpecifier() const { return specifier; }
const MCExpr *getSubExpr() const { return Expr; }
/// @}
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
bool evaluateAsRelocatableImpl(MCValue &Res,
const MCAssembler *Asm) const override {
return false;
}
void visitUsedExpr(MCStreamer &Streamer) const override;
MCFragment *findAssociatedFragment() const override {
return getSubExpr()->findAssociatedFragment();
}
static bool classof(const MCExpr *E) {
return E->getKind() == MCExpr::Target;
}
};
static inline ARMMCExpr::Specifier getSpecifier(const MCSymbolRefExpr *SRE) {
return ARMMCExpr::Specifier(SRE->getKind());
}
} // end namespace llvm
#endif