Skip to content

Commit

Permalink
Add support to set/get ordering for load/store from the C API
Browse files Browse the repository at this point in the history
Summary: As per title

Reviewers: chandlerc, bogner, majnemer, axw

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D11141

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243847 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
axw committed Aug 2, 2015
1 parent f03f83c commit 510a661
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/llvm-c/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -2792,6 +2792,8 @@ LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
const char *Name);
LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
LLVMAtomicOrdering LLVMGetOrdering(LLVMValueRef MemoryAccessInst);
void LLVMSetOrdering(LLVMValueRef MemoryAccessInst, LLVMAtomicOrdering Ordering);

/* Casts */
LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
Expand Down
35 changes: 34 additions & 1 deletion lib/IR/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2489,7 +2489,6 @@ LLVMValueRef LLVMBuildFree(LLVMBuilderRef B, LLVMValueRef PointerVal) {
CallInst::CreateFree(unwrap(PointerVal), unwrap(B)->GetInsertBlock())));
}


LLVMValueRef LLVMBuildLoad(LLVMBuilderRef B, LLVMValueRef PointerVal,
const char *Name) {
return wrap(unwrap(B)->CreateLoad(unwrap(PointerVal), Name));
Expand All @@ -2515,6 +2514,21 @@ static AtomicOrdering mapFromLLVMOrdering(LLVMAtomicOrdering Ordering) {
llvm_unreachable("Invalid LLVMAtomicOrdering value!");
}

static LLVMAtomicOrdering mapToLLVMOrdering(AtomicOrdering Ordering) {
switch (Ordering) {
case NotAtomic: return LLVMAtomicOrderingNotAtomic;
case Unordered: return LLVMAtomicOrderingUnordered;
case Monotonic: return LLVMAtomicOrderingMonotonic;
case Acquire: return LLVMAtomicOrderingAcquire;
case Release: return LLVMAtomicOrderingRelease;
case AcquireRelease: return LLVMAtomicOrderingAcquireRelease;
case SequentiallyConsistent:
return LLVMAtomicOrderingSequentiallyConsistent;
}

llvm_unreachable("Invalid AtomicOrdering value!");
}

LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering Ordering,
LLVMBool isSingleThread, const char *Name) {
return wrap(
Expand Down Expand Up @@ -2567,6 +2581,25 @@ void LLVMSetVolatile(LLVMValueRef MemAccessInst, LLVMBool isVolatile) {
return cast<StoreInst>(P)->setVolatile(isVolatile);
}

LLVMAtomicOrdering LLVMGetOrdering(LLVMValueRef MemAccessInst) {
Value *P = unwrap<Value>(MemAccessInst);
AtomicOrdering O;
if (LoadInst *LI = dyn_cast<LoadInst>(P))
O = LI->getOrdering();
else
O = cast<StoreInst>(P)->getOrdering();
return mapToLLVMOrdering(O);
}

void LLVMSetOrdering(LLVMValueRef MemAccessInst, LLVMAtomicOrdering Ordering) {
Value *P = unwrap<Value>(MemAccessInst);
AtomicOrdering O = mapFromLLVMOrdering(Ordering);

if (LoadInst *LI = dyn_cast<LoadInst>(P))
return LI->setOrdering(O);
return cast<StoreInst>(P)->setOrdering(O);
}

/*--.. Casts ...............................................................--*/

LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef B, LLVMValueRef Val,
Expand Down

0 comments on commit 510a661

Please sign in to comment.