Skip to content

Commit 1f2346d

Browse files
committed
[NFC] Drastically Reduce The Scope of the Global Context
Delete all of the formalism and infrastructure around maintaining our own copy of the global context. The final frontier is the Builtins, which need to lookup intrinsics in a given scratch context and convert them into the appropriate Swift annotations and types. As these utilities have wormed their way through the compiler, I have decided to leave this alone for now.
1 parent 2ca8e66 commit 1f2346d

File tree

9 files changed

+15
-63
lines changed

9 files changed

+15
-63
lines changed

include/swift/Basic/LLVMContext.h

Lines changed: 0 additions & 30 deletions
This file was deleted.

include/swift/SIL/SILModule.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,6 @@ class SILModule {
233233
// The list of SILProperties in the module.
234234
PropertyListType properties;
235235

236-
/// The remark output stream used to record SIL remarks to a file.
237-
std::unique_ptr<llvm::raw_fd_ostream> silRemarkStream;
238-
239236
/// The remark streamer used to serialize SIL remarks to a file.
240237
std::unique_ptr<swift::SILRemarkStreamer> silRemarkStreamer;
241238

@@ -526,9 +523,7 @@ class SILModule {
526523
swift::SILRemarkStreamer *getSILRemarkStreamer() {
527524
return silRemarkStreamer.get();
528525
}
529-
void setSILRemarkStreamer(
530-
std::unique_ptr<llvm::raw_fd_ostream> &&remarkStream,
531-
std::unique_ptr<swift::SILRemarkStreamer> &&remarkStreamer);
526+
void installSILRemarkStreamer();
532527

533528
// This is currently limited to VarDecl because the visibility of global
534529
// variables and class properties is straightforward, while the visibility of

lib/AST/Builtins.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,30 @@
2020
#include "swift/AST/Module.h"
2121
#include "swift/AST/ParameterList.h"
2222
#include "swift/AST/TypeCheckRequests.h"
23-
#include "swift/Basic/LLVMContext.h"
2423
#include "swift/Strings.h"
2524
#include "llvm/ADT/SmallString.h"
2625
#include "llvm/ADT/StringSwitch.h"
2726
#include "llvm/IR/Attributes.h"
2827
#include "llvm/IR/Instructions.h"
2928
#include "llvm/IR/Intrinsics.h"
3029
#include "llvm/IR/LLVMContext.h"
30+
#include "llvm/Support/ManagedStatic.h"
3131
#include <tuple>
32+
3233
using namespace swift;
3334

35+
// FIXME: The "Global Context" is a holdover from LLVM's removal of the global
36+
// context. LLVM's global context was used as scratch space to allocate some
37+
// attributes for the routines in this file, so we just made our own to work
38+
// around its removal. Really, it doesn't matter where we allocate these
39+
// attributes, but it's somewhat convenient for now that they're all in one
40+
// place instead of requiring a fresh context for every call. If we can
41+
// sequester ownership of a context (e.g. in SILModule) we could do away with
42+
// this, but there are callers of \c swift::getSwiftFunctionTypeForIntrinsic
43+
// all over the compiler.
44+
static llvm::ManagedStatic<llvm::LLVMContext> GlobalContext;
45+
static llvm::LLVMContext &getGlobalLLVMContext() { return *GlobalContext; }
46+
3447
struct BuiltinExtraInfoTy {
3548
const char *Attributes;
3649
};

lib/Basic/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ add_swift_host_library(swiftBasic STATIC
4949
FileTypes.cpp
5050
JSONSerialization.cpp
5151
LangOptions.cpp
52-
LLVMContext.cpp
5352
Located.cpp
5453
Mangler.cpp
5554
OutputFileMap.cpp

lib/Basic/LLVMContext.cpp

Lines changed: 0 additions & 21 deletions
This file was deleted.

lib/Immediate/Immediate.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "swift/AST/IRGenRequests.h"
2626
#include "swift/AST/Module.h"
2727
#include "swift/Basic/LLVM.h"
28-
#include "swift/Basic/LLVMContext.h"
2928
#include "swift/Frontend/Frontend.h"
3029
#include "swift/IRGen/IRGenPublic.h"
3130
#include "swift/SILOptimizer/PassManager/Passes.h"

lib/Immediate/REPL.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "swift/AST/Module.h"
2323
#include "swift/AST/NameLookup.h"
2424
#include "swift/AST/NameLookupRequests.h"
25-
#include "swift/Basic/LLVMContext.h"
2625
#include "swift/Frontend/Frontend.h"
2726
#include "swift/IDE/REPLCodeCompletion.h"
2827
#include "swift/IDE/Utils.h"

tools/sil-llvm-gen/SILLLVMGen.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "swift/AST/DiagnosticsFrontend.h"
2121
#include "swift/AST/IRGenRequests.h"
2222
#include "swift/AST/SILOptions.h"
23-
#include "swift/Basic/LLVMContext.h"
2423
#include "swift/Basic/LLVMInitialize.h"
2524
#include "swift/Frontend/DiagnosticVerifier.h"
2625
#include "swift/Frontend/Frontend.h"

tools/swift-llvm-opt/LLVMOpt.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
#include "swift/Subsystems.h"
2626
#include "swift/Basic/LLVMInitialize.h"
27-
#include "swift/Basic/LLVMContext.h"
2827
#include "swift/AST/IRGenOptions.h"
2928
#include "swift/LLVMPasses/PassesFwd.h"
3029
#include "swift/LLVMPasses/Passes.h"

0 commit comments

Comments
 (0)