15
15
// ===----------------------------------------------------------------------===//
16
16
17
17
#define DEBUG_TYPE " irgen"
18
- #include " swift/Subsystems .h"
18
+ #include " IRGenModule .h"
19
19
#include " swift/AST/DiagnosticsIRGen.h"
20
20
#include " swift/AST/IRGenOptions.h"
21
21
#include " swift/AST/LinkLibrary.h"
22
- #include " swift/SIL/SILModule.h"
23
22
#include " swift/Basic/Defer.h"
24
23
#include " swift/Basic/Dwarf.h"
25
24
#include " swift/Basic/Platform.h"
29
28
#include " swift/ClangImporter/ClangImporter.h"
30
29
#include " swift/IRGen/IRGenPublic.h"
31
30
#include " swift/IRGen/IRGenSILPasses.h"
32
- #include " swift/LLVMPasses/PassesFwd.h"
33
31
#include " swift/LLVMPasses/Passes.h"
34
- #include " swift/SILOptimizer/PassManager/Passes.h"
32
+ #include " swift/LLVMPasses/PassesFwd.h"
33
+ #include " swift/SIL/SILModule.h"
35
34
#include " swift/SILOptimizer/PassManager/PassManager.h"
36
35
#include " swift/SILOptimizer/PassManager/PassPipeline.h"
36
+ #include " swift/SILOptimizer/PassManager/Passes.h"
37
+ #include " swift/Subsystems.h"
37
38
#include " clang/Basic/TargetInfo.h"
38
- #include " llvm/Bitcode/BitcodeWriterPass.h"
39
+ #include " llvm/ADT/StringSet.h"
40
+ #include " llvm/Analysis/AliasAnalysis.h"
39
41
#include " llvm/Bitcode/BitcodeWriter.h"
42
+ #include " llvm/Bitcode/BitcodeWriterPass.h"
40
43
#include " llvm/CodeGen/BasicTTIImpl.h"
41
44
#include " llvm/IR/Constants.h"
42
45
#include " llvm/IR/DataLayout.h"
43
46
#include " llvm/IR/IRPrintingPasses.h"
44
- #include " llvm/IR/LegacyPassManager.h"
45
47
#include " llvm/IR/LLVMContext.h"
48
+ #include " llvm/IR/LegacyPassManager.h"
46
49
#include " llvm/IR/Module.h"
47
50
#include " llvm/IR/ValueSymbolTable.h"
48
51
#include " llvm/IR/Verifier.h"
49
52
#include " llvm/Linker/Linker.h"
50
53
#include " llvm/MC/SubtargetFeature.h"
54
+ #include " llvm/Object/ObjectFile.h"
55
+ #include " llvm/Support/CommandLine.h"
51
56
#include " llvm/Support/Debug.h"
52
57
#include " llvm/Support/ErrorHandling.h"
53
58
#include " llvm/Support/FileSystem.h"
54
59
#include " llvm/Support/FormattedStream.h"
55
- #include " llvm/Support/TargetRegistry.h"
56
- #include " llvm/Support/Path.h"
57
- #include " llvm/Support/Mutex.h"
58
60
#include " llvm/Support/MD5.h"
59
- #include " llvm/ADT/StringSet.h"
60
- #include " llvm/Analysis/AliasAnalysis.h"
61
+ #include " llvm/Support/Mutex.h"
62
+ #include " llvm/Support/Path.h"
63
+ #include " llvm/Support/TargetRegistry.h"
61
64
#include " llvm/Target/TargetMachine.h"
62
65
#include " llvm/Target/TargetSubtargetInfo.h"
63
- #include " llvm/Transforms/Instrumentation.h"
64
66
#include " llvm/Transforms/IPO.h"
65
67
#include " llvm/Transforms/IPO/AlwaysInliner.h"
66
68
#include " llvm/Transforms/IPO/PassManagerBuilder.h"
69
+ #include " llvm/Transforms/Instrumentation.h"
67
70
#include " llvm/Transforms/ObjCARC.h"
68
- #include " llvm/Object/ObjectFile.h"
69
- #include " IRGenModule.h"
70
71
71
72
#include < thread>
72
73
73
74
using namespace swift ;
74
75
using namespace irgen ;
75
76
using namespace llvm ;
76
77
78
+ static cl::opt<bool > DisableObjCARCContract (
79
+ " disable-objc-arc-contract" , cl::Hidden,
80
+ cl::desc (" Disable running objc arc contract for testing purposes" ));
81
+
77
82
namespace {
78
83
// We need this to access IRGenOptions from extension functions
79
84
class PassManagerBuilderWrapper : public PassManagerBuilder {
@@ -446,6 +451,13 @@ bool swift::performLLVM(IRGenOptions &Opts, DiagnosticEngine *Diags,
446
451
447
452
legacy::PassManager EmitPasses;
448
453
454
+ // Make sure we do ARC contraction under optimization. We don't
455
+ // rely on any other LLVM ARC transformations, but we do need ARC
456
+ // contraction to add the objc_retainAutoreleasedReturnValue
457
+ // assembly markers and remove clang.arc.used.
458
+ if (Opts.Optimize && !DisableObjCARCContract)
459
+ EmitPasses.add (createObjCARCContractPass ());
460
+
449
461
// Set up the final emission passes.
450
462
switch (Opts.OutputKind ) {
451
463
case IRGenOutputKind::Module:
@@ -466,13 +478,6 @@ bool swift::performLLVM(IRGenOptions &Opts, DiagnosticEngine *Diags,
466
478
EmitPasses.add (createTargetTransformInfoWrapperPass (
467
479
TargetMachine->getTargetIRAnalysis ()));
468
480
469
- // Make sure we do ARC contraction under optimization. We don't
470
- // rely on any other LLVM ARC transformations, but we do need ARC
471
- // contraction to add the objc_retainAutoreleasedReturnValue
472
- // assembly markers.
473
- if (Opts.Optimize )
474
- EmitPasses.add (createObjCARCContractPass ());
475
-
476
481
bool fail = TargetMachine->addPassesToEmitFile (EmitPasses, *RawOS,
477
482
FileType, !Opts.Verify );
478
483
if (fail) {
0 commit comments