Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions include/swift/Basic/LLVMContext.h

This file was deleted.

7 changes: 1 addition & 6 deletions include/swift/SIL/SILModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,6 @@ class SILModule {
// The list of SILProperties in the module.
PropertyListType properties;

/// The remark output stream used to record SIL remarks to a file.
std::unique_ptr<llvm::raw_fd_ostream> silRemarkStream;

/// The remark streamer used to serialize SIL remarks to a file.
std::unique_ptr<swift::SILRemarkStreamer> silRemarkStreamer;

Expand Down Expand Up @@ -526,9 +523,7 @@ class SILModule {
swift::SILRemarkStreamer *getSILRemarkStreamer() {
return silRemarkStreamer.get();
}
void setSILRemarkStreamer(
std::unique_ptr<llvm::raw_fd_ostream> &&remarkStream,
std::unique_ptr<swift::SILRemarkStreamer> &&remarkStreamer);
void installSILRemarkStreamer();

// This is currently limited to VarDecl because the visibility of global
// variables and class properties is straightforward, while the visibility of
Expand Down
40 changes: 25 additions & 15 deletions include/swift/SIL/SILRemarkStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,39 @@
namespace swift {

class SILRemarkStreamer {
llvm::remarks::RemarkStreamer &llvmStreamer;
private:
/// The \c LLVMContext the underlying streamer uses for scratch space.
std::unique_ptr<llvm::LLVMContext> streamerContext;
/// The remark output stream used to record SIL remarks to a file.
std::unique_ptr<llvm::raw_fd_ostream> remarkStream;

// Source manager for resolving source locations.
const SourceManager &srcMgr;
const ASTContext &ctx;
/// Convert diagnostics into LLVM remark objects.
/// The lifetime of the members of the result is bound to the lifetime of
/// the SIL remarks.
template <typename RemarkT>
llvm::remarks::Remark
toLLVMRemark(const OptRemark::Remark<RemarkT> &remark) const;

SILRemarkStreamer(std::unique_ptr<llvm::remarks::RemarkStreamer> &&streamer,
std::unique_ptr<llvm::raw_fd_ostream> &&stream,
const ASTContext &Ctx);

public:
static std::unique_ptr<SILRemarkStreamer> create(SILModule &silModule);

public:
SILRemarkStreamer(llvm::remarks::RemarkStreamer &llvmStreamer,
const SourceManager &srcMgr)
: llvmStreamer(llvmStreamer), srcMgr(srcMgr) {}
llvm::remarks::RemarkStreamer &getLLVMStreamer();
const llvm::remarks::RemarkStreamer &getLLVMStreamer() const;

const ASTContext &getASTContext() const { return ctx; }

/// Emit a remark through the streamer.
template <typename RemarkT>
void emit(const OptRemark::Remark<RemarkT> &remark);
};

std::pair<std::unique_ptr<llvm::raw_fd_ostream>,
std::unique_ptr<SILRemarkStreamer>>
createSILRemarkStreamer(SILModule &srcMgr, StringRef filename, StringRef passes,
llvm::remarks::Format format,
DiagnosticEngine &diagEngine, SourceManager &sourceMgr);

// Implementation for template member functions.

// OptRemark type -> llvm::remarks::Type
Expand Down Expand Up @@ -80,24 +88,26 @@ llvm::remarks::Remark SILRemarkStreamer::toLLVMRemark(
llvmRemark.PassName = optRemark.getPassName();
llvmRemark.RemarkName = optRemark.getIdentifier();
llvmRemark.FunctionName = optRemark.getDemangledFunctionName();
llvmRemark.Loc = toRemarkLocation(optRemark.getLocation(), srcMgr);
llvmRemark.Loc =
toRemarkLocation(optRemark.getLocation(), getASTContext().SourceMgr);

for (const OptRemark::Argument &arg : optRemark.getArgs()) {
llvmRemark.Args.emplace_back();
llvmRemark.Args.back().Key = arg.key;
llvmRemark.Args.back().Val = arg.val;
llvmRemark.Args.back().Loc = toRemarkLocation(arg.loc, srcMgr);
llvmRemark.Args.back().Loc =
toRemarkLocation(arg.loc, getASTContext().SourceMgr);
}

return llvmRemark;
}

template <typename RemarkT>
void SILRemarkStreamer::emit(const OptRemark::Remark<RemarkT> &optRemark) {
if (!llvmStreamer.matchesFilter(optRemark.getPassName()))
if (!getLLVMStreamer().matchesFilter(optRemark.getPassName()))
return;

return llvmStreamer.getSerializer().emit(toLLVMRemark(optRemark));
return getLLVMStreamer().getSerializer().emit(toLLVMRemark(optRemark));
}

} // namespace swift
Expand Down
15 changes: 14 additions & 1 deletion lib/AST/Builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,30 @@
#include "swift/AST/Module.h"
#include "swift/AST/ParameterList.h"
#include "swift/AST/TypeCheckRequests.h"
#include "swift/Basic/LLVMContext.h"
#include "swift/Strings.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/Support/ManagedStatic.h"
#include <tuple>

using namespace swift;

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

struct BuiltinExtraInfoTy {
const char *Attributes;
};
Expand Down
1 change: 0 additions & 1 deletion lib/Basic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ add_swift_host_library(swiftBasic STATIC
FileTypes.cpp
JSONSerialization.cpp
LangOptions.cpp
LLVMContext.cpp
Located.cpp
Mangler.cpp
OutputFileMap.cpp
Expand Down
21 changes: 0 additions & 21 deletions lib/Basic/LLVMContext.cpp

This file was deleted.

12 changes: 3 additions & 9 deletions lib/FrontendTool/FrontendTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include "swift/Basic/Edit.h"
#include "swift/Basic/FileSystem.h"
#include "swift/Basic/JSONSerialization.h"
#include "swift/Basic/LLVMContext.h"
#include "swift/Basic/LLVMInitialize.h"
#include "swift/Basic/Platform.h"
#include "swift/Basic/PrettyStackTrace.h"
Expand Down Expand Up @@ -779,8 +778,6 @@ static bool buildModuleFromInterface(const CompilerInvocation &Invocation,

static bool compileLLVMIR(const CompilerInvocation &Invocation,
CompilerInstance &Instance) {
auto &LLVMContext = getGlobalLLVMContext();

// Load in bitcode file.
assert(Invocation.getFrontendOptions().InputsAndOutputs.hasSingleInput() &&
"We expect a single input for bitcode input!");
Expand All @@ -800,8 +797,9 @@ static bool compileLLVMIR(const CompilerInvocation &Invocation,
llvm::MemoryBuffer *MainFile = FileBufOrErr.get().get();

llvm::SMDiagnostic Err;
auto LLVMContext = std::make_unique<llvm::LLVMContext>();
std::unique_ptr<llvm::Module> Module =
llvm::parseIR(MainFile->getMemBufferRef(), Err, LLVMContext);
llvm::parseIR(MainFile->getMemBufferRef(), Err, *LLVMContext.get());
if (!Module) {
// TODO: Translate from the diagnostic info to the SourceManager location
// if available.
Expand Down Expand Up @@ -1558,7 +1556,6 @@ static bool performCompileStepsPostSILGen(
FrontendOptions opts = Invocation.getFrontendOptions();
FrontendOptions::ActionType Action = opts.RequestedAction;
const ASTContext &Context = Instance.getASTContext();
const SILOptions &SILOpts = Invocation.getSILOptions();
const IRGenOptions &IRGenOpts = Invocation.getIRGenOptions();

Optional<BufferIndirectlyCausingDiagnosticRAII> ricd;
Expand All @@ -1582,10 +1579,7 @@ static bool performCompileStepsPostSILGen(
return Context.hadError();
}

auto pair = createSILRemarkStreamer(
*SM, SILOpts.OptRecordFile, SILOpts.OptRecordPasses,
SILOpts.OptRecordFormat, Instance.getDiags(), Instance.getSourceMgr());
SM->setSILRemarkStreamer(std::move(pair.first), std::move(pair.second));
SM->installSILRemarkStreamer();

// This is the action to be used to serialize SILModule.
// It may be invoked multiple times, but it will perform
Expand Down
1 change: 0 additions & 1 deletion lib/Immediate/Immediate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "swift/AST/IRGenRequests.h"
#include "swift/AST/Module.h"
#include "swift/Basic/LLVM.h"
#include "swift/Basic/LLVMContext.h"
#include "swift/Frontend/Frontend.h"
#include "swift/IRGen/IRGenPublic.h"
#include "swift/SILOptimizer/PassManager/Passes.h"
Expand Down
14 changes: 6 additions & 8 deletions lib/Immediate/REPL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "swift/AST/Module.h"
#include "swift/AST/NameLookup.h"
#include "swift/AST/NameLookupRequests.h"
#include "swift/Basic/LLVMContext.h"
#include "swift/Frontend/Frontend.h"
#include "swift/IDE/REPLCodeCompletion.h"
#include "swift/IDE/Utils.h"
Expand Down Expand Up @@ -765,13 +764,13 @@ static void printOrDumpDecl(Decl *d, PrintOrDump which) {

/// The compiler and execution environment for the REPL.
class REPLEnvironment {
std::unique_ptr<llvm::LLVMContext> LLVMContext;
CompilerInstance &CI;
ModuleDecl *MostRecentModule;
ProcessCmdLine CmdLine;
llvm::SmallPtrSet<swift::ModuleDecl *, 8> ImportedModules;
SmallVector<llvm::Function*, 8> InitFns;
bool RanGlobalInitializers;
llvm::LLVMContext &LLVMContext;
llvm::Module *Module;
llvm::StringSet<> FuncsAlreadyGenerated;
llvm::StringSet<> GlobalsAlreadyEmitted;
Expand Down Expand Up @@ -1028,15 +1027,14 @@ class REPLEnvironment {
public:
REPLEnvironment(CompilerInstance &CI,
const ProcessCmdLine &CmdLine,
llvm::LLVMContext &LLVMCtx,
bool ParseStdlib)
: CI(CI),
: LLVMContext(std::make_unique<llvm::LLVMContext>()),
CI(CI),
MostRecentModule(CI.getMainModule()),
CmdLine(CmdLine),
RanGlobalInitializers(false),
LLVMContext(LLVMCtx),
Module(new llvm::Module("REPL", LLVMContext)),
DumpModule("REPL", LLVMContext),
Module(new llvm::Module("REPL", *LLVMContext.get())),
DumpModule("REPL", *LLVMContext.get()),
IRGenOpts(),
SILOpts(),
Input(*this)
Expand Down Expand Up @@ -1281,7 +1279,7 @@ void PrettyStackTraceREPL::print(llvm::raw_ostream &out) const {

void swift::runREPL(CompilerInstance &CI, const ProcessCmdLine &CmdLine,
bool ParseStdlib) {
REPLEnvironment env(CI, CmdLine, getGlobalLLVMContext(), ParseStdlib);
REPLEnvironment env(CI, CmdLine, ParseStdlib);
if (CI.getASTContext().hadError())
return;

Expand Down
9 changes: 4 additions & 5 deletions lib/SIL/IR/SILModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/YAMLTraits.h"
#include <functional>
Expand Down Expand Up @@ -698,11 +699,9 @@ void SILModule::serialize() {
setSerialized();
}

void SILModule::setSILRemarkStreamer(
std::unique_ptr<llvm::raw_fd_ostream> &&remarkStream,
std::unique_ptr<swift::SILRemarkStreamer> &&remarkStreamer) {
silRemarkStream = std::move(remarkStream);
silRemarkStreamer = std::move(remarkStreamer);
void SILModule::installSILRemarkStreamer() {
assert(!silRemarkStreamer && "SIL Remark Streamer is already installed!");
silRemarkStreamer = SILRemarkStreamer::create(*this);
}

bool SILModule::isStdlibModule() const {
Expand Down
Loading