[llvm] [RISCV][GISel] Select G_FENCE. (PR #73184)
Michael Maitland via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 27 11:49:38 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
----------------
michaelmaitland wrote:
nit: Is 2.3 version a thing? I can only find [version 20191213](https://drive.google.com/file/d/1s0lZxUZaa7eV_O0_WsZzaurFLLww7ou5/view) as the only versioned pdf after 2.2. My google search was `riscv instruction set volume i "this is version 2.3"`.
https://github.com/llvm/llvm-project/pull/73184
More information about the llvm-commits
mailing list