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

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

Issue 939073008: Rebased PNaCl localmods in LLVM to 223109 (Closed)
Patch Set: undo localmod Created 5 years, 9 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/NaCl/Makefile ('k') | lib/Transforms/NaCl/PNaClSjLjEH.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 //===-- PNaClABISimplify.cpp - Lists PNaCl ABI simplification passes ------===//
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 file implements the meta-passes "-pnacl-abi-simplify-preopt"
11 // and "-pnacl-abi-simplify-postopt". It lists their constituent
12 // passes.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #include "llvm/Analysis/NaCl.h"
17 #include "llvm/PassManager.h"
18 #include "llvm/Transforms/IPO.h"
19 #include "llvm/Transforms/NaCl.h"
20 #include "llvm/Transforms/Scalar.h"
21
22 using namespace llvm;
23
24 static cl::opt<bool>
25 EnableSjLjEH("enable-pnacl-sjlj-eh",
26 cl::desc("Enable use of SJLJ-based C++ exception handling "
27 "as part of the pnacl-abi-simplify passes"),
28 cl::init(false));
29
30 void llvm::PNaClABISimplifyAddPreOptPasses(PassManagerBase &PM) {
31 if (EnableSjLjEH) {
32 // This comes before ExpandTls because it introduces references to
33 // a TLS variable, __pnacl_eh_stack. This comes before
34 // InternalizePass because it assumes various variables (including
35 // __pnacl_eh_stack) have not been internalized yet.
36 PM.add(createPNaClSjLjEHPass());
37 } else {
38 // LowerInvoke prevents use of C++ exception handling by removing
39 // references to BasicBlocks which handle exceptions.
40 PM.add(createLowerInvokePass());
41 // Remove landingpad blocks made unreachable by LowerInvoke.
42 PM.add(createCFGSimplificationPass());
43 }
44
45 // Internalize all symbols in the module except the entry point. A PNaCl
46 // pexe is only allowed to export "_start", whereas a PNaCl PSO is only
47 // allowed to export "__pnacl_pso_root".
48 const char *SymbolsToPreserve[] = { "_start", "__pnacl_pso_root" };
49 PM.add(createInternalizePass(SymbolsToPreserve));
50
51 // Expand out computed gotos (indirectbr and blockaddresses) into switches.
52 PM.add(createExpandIndirectBrPass());
53
54 // LowerExpect converts Intrinsic::expect into branch weights,
55 // which can then be removed after BlockPlacement.
56 PM.add(createLowerExpectIntrinsicPass());
57 // Rewrite unsupported intrinsics to simpler and portable constructs.
58 PM.add(createRewriteLLVMIntrinsicsPass());
59
60 // Expand out some uses of struct types.
61 PM.add(createExpandVarArgsPass());
62 PM.add(createExpandArithWithOverflowPass());
63 // ExpandStructRegs must be run after ExpandArithWithOverflow to
64 // expand out the insertvalue instructions that
65 // ExpandArithWithOverflow introduces. ExpandStructRegs must be run
66 // after ExpandVarArgs so that struct-typed "va_arg" instructions
67 // have been removed.
68 PM.add(createExpandStructRegsPass());
69
70 PM.add(createExpandCtorsPass());
71 PM.add(createResolveAliasesPass());
72 PM.add(createExpandTlsPass());
73 // GlobalCleanup needs to run after ExpandTls because
74 // __tls_template_start etc. are extern_weak before expansion
75 PM.add(createGlobalCleanupPass());
76 }
77
78 void llvm::PNaClABISimplifyAddPostOptPasses(PassManagerBase &PM) {
79 PM.add(createRewritePNaClLibraryCallsPass());
80
81 // We place ExpandByVal after optimization passes because some byval
82 // arguments can be expanded away by the ArgPromotion pass. Leaving
83 // in "byval" during optimization also allows some dead stores to be
84 // eliminated, because "byval" is a stronger constraint than what
85 // ExpandByVal expands it to.
86 PM.add(createExpandByValPass());
87
88 // We place ExpandSmallArguments after optimization passes because
89 // some optimizations undo its changes. Note that
90 // ExpandSmallArguments requires that ExpandVarArgs has already been
91 // run.
92 PM.add(createExpandSmallArgumentsPass());
93
94 PM.add(createPromoteI1OpsPass());
95
96 // Vector simplifications.
97 //
98 // The following pass relies on ConstantInsertExtractElementIndex running
99 // after it, and it must run before GlobalizeConstantVectors because the mask
100 // argument of shufflevector must be a constant (the pass would otherwise
101 // violate this requirement).
102 PM.add(createExpandShuffleVectorPass());
103 // We should not place arbitrary passes after ExpandConstantExpr
104 // because they might reintroduce ConstantExprs.
105 PM.add(createExpandConstantExprPass());
106 // GlobalizeConstantVectors does not handle nested ConstantExprs, so we
107 // run ExpandConstantExpr first.
108 PM.add(createGlobalizeConstantVectorsPass());
109 // The following pass inserts GEPs, it must precede ExpandGetElementPtr. It
110 // also creates vector loads and stores, the subsequent pass cleans them up to
111 // fix their alignment.
112 PM.add(createConstantInsertExtractElementIndexPass());
113 PM.add(createFixVectorLoadStoreAlignmentPass());
114
115 // Optimization passes and ExpandByVal introduce
116 // memset/memcpy/memmove intrinsics with a 64-bit size argument.
117 // This pass converts those arguments to 32-bit.
118 PM.add(createCanonicalizeMemIntrinsicsPass());
119
120 // We place StripMetadata after optimization passes because
121 // optimizations depend on the metadata.
122 PM.add(createStripMetadataPass());
123
124 // ConstantMerge cleans up after passes such as GlobalizeConstantVectors. It
125 // must run before the FlattenGlobals pass because FlattenGlobals loses
126 // information that otherwise helps ConstantMerge do a good job.
127 PM.add(createConstantMergePass());
128 // FlattenGlobals introduces ConstantExpr bitcasts of globals which
129 // are expanded out later. ReplacePtrsWithInts also creates some
130 // ConstantExprs, and it locally creates an ExpandConstantExprPass
131 // to clean both of these up.
132 PM.add(createFlattenGlobalsPass());
133
134 // The type legalization passes (ExpandLargeIntegers and PromoteIntegers) do
135 // not handle constexprs and create GEPs, so they go between those passes.
136 PM.add(createExpandLargeIntegersPass());
137 PM.add(createPromoteIntegersPass());
138 // ExpandGetElementPtr must follow ExpandConstantExpr to expand the
139 // getelementptr instructions it creates.
140 PM.add(createExpandGetElementPtrPass());
141 // Rewrite atomic and volatile instructions with intrinsic calls.
142 PM.add(createRewriteAtomicsPass());
143 // Remove ``asm("":::"memory")``. This must occur after rewriting
144 // atomics: a ``fence seq_cst`` surrounded by ``asm("":::"memory")``
145 // has special meaning and is translated differently.
146 PM.add(createRemoveAsmMemoryPass());
147
148 PM.add(createSimplifyAllocasPass());
149
150 // ReplacePtrsWithInts assumes that getelementptr instructions and
151 // ConstantExprs have already been expanded out.
152 PM.add(createReplacePtrsWithIntsPass());
153
154 // The atomic cmpxchg instruction returns a struct, and is rewritten to an
155 // intrinsic as a post-opt pass, we therefore need to expand struct regs one
156 // last time.
157 PM.add(createExpandStructRegsPass());
158
159 // We place StripAttributes after optimization passes because many
160 // analyses add attributes to reflect their results.
161 // StripAttributes must come after ExpandByVal and
162 // ExpandSmallArguments.
163 PM.add(createStripAttributesPass());
164
165 // Strip dead prototytes to appease the intrinsic ABI checks.
166 // ExpandVarArgs leaves around vararg intrinsics, and
167 // ReplacePtrsWithInts leaves the lifetime.start/end intrinsics.
168 PM.add(createStripDeadPrototypesPass());
169
170 // Eliminate simple dead code that the post-opt passes could have
171 // created.
172 PM.add(createDeadInstEliminationPass());
173 PM.add(createDeadCodeEliminationPass());
174 }
OLDNEW
« no previous file with comments | « lib/Transforms/NaCl/Makefile ('k') | lib/Transforms/NaCl/PNaClSjLjEH.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698