Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(558)

Side by Side Diff: lib/Transforms/NaCl/AddPNaClExternalDecls.cpp

Issue 939073008: Rebased PNaCl localmods in LLVM to 223109 (Closed)
Patch Set: undo localmod Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/Transforms/MinSFI/Utils.cpp ('k') | lib/Transforms/NaCl/BackendCanonicalize.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 //===- AddPNaClExternalDecls.cpp - Add decls for PNaCl external functions -===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This pass adds function declarations for external functions used by PNaCl.
11 // These externals are implemented in native libraries and calls to them are
12 // created as part of the translation process.
13 //
14 // Running this pass is a precondition for running ResolvePNaClIntrinsics. They
15 // are separate because one is a ModulePass and the other is a FunctionPass.
16 //
17 //===----------------------------------------------------------------------===//
18
19 #include "llvm/IR/DerivedTypes.h"
20 #include "llvm/IR/Intrinsics.h"
21 #include "llvm/IR/Module.h"
22 #include "llvm/IR/NaClAtomicIntrinsics.h"
23 #include "llvm/IR/Type.h"
24 #include "llvm/Pass.h"
25 #include "llvm/Transforms/NaCl.h"
26
27 using namespace llvm;
28
29 namespace {
30 // This is a module pass because it adds declarations to the module.
31 class AddPNaClExternalDecls : public ModulePass {
32 public:
33 static char ID;
34 AddPNaClExternalDecls() : ModulePass(ID) {
35 initializeAddPNaClExternalDeclsPass(*PassRegistry::getPassRegistry());
36 }
37
38 virtual bool runOnModule(Module &M);
39 };
40 }
41
42 bool AddPNaClExternalDecls::runOnModule(Module &M) {
43 // Add declarations for a pre-defined set of external functions to the module.
44 // The function names must match the functions implemented in native code (in
45 // pnacl/support). The function types must match the types of the LLVM
46 // intrinsics.
47 // We expect these declarations not to exist in the module before this pass
48 // runs, but don't assert it; it will be handled by the ABI verifier.
49 LLVMContext &C = M.getContext();
50 M.getOrInsertFunction("setjmp",
51 // return type
52 Type::getInt32Ty(C),
53 // arguments
54 Type::getInt8Ty(C)->getPointerTo(),
55 NULL);
56 M.getOrInsertFunction("longjmp",
57 // return type
58 Type::getVoidTy(C),
59 // arguments
60 Type::getInt8Ty(C)->getPointerTo(),
61 Type::getInt32Ty(C),
62 NULL);
63
64 // Add Intrinsic declarations needed by ResolvePNaClIntrinsics up front.
65 Intrinsic::getDeclaration(&M, Intrinsic::nacl_setjmp);
66 Intrinsic::getDeclaration(&M, Intrinsic::nacl_longjmp);
67 NaCl::AtomicIntrinsics AI(C);
68 NaCl::AtomicIntrinsics::View V = AI.allIntrinsicsAndOverloads();
69 for (NaCl::AtomicIntrinsics::View::iterator I = V.begin(), E = V.end();
70 I != E; ++I) {
71 I->getDeclaration(&M);
72 }
73 Intrinsic::getDeclaration(&M, Intrinsic::nacl_atomic_is_lock_free);
74
75 return true;
76 }
77
78 char AddPNaClExternalDecls::ID = 0;
79 INITIALIZE_PASS(AddPNaClExternalDecls, "add-pnacl-external-decls",
80 "Add declarations of external functions used by PNaCl",
81 false, false)
82
83 ModulePass *llvm::createAddPNaClExternalDeclsPass() {
84 return new AddPNaClExternalDecls();
85 }
OLDNEW
« no previous file with comments | « lib/Transforms/MinSFI/Utils.cpp ('k') | lib/Transforms/NaCl/BackendCanonicalize.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698