Skip to content

Commit 5add051

Browse files
authored
Merge pull request #17172 from jckarter/jit-relative-references-4.2
[4.2] IRGen: More specifically curtail JIT use of relative references to the integrated REPL.
2 parents d04931c + 5e3c57b commit 5add051

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

include/swift/AST/IRGenOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ class IRGenOptions {
103103
/// \brief Whether we're generating IR for the JIT.
104104
unsigned UseJIT : 1;
105105

106+
/// \brief Whether we're generating code for the integrated REPL.
107+
unsigned IntegratedREPL : 1;
108+
106109
/// \brief Whether we should run LLVM optimizations after IRGen.
107110
unsigned DisableLLVMOptzns : 1;
108111

@@ -182,6 +185,7 @@ class IRGenOptions {
182185
Verify(true), OptMode(OptimizationMode::NotSet),
183186
Sanitizers(OptionSet<SanitizerKind>()),
184187
DebugInfoKind(IRGenDebugInfoKind::None), UseJIT(false),
188+
IntegratedREPL(false),
185189
DisableLLVMOptzns(false), DisableSwiftSpecificLLVMOptzns(false),
186190
DisableLLVMSLPVectorizer(false), DisableFPElim(true), Playground(false),
187191
EmitStackPromotionChecks(false), PrintInlineTree(false),

lib/IRGen/GenDecl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2580,12 +2580,12 @@ IRGenModule::getAddrOfLLVMVariableOrGOTEquivalent(LinkEntity entity,
25802580
// binary, then we ought to be able to directly relative-reference the
25812581
// symbol. However, some platforms don't have the necessary relocations to
25822582
// represent a relative reference to an undefined symbol, so conservatively
2583-
// produce an indirect reference in this case. Also, some JIT modes
2584-
// incrementally add new definitions that refer back to existing ones
2583+
// produce an indirect reference in this case. Also, the integrated REPL
2584+
// incrementally adds new definitions that refer back to existing ones
25852585
// relatively, so always use indirect references in this situation.
25862586
auto entry = GlobalVars[entity];
25872587
if (forceIndirectness == ConstantReference::Direct &&
2588-
!IRGen.Opts.UseJIT &&
2588+
!IRGen.Opts.IntegratedREPL &&
25892589
(!entity.isAvailableExternally(*this) || isDefinition(entry))) {
25902590
// FIXME: Relative references to aliases break MC on 32-bit Mach-O
25912591
// platforms (rdar://problem/22450593 ), so substitute an alias with its

lib/IRGen/IRGenMangler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ IRGenMangler::mangleTypeForReflection(IRGenModule &IGM,
9292

9393
if (IGM.CurSourceFile
9494
&& !isa<ClangModuleUnit>(IGM.CurSourceFile)
95-
&& !IGM.getOptions().UseJIT) {
95+
&& !IGM.getOptions().IntegratedREPL) {
9696
CanSymbolicReference = [&](const DeclContext *dc) -> bool {
9797
// Symbolically reference types that are defined in the same file unit
9898
// as we're referencing from.

lib/Immediate/REPL.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,7 @@ class REPLEnvironment {
10041004
IRGenOpts.OptMode = OptimizationMode::NoOptimization;
10051005
IRGenOpts.OutputKind = IRGenOutputKind::Module;
10061006
IRGenOpts.UseJIT = true;
1007+
IRGenOpts.IntegratedREPL = true;
10071008
IRGenOpts.DebugInfoKind = IRGenDebugInfoKind::None;
10081009

10091010
if (!ParseStdlib) {

0 commit comments

Comments
 (0)