[PATCH] D94784: [llvm][nvptx] add atomicity to counter in ISelLowering
Theodore Popp via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 15 08:13:59 PST 2021
tpopp created this revision.
tpopp added reviewers: bkramer, tra.
Herald added subscribers: jfb, hiraditya, jholewinski.
tpopp requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Previously uniqueCallSite could have race conditions between different
threads. Now it is accessed with an atomic RMW and will be unique
between different threads.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D94784
Files:
llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
llvm/lib/Target/NVPTX/NVPTXISelLowering.h
Index: llvm/lib/Target/NVPTX/NVPTXISelLowering.h
===================================================================
--- llvm/lib/Target/NVPTX/NVPTXISelLowering.h
+++ llvm/lib/Target/NVPTX/NVPTXISelLowering.h
@@ -491,7 +491,8 @@
std::string getPrototype(const DataLayout &DL, Type *, const ArgListTy &,
const SmallVectorImpl<ISD::OutputArg> &,
- MaybeAlign retAlignment, const CallBase &CB) const;
+ MaybeAlign retAlignment, const CallBase &CB,
+ const unsigned &uniqueCallSite) const;
SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
const SmallVectorImpl<ISD::OutputArg> &Outs,
Index: llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
===================================================================
--- llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
+++ llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
@@ -65,7 +65,7 @@
using namespace llvm;
-static unsigned int uniqueCallSite = 0;
+static std::atomic<unsigned> globalUniqueCallSite = ATOMIC_VAR_INIT(0);
static cl::opt<bool> sched4reg(
"nvptx-sched4reg",
@@ -1243,7 +1243,7 @@
std::string NVPTXTargetLowering::getPrototype(
const DataLayout &DL, Type *retTy, const ArgListTy &Args,
const SmallVectorImpl<ISD::OutputArg> &Outs, MaybeAlign retAlignment,
- const CallBase &CB) const {
+ const CallBase &CB, const unsigned &uniqueCallSite) const {
auto PtrVT = getPointerTy(DL);
bool isABI = (STI.getSmVersion() >= 20);
@@ -1422,6 +1422,7 @@
if (!isABI)
return Chain;
+ unsigned uniqueCallSite = globalUniqueCallSite.fetch_add(1);
SDValue tempChain = Chain;
Chain = DAG.getCALLSEQ_START(Chain, uniqueCallSite, 0, dl);
SDValue InFlag = Chain.getValue(1);
@@ -1678,7 +1679,8 @@
// The prototype is embedded in a string and put as the operand for a
// CallPrototype SDNode which will print out to the value of the string.
SDVTList ProtoVTs = DAG.getVTList(MVT::Other, MVT::Glue);
- std::string Proto = getPrototype(DL, RetTy, Args, Outs, retAlignment, *CB);
+ std::string Proto =
+ getPrototype(DL, RetTy, Args, Outs, retAlignment, *CB, uniqueCallSite);
const char *ProtoStr =
nvTM->getManagedStrPool()->getManagedString(Proto.c_str())->c_str();
SDValue ProtoOps[] = {
@@ -1838,7 +1840,6 @@
true),
InFlag, dl);
InFlag = Chain.getValue(1);
- uniqueCallSite++;
// Append ProxyReg instructions to the chain to make sure that `callseq_end`
// will not get lost. Otherwise, during libcalls expansion, the nodes can become
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94784.316956.patch
Type: text/x-patch
Size: 2718 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210115/52800169/attachment.bin>
More information about the llvm-commits
mailing list