[llvm] f22af40 - [MC,AMDGPU] Migrate MCAsmLayout to MCAssembler

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 1 16:07:54 PDT 2024


Author: Fangrui Song
Date: 2024-07-01T16:07:48-07:00
New Revision: f22af401a4535f66751f24ade2a948ef695512d9

URL: https://github.com/llvm/llvm-project/commit/f22af401a4535f66751f24ade2a948ef695512d9
DIFF: https://github.com/llvm/llvm-project/commit/f22af401a4535f66751f24ade2a948ef695512d9.diff

LOG: [MC,AMDGPU] Migrate MCAsmLayout to MCAssembler

Added: 
    

Modified: 
    llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp
    llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp
index 83fbf4ac53d50..4962b796ac38a 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<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) {

diff  --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h
index 207a619d45a1f..9b2e2a68485d7 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<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:


        


More information about the llvm-commits mailing list