[PATCH] D114860: [llvm-c] Make LLVMAddAlias opaque pointer compatible
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 1 03:19:25 PST 2021
nikic created this revision.
nikic added a reviewer: opaque-pointers.
Herald added a reviewer: deadalnix.
Herald added subscribers: jeroen.dobbelaere, dexonsmith, hiraditya.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Deprecate LLVMAddAlias in favor of LLVMAddAlias2, which accepts a value type and an address space. Previously these were extracted from the pointer type.
https://reviews.llvm.org/D114860
Files:
llvm/include/llvm-c/Core.h
llvm/lib/IR/Core.cpp
llvm/tools/llvm-c-test/echo.cpp
llvm/unittests/IR/ConstantsTest.cpp
Index: llvm/unittests/IR/ConstantsTest.cpp
===================================================================
--- llvm/unittests/IR/ConstantsTest.cpp
+++ llvm/unittests/IR/ConstantsTest.cpp
@@ -404,7 +404,7 @@
Type *I16PTy = PointerType::get(I16Ty, 0);
Constant *Aliasee = ConstantExpr::getBitCast(G, I16PTy);
LLVMValueRef AliasRef =
- LLVMAddAlias(wrap(M.get()), wrap(I16PTy), wrap(Aliasee), "a");
+ LLVMAddAlias2(wrap(M.get()), wrap(I16Ty), 0, wrap(Aliasee), "a");
ASSERT_EQ(unwrap<GlobalAlias>(AliasRef)->getAliasee(), Aliasee);
}
Index: llvm/tools/llvm-c-test/echo.cpp
===================================================================
--- llvm/tools/llvm-c-test/echo.cpp
+++ llvm/tools/llvm-c-test/echo.cpp
@@ -1056,9 +1056,11 @@
const char *Name = LLVMGetValueName2(Cur, &NameLen);
if (LLVMGetNamedGlobalAlias(M, Name, NameLen))
report_fatal_error("Global alias already cloned");
- LLVMTypeRef CurType = TypeCloner(M).Clone(Cur);
+ LLVMTypeRef PtrType = TypeCloner(M).Clone(Cur);
+ LLVMTypeRef ValType = TypeCloner(M).Clone(LLVMGlobalGetValueType(Cur));
+ unsigned AddrSpace = LLVMGetPointerAddressSpace(PtrType);
// FIXME: Allow NULL aliasee.
- LLVMAddAlias(M, CurType, LLVMGetUndef(CurType), Name);
+ LLVMAddAlias2(M, ValType, AddrSpace, LLVMGetUndef(PtrType), Name);
Next = LLVMGetNextGlobalAlias(Cur);
if (Next == nullptr) {
Index: llvm/lib/IR/Core.cpp
===================================================================
--- llvm/lib/IR/Core.cpp
+++ llvm/lib/IR/Core.cpp
@@ -2266,6 +2266,14 @@
unwrap<Constant>(Aliasee), unwrap(M)));
}
+LLVMValueRef LLVMAddAlias2(LLVMModuleRef M, LLVMTypeRef ValueTy,
+ unsigned AddrSpace, LLVMValueRef Aliasee,
+ const char *Name) {
+ return wrap(GlobalAlias::create(unwrap(ValueTy), AddrSpace,
+ GlobalValue::ExternalLinkage, Name,
+ unwrap<Constant>(Aliasee), unwrap(M)));
+}
+
LLVMValueRef LLVMGetNamedGlobalAlias(LLVMModuleRef M,
const char *Name, size_t NameLen) {
return wrap(unwrap(M)->getNamedAlias(Name));
Index: llvm/include/llvm-c/Core.h
===================================================================
--- llvm/include/llvm-c/Core.h
+++ llvm/include/llvm-c/Core.h
@@ -2377,9 +2377,20 @@
*
* @{
*/
+
+/** Deprecated: Use LLVMAddAlias2 instead. */
LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
const char *Name);
+/**
+ * Add a GlobalAlias with the given value type, address space and aliasee.
+ *
+ * @see llvm::GlobalAlias::create()
+ */
+LLVMValueRef LLVMAddAlias2(LLVMModuleRef M, LLVMTypeRef ValueTy,
+ unsigned AddrSpace, LLVMValueRef Aliasee,
+ const char *Name);
+
/**
* Obtain a GlobalAlias value from a Module by its name.
*
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114860.390970.patch
Type: text/x-patch
Size: 2999 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211201/d599fe02/attachment.bin>
More information about the llvm-commits
mailing list