aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorEli Bendersky <eliben@chromium.org>2013-05-28 11:23:28 -0700
committerEli Bendersky <eliben@chromium.org>2013-05-28 11:23:28 -0700
commitffc13bcb40d4257202295fc0ffe25b38bdf64263 (patch)
treee3269675fec1127c195d6b3c248a6a47376b32f0 /tools
parenta7b1caf4ea69d2cc6ff207fcef7085494bbc686a (diff)
Add two passes that implement conversions from PNaCl's specific intrinsics
to external function calls during the translation stage (llc). One of the passes is a ModulePass that adds the appropriate function declarations to the module. The other is a FunctionPass that performs the actual call replacement. This split exists because of bitcode streaming. Initially the passes handle the llvm.nacl.{set|long}jmp intrinsics. In the future they may handle additional intrinsics that are part of the PNaCl stable bitcode ABI. This CL also removes the previous approach to handling this conversion (in SelectionDAGBuilder.cpp). That ended up not working - more details in issue 3429. BUG=https://code.google.com/p/nativeclient/issues/detail?id=3429 R=mseaborn@chromium.org Review URL: https://codereview.chromium.org/16047002
Diffstat (limited to 'tools')
-rw-r--r--tools/llc/llc.cpp23
-rw-r--r--tools/opt/opt.cpp2
-rw-r--r--tools/pnacl-llc/pnacl-llc.cpp13
3 files changed, 37 insertions, 1 deletions
diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp
index 64bb6991d8..0fcd1f3c06 100644
--- a/tools/llc/llc.cpp
+++ b/tools/llc/llc.cpp
@@ -15,7 +15,7 @@
#include "llvm/IR/LLVMContext.h"
#include "llvm/ADT/Triple.h"
-#include "llvm/Analysis/NaCl.h"
+#include "llvm/Analysis/NaCl.h" // @LOCALMOD
#include "llvm/Assembly/PrintModulePass.h"
#include "llvm/Support/DataStream.h" // @LOCALMOD
#include "llvm/CodeGen/CommandFlags.h"
@@ -33,6 +33,7 @@
#include "llvm/Support/Host.h"
#include "llvm/Support/IRReader.h"
#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Transforms/NaCl.h" // @LOCALMOD
#if !defined(__native_client__)
#include "llvm/Support/PluginLoader.h"
#endif
@@ -392,6 +393,7 @@ static int compileModule(char **argv, LLVMContext &Context) {
VerifyPass->runOnModule(*mod);
CheckABIVerifyErrors(ABIErrorReporter, "Module");
}
+
#if defined(__native_client__) && defined(NACL_SRPC)
RecordMetadataForSrpc(*mod);
@@ -413,6 +415,19 @@ static int compileModule(char **argv, LLVMContext &Context) {
if (!TargetTriple.empty())
mod->setTargetTriple(Triple::normalize(TargetTriple));
TheTriple = Triple(mod->getTargetTriple());
+
+ // @LOCALMOD-BEGIN
+ // Add declarations for external functions required by PNaCl. The
+ // ResolvePNaClIntrinsics function pass running during streaming
+ // depends on these declarations being in the module.
+ if (TheTriple.isOSNaCl()) {
+ // TODO(eliben): pnacl-llc presumably won't need the isOSNaCl
+ // test.
+ OwningPtr<ModulePass> AddPNaClExternalDeclsPass(
+ createAddPNaClExternalDeclsPass());
+ AddPNaClExternalDeclsPass->runOnModule(*mod);
+ }
+ // @LOCALMOD-END
} else {
TheTriple = Triple(Triple::normalize(TargetTriple));
}
@@ -525,6 +540,12 @@ static int compileModule(char **argv, LLVMContext &Context) {
FunctionVerifyPass = createPNaClABIVerifyFunctionsPass(&ABIErrorReporter);
PM->add(FunctionVerifyPass);
}
+
+ if (TheTriple.isOSNaCl()) {
+ // Add the intrinsic resolution pass. It assumes ABI-conformant code.
+ PM->add(createResolvePNaClIntrinsicsPass());
+ }
+
// @LOCALMOD-END
// Add an appropriate TargetLibraryInfo pass for the module's triple.
diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp
index 35e18d02ad..f12c36a7c7 100644
--- a/tools/opt/opt.cpp
+++ b/tools/opt/opt.cpp
@@ -598,6 +598,7 @@ int main(int argc, char **argv) {
initializeInstrumentation(Registry);
initializeTarget(Registry);
// @LOCALMOD-BEGIN
+ initializeAddPNaClExternalDeclsPass(Registry);
initializeExpandByValPass(Registry);
initializeExpandConstantExprPass(Registry);
initializeExpandCtorsPass(Registry);
@@ -614,6 +615,7 @@ int main(int argc, char **argv) {
initializePromoteIntegersPass(Registry);
initializeReplacePtrsWithIntsPass(Registry);
initializeResolveAliasesPass(Registry);
+ initializeResolvePNaClIntrinsicsPass(Registry);
initializeRewritePNaClLibraryCallsPass(Registry);
initializeStripMetadataPass(Registry);
// @LOCALMOD-END
diff --git a/tools/pnacl-llc/pnacl-llc.cpp b/tools/pnacl-llc/pnacl-llc.cpp
index f75bada099..060c1b6c94 100644
--- a/tools/pnacl-llc/pnacl-llc.cpp
+++ b/tools/pnacl-llc/pnacl-llc.cpp
@@ -38,6 +38,7 @@
#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Target/TargetLibraryInfo.h"
#include "llvm/Target/TargetMachine.h"
+#include "llvm/Transforms/NaCl.h"
#include <memory>
@@ -326,6 +327,14 @@ static int compileModule(char **argv, LLVMContext &Context) {
VerifyPass->runOnModule(*mod);
CheckABIVerifyErrors(ABIErrorReporter, "Module");
}
+
+ // Add declarations for external functions required by PNaCl. The
+ // ResolvePNaClIntrinsics function pass running during streaming
+ // depends on these declarations being in the module.
+ OwningPtr<ModulePass> AddPNaClExternalDeclsPass(
+ createAddPNaClExternalDeclsPass());
+ AddPNaClExternalDeclsPass->runOnModule(*mod);
+
#if defined(__native_client__) && defined(NACL_SRPC)
// Record that this isn't a shared library.
// TODO(eliben): clean this up more once the pnacl-llc switch-over is
@@ -462,6 +471,10 @@ static int compileModule(char **argv, LLVMContext &Context) {
FunctionVerifyPass = createPNaClABIVerifyFunctionsPass(&ABIErrorReporter);
PM->add(FunctionVerifyPass);
}
+
+ // Add the intrinsic resolution pass. It assumes ABI-conformant code.
+ PM->add(createResolvePNaClIntrinsicsPass());
+
// @LOCALMOD-END
// Add an appropriate TargetLibraryInfo pass for the module's triple.