This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen] Introduce a generic MEMBARRIER instruction [mostly-nfc]
ClosedPublic

Authored by reames on Jan 10 2023, 9:49 AM.

Details

Summary

This is a follow up to D141317 which extends the common code to include a target independent pseudo instruction. This is an alternative to (subset of) D92842 which tries to be as close to NFC as possible.

A couple things to call out for reviewers.

  1. I couldn't find a way to do tablegen matching for a generic SDAG node to a generic MI. I hacked this up, but surely there's something obvious I'm missing here? If not, I can cleanup the hacky code; I just didn't bother in the hopes there was a table gen based approach I'd missed.
  1. The test change in X86 is because we loose the scheduling information on the instruction. However, I think this was actually a bug in x86 since no instruction was emitted for a MEMBARRIER. Concluding that a meta instruction has latency just seems wrong?
  1. More generally, is there anything specifically I need to do around scheduling info for the generic instruction? I'm unfamiliar with that part of our system.
  1. I intentionally left some parts of D92842 out. Specifically, several of the changes in the X86 code (data independence and outlining) appear functional, and likely worthy of their own review. Additionally, I'm not handling ARM/AArch64 at all. Those targets need the ordering whereas none of the others do. I want to get this in and tested before retrofitting in ordering to support those targets.

Diff Detail

Event Timeline

reames created this revision.Jan 10 2023, 9:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 10 2023, 9:49 AM
reames requested review of this revision.Jan 10 2023, 9:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 10 2023, 9:49 AM
Herald added a subscriber: wdng. · View Herald Transcript
reames updated this revision to Diff 487882.Jan 10 2023, 10:36 AM

Rebase, and add RISCV since the change to add MEMBARRIER landed.

craig.topper added inline comments.Jan 10 2023, 12:23 PM
llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
2908

I don't know of any target independent isel patterns today. I think all of the target independent opcodes are handled in this switch. The ones that do setNodeId(-1) are converted to MachineInstr in InstrEmitter.cpp.

Not sure what the "generalize op types" part of this comment means.

reames updated this revision to Diff 487963.Jan 10 2023, 1:17 PM

Cleanup the manual selection since there doesn't appear to be a td means for this.

arsenm accepted this revision.Jan 10 2023, 1:20 PM
This revision is now accepted and ready to land.Jan 10 2023, 1:20 PM

Broadly, this looks right. I'm glad stuff is finally moving on changes in this direction.

Why does this barrier not need an ordering, but ARM/AArch64 do? Some of the targets in this patch still have weak memory orderings (RISC-V). Is the plan to update the MEMBARRIER with the ordering later, in a way that won't actually affect the selection for these targets so far?

Broadly, this looks right. I'm glad stuff is finally moving on changes in this direction.

Why does this barrier not need an ordering, but ARM/AArch64 do? Some of the targets in this patch still have weak memory orderings (RISC-V). Is the plan to update the MEMBARRIER with the ordering later, in a way that won't actually affect the selection for these targets so far?

I am working incrementally so that each patch is self contained, with as few test deltas as I can manage. As I said in the commit comment, this is merely staging, not a inherent disagreement on the result.

I've taken a quick look at ARM/AArch64 and don't see optimizations actually using the order on their compiler_barrier. We do have one backend which does, but that's AMDGPU which doesn't distinguish between a membarrier and a atomic_fence until late expansion.

I've taken a quick look at ARM/AArch64 and don't see optimizations actually using the order on their compiler_barrier.

The ARM/AArch64 patch is here: https://reviews.llvm.org/D141513. As expected, that didn't need the ordering.

skan added a subscriber: skan.Jan 21 2023, 12:07 AM