Skip to content

Commit 45f11c8

Browse files
committed
[IRGen] Allow IRGenDescriptor to hold a FileUnit
This will allow it to better interact with the SILGen descriptor.
1 parent 949d400 commit 45f11c8

File tree

5 files changed

+26
-25
lines changed

5 files changed

+26
-25
lines changed

include/swift/AST/IRGenRequests.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class GeneratedModule final {
123123
};
124124

125125
struct IRGenDescriptor {
126-
llvm::PointerUnion<ModuleDecl *, SourceFile *> Ctx;
126+
llvm::PointerUnion<FileUnit *, ModuleDecl *> Ctx;
127127

128128
const IRGenOptions &Opts;
129129
const TBDGenOptions &TBDOpts;
@@ -151,12 +151,12 @@ struct IRGenDescriptor {
151151

152152
public:
153153
static IRGenDescriptor
154-
forFile(SourceFile &SF, const IRGenOptions &Opts,
154+
forFile(FileUnit *file, const IRGenOptions &Opts,
155155
const TBDGenOptions &TBDOpts, std::unique_ptr<SILModule> &&SILMod,
156156
StringRef ModuleName, const PrimarySpecificPaths &PSPs,
157157
StringRef PrivateDiscriminator,
158158
llvm::GlobalVariable **outModuleHash) {
159-
return IRGenDescriptor{&SF,
159+
return IRGenDescriptor{file,
160160
Opts,
161161
TBDOpts,
162162
SILMod.release(),

include/swift/Subsystems.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,11 @@ namespace swift {
215215
ArrayRef<std::string> parallelOutputFilenames,
216216
llvm::GlobalVariable **outModuleHash = nullptr);
217217

218-
/// Turn the given Swift module into either LLVM IR or native code
218+
/// Turn the given Swift file into either LLVM IR or native code
219219
/// and return the generated LLVM IR module.
220220
/// If you set an outModuleHash, then you need to call performLLVM.
221221
GeneratedModule
222-
performIRGeneration(SourceFile &SF, const IRGenOptions &Opts,
222+
performIRGeneration(FileUnit *file, const IRGenOptions &Opts,
223223
const TBDGenOptions &TBDOpts,
224224
std::unique_ptr<SILModule> SILMod,
225225
StringRef ModuleName, const PrimarySpecificPaths &PSPs,

lib/FrontendTool/FrontendTool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1508,7 +1508,7 @@ generateIR(const IRGenOptions &IRGenOpts, const TBDGenOptions &TBDOpts,
15081508
llvm::GlobalVariable *&HashGlobal,
15091509
ArrayRef<std::string> parallelOutputFilenames) {
15101510
if (auto *SF = MSF.dyn_cast<SourceFile *>()) {
1511-
return performIRGeneration(*SF, IRGenOpts, TBDOpts,
1511+
return performIRGeneration(SF, IRGenOpts, TBDOpts,
15121512
std::move(SM), OutputFilename, PSPs,
15131513
SF->getPrivateDiscriminator().str(),
15141514
&HashGlobal);

lib/IRGen/IRGen.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,8 @@ GeneratedModule IRGenRequest::evaluate(Evaluator &evaluator,
907907
auto SILMod = std::unique_ptr<SILModule>(desc.SILMod);
908908
auto *M = desc.getParentModule();
909909
auto filesToEmit = desc.getFiles();
910-
auto *primaryFile = desc.Ctx.dyn_cast<SourceFile *>();
910+
auto *primaryFile =
911+
dyn_cast_or_null<SourceFile>(desc.Ctx.dyn_cast<FileUnit *>());
911912

912913
auto &Ctx = M->getASTContext();
913914
assert(!Ctx.hadError());
@@ -1326,16 +1327,16 @@ GeneratedModule swift::performIRGeneration(
13261327
}
13271328

13281329
GeneratedModule swift::
1329-
performIRGeneration(SourceFile &SF, const IRGenOptions &Opts,
1330+
performIRGeneration(FileUnit *file, const IRGenOptions &Opts,
13301331
const TBDGenOptions &TBDOpts,
13311332
std::unique_ptr<SILModule> SILMod,
13321333
StringRef ModuleName, const PrimarySpecificPaths &PSPs,
13331334
StringRef PrivateDiscriminator,
13341335
llvm::GlobalVariable **outModuleHash) {
1335-
auto desc = IRGenDescriptor::forFile(SF, Opts, TBDOpts, std::move(SILMod),
1336+
auto desc = IRGenDescriptor::forFile(file, Opts, TBDOpts, std::move(SILMod),
13361337
ModuleName, PSPs, PrivateDiscriminator,
13371338
outModuleHash);
1338-
return llvm::cantFail(SF.getASTContext().evaluator(IRGenRequest{desc}));
1339+
return llvm::cantFail(file->getASTContext().evaluator(IRGenRequest{desc}));
13391340
}
13401341

13411342
void

lib/IRGen/IRGenRequests.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,12 @@ llvm::orc::ThreadSafeModule GeneratedModule::intoThreadSafeContext() && {
3939
void swift::simple_display(llvm::raw_ostream &out,
4040
const IRGenDescriptor &desc) {
4141
auto *MD = desc.Ctx.dyn_cast<ModuleDecl *>();
42-
auto *SF = desc.Ctx.dyn_cast<SourceFile *>();
4342
if (MD) {
4443
out << "IR Generation for module " << MD->getName();
4544
} else {
46-
assert(SF);
45+
auto *file = desc.Ctx.get<FileUnit *>();
4746
out << "IR Generation for file ";
48-
out << '\"' << SF->getFilename() << '\"';
47+
simple_display(out, file);
4948
}
5049
}
5150

@@ -58,29 +57,30 @@ TinyPtrVector<FileUnit *> IRGenDescriptor::getFiles() const {
5857
if (auto *mod = Ctx.dyn_cast<ModuleDecl *>())
5958
return TinyPtrVector<FileUnit *>(mod->getFiles());
6059

61-
// For a primary source file, we emit IR for both it and potentially its
60+
// For a primary file, we emit IR for both it and potentially its
6261
// SynthesizedFileUnit.
63-
auto *SF = Ctx.get<SourceFile *>();
62+
auto *primary = Ctx.get<FileUnit *>();
6463
TinyPtrVector<FileUnit *> files;
65-
files.push_back(SF);
66-
67-
if (auto *synthesizedFile = SF->getSynthesizedFile())
68-
files.push_back(synthesizedFile);
64+
files.push_back(primary);
6965

66+
if (auto *SF = dyn_cast<SourceFile>(primary)) {
67+
if (auto *synthesizedFile = SF->getSynthesizedFile())
68+
files.push_back(synthesizedFile);
69+
}
7070
return files;
7171
}
7272

7373
ModuleDecl *IRGenDescriptor::getParentModule() const {
74-
if (auto *SF = Ctx.dyn_cast<SourceFile *>())
75-
return SF->getParentModule();
74+
if (auto *file = Ctx.dyn_cast<FileUnit *>())
75+
return file->getParentModule();
7676
return Ctx.get<ModuleDecl *>();
7777
}
7878

7979
std::vector<std::string> IRGenDescriptor::getLinkerDirectives() const {
8080
auto opts = TBDOpts;
8181
opts.LinkerDirectivesOnly = true;
82-
if (auto *SF = Ctx.dyn_cast<SourceFile *>()) {
83-
return getPublicSymbols(TBDGenDescriptor::forFile(SF, opts));
82+
if (auto *file = Ctx.dyn_cast<FileUnit *>()) {
83+
return getPublicSymbols(TBDGenDescriptor::forFile(file, opts));
8484
} else {
8585
auto *M = Ctx.get<ModuleDecl *>();
8686
return getPublicSymbols(TBDGenDescriptor::forModule(M, opts));
@@ -96,8 +96,8 @@ evaluator::DependencySource IRGenRequest::readDependencySource(
9696
return {nullptr, e.getActiveSourceScope()};
9797
}
9898

99-
auto *SF = desc.Ctx.get<SourceFile *>();
100-
return {SF, evaluator::DependencyScope::Cascading};
99+
auto *primary = desc.Ctx.get<FileUnit *>();
100+
return {dyn_cast<SourceFile>(primary), evaluator::DependencyScope::Cascading};
101101
}
102102

103103
// Define request evaluation functions for each of the IRGen requests.

0 commit comments

Comments
 (0)