Skip to content

Commit 913df8b

Browse files
committed
Deprecate simplifyLibCalls and unify SROA
All the SROA variants in the C API no longer make a difference.
1 parent 5440d21 commit 913df8b

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

Sources/LLVM/PassManager.swift

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public enum Pass {
8989
/// This pass converts SwitchInst instructions into a sequence of chained
9090
/// binary branch instructions.
9191
case lowerSwitch
92-
/// This pass is used to promote memory references to
92+
/// This pass is used to promote memory references to
9393
/// be register references. A simple example of the transformation performed
9494
/// by this pass is going from code like this:
9595
///
@@ -120,10 +120,6 @@ public enum Pass {
120120
case reassociate
121121
/// Sparse conditional constant propagation.
122122
case sccp
123-
/// Replace aggregates or pieces of aggregates with scalar SSA values.
124-
case scalarReplAggregates
125-
/// Replace aggregates or pieces of aggregates with scalar SSA values.
126-
case scalarReplAggregatesSSA
127123
/// This pass eliminates call instructions to the current function which occur
128124
/// immediately before return instructions.
129125
case tailCallElimination
@@ -186,6 +182,8 @@ public enum Pass {
186182
/// Return a new pass object which transforms invoke instructions into calls,
187183
/// if the callee can *not* unwind the stack.
188184
case pruneEH
185+
186+
case scalarReplacementOfAggregates
189187
/// This pass removes any function declarations (prototypes) that are not used.
190188
case stripDeadPrototypes
191189
/// These functions removes symbols from functions and modules without
@@ -197,6 +195,17 @@ public enum Pass {
197195
/// This pass performs a superword-level parallelism pass to combine
198196
/// similar independent instructions into vector instructions.
199197
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'")
200209
}
201210

202211
/// A `FunctionPassManager` is an object that collects a sequence of passes
@@ -205,6 +214,7 @@ public enum Pass {
205214
@available(*, deprecated, message: "Use the PassPipeliner instead")
206215
public class FunctionPassManager {
207216
internal let llvm: LLVMPassManagerRef
217+
var alivePassObjects = [Any]()
208218

209219
/// Creates a `FunctionPassManager` bound to the given module's IR.
210220
public init(module: Module) {
@@ -218,7 +228,7 @@ public class FunctionPassManager {
218228
/// list of passes to run.
219229
public func add(_ passes: Pass...) {
220230
for pass in passes {
221-
PassPipeliner.passMapping[pass]!(llvm)
231+
PassPipeliner.configurePass(pass, passManager: llvm, keepalive: &alivePassObjects)
222232
}
223233
}
224234

Sources/llvmshims/include/shim.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,10 @@ uint64_t LLVMGlobalGetGUID(LLVMValueRef Global);
9696
void LLVMAppendExistingBasicBlock(LLVMValueRef Fn,
9797
LLVMBasicBlockRef BB);
9898

99+
void LLVMAddAddDiscriminatorsPass(LLVMPassManagerRef PM);
100+
101+
void LLVMAddInternalizePassWithMustPreservePredicate(
102+
LLVMPassManagerRef PM, void *Context,
103+
LLVMBool (*MustPreserve)(LLVMValueRef, void *));
104+
99105
#endif /* LLVMSWIFT_LLVM_SHIM_H */

Sources/llvmshims/src/shim.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
#include "llvm/IR/Intrinsics.h"
66
#include "llvm/IR/Function.h"
77
#include "llvm/IR/IRBuilder.h"
8+
#include "llvm/IR/LegacyPassManager.h"
89
#include "llvm/Support/ARMTargetParser.h"
910
#include "llvm/Object/MachOUniversal.h"
1011
#include "llvm/Object/ObjectFile.h"
1112
#include "llvm/ADT/SmallVector.h"
13+
#include "llvm/Transforms/Utils.h"
14+
#include "llvm/Transforms/IPO.h"
1215

1316
extern "C" {
1417
typedef struct LLVMOpaqueBinary *LLVMBinaryRef;
@@ -120,6 +123,14 @@ extern "C" {
120123
// https://reviews.llvm.org/D59658
121124
void LLVMAppendExistingBasicBlock(LLVMValueRef Fn,
122125
LLVMBasicBlockRef BB);
126+
127+
// https://reviews.llvm.org/D58624
128+
void LLVMAddAddDiscriminatorsPass(LLVMPassManagerRef PM);
129+
130+
// https://reviews.llvm.org/D62456
131+
void LLVMAddInternalizePassWithMustPreservePredicate(
132+
LLVMPassManagerRef PM, void *Context,
133+
LLVMBool (*MustPreserve)(LLVMValueRef, void *));
123134
}
124135

125136
using namespace llvm;
@@ -354,3 +365,15 @@ void LLVMAppendExistingBasicBlock(LLVMValueRef Fn,
354365
LLVMBasicBlockRef BB) {
355366
unwrap<Function>(Fn)->getBasicBlockList().push_back(unwrap(BB));
356367
}
368+
369+
void LLVMAddAddDiscriminatorsPass(LLVMPassManagerRef PM) {
370+
unwrap(PM)->add(createAddDiscriminatorsPass());
371+
}
372+
373+
void LLVMAddInternalizePassWithMustPreservePredicate(
374+
LLVMPassManagerRef PM, void *Context,
375+
LLVMBool (*Pred)(LLVMValueRef, void *)) {
376+
unwrap(PM)->add(createInternalizePass([=](const GlobalValue &GV) {
377+
return Pred(wrap(&GV), Context) == 0 ? false : true;
378+
}));
379+
}

0 commit comments

Comments
 (0)