diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp index 83fbf4ac53d507..4962b796ac38a0 100644 --- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp +++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp @@ -10,6 +10,8 @@ #include "GCNSubtarget.h" #include "Utils/AMDGPUBaseInfo.h" #include "llvm/IR/Function.h" +#include "llvm/MC/MCAsmLayout.h" +#include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSymbol.h" @@ -93,11 +95,12 @@ static int64_t op(AMDGPUMCExpr::VariantKind Kind, int64_t Arg1, int64_t Arg2) { } } -bool AMDGPUMCExpr::evaluateExtraSGPRs(MCValue &Res, const MCAsmLayout *Layout, +bool AMDGPUMCExpr::evaluateExtraSGPRs(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const { auto TryGetMCExprValue = [&](const MCExpr *Arg, uint64_t &ConstantValue) { MCValue MCVal; - if (!Arg->evaluateAsRelocatable(MCVal, Layout, Fixup) || + if (!Arg->evaluateAsRelocatable(MCVal, Asm ? Asm->getLayout() : nullptr, + Fixup) || !MCVal.isAbsolute()) return false; @@ -123,11 +126,12 @@ bool AMDGPUMCExpr::evaluateExtraSGPRs(MCValue &Res, const MCAsmLayout *Layout, return true; } -bool AMDGPUMCExpr::evaluateTotalNumVGPR(MCValue &Res, const MCAsmLayout *Layout, +bool AMDGPUMCExpr::evaluateTotalNumVGPR(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const { auto TryGetMCExprValue = [&](const MCExpr *Arg, uint64_t &ConstantValue) { MCValue MCVal; - if (!Arg->evaluateAsRelocatable(MCVal, Layout, Fixup) || + if (!Arg->evaluateAsRelocatable(MCVal, Asm ? Asm->getLayout() : nullptr, + Fixup) || !MCVal.isAbsolute()) return false; @@ -151,11 +155,12 @@ bool AMDGPUMCExpr::evaluateTotalNumVGPR(MCValue &Res, const MCAsmLayout *Layout, return true; } -bool AMDGPUMCExpr::evaluateAlignTo(MCValue &Res, const MCAsmLayout *Layout, +bool AMDGPUMCExpr::evaluateAlignTo(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const { auto TryGetMCExprValue = [&](const MCExpr *Arg, uint64_t &ConstantValue) { MCValue MCVal; - if (!Arg->evaluateAsRelocatable(MCVal, Layout, Fixup) || + if (!Arg->evaluateAsRelocatable(MCVal, Asm ? Asm->getLayout() : nullptr, + Fixup) || !MCVal.isAbsolute()) return false; @@ -173,11 +178,12 @@ bool AMDGPUMCExpr::evaluateAlignTo(MCValue &Res, const MCAsmLayout *Layout, return true; } -bool AMDGPUMCExpr::evaluateOccupancy(MCValue &Res, const MCAsmLayout *Layout, +bool AMDGPUMCExpr::evaluateOccupancy(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const { auto TryGetMCExprValue = [&](const MCExpr *Arg, uint64_t &ConstantValue) { MCValue MCVal; - if (!Arg->evaluateAsRelocatable(MCVal, Layout, Fixup) || + if (!Arg->evaluateAsRelocatable(MCVal, Asm ? Asm->getLayout() : nullptr, + Fixup) || !MCVal.isAbsolute()) return false; @@ -221,18 +227,19 @@ bool AMDGPUMCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const { std::optional Total; + MCAssembler *Asm = Layout ? &Layout->getAssembler() : nullptr; switch (Kind) { default: break; case AGVK_ExtraSGPRs: - return evaluateExtraSGPRs(Res, Layout, Fixup); + return evaluateExtraSGPRs(Res, Asm, Fixup); case AGVK_AlignTo: - return evaluateAlignTo(Res, Layout, Fixup); + return evaluateAlignTo(Res, Asm, Fixup); case AGVK_TotalNumVGPRs: - return evaluateTotalNumVGPR(Res, Layout, Fixup); + return evaluateTotalNumVGPR(Res, Asm, Fixup); case AGVK_Occupancy: - return evaluateOccupancy(Res, Layout, Fixup); + return evaluateOccupancy(Res, Asm, Fixup); } for (const MCExpr *Arg : Args) { diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h index 207a619d45a1fa..9b2e2a68485d71 100644 --- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h +++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h @@ -48,13 +48,13 @@ class AMDGPUMCExpr : public MCTargetExpr { AMDGPUMCExpr(VariantKind Kind, ArrayRef Args, MCContext &Ctx); ~AMDGPUMCExpr(); - bool evaluateExtraSGPRs(MCValue &Res, const MCAsmLayout *Layout, + bool evaluateExtraSGPRs(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const; - bool evaluateTotalNumVGPR(MCValue &Res, const MCAsmLayout *Layout, + bool evaluateTotalNumVGPR(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const; - bool evaluateAlignTo(MCValue &Res, const MCAsmLayout *Layout, + bool evaluateAlignTo(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const; - bool evaluateOccupancy(MCValue &Res, const MCAsmLayout *Layout, + bool evaluateOccupancy(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const; public: