This is an archive of the discontinued LLVM Phabricator instance.

Add a thread-model knob for lowering atomics on baremetal & single threaded systems
ClosedPublic

Authored by jroelofs on Aug 20 2014, 8:16 AM.

Details

Reviewers
rengolin

Diff Detail

Event Timeline

jroelofs updated this revision to Diff 12701.Aug 20 2014, 8:16 AM
jroelofs retitled this revision from to Add a thread-model knob for lowering atomics on baremetal & single threaded systems.
jroelofs updated this object.
jroelofs edited the test plan for this revision. (Show Details)
jroelofs added a reviewer: rengolin.
jroelofs added a subscriber: Unknown Object (MLST).

A few inline comments.

I would also suggest tests for atomic loads/stores/fences and not just atomicRMW.

lib/Target/ARM/ARMISelLowering.cpp
752

single threded -> single threaded

757

This repetition of the test for ThreadModel::Single looks unnecessary to me.

Why not test for it first, then put the rest in an else block ?

if (TM.Options>ThreadModel == ThreadModel::Single) {
  setOperationAction(ISD::ATOMIC_FENCE,  MVT::Other, Expand);
else if (Subtarget->hasAnyDataBarrier() && !Subtarget->isThumb1Only()) {
...

As a bonus, it makes the logic simpler, avoiding setting insertFencesForAtomic (which is a no-op in that case I believe, since all atomic operations will have been lowered before).

lib/Target/ARM/ARMTargetMachine.cpp
161

Shouldn't this pass be disabled when the ThreadModel is single? Especially as it runs first, I expect it will turn for example atomicrmw add in a loop of ldrex/strex instead of a simple add instruction (whenever the subtarget does not disable it at least).

jroelofs added inline comments.Aug 20 2014, 1:49 PM
lib/Target/ARM/ARMISelLowering.cpp
757

That does look cleaner.

lib/Target/ARM/ARMTargetMachine.cpp
161

Oh, good point!

jroelofs updated this revision to Diff 12713.Aug 20 2014, 2:19 PM

Follow up on morisset's comments.

rengolin accepted this revision.Aug 21 2014, 5:02 AM
rengolin edited edge metadata.

I wasn't following the atomics discussion, but this patch looks good. If Morisset is happy with your changer, LGTM.

thanks,
--renato

This revision is now accepted and ready to land.Aug 21 2014, 5:02 AM

I added a couple load, store, and fence tests, and committed this as r216182.

Thanks for the review!

Jon

jroelofs closed this revision.Aug 21 2014, 7:46 AM