@@ -3,7 +3,7 @@ import cllvm
3
3
#endif
4
4
5
5
/// A subset of supported LLVM IR optimizer passes.
6
- public enum FunctionPass {
6
+ public enum Pass {
7
7
/// This pass uses the SSA based Aggressive DCE algorithm. This algorithm
8
8
/// assumes instructions are dead until proven otherwise, which makes
9
9
/// it more successful are removing non-obviously dead instructions.
@@ -44,6 +44,20 @@ public enum FunctionPass {
44
44
/// %Z = add int 2, %X
45
45
/// ```
46
46
case instructionCombining
47
+ /// Working in conjunction with the linker, iterate through all functions and
48
+ /// global values in the module and attempt to change their linkage from
49
+ /// external to internal.
50
+ ///
51
+ /// To preserve the linkage of a global value, return `true` from the given
52
+ /// callback.
53
+ case internalize( mustPreserve: ( IRGlobal ) -> Bool )
54
+ /// Working in conjunction with the linker, iterate through all functions and
55
+ /// global values in the module and attempt to change their linkage from
56
+ /// external to internal.
57
+ ///
58
+ /// When a function with the name "main" is encountered, if the value of
59
+ /// `preserveMain` is `true`, "main" will not be internalized.
60
+ case internalizeAll( preserveMain: Bool )
47
61
/// Thread control through mult-pred/multi-succ blocks where some preds
48
62
/// always go to some succ. Thresholds other than minus one override the
49
63
/// internal BB duplication default threshold.
@@ -75,7 +89,7 @@ public enum FunctionPass {
75
89
/// This pass converts SwitchInst instructions into a sequence of chained
76
90
/// binary branch instructions.
77
91
case lowerSwitch
78
- /// This pass is used to promote memory references to
92
+ /// This pass is used to promote memory references to
79
93
/// be register references. A simple example of the transformation performed
80
94
/// by this pass is going from code like this:
81
95
///
@@ -92,6 +106,10 @@ public enum FunctionPass {
92
106
/// ret i32 42
93
107
/// ```
94
108
case promoteMemoryToRegister
109
+ /// Adds DWARF discriminators to the IR. Discriminators are
110
+ /// used to decide what CFG path was taken inside sub-graphs whose instructions
111
+ /// share the same line and column number information.
112
+ case addDiscriminators
95
113
/// This pass reassociates commutative expressions in an order that
96
114
/// is designed to promote better constant propagation, GCSE, LICM, PRE, etc.
97
115
///
@@ -102,12 +120,6 @@ public enum FunctionPass {
102
120
case reassociate
103
121
/// Sparse conditional constant propagation.
104
122
case sccp
105
- /// Replace aggregates or pieces of aggregates with scalar SSA values.
106
- case scalarReplAggregates
107
- /// Replace aggregates or pieces of aggregates with scalar SSA values.
108
- case scalarReplAggregatesSSA
109
- /// Tries to inline the fast path of library calls such as sqrt.
110
- case simplifyLibCalls
111
123
/// This pass eliminates call instructions to the current function which occur
112
124
/// immediately before return instructions.
113
125
case tailCallElimination
@@ -170,6 +182,8 @@ public enum FunctionPass {
170
182
/// Return a new pass object which transforms invoke instructions into calls,
171
183
/// if the callee can *not* unwind the stack.
172
184
case pruneEH
185
+
186
+ case scalarReplacementOfAggregates
173
187
/// This pass removes any function declarations (prototypes) that are not used.
174
188
case stripDeadPrototypes
175
189
/// These functions removes symbols from functions and modules without
@@ -181,73 +195,26 @@ public enum FunctionPass {
181
195
/// This pass performs a superword-level parallelism pass to combine
182
196
/// similar independent instructions into vector instructions.
183
197
case slpVectorize
198
+ /// An invalid pass that crashes when added to the pass manager.
199
+ case invalid( reason: String )
200
+ }
201
+
202
+ extension Pass {
203
+ @available ( * , deprecated, message: " Pass has been removed " )
204
+ static let simplifyLibCalls : Pass = . invalid( reason: " Pass has been removed " )
205
+ @available ( * , deprecated, message: " Use the scalarReplacementOfAggregates instead " )
206
+ static let scalarReplAggregates : Pass = . invalid( reason: " Pass has been renamed to 'scalarReplacementOfAggregates' " )
207
+ @available ( * , deprecated, message: " Use the scalarReplacementOfAggregates instead " )
208
+ static let scalarReplAggregatesSSA : Pass = . invalid( reason: " Pass has been renamed to 'scalarReplacementOfAggregates' " )
184
209
}
185
210
186
211
/// A `FunctionPassManager` is an object that collects a sequence of passes
187
212
/// which run over a particular IR construct, and runs each of them in sequence
188
213
/// over each such construct.
214
+ @available ( * , deprecated, message: " Use the PassPipeliner instead " )
189
215
public class FunctionPassManager {
190
216
internal let llvm : LLVMPassManagerRef
191
-
192
- private static let passMapping : [ FunctionPass : ( LLVMPassManagerRef ) -> Void ] = [
193
- . aggressiveDCE: LLVMAddAggressiveDCEPass,
194
- . bitTrackingDCE: LLVMAddBitTrackingDCEPass,
195
- . alignmentFromAssumptions: LLVMAddAlignmentFromAssumptionsPass,
196
- . cfgSimplification: LLVMAddCFGSimplificationPass,
197
- . deadStoreElimination: LLVMAddDeadStoreEliminationPass,
198
- . scalarizer: LLVMAddScalarizerPass,
199
- . mergedLoadStoreMotion: LLVMAddMergedLoadStoreMotionPass,
200
- . gvn: LLVMAddGVNPass,
201
- . indVarSimplify: LLVMAddIndVarSimplifyPass,
202
- . instructionCombining: LLVMAddInstructionCombiningPass,
203
- . jumpThreading: LLVMAddJumpThreadingPass,
204
- . licm: LLVMAddLICMPass,
205
- . loopDeletion: LLVMAddLoopDeletionPass,
206
- . loopIdiom: LLVMAddLoopIdiomPass,
207
- . loopRotate: LLVMAddLoopRotatePass,
208
- . loopReroll: LLVMAddLoopRerollPass,
209
- . loopUnroll: LLVMAddLoopUnrollPass,
210
- . loopUnrollAndJam: LLVMAddLoopUnrollAndJamPass,
211
- . loopUnswitch: LLVMAddLoopUnswitchPass,
212
- . lowerAtomic: LLVMAddLowerAtomicPass,
213
- . memCpyOpt: LLVMAddMemCpyOptPass,
214
- . partiallyInlineLibCalls: LLVMAddPartiallyInlineLibCallsPass,
215
- . lowerSwitch: LLVMAddLowerSwitchPass,
216
- . promoteMemoryToRegister: LLVMAddPromoteMemoryToRegisterPass,
217
- . reassociate: LLVMAddReassociatePass,
218
- . sccp: LLVMAddSCCPPass,
219
- . scalarReplAggregates: LLVMAddScalarReplAggregatesPass,
220
- . scalarReplAggregatesSSA: LLVMAddScalarReplAggregatesPassSSA,
221
- . simplifyLibCalls: LLVMAddSimplifyLibCallsPass,
222
- . tailCallElimination: LLVMAddTailCallEliminationPass,
223
- . constantPropagation: LLVMAddConstantPropagationPass,
224
- . demoteMemoryToRegister: LLVMAddDemoteMemoryToRegisterPass,
225
- . verifier: LLVMAddVerifierPass,
226
- . correlatedValuePropagation: LLVMAddCorrelatedValuePropagationPass,
227
- . earlyCSE: LLVMAddEarlyCSEPass,
228
- . lowerExpectIntrinsic: LLVMAddLowerExpectIntrinsicPass,
229
- . typeBasedAliasAnalysis: LLVMAddTypeBasedAliasAnalysisPass,
230
- . scopedNoAliasAA: LLVMAddScopedNoAliasAAPass,
231
- . basicAliasAnalysis: LLVMAddBasicAliasAnalysisPass,
232
- . unifyFunctionExitNodes: LLVMAddUnifyFunctionExitNodesPass,
233
- . alwaysInliner: LLVMAddAlwaysInlinerPass,
234
- . argumentPromotion: LLVMAddArgumentPromotionPass,
235
- . constantMerge: LLVMAddConstantMergePass,
236
- . deadArgElimination: LLVMAddDeadArgEliminationPass,
237
- . functionAttrs: LLVMAddFunctionAttrsPass,
238
- . functionInlining: LLVMAddFunctionInliningPass,
239
- . globalDCE: LLVMAddGlobalDCEPass,
240
- . globalOptimizer: LLVMAddGlobalOptimizerPass,
241
- . ipConstantPropagation: LLVMAddIPConstantPropagationPass,
242
- . ipscc: LLVMAddIPSCCPPass,
243
- . pruneEH: LLVMAddPruneEHPass,
244
- . stripDeadPrototypes: LLVMAddStripDeadPrototypesPass,
245
- . stripSymbols: LLVMAddStripSymbolsPass,
246
- . loopVectorize: LLVMAddLoopVectorizePass,
247
- . slpVectorize: LLVMAddSLPVectorizePass,
248
- // .internalize: LLVMAddInternalizePass,
249
- // .sroaWithThreshhold: LLVMAddScalarReplAggregatesPassWithThreshold,
250
- ]
217
+ var alivePassObjects = [ Any] ( )
251
218
252
219
/// Creates a `FunctionPassManager` bound to the given module's IR.
253
220
public init ( module: Module ) {
@@ -259,9 +226,9 @@ public class FunctionPassManager {
259
226
///
260
227
/// - parameter passes: A list of function passes to add to the pass manager's
261
228
/// list of passes to run.
262
- public func add( _ passes: FunctionPass ... ) {
229
+ public func add( _ passes: Pass ... ) {
263
230
for pass in passes {
264
- FunctionPassManager . passMapping [ pass ] ! ( llvm)
231
+ PassPipeliner . configurePass ( pass , passManager : llvm, keepalive : & alivePassObjects )
265
232
}
266
233
}
267
234
@@ -272,3 +239,7 @@ public class FunctionPassManager {
272
239
LLVMRunFunctionPassManager ( llvm, function. asLLVM ( ) )
273
240
}
274
241
}
242
+
243
+ @available ( * , deprecated, renamed: " Pass " )
244
+ public typealias FunctionPass = Pass
245
+
0 commit comments