[llvm] [RISCV][GISel] Select G_FENCE. (PR #73184)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 27 12:16:51 PST 2023
================
@@ -1099,6 +1110,63 @@ bool RISCVInstructionSelector::selectFPCompare(MachineInstr &MI,
return true;
}
+void RISCVInstructionSelector::emitFence(AtomicOrdering FenceOrdering,
+ SyncScope::ID FenceSSID,
+ MachineIRBuilder &MIB) const {
+ if (STI.hasStdExtZtso()) {
+ // The only fence that needs an instruction is a sequentially-consistent
+ // cross-thread fence.
+ if (FenceOrdering == AtomicOrdering::SequentiallyConsistent &&
+ FenceSSID == SyncScope::System) {
+ // fence rw, rw
+ MIB.buildInstr(RISCV::FENCE, {}, {})
+ .addImm(RISCVFenceField::R | RISCVFenceField::W)
+ .addImm(RISCVFenceField::R | RISCVFenceField::W);
+ return;
+ }
+
+ // MEMBARRIER is a compiler barrier; it codegens to a no-op.
+ MIB.buildInstr(TargetOpcode::MEMBARRIER, {}, {});
+ return;
+ }
+
+ // singlethread fences only synchronize with signal handlers on the same
+ // thread and thus only need to preserve instruction order, not actually
+ // enforce memory ordering.
+ if (FenceSSID == SyncScope::SingleThread) {
+ MIB.buildInstr(TargetOpcode::MEMBARRIER, {}, {});
+ return;
+ }
+
+ // Refer to Table A.6 in the version 2.3 draft of the RISC-V Instruction Set
----------------
topperc wrote:
Maybe not. I copied this comment from RISCVInstrInfo.td which is where I translated this from.
https://github.com/llvm/llvm-project/pull/73184
More information about the llvm-commits
mailing list