[llvm] r327479 - [LLVM-C] Redo unnamed_address attribute bindings
Robert Widmann via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 13 23:45:51 PDT 2018
Author: codafi
Date: Tue Mar 13 23:45:51 2018
New Revision: 327479
URL: http://llvm.org/viewvc/llvm-project?rev=327479&view=rev
Log:
[LLVM-C] Redo unnamed_address attribute bindings
Summary:
The old bindings should have used an enum instead of a boolean. This
deprecates LLVMHasUnnamedAddr and LLVMSetUnnamedAddr , replacing them
with LLVMGetUnnamedAddress and LLVMSetUnnamedAddress respectively that do.
Though it is unlikely LLVM will gain more supported global value linker
hints, the new API can scale to accommodate this.
Reviewers: deadalnix, whitequark
Reviewed By: whitequark
Subscribers: llvm-commits, harlanhaskins
Differential Revision: https://reviews.llvm.org/D43448
Modified:
llvm/trunk/include/llvm-c/Core.h
llvm/trunk/lib/IR/Core.cpp
llvm/trunk/test/Bindings/llvm-c/echo.ll
llvm/trunk/tools/llvm-c-test/echo.cpp
Modified: llvm/trunk/include/llvm-c/Core.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/Core.h?rev=327479&r1=327478&r2=327479&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/Core.h (original)
+++ llvm/trunk/include/llvm-c/Core.h Tue Mar 13 23:45:51 2018
@@ -187,6 +187,12 @@ typedef enum {
} LLVMVisibility;
typedef enum {
+ LLVMNoUnnamedAddr, /**< Address of the GV is significant. */
+ LLVMLocalUnnamedAddr, /**< Address of the GV is locally insignificant. */
+ LLVMGlobalUnnamedAddr /**< Address of the GV is globally insignificant. */
+} LLVMUnnamedAddr;
+
+typedef enum {
LLVMDefaultStorageClass = 0,
LLVMDLLImportStorageClass = 1, /**< Function to be imported from DLL. */
LLVMDLLExportStorageClass = 2 /**< Function to be accessible from DLL. */
@@ -1844,7 +1850,12 @@ LLVMVisibility LLVMGetVisibility(LLVMVal
void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global);
void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class);
+LLVMUnnamedAddr LLVMGetUnnamedAddress(LLVMValueRef Global);
+void LLVMSetUnnamedAddress(LLVMValueRef Global, LLVMUnnamedAddr UnnamedAddr);
+
+/** Deprecated: Use LLVMGetUnnamedAddress instead. */
LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global);
+/** Deprecated: Use LLVMSetUnnamedAddress instead. */
void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr);
/**
Modified: llvm/trunk/lib/IR/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Core.cpp?rev=327479&r1=327478&r2=327479&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Core.cpp (original)
+++ llvm/trunk/lib/IR/Core.cpp Tue Mar 13 23:45:51 2018
@@ -1607,6 +1607,30 @@ void LLVMSetDLLStorageClass(LLVMValueRef
static_cast<GlobalValue::DLLStorageClassTypes>(Class));
}
+LLVMUnnamedAddr LLVMGetUnnamedAddress(LLVMValueRef Global) {
+ switch (unwrap<GlobalValue>(Global)->getUnnamedAddr()) {
+ case GlobalVariable::UnnamedAddr::None:
+ return LLVMNoUnnamedAddr;
+ case GlobalVariable::UnnamedAddr::Local:
+ return LLVMLocalUnnamedAddr;
+ case GlobalVariable::UnnamedAddr::Global:
+ return LLVMGlobalUnnamedAddr;
+ }
+}
+
+void LLVMSetUnnamedAddress(LLVMValueRef Global, LLVMUnnamedAddr UnnamedAddr) {
+ GlobalValue *GV = unwrap<GlobalValue>(Global);
+
+ switch (UnnamedAddr) {
+ case LLVMNoUnnamedAddr:
+ return GV->setUnnamedAddr(GlobalVariable::UnnamedAddr::None);
+ case LLVMLocalUnnamedAddr:
+ return GV->setUnnamedAddr(GlobalVariable::UnnamedAddr::Local);
+ case LLVMGlobalUnnamedAddr:
+ return GV->setUnnamedAddr(GlobalVariable::UnnamedAddr::Global);
+ }
+}
+
LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global) {
return unwrap<GlobalValue>(Global)->hasGlobalUnnamedAddr();
}
Modified: llvm/trunk/test/Bindings/llvm-c/echo.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bindings/llvm-c/echo.ll?rev=327479&r1=327478&r2=327479&view=diff
==============================================================================
--- llvm/trunk/test/Bindings/llvm-c/echo.ll (original)
+++ llvm/trunk/test/Bindings/llvm-c/echo.ll Tue Mar 13 23:45:51 2018
@@ -14,6 +14,7 @@ target triple = "x86_64-apple-macosx10.1
@tl = thread_local global { i64, %S* } { i64 1, %S* @cst }
@arr = linkonce_odr global [5 x i8] [ i8 2, i8 3, i8 5, i8 7, i8 11 ]
@str = private unnamed_addr constant [13 x i8] c"hello world\0A\00"
+ at locStr = private local_unnamed_addr constant [13 x i8] c"hello world\0A\00"
@hidden = hidden global i32 7
@protected = protected global i32 23
@section = global i32 27, section ".custom"
Modified: llvm/trunk/tools/llvm-c-test/echo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-c-test/echo.cpp?rev=327479&r1=327478&r2=327479&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-c-test/echo.cpp (original)
+++ llvm/trunk/tools/llvm-c-test/echo.cpp Tue Mar 13 23:45:51 2018
@@ -864,7 +864,7 @@ static void clone_symbols(LLVMModuleRef
LLVMSetLinkage(G, LLVMGetLinkage(Cur));
LLVMSetSection(G, LLVMGetSection(Cur));
LLVMSetVisibility(G, LLVMGetVisibility(Cur));
- LLVMSetUnnamedAddr(G, LLVMHasUnnamedAddr(Cur));
+ LLVMSetUnnamedAddress(G, LLVMGetUnnamedAddress(Cur));
LLVMSetAlignment(G, LLVMGetAlignment(Cur));
Next = LLVMGetNextGlobal(Cur);
More information about the llvm-commits
mailing list