Skip to content

Commit df5e431

Browse files
[Target][AMDGPU] Fix TSan error on AMDGPU Target. (#79529)
Updating the value of the global flag within the code was flagged as a TSAN error. Fixing that.
1 parent 76ead96 commit df5e431

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ char &llvm::AMDGPUResourceUsageAnalysisID = AMDGPUResourceUsageAnalysis::ID;
4646
// In code object v4 and older, we need to tell the runtime some amount ahead of
4747
// time if we don't know the true stack size. Assume a smaller number if this is
4848
// only due to dynamic / non-entry block allocas.
49-
static cl::opt<uint32_t> AssumedStackSizeForExternalCall(
49+
static cl::opt<uint32_t> clAssumedStackSizeForExternalCall(
5050
"amdgpu-assume-external-call-stack-size",
5151
cl::desc("Assumed stack use of any external call (in bytes)"), cl::Hidden,
5252
cl::init(16384));
5353

54-
static cl::opt<uint32_t> AssumedStackSizeForDynamicSizeObjects(
54+
static cl::opt<uint32_t> clAssumedStackSizeForDynamicSizeObjects(
5555
"amdgpu-assume-dynamic-stack-object-size",
5656
cl::desc("Assumed extra stack use if there are any "
5757
"variable sized objects (in bytes)"),
@@ -112,11 +112,14 @@ bool AMDGPUResourceUsageAnalysis::runOnModule(Module &M) {
112112

113113
// By default, for code object v5 and later, track only the minimum scratch
114114
// size
115+
uint32_t AssumedStackSizeForDynamicSizeObjects =
116+
clAssumedStackSizeForDynamicSizeObjects;
117+
uint32_t AssumedStackSizeForExternalCall = clAssumedStackSizeForExternalCall;
115118
if (AMDGPU::getAMDHSACodeObjectVersion(M) >= AMDGPU::AMDHSA_COV5 ||
116119
STI.getTargetTriple().getOS() == Triple::AMDPAL) {
117-
if (!AssumedStackSizeForDynamicSizeObjects.getNumOccurrences())
120+
if (clAssumedStackSizeForDynamicSizeObjects.getNumOccurrences() == 0)
118121
AssumedStackSizeForDynamicSizeObjects = 0;
119-
if (!AssumedStackSizeForExternalCall.getNumOccurrences())
122+
if (clAssumedStackSizeForExternalCall.getNumOccurrences() == 0)
120123
AssumedStackSizeForExternalCall = 0;
121124
}
122125

@@ -132,7 +135,8 @@ bool AMDGPUResourceUsageAnalysis::runOnModule(Module &M) {
132135
CallGraphResourceInfo.insert(std::pair(F, SIFunctionResourceInfo()));
133136
SIFunctionResourceInfo &Info = CI.first->second;
134137
assert(CI.second && "should only be called once per function");
135-
Info = analyzeResourceUsage(*MF, TM);
138+
Info = analyzeResourceUsage(*MF, TM, AssumedStackSizeForDynamicSizeObjects,
139+
AssumedStackSizeForExternalCall);
136140
HasIndirectCall |= Info.HasIndirectCall;
137141
}
138142

@@ -152,7 +156,8 @@ bool AMDGPUResourceUsageAnalysis::runOnModule(Module &M) {
152156
SIFunctionResourceInfo &Info = CI.first->second;
153157
MachineFunction *MF = MMI.getMachineFunction(*F);
154158
assert(MF && "function must have been generated already");
155-
Info = analyzeResourceUsage(*MF, TM);
159+
Info = analyzeResourceUsage(*MF, TM, AssumedStackSizeForDynamicSizeObjects,
160+
AssumedStackSizeForExternalCall);
156161
HasIndirectCall |= Info.HasIndirectCall;
157162
}
158163

@@ -164,7 +169,9 @@ bool AMDGPUResourceUsageAnalysis::runOnModule(Module &M) {
164169

165170
AMDGPUResourceUsageAnalysis::SIFunctionResourceInfo
166171
AMDGPUResourceUsageAnalysis::analyzeResourceUsage(
167-
const MachineFunction &MF, const TargetMachine &TM) const {
172+
const MachineFunction &MF, const TargetMachine &TM,
173+
uint32_t AssumedStackSizeForDynamicSizeObjects,
174+
uint32_t AssumedStackSizeForExternalCall) const {
168175
SIFunctionResourceInfo Info;
169176

170177
const SIMachineFunctionInfo *MFI = MF.getInfo<SIMachineFunctionInfo>();
@@ -541,9 +548,9 @@ AMDGPUResourceUsageAnalysis::analyzeResourceUsage(
541548
// directly call the tail called function. If a kernel directly
542549
// calls a tail recursive function, we'll assume maximum stack size
543550
// based on the regular call instruction.
544-
CalleeFrameSize =
545-
std::max(CalleeFrameSize,
546-
static_cast<uint64_t>(AssumedStackSizeForExternalCall));
551+
CalleeFrameSize = std::max(
552+
CalleeFrameSize,
553+
static_cast<uint64_t>(AssumedStackSizeForExternalCall));
547554
}
548555
}
549556

llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@ struct AMDGPUResourceUsageAnalysis : public ModulePass {
7272
}
7373

7474
private:
75-
SIFunctionResourceInfo analyzeResourceUsage(const MachineFunction &MF,
76-
const TargetMachine &TM) const;
75+
SIFunctionResourceInfo
76+
analyzeResourceUsage(const MachineFunction &MF, const TargetMachine &TM,
77+
uint32_t AssumedStackSizeForDynamicSizeObjects,
78+
uint32_t AssumedStackSizeForExternalCall) const;
7779
void propagateIndirectCallRegisterUsage();
7880

7981
DenseMap<const Function *, SIFunctionResourceInfo> CallGraphResourceInfo;

0 commit comments

Comments
 (0)