forked from rust-lang/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
62: Add the yk-linkage llvm pass. r=ltratt a=vext01 Co-authored-by: Edd Barrett <vext01@gmail.com>
- Loading branch information
Showing
5 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef LLVM_TRANSFORMS_YK_LINKAGE_H | ||
#define LLVM_TRANSFORMS_YK_LINKAGE_H | ||
|
||
#include "llvm/Pass.h" | ||
|
||
namespace llvm { | ||
ModulePass *createYkLinkagePass(); | ||
} // namespace llvm | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//===- Linkage.cpp - Ajdust linkage for the Yk JIT -----------------===// | ||
// | ||
// The JIT relies upon the use of `dlsym()` at runtime in order to lookup any | ||
// given function from its virtual address. For this to work the symbols for | ||
// all functions must be in the dynamic symbol table. | ||
// | ||
// `yk-config` already provides the `--export-dynamic` flag in order to ensure | ||
// that all *externally visible* symbols make it in to the dynamic symbol table, | ||
// but that's not enough: functions marked for internal linkage (e.g. `static` | ||
// functions in C) will be missed. | ||
// | ||
// This pass walks the functions of a module and flips any with internal linkage | ||
// to external linkage. | ||
// | ||
// Note that whilst symbols with internal linkage can have the same name and be | ||
// distinct, this is not so for symbols with external linkage. That's OK for | ||
// us because Yk requires the use of LTO, and the LTO module merger will have | ||
// already mangled the names for us so that symbol clashes can't occur. | ||
|
||
#include "llvm/Transforms/Yk/Linkage.h" | ||
#include "llvm/IR/Function.h" | ||
#include "llvm/IR/Module.h" | ||
#include "llvm/InitializePasses.h" | ||
#include "llvm/Pass.h" | ||
|
||
#define DEBUG_TYPE "yk-linkage" | ||
|
||
using namespace llvm; | ||
|
||
namespace llvm { | ||
void initializeYkLinkagePass(PassRegistry &); | ||
} // namespace llvm | ||
|
||
namespace { | ||
class YkLinkage : public ModulePass { | ||
public: | ||
static char ID; | ||
YkLinkage() : ModulePass(ID) { | ||
initializeYkLinkagePass(*PassRegistry::getPassRegistry()); | ||
} | ||
|
||
bool runOnModule(Module &M) override { | ||
for (Function &F : M) { | ||
if (F.hasInternalLinkage()) { | ||
F.setLinkage(GlobalVariable::ExternalLinkage); | ||
} | ||
} | ||
return true; | ||
} | ||
}; | ||
} // namespace | ||
|
||
char YkLinkage::ID = 0; | ||
INITIALIZE_PASS(YkLinkage, DEBUG_TYPE, "yk-linkage", false, false) | ||
|
||
ModulePass *llvm::createYkLinkagePass() { return new YkLinkage(); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
; Checks that the yk-linkage pass changes functions to have external linkage. | ||
; | ||
; RUN: llc --yk-linkage -o - < %s | FileCheck %s | ||
; RUN: llc -o - < %s | FileCheck --check-prefix CHECK-NOPASS %s | ||
|
||
; CHECK: .globl myfunc | ||
; CHECK-NOPASS-NOT: .globl myfunc | ||
define internal void @myfunc() noinline { | ||
ret void | ||
} |