llvm.org GIT mirror llvm / e6cda0e
Expose IRBuilder::CreateAtomicCmpXchg as LLVMBuildAtomicCmpXchg in the C API. Summary: Also expose getters and setters in the C API, so that the change can be tested. Reviewers: nhaehnle, axw, joker.eph Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D18260 From: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@263886 91177308-0d34-0410-b5e6-96231b3b80d8 Mehdi Amini 4 years ago
4 changed file(s) with 91 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
29392939 LLVMValueRef PTR, LLVMValueRef Val,
29402940 LLVMAtomicOrdering ordering,
29412941 LLVMBool singleThread);
2942 LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef B, LLVMValueRef Ptr,
2943 LLVMValueRef Cmp, LLVMValueRef New,
2944 LLVMAtomicOrdering SuccessOrdering,
2945 LLVMAtomicOrdering FailureOrdering,
2946 LLVMBool SingleThread);
2947
2948 LLVMBool LLVMIsAtomicSingleThread(LLVMValueRef AtomicInst);
2949 void LLVMSetAtomicSingleThread(LLVMValueRef AtomicInst, LLVMBool SingleThread);
2950
2951 LLVMAtomicOrdering LLVMGetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst);
2952 void LLVMSetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst,
2953 LLVMAtomicOrdering Ordering);
2954 LLVMAtomicOrdering LLVMGetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst);
2955 void LLVMSetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst,
2956 LLVMAtomicOrdering Ordering);
29422957
29432958 /**
29442959 * @}
29072907 mapFromLLVMOrdering(ordering), singleThread ? SingleThread : CrossThread));
29082908 }
29092909
2910 LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef B, LLVMValueRef Ptr,
2911 LLVMValueRef Cmp, LLVMValueRef New,
2912 LLVMAtomicOrdering SuccessOrdering,
2913 LLVMAtomicOrdering FailureOrdering,
2914 LLVMBool singleThread) {
2915
2916 return wrap(unwrap(B)->CreateAtomicCmpXchg(unwrap(Ptr), unwrap(Cmp),
2917 unwrap(New), mapFromLLVMOrdering(SuccessOrdering),
2918 mapFromLLVMOrdering(FailureOrdering),
2919 singleThread ? SingleThread : CrossThread));
2920 }
2921
2922
2923 LLVMBool LLVMIsAtomicSingleThread(LLVMValueRef AtomicInst) {
2924 Value *P = unwrap(AtomicInst);
2925
2926 if (AtomicRMWInst *I = dyn_cast(P))
2927 return I->getSynchScope() == SingleThread;
2928 return cast(P)->getSynchScope() == SingleThread;
2929 }
2930
2931 void LLVMSetAtomicSingleThread(LLVMValueRef AtomicInst, LLVMBool NewValue) {
2932 Value *P = unwrap(AtomicInst);
2933 SynchronizationScope Sync = NewValue ? SingleThread : CrossThread;
2934
2935 if (AtomicRMWInst *I = dyn_cast(P))
2936 return I->setSynchScope(Sync);
2937 return cast(P)->setSynchScope(Sync);
2938 }
2939
2940 LLVMAtomicOrdering LLVMGetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst) {
2941 Value *P = unwrap(CmpXchgInst);
2942 return mapToLLVMOrdering(cast(P)->getSuccessOrdering());
2943 }
2944
2945 void LLVMSetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst,
2946 LLVMAtomicOrdering Ordering) {
2947 Value *P = unwrap(CmpXchgInst);
2948 AtomicOrdering O = mapFromLLVMOrdering(Ordering);
2949
2950 return cast(P)->setSuccessOrdering(O);
2951 }
2952
2953 LLVMAtomicOrdering LLVMGetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst) {
2954 Value *P = unwrap(CmpXchgInst);
2955 return mapToLLVMOrdering(cast(P)->getFailureOrdering());
2956 }
2957
2958 void LLVMSetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst,
2959 LLVMAtomicOrdering Ordering) {
2960 Value *P = unwrap(CmpXchgInst);
2961 AtomicOrdering O = mapFromLLVMOrdering(Ordering);
2962
2963 return cast(P)->setFailureOrdering(O);
2964 }
29102965
29112966 /*===-- Module providers --------------------------------------------------===*/
29122967
0 ; RUN: llvm-as < %s | llvm-dis > %t.orig
1 ; RUN: llvm-as < %s | llvm-c-test --echo > %t.echo
2 ; RUN: diff -w %t.orig %t.echo
3
4 define i32 @main() {
5 %1 = alloca i32
6 %2 = cmpxchg i32* %1, i32 2, i32 3 seq_cst acquire
7 %3 = extractvalue { i32, i1 } %2, 0
8 ret i32 %3
9 }
521521 Dst = LLVMBuildGEP(Builder, Ptr, Idx.data(), NumIdx, Name);
522522 break;
523523 }
524 case LLVMAtomicCmpXchg: {
525 LLVMValueRef Ptr = CloneValue(LLVMGetOperand(Src, 0));
526 LLVMValueRef Cmp = CloneValue(LLVMGetOperand(Src, 1));
527 LLVMValueRef New = CloneValue(LLVMGetOperand(Src, 2));
528 LLVMAtomicOrdering Succ = LLVMGetCmpXchgSuccessOrdering(Src);
529 LLVMAtomicOrdering Fail = LLVMGetCmpXchgFailureOrdering(Src);
530 LLVMBool SingleThread = LLVMIsAtomicSingleThread(Src);
531
532 Dst = LLVMBuildAtomicCmpXchg(Builder, Ptr, Cmp, New, Succ, Fail,
533 SingleThread);
534 } break;
524535 case LLVMBitCast: {
525536 LLVMValueRef V = CloneValue(LLVMGetOperand(Src, 0));
526537 Dst = LLVMBuildBitCast(Builder, V, CloneType(Src), Name);