[llvm] [LLVM] Add a C API for creating instructions with custom syncscopes. (PR #104775)

Tim Besard via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 19 11:48:02 PDT 2024


================
@@ -4369,12 +4369,14 @@ int LLVMGetMaskValue(LLVMValueRef SVInst, unsigned Elt) {
 int LLVMGetUndefMaskElem(void) { return PoisonMaskElem; }
 
 LLVMBool LLVMIsAtomicSingleThread(LLVMValueRef AtomicInst) {
-  return getAtomicSyncScopeID(unwrap<Instruction>(AtomicInst)).value() ==
-         SyncScope::SingleThread;
+  Instruction *I = unwrap<Instruction>(AtomicInst);
+  if (!I->isAtomic())
+    return 0;
+  return getAtomicSyncScopeID(I).value() == SyncScope::SingleThread;
 }
 
 unsigned LLVMGetAtomicSyncScopeID(LLVMValueRef AtomicInst) {
-  return getAtomicSyncScopeID(unwrap<Instruction>(AtomicInst)).value();
+  return getAtomicSyncScopeID(unwrap<Instruction>(AtomicInst)).value_or(-1);
 }
----------------
maleadt wrote:

I'm not really happy with this, but `LLVMIsAtomicSingleThread` used to work on non-atomic instructions, so I guess it needs to keep working like that. And because of how `llvm-c-test --echo` clones instructions, that implies `LLVMGetAtomicSyncScopeID` needs to support it as well. Or should I add an `LLVMInstructionIsAtomic` wrapper for `isAtomic` and make `LLVMGetAtomicSyncScopeID` only support relevant instructions?

https://github.com/llvm/llvm-project/pull/104775


More information about the llvm-commits mailing list