Skip to content

Commit 6eb9e21

Browse files
authored
RFC: [AMDGPU] Check subtarget features for consistency (#86957)
Implement GCNSubtarget::checkSubtargetFeatures as a canonical place to check subtarget features for consistency and diagnose any inconsistencies. To start with, the implementation just checks that either wavefrontsize32 or wavefrontsize64 is selected. checkSubtargetFeatures is called at the start of instruction selection. This is pretty arbitrary. It is just a convenient point at which we have access to the subtarget that we're going to use for codegenning a particular function.
1 parent 1494d88 commit 6eb9e21

File tree

7 files changed

+31
-5
lines changed

7 files changed

+31
-5
lines changed

llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ bool AMDGPUDAGToDAGISel::runOnMachineFunction(MachineFunction &MF) {
132132
}
133133
#endif
134134
Subtarget = &MF.getSubtarget<GCNSubtarget>();
135+
Subtarget->checkSubtargetFeatures(MF.getFunction());
135136
Mode = SIModeRegisterDefaults(MF.getFunction(), *Subtarget);
136137
return SelectionDAGISel::runOnMachineFunction(MF);
137138
}

llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ void AMDGPUInstructionSelector::setupMF(MachineFunction &MF, GISelKnownBits *KB,
6363
BlockFrequencyInfo *BFI) {
6464
MRI = &MF.getRegInfo();
6565
Subtarget = &MF.getSubtarget<GCNSubtarget>();
66+
Subtarget->checkSubtargetFeatures(MF.getFunction());
6667
InstructionSelector::setupMF(MF, KB, CoverageInfo, PSI, BFI);
6768
}
6869

llvm/lib/Target/AMDGPU/AMDGPUSubtarget.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/CodeGen/GlobalISel/InlineAsmLowering.h"
2626
#include "llvm/CodeGen/MachineScheduler.h"
2727
#include "llvm/CodeGen/TargetFrameLowering.h"
28+
#include "llvm/IR/DiagnosticInfo.h"
2829
#include "llvm/IR/IntrinsicsAMDGPU.h"
2930
#include "llvm/IR/IntrinsicsR600.h"
3031
#include "llvm/IR/MDBuilder.h"
@@ -165,6 +166,15 @@ GCNSubtarget::initializeSubtargetDependencies(const Triple &TT,
165166
return *this;
166167
}
167168

169+
void GCNSubtarget::checkSubtargetFeatures(const Function &F) const {
170+
LLVMContext &Ctx = F.getContext();
171+
if (hasFeature(AMDGPU::FeatureWavefrontSize32) ==
172+
hasFeature(AMDGPU::FeatureWavefrontSize64)) {
173+
Ctx.diagnose(DiagnosticInfoUnsupported(
174+
F, "must specify exactly one of wavefrontsize32 and wavefrontsize64"));
175+
}
176+
}
177+
168178
AMDGPUSubtarget::AMDGPUSubtarget(const Triple &TT) : TargetTriple(TT) {}
169179

170180
bool AMDGPUSubtarget::useRealTrue16Insts() const {

llvm/lib/Target/AMDGPU/GCNSubtarget.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ class GCNSubtarget final : public AMDGPUGenSubtargetInfo,
250250
GCNSubtarget &initializeSubtargetDependencies(const Triple &TT,
251251
StringRef GPU, StringRef FS);
252252

253+
/// Diagnose inconsistent subtarget features before attempting to codegen
254+
/// function \p F.
255+
void checkSubtargetFeatures(const Function &F) const;
256+
253257
const SIInstrInfo *getInstrInfo() const override {
254258
return &InstrInfo;
255259
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
; RUN: not llc -global-isel=0 -mtriple=amdgcn -mcpu=gfx1100 -mattr=-wavefrontsize32,-wavefrontsize64 < %s 2>&1 | FileCheck %s -check-prefix=ERR -implicit-check-not=error:
2+
; RUN: not llc -global-isel=1 -mtriple=amdgcn -mcpu=gfx1100 -mattr=-wavefrontsize32,-wavefrontsize64 < %s 2>&1 | FileCheck %s -check-prefix=ERR -implicit-check-not=error:
3+
; RUN: not llc -global-isel=0 -mtriple=amdgcn -mcpu=gfx1100 -mattr=+wavefrontsize32,+wavefrontsize64 < %s 2>&1 | FileCheck %s -check-prefix=ERR -implicit-check-not=error:
4+
; RUN: not llc -global-isel=1 -mtriple=amdgcn -mcpu=gfx1100 -mattr=+wavefrontsize32,+wavefrontsize64 < %s 2>&1 | FileCheck %s -check-prefix=ERR -implicit-check-not=error:
5+
6+
; ERR: error: {{.*}} in function f void (): must specify exactly one of wavefrontsize32 and wavefrontsize64
7+
8+
define void @f() {
9+
ret void
10+
}

llvm/test/CodeGen/AMDGPU/remove-incompatible-wave32-feature.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
; RUN: FileCheck --check-prefix=WARN-GFX90A %s < %t
99
; RUN: llc -mtriple=amdgcn -mcpu=gfx90a -mattr=+wavefrontsize64 -verify-machineinstrs < %s
1010

11-
; RUN: llc -mtriple=amdgcn -mcpu=gfx1011 -mattr=+wavefrontsize64 -stop-after=amdgpu-remove-incompatible-functions\
11+
; RUN: llc -mtriple=amdgcn -mcpu=gfx1011 -mattr=-wavefrontsize32,+wavefrontsize64 -stop-after=amdgpu-remove-incompatible-functions\
1212
; RUN: -pass-remarks=amdgpu-remove-incompatible-functions < %s 2>%t | FileCheck -check-prefixes=GFX10 %s
13-
; RUN: llc -mtriple=amdgcn -mcpu=gfx1011 -mattr=+wavefrontsize64 -verify-machineinstrs < %s
13+
; RUN: llc -mtriple=amdgcn -mcpu=gfx1011 -mattr=-wavefrontsize32,+wavefrontsize64 -verify-machineinstrs < %s
1414

15-
; RUN: llc -mtriple=amdgcn -mcpu=gfx1100 -mattr=+wavefrontsize64 -stop-after=amdgpu-remove-incompatible-functions\
15+
; RUN: llc -mtriple=amdgcn -mcpu=gfx1100 -mattr=-wavefrontsize32,+wavefrontsize64 -stop-after=amdgpu-remove-incompatible-functions\
1616
; RUN: -pass-remarks=amdgpu-remove-incompatible-functions < %s 2>%t | FileCheck -check-prefixes=GFX11 %s
17-
; RUN: llc -mtriple=amdgcn -mcpu=gfx1100 -mattr=+wavefrontsize64 -verify-machineinstrs < %s
17+
; RUN: llc -mtriple=amdgcn -mcpu=gfx1100 -mattr=-wavefrontsize32,+wavefrontsize64 -verify-machineinstrs < %s
1818

1919
; WARN-GFX906: removing function 'needs_wavefrontsize32': +wavefrontsize32 is not supported on the current target
2020
; WARN-GFX906-NOT: not supported

llvm/test/CodeGen/AMDGPU/unknown-processor.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: llc -mtriple=amdgcn-- -mcpu=unknown -verify-machineinstrs < %s 2>&1 | FileCheck -check-prefix=ERROR -check-prefix=GCN %s
1+
; RUN: not llc -mtriple=amdgcn-- -mcpu=unknown -verify-machineinstrs < %s 2>&1 | FileCheck -check-prefix=ERROR -check-prefix=GCN %s
22
; RUN: llc -mtriple=r600-- -mcpu=unknown -verify-machineinstrs < %s 2>&1 | FileCheck -check-prefix=ERROR -check-prefix=R600 %s
33
target datalayout = "A5"
44

0 commit comments

Comments
 (0)