How to create a atomic store/load with LLVM IR from C++?

I was skinning through LLVM Atomic Instructions and Concurrency Guid, trying to figure how to create atomic (thread safe) store/loads.

I saw that there are load atomic and store atomic instructions.

load atomic and store atomic provide the same basic functionality as non-atomic loads and stores, but provide additional guarantees in situations where threads and signals are involved.

I’m wondering how I can create them with the C++ API, currently I’m creating them with a IRBuilder like so CreateLoad and CreateStore.

How can I create load atomic and store atomic operations?

You call setAtomic on the LoadInst or StoreInst returned by the Create* functions. E.g. this one.

2 Likes

Thanks!