Skip to content

Commit

Permalink
[MC,AMDGPU] Migrate MCAsmLayout to MCAssembler
Browse files Browse the repository at this point in the history
  • Loading branch information
MaskRay committed Jul 1, 2024
1 parent ffca4ef commit f22af40
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
31 changes: 19 additions & 12 deletions llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -221,18 +227,19 @@ bool AMDGPUMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
const MCAsmLayout *Layout,
const MCFixup *Fixup) const {
std::optional<int64_t> 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) {
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ class AMDGPUMCExpr : public MCTargetExpr {
AMDGPUMCExpr(VariantKind Kind, ArrayRef<const MCExpr *> 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:
Expand Down

0 comments on commit f22af40

Please sign in to comment.