Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions llvm/lib/Transforms/Yk/ModuleClone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
//
// Sometimes we are unable to clone a function. For example when a function has
// its address taken. Cloning such a function would break "function pointer
// identity", which the program may be relying on.
// identity", which the program may be relying on. In this case, we mark the
// original function as yk_outline to prevent tracing calls from being added.
//===----------------------------------------------------------------------===//

#include "llvm/Transforms/Yk/ModuleClone.h"
Expand All @@ -28,6 +29,7 @@
#include "llvm/IR/Verifier.h"
#include "llvm/Linker/Linker.h"
#include "llvm/Pass.h"
#include "llvm/Support/Debug.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/Transforms/Yk/ControlPoint.h"
#include "llvm/YkIR/YkIRWriter.h"
Expand Down Expand Up @@ -56,11 +58,7 @@ bool ModuleClonePass::shouldClone(Function &F) {
if (F.isDeclaration()) {
return false;
}
// If the address of a function is taken, then cloning it would break
// function pointer identity, which the program may rely on.
if (F.hasAddressTaken()) {
return false;
}
// Note: address-taken functions are handled separately in cloneFunctionsInModule.
// For now we don't clone functions that contain a call to the control
// point.
if (containsControlPoint(F)) {
Expand All @@ -85,6 +83,18 @@ ModuleClonePass::cloneFunctionsInModule(Module &M) {
for (Function *F : Funcs) {
auto OrigName = F->getName().str();

// If the address of a function is taken, then cloning it would break
// function pointer identity, which the program may rely on. We mark the
// original as yk_outline to prevent tracing calls from being added.
if (F->hasAddressTaken()) {
// Debug print
// errs() << "yk-module-clone: address-taken function: " << F->getName() << "\n";
F->addFnAttr(YK_OUTLINE_FNATTR);
F->setMetadata(YK_SWT_OPT_MD, OptMD);
CloneMap[F] = nullptr;
continue;
}

// Maybe clone the function.
Function *ClonedOptFunc = nullptr;
if (shouldClone(*F)) {
Expand Down