Skip to content

Commit 8d5d2e1

Browse files
committed
First effort to replace function aliasing with cloning
This works, I think, but we hit a new error relating to lack of DCE after NVVM Reflect
1 parent dabdbd4 commit 8d5d2e1

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

libclc/utils/libclc-remangler/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set(LLVM_LINK_COMPONENTS
55
Core
66
Demangle
77
Support
8+
TransformUtils
89
)
910

1011
add_clang_tool(libclc-remangler LibclcRemangler.cpp)

libclc/utils/libclc-remangler/LibclcRemangler.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
#include "llvm/Support/Signals.h"
5959
#include "llvm/Support/ToolOutputFile.h"
6060
#include "llvm/Support/raw_ostream.h"
61+
#include "llvm/Transforms/Utils/ValueMapper.h"
62+
#include "llvm/Transforms/Utils/Cloning.h"
6163

6264
#include <iostream>
6365
#include <memory>
@@ -564,9 +566,12 @@ bool createAliasFromMap(
564566

565567
Function *Aliasee = M->getFunction(AliaseeName);
566568
if (Aliasee) {
567-
GlobalAlias::create(AliasName, Aliasee);
569+
// TODO - rename 'alias*' to 'clone*'
570+
ValueToValueMapTy Dummy;
571+
Function *NewF = CloneFunction(Aliasee, Dummy);
572+
NewF->setName(std::string(AliasName));
568573
} else if (Verbose) {
569-
std::cout << "Could not create alias " << AliasName.data() << " : missing "
574+
std::cout << "Could not create copy " << AliasName.data() << " : missing "
570575
<< AliaseeName.data() << std::endl;
571576
}
572577

@@ -661,10 +666,14 @@ int main(int argc, const char **argv) {
661666
return 1;
662667
}
663668

664-
bool Success = true;
669+
std::vector<Function *> FuncList;
665670
for (auto &Func : M->getFunctionList())
666-
Success = remangleFunction(Func, M.get(), Replacements) && Success;
671+
FuncList.push_back(&Func);
667672

673+
bool Success = true;
674+
for (auto Func : FuncList){
675+
Success = remangleFunction(*Func, M.get(), Replacements) && Success;
676+
}
668677
// Only fail after all to give as much context as possible.
669678
if (!Success) {
670679
errs() << "Failed to remangle all mangled functions in module.\n";

0 commit comments

Comments
 (0)