Skip to content

Commit 4bb481b

Browse files
committed
[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 llvm-svn: 327479
1 parent 2d603a1 commit 4bb481b

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

llvm/include/llvm-c/Core.h

+11
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,12 @@ typedef enum {
186186
LLVMProtectedVisibility /**< The GV is protected */
187187
} LLVMVisibility;
188188

189+
typedef enum {
190+
LLVMNoUnnamedAddr, /**< Address of the GV is significant. */
191+
LLVMLocalUnnamedAddr, /**< Address of the GV is locally insignificant. */
192+
LLVMGlobalUnnamedAddr /**< Address of the GV is globally insignificant. */
193+
} LLVMUnnamedAddr;
194+
189195
typedef enum {
190196
LLVMDefaultStorageClass = 0,
191197
LLVMDLLImportStorageClass = 1, /**< Function to be imported from DLL. */
@@ -1844,7 +1850,12 @@ LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
18441850
void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
18451851
LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global);
18461852
void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class);
1853+
LLVMUnnamedAddr LLVMGetUnnamedAddress(LLVMValueRef Global);
1854+
void LLVMSetUnnamedAddress(LLVMValueRef Global, LLVMUnnamedAddr UnnamedAddr);
1855+
1856+
/** Deprecated: Use LLVMGetUnnamedAddress instead. */
18471857
LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global);
1858+
/** Deprecated: Use LLVMSetUnnamedAddress instead. */
18481859
void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr);
18491860

18501861
/**

llvm/lib/IR/Core.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -1607,6 +1607,30 @@ void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class) {
16071607
static_cast<GlobalValue::DLLStorageClassTypes>(Class));
16081608
}
16091609

1610+
LLVMUnnamedAddr LLVMGetUnnamedAddress(LLVMValueRef Global) {
1611+
switch (unwrap<GlobalValue>(Global)->getUnnamedAddr()) {
1612+
case GlobalVariable::UnnamedAddr::None:
1613+
return LLVMNoUnnamedAddr;
1614+
case GlobalVariable::UnnamedAddr::Local:
1615+
return LLVMLocalUnnamedAddr;
1616+
case GlobalVariable::UnnamedAddr::Global:
1617+
return LLVMGlobalUnnamedAddr;
1618+
}
1619+
}
1620+
1621+
void LLVMSetUnnamedAddress(LLVMValueRef Global, LLVMUnnamedAddr UnnamedAddr) {
1622+
GlobalValue *GV = unwrap<GlobalValue>(Global);
1623+
1624+
switch (UnnamedAddr) {
1625+
case LLVMNoUnnamedAddr:
1626+
return GV->setUnnamedAddr(GlobalVariable::UnnamedAddr::None);
1627+
case LLVMLocalUnnamedAddr:
1628+
return GV->setUnnamedAddr(GlobalVariable::UnnamedAddr::Local);
1629+
case LLVMGlobalUnnamedAddr:
1630+
return GV->setUnnamedAddr(GlobalVariable::UnnamedAddr::Global);
1631+
}
1632+
}
1633+
16101634
LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global) {
16111635
return unwrap<GlobalValue>(Global)->hasGlobalUnnamedAddr();
16121636
}

llvm/test/Bindings/llvm-c/echo.ll

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ target triple = "x86_64-apple-macosx10.11.0"
1414
@tl = thread_local global { i64, %S* } { i64 1, %S* @cst }
1515
@arr = linkonce_odr global [5 x i8] [ i8 2, i8 3, i8 5, i8 7, i8 11 ]
1616
@str = private unnamed_addr constant [13 x i8] c"hello world\0A\00"
17+
@locStr = private local_unnamed_addr constant [13 x i8] c"hello world\0A\00"
1718
@hidden = hidden global i32 7
1819
@protected = protected global i32 23
1920
@section = global i32 27, section ".custom"

llvm/tools/llvm-c-test/echo.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ static void clone_symbols(LLVMModuleRef Src, LLVMModuleRef M) {
864864
LLVMSetLinkage(G, LLVMGetLinkage(Cur));
865865
LLVMSetSection(G, LLVMGetSection(Cur));
866866
LLVMSetVisibility(G, LLVMGetVisibility(Cur));
867-
LLVMSetUnnamedAddr(G, LLVMHasUnnamedAddr(Cur));
867+
LLVMSetUnnamedAddress(G, LLVMGetUnnamedAddress(Cur));
868868
LLVMSetAlignment(G, LLVMGetAlignment(Cur));
869869

870870
Next = LLVMGetNextGlobal(Cur);

0 commit comments

Comments
 (0)