Skip to content

Commit 2f8c098

Browse files
[Target][AMDGPU] Fix TSan error on AMDGPU Target.
Updating the value of the global flag within the code was flagged as a TSAN error. Fixing that.
1 parent 320a519 commit 2f8c098

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.cpp

Lines changed: 18 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,15 @@ 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.getValue();
117+
uint32_t AssumedStackSizeForExternalCall =
118+
clAssumedStackSizeForExternalCall.getValue();
115119
if (AMDGPU::getAMDHSACodeObjectVersion(M) >= AMDGPU::AMDHSA_COV5 ||
116120
STI.getTargetTriple().getOS() == Triple::AMDPAL) {
117-
if (!AssumedStackSizeForDynamicSizeObjects.getNumOccurrences())
121+
if (!clAssumedStackSizeForDynamicSizeObjects.getNumOccurrences())
118122
AssumedStackSizeForDynamicSizeObjects = 0;
119-
if (!AssumedStackSizeForExternalCall.getNumOccurrences())
123+
if (!clAssumedStackSizeForExternalCall.getNumOccurrences())
120124
AssumedStackSizeForExternalCall = 0;
121125
}
122126

@@ -132,7 +136,8 @@ bool AMDGPUResourceUsageAnalysis::runOnModule(Module &M) {
132136
CallGraphResourceInfo.insert(std::pair(F, SIFunctionResourceInfo()));
133137
SIFunctionResourceInfo &Info = CI.first->second;
134138
assert(CI.second && "should only be called once per function");
135-
Info = analyzeResourceUsage(*MF, TM);
139+
Info = analyzeResourceUsage(*MF, TM, AssumedStackSizeForDynamicSizeObjects,
140+
AssumedStackSizeForExternalCall);
136141
HasIndirectCall |= Info.HasIndirectCall;
137142
}
138143

@@ -152,7 +157,8 @@ bool AMDGPUResourceUsageAnalysis::runOnModule(Module &M) {
152157
SIFunctionResourceInfo &Info = CI.first->second;
153158
MachineFunction *MF = MMI.getMachineFunction(*F);
154159
assert(MF && "function must have been generated already");
155-
Info = analyzeResourceUsage(*MF, TM);
160+
Info = analyzeResourceUsage(*MF, TM, AssumedStackSizeForDynamicSizeObjects,
161+
AssumedStackSizeForExternalCall);
156162
HasIndirectCall |= Info.HasIndirectCall;
157163
}
158164

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

165171
AMDGPUResourceUsageAnalysis::SIFunctionResourceInfo
166172
AMDGPUResourceUsageAnalysis::analyzeResourceUsage(
167-
const MachineFunction &MF, const TargetMachine &TM) const {
173+
const MachineFunction &MF, const TargetMachine &TM,
174+
uint32_t AssumedStackSizeForDynamicSizeObjects,
175+
uint32_t AssumedStackSizeForExternalCall) const {
168176
SIFunctionResourceInfo Info;
169177

170178
const SIMachineFunctionInfo *MFI = MF.getInfo<SIMachineFunctionInfo>();
@@ -541,9 +549,9 @@ AMDGPUResourceUsageAnalysis::analyzeResourceUsage(
541549
// directly call the tail called function. If a kernel directly
542550
// calls a tail recursive function, we'll assume maximum stack size
543551
// based on the regular call instruction.
544-
CalleeFrameSize =
545-
std::max(CalleeFrameSize,
546-
static_cast<uint64_t>(AssumedStackSizeForExternalCall));
552+
CalleeFrameSize = std::max(
553+
CalleeFrameSize,
554+
static_cast<uint64_t>(AssumedStackSizeForExternalCall));
547555
}
548556
}
549557

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)