summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-c-test
diff options
context:
space:
mode:
authorRobert Widmann <devteam.codafi@gmail.com>2018-05-20 23:49:08 +0000
committerRobert Widmann <devteam.codafi@gmail.com>2018-05-20 23:49:08 +0000
commit360d6e35e695c54078f37fa7806f562e8e08ff62 (patch)
tree74ad00d4ee708d8861450e91f84c53e931a02d8e /llvm/tools/llvm-c-test
parent55b40673505b8786a77d55f6541c944ba8238f4c (diff)
downloadbcm5719-llvm-360d6e35e695c54078f37fa7806f562e8e08ff62.tar.gz
bcm5719-llvm-360d6e35e695c54078f37fa7806f562e8e08ff62.zip
[LLVM-C] Improve Bindings For Aliases
Summary: Add wrappers for a module's alias iterators and a getter and setter for the aliasee value. Reviewers: whitequark, deadalnix Reviewed By: whitequark Subscribers: llvm-commits, harlanhaskins Differential Revision: https://reviews.llvm.org/D46808 llvm-svn: 332826
Diffstat (limited to 'llvm/tools/llvm-c-test')
-rw-r--r--llvm/tools/llvm-c-test/echo.cpp94
1 files changed, 88 insertions, 6 deletions
diff --git a/llvm/tools/llvm-c-test/echo.cpp b/llvm/tools/llvm-c-test/echo.cpp
index ca3a1be0684..a9cd4cf5cbb 100644
--- a/llvm/tools/llvm-c-test/echo.cpp
+++ b/llvm/tools/llvm-c-test/echo.cpp
@@ -248,10 +248,19 @@ static LLVMValueRef clone_constant_impl(LLVMValueRef Cst, LLVMModuleRef M) {
// Try global variable
if (LLVMIsAGlobalVariable(Cst)) {
check_value_kind(Cst, LLVMGlobalVariableValueKind);
- LLVMValueRef Dst = LLVMGetNamedGlobal(M, Name);
+ LLVMValueRef Dst = LLVMGetNamedGlobal(M, Name);
if (Dst)
return Dst;
- report_fatal_error("Could not find function");
+ report_fatal_error("Could not find variable");
+ }
+
+ // Try global alias
+ if (LLVMIsAGlobalAlias(Cst)) {
+ check_value_kind(Cst, LLVMGlobalAliasValueKind);
+ LLVMValueRef Dst = LLVMGetNamedGlobalAlias(M, Name, NameLen);
+ if (Dst)
+ return Dst;
+ report_fatal_error("Could not find alias");
}
fprintf(stderr, "Could not find @%s\n", Name);
@@ -822,6 +831,8 @@ struct FunCloner {
};
static void declare_symbols(LLVMModuleRef Src, LLVMModuleRef M) {
+ auto Ctx = LLVMGetModuleContext(M);
+
LLVMValueRef Begin = LLVMGetFirstGlobal(Src);
LLVMValueRef End = LLVMGetLastGlobal(Src);
@@ -860,11 +871,9 @@ FunDecl:
if (!Begin) {
if (End != nullptr)
report_fatal_error("Range has an end but no beginning");
- return;
+ goto AliasDecl;
}
- auto Ctx = LLVMGetModuleContext(M);
-
Cur = Begin;
Next = nullptr;
while (true) {
@@ -900,6 +909,40 @@ FunDecl:
Cur = Next;
}
+
+AliasDecl:
+ Begin = LLVMGetFirstGlobalAlias(Src);
+ End = LLVMGetLastGlobalAlias(Src);
+ if (!Begin) {
+ if (End != nullptr)
+ report_fatal_error("Range has an end but no beginning");
+ return;
+ }
+
+ Cur = Begin;
+ Next = nullptr;
+ while (true) {
+ size_t NameLen;
+ const char *Name = LLVMGetValueName2(Cur, &NameLen);
+ if (LLVMGetNamedGlobalAlias(M, Name, NameLen))
+ report_fatal_error("Global alias already cloned");
+ LLVMTypeRef CurType = TypeCloner(M).Clone(Cur);
+ // FIXME: Allow NULL aliasee.
+ LLVMAddAlias(M, CurType, LLVMGetUndef(CurType), Name);
+
+ Next = LLVMGetNextGlobalAlias(Cur);
+ if (Next == nullptr) {
+ if (Cur != End)
+ report_fatal_error("");
+ break;
+ }
+
+ LLVMValueRef Prev = LLVMGetPreviousGlobalAlias(Next);
+ if (Prev != Cur)
+ report_fatal_error("Next.Previous global is not Current");
+
+ Cur = Next;
+ }
}
static void clone_symbols(LLVMModuleRef Src, LLVMModuleRef M) {
@@ -953,7 +996,7 @@ FunClone:
if (!Begin) {
if (End != nullptr)
report_fatal_error("Range has an end but no beginning");
- return;
+ goto AliasClone;
}
Cur = Begin;
@@ -991,6 +1034,45 @@ FunClone:
Cur = Next;
}
+
+AliasClone:
+ Begin = LLVMGetFirstGlobalAlias(Src);
+ End = LLVMGetLastGlobalAlias(Src);
+ if (!Begin) {
+ if (End != nullptr)
+ report_fatal_error("Range has an end but no beginning");
+ return;
+ }
+
+ Cur = Begin;
+ Next = nullptr;
+ while (true) {
+ size_t NameLen;
+ const char *Name = LLVMGetValueName2(Cur, &NameLen);
+ LLVMValueRef Alias = LLVMGetNamedGlobalAlias(M, Name, NameLen);
+ if (!Alias)
+ report_fatal_error("Global alias must have been declared already");
+
+ if (LLVMValueRef Aliasee = LLVMAliasGetAliasee(Cur)) {
+ LLVMAliasSetAliasee(Alias, clone_constant(Aliasee, M));
+ }
+
+ LLVMSetLinkage(Alias, LLVMGetLinkage(Cur));
+ LLVMSetUnnamedAddress(Alias, LLVMGetUnnamedAddress(Cur));
+
+ Next = LLVMGetNextGlobalAlias(Cur);
+ if (Next == nullptr) {
+ if (Cur != End)
+ report_fatal_error("Last global alias does not match End");
+ break;
+ }
+
+ LLVMValueRef Prev = LLVMGetPreviousGlobalAlias(Next);
+ if (Prev != Cur)
+ report_fatal_error("Next.Previous global alias is not Current");
+
+ Cur = Next;
+ }
}
int llvm_echo(void) {
OpenPOWER on IntegriCloud