From 6334e1351f8f7bb58b3399d7c001eed0a32e1c64 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Tue, 16 Apr 2013 08:58:59 +0000 Subject: Add four new functions and one new enum to the C API: LLVMGetThreadLocalMode - exposes GlobalVariable::getThreadLocalMode LLVMSetThreadLocalMode - exposes GlobalVariable::setThreadLocalMode LLVMIsExternallyInitialized - exposes GlobalVariable::isExternallyInitialized LLVMSetExternallyInitialized - exposes GlobalVariable::setExternallyInitialized LLVMThreadLocalMode - maps to GlobalVariable::ThreadLocalMode Patch by Moritz Maxeiner! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179588 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/Core.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'lib/IR/Core.cpp') diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp index 983b49c..f1f7eb3 100644 --- a/lib/IR/Core.cpp +++ b/lib/IR/Core.cpp @@ -1301,6 +1301,53 @@ void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant) { unwrap(GlobalVar)->setConstant(IsConstant != 0); } +LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar) { + switch (unwrap(GlobalVar)->getThreadLocalMode()) { + case GlobalVariable::NotThreadLocal: + return LLVMNotThreadLocal; + case GlobalVariable::GeneralDynamicTLSModel: + return LLVMGeneralDynamicTLSModel; + case GlobalVariable::LocalDynamicTLSModel: + return LLVMLocalDynamicTLSModel; + case GlobalVariable::InitialExecTLSModel: + return LLVMInitialExecTLSModel; + case GlobalVariable::LocalExecTLSModel: + return LLVMLocalExecTLSModel; + } + + llvm_unreachable("Invalid GlobalVariable thread local mode"); +} + +void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode) { + GlobalVariable *GV = unwrap(GlobalVar); + + switch (Mode) { + case LLVMNotThreadLocal: + GV->setThreadLocalMode(GlobalVariable::NotThreadLocal); + break; + case LLVMGeneralDynamicTLSModel: + GV->setThreadLocalMode(GlobalVariable::GeneralDynamicTLSModel); + break; + case LLVMLocalDynamicTLSModel: + GV->setThreadLocalMode(GlobalVariable::LocalDynamicTLSModel); + break; + case LLVMInitialExecTLSModel: + GV->setThreadLocalMode(GlobalVariable::InitialExecTLSModel); + break; + case LLVMLocalExecTLSModel: + GV->setThreadLocalMode(GlobalVariable::LocalExecTLSModel); + break; + } +} + +LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar) { + return unwrap(GlobalVar)->isExternallyInitialized(); +} + +void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit) { + unwrap(GlobalVar)->setExternallyInitialized(IsExtInit); +} + /*--.. Operations on aliases ......................................--*/ LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee, -- cgit v1.1 From 68ee1520ce777871353e33fcc63725439e611f4e Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Tue, 16 Apr 2013 23:12:43 +0000 Subject: C API: Add LLVMAddTargetDependentFunctionAttr() git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179645 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/Core.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lib/IR/Core.cpp') diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp index f1f7eb3..e769ab4 100644 --- a/lib/IR/Core.cpp +++ b/lib/IR/Core.cpp @@ -1443,6 +1443,17 @@ void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) { Func->setAttributes(PALnew); } +void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A, + const char *V) { + Function *Func = unwrap(Fn); + int Idx = AttributeSet::FunctionIndex; + AttrBuilder B; + + B.addAttribute(A, V); + AttributeSet Set = AttributeSet::get(Func->getContext(), Idx, B); + Func->addAttributes(Idx, Set); +} + void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) { Function *Func = unwrap(Fn); const AttributeSet PAL = Func->getAttributes(); -- cgit v1.1 From 4074343b2d9bec7a70c500b2f62b3cd63b44f8c9 Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Tue, 16 Apr 2013 23:12:47 +0000 Subject: C API: Add LLVMGetBufferStart() git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179646 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/Core.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/IR/Core.cpp') diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp index e769ab4..e0f76d3 100644 --- a/lib/IR/Core.cpp +++ b/lib/IR/Core.cpp @@ -2455,6 +2455,9 @@ LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy( StringRef(BufferName))); } +const char* LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf) { + return unwrap(MemBuf)->getBufferStart(); +} void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf) { delete unwrap(MemBuf); -- cgit v1.1 From edc93b356da17d404467d47456bb27b99c775e39 Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Tue, 16 Apr 2013 23:12:51 +0000 Subject: C API: Add LLVMGetBufferSize() git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179647 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/Core.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/IR/Core.cpp') diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp index e0f76d3..50d1aaa 100644 --- a/lib/IR/Core.cpp +++ b/lib/IR/Core.cpp @@ -2459,6 +2459,10 @@ const char* LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf) { return unwrap(MemBuf)->getBufferStart(); } +size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf) { + return unwrap(MemBuf)->getBufferSize(); +} + void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf) { delete unwrap(MemBuf); } -- cgit v1.1 From a73dd3e575761fa4559edfd0d3550b3820c1c68d Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Wed, 17 Apr 2013 17:51:19 +0000 Subject: Don't store AttributeSet::FunctionIndex as an int. GCC complains: Core.cpp:1449:27: warning: overflow in implicit constant conversion [-Woverflow] I'm not sure if that's really a problem here, but using the enum type is better style anyways. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179696 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/Core.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/IR/Core.cpp') diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp index 50d1aaa..c994ef2 100644 --- a/lib/IR/Core.cpp +++ b/lib/IR/Core.cpp @@ -1446,7 +1446,7 @@ void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) { void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A, const char *V) { Function *Func = unwrap(Fn); - int Idx = AttributeSet::FunctionIndex; + AttributeSet::AttrIndex Idx = AttributeSet::FunctionIndex; AttrBuilder B; B.addAttribute(A, V); -- cgit v1.1 From 403569373f1e63cc96ea8274b18088bf7ff17bd6 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Wed, 17 Apr 2013 18:26:02 +0000 Subject: Appease a gcc warning about an overflow in a constant conversion. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179703 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/Core.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/IR/Core.cpp') diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp index c994ef2..53244e7 100644 --- a/lib/IR/Core.cpp +++ b/lib/IR/Core.cpp @@ -1446,7 +1446,8 @@ void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) { void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A, const char *V) { Function *Func = unwrap(Fn); - AttributeSet::AttrIndex Idx = AttributeSet::FunctionIndex; + AttributeSet::AttrIndex Idx = + AttributeSet::AttrIndex(AttributeSet::FunctionIndex); AttrBuilder B; B.addAttribute(A, V); -- cgit v1.1 From 4bfeee1302eaeb6cf8f4248e3bb4fdf31a11dce1 Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Thu, 18 Apr 2013 19:50:53 +0000 Subject: C API: Fix coding style git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179785 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/Core.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/IR/Core.cpp') diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp index 53244e7..a47976f 100644 --- a/lib/IR/Core.cpp +++ b/lib/IR/Core.cpp @@ -2456,7 +2456,7 @@ LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy( StringRef(BufferName))); } -const char* LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf) { +const char *LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf) { return unwrap(MemBuf)->getBufferStart(); } -- cgit v1.1 From 3e39731e88f2d4f597cebc74388fd6650ca4f604 Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Mon, 22 Apr 2013 22:47:22 +0000 Subject: Move C++ code out of the C headers and into either C++ headers or the C++ files themselves. This enables people to use just a C compiler to interoperate with LLVM. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180063 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/Core.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/IR/Core.cpp') diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp index a47976f..1585f25 100644 --- a/lib/IR/Core.cpp +++ b/lib/IR/Core.cpp @@ -13,6 +13,7 @@ //===----------------------------------------------------------------------===// #include "llvm-c/Core.h" +#include "llvm/Wrap.h" #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/IR/Attributes.h" #include "llvm/IR/Constants.h" -- cgit v1.1 From 8effd8dc98a793181b086dbfde31cdcbd2047200 Mon Sep 17 00:00:00 2001 From: Carlo Kok Date: Tue, 23 Apr 2013 13:21:19 +0000 Subject: Expose IRBuilder::CreateAtomicRMW as LLVMBuildAtomicRMW in llvm-c. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180100 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/Core.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'lib/IR/Core.cpp') diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp index 1585f25..c79c483 100644 --- a/lib/IR/Core.cpp +++ b/lib/IR/Core.cpp @@ -2391,6 +2391,42 @@ LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef B, LLVMValueRef LHS, return wrap(unwrap(B)->CreatePtrDiff(unwrap(LHS), unwrap(RHS), Name)); } +LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B,LLVMAtomicRMWBinOp op, + LLVMValueRef PTR, LLVMValueRef Val, + LLVMAtomicOrdering ordering, + LLVMBool singleThread) { + AtomicRMWInst::BinOp intop; + switch (op) { + case LLVMAtomicRMWBinOpXchg: intop = AtomicRMWInst::Xchg; break; + case LLVMAtomicRMWBinOpAdd: intop = AtomicRMWInst::Add; break; + case LLVMAtomicRMWBinOpSub: intop = AtomicRMWInst::Sub; break; + case LLVMAtomicRMWBinOpAnd: intop = AtomicRMWInst::And; break; + case LLVMAtomicRMWBinOpNand: intop = AtomicRMWInst::Nand; break; + case LLVMAtomicRMWBinOpOr: intop = AtomicRMWInst::Or; break; + case LLVMAtomicRMWBinOpXor: intop = AtomicRMWInst::Xor; break; + case LLVMAtomicRMWBinOpMax: intop = AtomicRMWInst::Max; break; + case LLVMAtomicRMWBinOpMin: intop = AtomicRMWInst::Min; break; + case LLVMAtomicRMWBinOpUMax: intop = AtomicRMWInst::UMax; break; + case LLVMAtomicRMWBinOpUMin: intop = AtomicRMWInst::UMin; break; + } + AtomicOrdering intordering; + switch (ordering) { + case LLVMAtomicOrderingNotAtomic: intordering = NotAtomic; break; + case LLVMAtomicOrderingUnordered: intordering = Unordered; break; + case LLVMAtomicOrderingMonotonic: intordering = Monotonic; break; + case LLVMAtomicOrderingAcquire: intordering = Acquire; break; + case LLVMAtomicOrderingRelease: intordering = Release; break; + case LLVMAtomicOrderingAcquireRelease: + intordering = AcquireRelease; + break; + case LLVMAtomicOrderingSequentiallyConsistent: + intordering = SequentiallyConsistent; + break; + } + return wrap(unwrap(B)->CreateAtomicRMW(intop, unwrap(PTR), unwrap(Val), + intordering, singleThread ? SingleThread : CrossThread)); +} + /*===-- Module providers --------------------------------------------------===*/ -- cgit v1.1 From 40be1e85665d10f5444186f0e7106e368dd735b8 Mon Sep 17 00:00:00 2001 From: Filip Pizlo Date: Wed, 1 May 2013 20:59:00 +0000 Subject: This patch breaks up Wrap.h so that it does not have to include all of the things, and renames it to CBindingWrapping.h. I also moved CBindingWrapping.h into Support/. This new file just contains the macros for defining different wrap/unwrap methods. The calls to those macros, as well as any custom wrap/unwrap definitions (like for array of Values for example), are put into corresponding C++ headers. Doing this required some #include surgery, since some .cpp files relied on the fact that including Wrap.h implicitly caused the inclusion of a bunch of other things. This also now means that the C++ headers will include their corresponding C API headers; for example Value.h must include llvm-c/Core.h. I think this is harmless, since the C API headers contain just external function declarations and some C types, so I don't believe there should be any nasty dependency issues here. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180881 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/Core.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/IR/Core.cpp') diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp index c79c483..889d574 100644 --- a/lib/IR/Core.cpp +++ b/lib/IR/Core.cpp @@ -13,7 +13,6 @@ //===----------------------------------------------------------------------===// #include "llvm-c/Core.h" -#include "llvm/Wrap.h" #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/IR/Attributes.h" #include "llvm/IR/Constants.h" @@ -22,7 +21,9 @@ #include "llvm/IR/GlobalVariable.h" #include "llvm/IR/InlineAsm.h" #include "llvm/IR/IntrinsicInst.h" +#include "llvm/IR/IRBuilder.h" #include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Module.h" #include "llvm/PassManager.h" #include "llvm/Support/CallSite.h" #include "llvm/Support/Debug.h" -- cgit v1.1