Skip to content

Commit e19cbe4

Browse files
committed
[SPIRV] Don't specialize MachineModuleInfo just to access the LLVMContext. NFC
The MachineModuleInfo reference was removed from the MachineFunction in llvm#100357, which broke this code. Instead of finding another way to get at the MMI, just avoid using it - we can get at the LLVMContext from the MachineFunction itself.
1 parent 842a332 commit e19cbe4

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,26 @@
3232
#include "llvm/IR/IntrinsicsSPIRV.h"
3333
#include "llvm/Support/Debug.h"
3434

35-
namespace llvm {
35+
namespace {
3636

37-
class SPIRVMachineModuleInfo : public MachineModuleInfoImpl {
38-
public:
39-
SyncScope::ID Work_ItemSSID;
40-
SyncScope::ID WorkGroupSSID;
41-
SyncScope::ID DeviceSSID;
42-
SyncScope::ID AllSVMDevicesSSID;
43-
SyncScope::ID SubGroupSSID;
44-
45-
SPIRVMachineModuleInfo(const MachineModuleInfo &MMI) {
46-
LLVMContext &CTX = MMI.getModule()->getContext();
47-
Work_ItemSSID = CTX.getOrInsertSyncScopeID("work_item");
48-
WorkGroupSSID = CTX.getOrInsertSyncScopeID("workgroup");
49-
DeviceSSID = CTX.getOrInsertSyncScopeID("device");
50-
AllSVMDevicesSSID = CTX.getOrInsertSyncScopeID("all_svm_devices");
51-
SubGroupSSID = CTX.getOrInsertSyncScopeID("sub_group");
37+
struct SyncScopeIDs {
38+
llvm::SyncScope::ID Work_ItemSSID;
39+
llvm::SyncScope::ID WorkGroupSSID;
40+
llvm::SyncScope::ID DeviceSSID;
41+
llvm::SyncScope::ID AllSVMDevicesSSID;
42+
llvm::SyncScope::ID SubGroupSSID;
43+
44+
SyncScopeIDs() {}
45+
SyncScopeIDs(llvm::LLVMContext &Context) {
46+
Work_ItemSSID = Context.getOrInsertSyncScopeID("work_item");
47+
WorkGroupSSID = Context.getOrInsertSyncScopeID("workgroup");
48+
DeviceSSID = Context.getOrInsertSyncScopeID("device");
49+
AllSVMDevicesSSID = Context.getOrInsertSyncScopeID("all_svm_devices");
50+
SubGroupSSID = Context.getOrInsertSyncScopeID("sub_group");
5251
}
5352
};
5453

55-
} // end namespace llvm
54+
} // namespace
5655

5756
#define DEBUG_TYPE "spirv-isel"
5857

@@ -76,7 +75,7 @@ class SPIRVInstructionSelector : public InstructionSelector {
7675
const RegisterBankInfo &RBI;
7776
SPIRVGlobalRegistry &GR;
7877
MachineRegisterInfo *MRI;
79-
SPIRVMachineModuleInfo *MMI = nullptr;
78+
SyncScopeIDs SSIDs;
8079

8180
/// We need to keep track of the number we give to anonymous global values to
8281
/// generate the same name every time when this is needed.
@@ -280,7 +279,7 @@ void SPIRVInstructionSelector::setupMF(MachineFunction &MF, GISelKnownBits *KB,
280279
CodeGenCoverage *CoverageInfo,
281280
ProfileSummaryInfo *PSI,
282281
BlockFrequencyInfo *BFI) {
283-
MMI = &MF.getMMI().getObjFileInfo<SPIRVMachineModuleInfo>();
282+
SSIDs = SyncScopeIDs(MF.getFunction().getContext());
284283
MRI = &MF.getRegInfo();
285284
GR.setCurrentFunc(MF);
286285
InstructionSelector::setupMF(MF, KB, CoverageInfo, PSI, BFI);
@@ -721,16 +720,16 @@ bool SPIRVInstructionSelector::selectBitcast(Register ResVReg,
721720
}
722721

723722
static SPIRV::Scope::Scope getScope(SyncScope::ID Ord,
724-
SPIRVMachineModuleInfo *MMI) {
725-
if (Ord == SyncScope::SingleThread || Ord == MMI->Work_ItemSSID)
723+
const SyncScopeIDs &SSIDs) {
724+
if (Ord == SyncScope::SingleThread || Ord == SSIDs.Work_ItemSSID)
726725
return SPIRV::Scope::Invocation;
727-
else if (Ord == SyncScope::System || Ord == MMI->DeviceSSID)
726+
else if (Ord == SyncScope::System || Ord == SSIDs.DeviceSSID)
728727
return SPIRV::Scope::Device;
729-
else if (Ord == MMI->WorkGroupSSID)
728+
else if (Ord == SSIDs.WorkGroupSSID)
730729
return SPIRV::Scope::Workgroup;
731-
else if (Ord == MMI->AllSVMDevicesSSID)
730+
else if (Ord == SSIDs.AllSVMDevicesSSID)
732731
return SPIRV::Scope::CrossDevice;
733-
else if (Ord == MMI->SubGroupSSID)
732+
else if (Ord == SSIDs.SubGroupSSID)
734733
return SPIRV::Scope::Subgroup;
735734
else
736735
// OpenCL approach is: "The functions that do not have memory_scope argument
@@ -896,7 +895,7 @@ bool SPIRVInstructionSelector::selectAtomicRMW(Register ResVReg,
896895
assert(I.hasOneMemOperand());
897896
const MachineMemOperand *MemOp = *I.memoperands_begin();
898897
uint32_t Scope =
899-
static_cast<uint32_t>(getScope(MemOp->getSyncScopeID(), MMI));
898+
static_cast<uint32_t>(getScope(MemOp->getSyncScopeID(), SSIDs));
900899
Register ScopeReg = buildI32Constant(Scope, I);
901900

902901
Register Ptr = I.getOperand(1).getReg();
@@ -967,7 +966,7 @@ bool SPIRVInstructionSelector::selectFence(MachineInstr &I) const {
967966
uint32_t MemSem = static_cast<uint32_t>(getMemSemantics(AO));
968967
Register MemSemReg = buildI32Constant(MemSem, I);
969968
SyncScope::ID Ord = SyncScope::ID(I.getOperand(1).getImm());
970-
uint32_t Scope = static_cast<uint32_t>(getScope(Ord, MMI));
969+
uint32_t Scope = static_cast<uint32_t>(getScope(Ord, SSIDs));
971970
Register ScopeReg = buildI32Constant(Scope, I);
972971
MachineBasicBlock &BB = *I.getParent();
973972
return BuildMI(BB, I, I.getDebugLoc(), TII.get(SPIRV::OpMemoryBarrier))
@@ -987,7 +986,7 @@ bool SPIRVInstructionSelector::selectAtomicCmpXchg(Register ResVReg,
987986
assert(I.hasOneMemOperand());
988987
const MachineMemOperand *MemOp = *I.memoperands_begin();
989988
unsigned Scope =
990-
static_cast<uint32_t>(getScope(MemOp->getSyncScopeID(), MMI));
989+
static_cast<uint32_t>(getScope(MemOp->getSyncScopeID(), SSIDs));
991990
ScopeReg = buildI32Constant(Scope, I);
992991

993992
unsigned ScSem = static_cast<uint32_t>(

0 commit comments

Comments
 (0)