This is an archive of the discontinued LLVM Phabricator instance.

[globalisel][irtranslator] Add support for atomicrmw and (strong) cmpxchg
ClosedPublic

Authored by dsanders on Nov 15 2017, 10:51 AM.

Details

Summary

This patch adds support for the atomicrmw instructions and the strong
cmpxchg instruction to the IRTranslator.

I've left out weak cmpxchg because LangRef.rst isn't entirely clear on what
difference it makes to the backend. As far as I can tell from the code, it
only matters to AtomicExpandPass which is run at the LLVM-IR level.

Diff Detail

Repository
rL LLVM

Event Timeline

dsanders created this revision.Nov 15 2017, 10:51 AM
dsanders updated this revision to Diff 123355.Nov 17 2017, 8:59 AM

Rename G_ATOMIC_CMPXCHG to G_ATOMIC_CMPXCHG_WITH_SUCCESS. There is a gap between
the LLVM-IR cmpxchg instruction and the SDNode that is usable in SelectionDAG
patterns. IRTranslate into a LLVM-IR-like representation. We'll then bridge the
gap in the legalizer.

qcolombet accepted this revision.Dec 4 2017, 1:06 PM

LGTM nitpicks below

include/llvm/Target/GenericOpcodes.td
501 ↗(On Diff #123355)

type2 => type1 (not super important, I believe it would work either way)

lib/CodeGen/GlobalISel/IRTranslator.cpp
1134 ↗(On Diff #123355)

Use ResType instead of I.getType()

1145 ↗(On Diff #123355)

Aditya pushed patches to make this kind of blob of create vregs unnecessary.
Could you use something similar here?

Edit: Oh part of this, is because we have only one value for the result, right?

1159 ↗(On Diff #123355)

SmallVect... 2?

lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
710 ↗(On Diff #123355)

Could we macro-generate those?
Like
GENERATE_BUILD_ATOMICRMW(Xchg, XCHG)
GENERATE_BUILD_ATOMICRMW(Sub, SUB)

That way if we have to make a change we only have to change the macro.

785 ↗(On Diff #123355)

Different NFC patch ;).

This revision is now accepted and ready to land.Dec 4 2017, 1:06 PM
dsanders updated this revision to Diff 152994.Jun 26 2018, 5:52 PM
dsanders marked an inline comment as done.

Rebased to master. This is still ready to commit but it needs a corresponding change to ISel
to be able to land.

This revision was automatically updated to reflect the committed changes.