[NFC] Grab the private discriminator for a file in IRGenDebugInfo

This was being done at an odd point in the frontend presumably because by that point the private discriminator had been fully computed.  Instead, push the conditions for generating the prefix data down to debug info generation and stop mutating IRGenOptions::DebugFlag in the frontend.
This commit is contained in:
Robert Widmann
2020-01-10 11:17:05 -08:00
parent fad29a306c
commit eb61931012
10 changed files with 52 additions and 40 deletions

View File

@@ -303,6 +303,16 @@ public:
return OptMode == OptimizationMode::ForSize;
}
std::string getDebugFlags(StringRef PrivateDiscriminator) const {
std::string Flags = DebugFlags;
if (!PrivateDiscriminator.empty()) {
if (!Flags.empty())
Flags += " ";
Flags += ("-private-discriminator " + PrivateDiscriminator).str();
}
return Flags;
}
/// Return a hash code of any components from these options that should
/// contribute to a Swift Bridging PCH hash.
llvm::hash_code getPCHHashComponents() const {

View File

@@ -31,6 +31,7 @@ class IRGenModule;
std::pair<IRGenerator *, IRGenModule *>
createIRGenModule(SILModule *SILMod, StringRef OutputFilename,
StringRef MainInputFilenameForDebugInfo,
StringRef PrivateDiscriminator,
llvm::LLVMContext &LLVMContext);
/// Delete the IRGenModule and IRGenerator obtained by the above call.

View File

@@ -284,6 +284,7 @@ namespace swift {
performIRGeneration(IRGenOptions &Opts, SourceFile &SF,
std::unique_ptr<SILModule> SILMod,
StringRef ModuleName, const PrimarySpecificPaths &PSPs,
StringRef PrivateDiscriminator,
llvm::LLVMContext &LLVMContext,
llvm::GlobalVariable **outModuleHash = nullptr,
llvm::StringSet<> *LinkerDirectives = nullptr);

View File

@@ -1371,21 +1371,6 @@ static bool performCompile(CompilerInstance &Instance,
ReturnValue, observer, Stats);
}
/// Get the main source file's private discriminator and attach it to
/// the compile unit's flags.
static void setPrivateDiscriminatorIfNeeded(IRGenOptions &IRGenOpts,
ModuleOrSourceFile MSF) {
if (IRGenOpts.DebugInfoLevel == IRGenDebugInfoLevel::None ||
!MSF.is<SourceFile *>())
return;
Identifier PD = MSF.get<SourceFile *>()->getPrivateDiscriminator();
if (!PD.empty()) {
if (!IRGenOpts.DebugFlags.empty())
IRGenOpts.DebugFlags += " ";
IRGenOpts.DebugFlags += ("-private-discriminator " + PD.str()).str();
}
}
static bool serializeSIB(SILModule *SM, const PrimarySpecificPaths &PSPs,
ASTContext &Context, ModuleOrSourceFile MSF) {
const std::string &moduleOutputPath =
@@ -1414,6 +1399,7 @@ static void generateIR(IRGenOptions &IRGenOpts, std::unique_ptr<SILModule> SM,
IRModule = MSF.is<SourceFile *>()
? performIRGeneration(IRGenOpts, *MSF.get<SourceFile *>(),
std::move(SM), OutputFilename, PSPs,
MSF.get<SourceFile *>()->getPrivateDiscriminator().str(),
LLVMContext, &HashGlobal,
&LinkerDirectives)
: performIRGeneration(IRGenOpts, MSF.get<ModuleDecl *>(),
@@ -1601,8 +1587,6 @@ static bool performCompileStepsPostSILGen(
emitAnyWholeModulePostTypeCheckSupplementaryOutputs(Instance, Invocation,
moduleIsPublic);
setPrivateDiscriminatorIfNeeded(IRGenOpts, MSF);
if (Action == FrontendOptions::ActionType::EmitSIB)
return serializeSIB(SM.get(), PSPs, Instance.getASTContext(), MSF);

View File

@@ -808,6 +808,7 @@ static void initLLVMModule(const IRGenModule &IGM, ModuleDecl &M) {
std::pair<IRGenerator *, IRGenModule *>
swift::irgen::createIRGenModule(SILModule *SILMod, StringRef OutputFilename,
StringRef MainInputFilenameForDebugInfo,
StringRef PrivateDiscriminator,
llvm::LLVMContext &LLVMContext) {
IRGenOptions Opts;
@@ -819,7 +820,8 @@ swift::irgen::createIRGenModule(SILModule *SILMod, StringRef OutputFilename,
// Create the IR emitter.
IRGenModule *IGM =
new IRGenModule(*irgen, std::move(targetMachine), nullptr, LLVMContext,
"", OutputFilename, MainInputFilenameForDebugInfo);
"", OutputFilename, MainInputFilenameForDebugInfo,
PrivateDiscriminator);
initLLVMModule(*IGM, *SILMod->getSwiftModule());
@@ -858,6 +860,7 @@ static std::unique_ptr<llvm::Module>
performIRGeneration(IRGenOptions &Opts, ModuleDecl *M,
std::unique_ptr<SILModule> SILMod, StringRef ModuleName,
const PrimarySpecificPaths &PSPs,
StringRef PrivateDiscriminator,
llvm::LLVMContext &LLVMContext, SourceFile *SF = nullptr,
llvm::GlobalVariable **outModuleHash = nullptr,
llvm::StringSet<> *linkerDirectives = nullptr) {
@@ -872,7 +875,8 @@ performIRGeneration(IRGenOptions &Opts, ModuleDecl *M,
// Create the IR emitter.
IRGenModule IGM(irgen, std::move(targetMachine), nullptr, LLVMContext,
ModuleName, PSPs.OutputFilename,
PSPs.MainInputFilenameForDebugInfo);
PSPs.MainInputFilenameForDebugInfo,
PrivateDiscriminator);
initLLVMModule(IGM, *SILMod->getSwiftModule());
@@ -1119,7 +1123,8 @@ static void performParallelIRGeneration(
// Create the IR emitter.
IRGenModule *IGM =
new IRGenModule(irgen, std::move(targetMachine), nextSF, *Context,
ModuleName, *OutputIter++, nextSF->getFilename());
ModuleName, *OutputIter++, nextSF->getFilename(),
nextSF->getPrivateDiscriminator().str());
IGMcreated = true;
initLLVMModule(*IGM, *SILMod->getSwiftModule());
@@ -1279,19 +1284,21 @@ std::unique_ptr<llvm::Module> swift::performIRGeneration(
return nullptr;
}
return ::performIRGeneration(Opts, M, std::move(SILMod), ModuleName, PSPs,
LLVMContext, nullptr, outModuleHash,
LinkerDirectives);
"", LLVMContext, nullptr,
outModuleHash, LinkerDirectives);
}
std::unique_ptr<llvm::Module> swift::
performIRGeneration(IRGenOptions &Opts, SourceFile &SF,
std::unique_ptr<SILModule> SILMod,
StringRef ModuleName, const PrimarySpecificPaths &PSPs,
StringRef PrivateDiscriminator,
llvm::LLVMContext &LLVMContext,
llvm::GlobalVariable **outModuleHash,
llvm::StringSet<> *LinkerDirectives) {
return ::performIRGeneration(Opts, SF.getParentModule(), std::move(SILMod),
ModuleName, PSPs, LLVMContext, &SF,
ModuleName, PSPs, PrivateDiscriminator,
LLVMContext, &SF,
outModuleHash, LinkerDirectives);
}
@@ -1311,7 +1318,7 @@ swift::createSwiftModuleObjectFile(SILModule &SILMod, StringRef Buffer,
if (!targetMachine) return;
IRGenModule IGM(irgen, std::move(targetMachine), nullptr, VMContext,
OutputPath, OutputPath, "");
OutputPath, OutputPath, "", "");
initLLVMModule(IGM, *SILMod.getSwiftModule());
auto *Ty = llvm::ArrayType::get(IGM.Int8Ty, Buffer.size());
auto *Data =

View File

@@ -143,7 +143,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
public:
IRGenDebugInfoImpl(const IRGenOptions &Opts, ClangImporter &CI,
IRGenModule &IGM, llvm::Module &M,
StringRef MainOutputFilenameForDebugInfo);
StringRef MainOutputFilenameForDebugInfo,
StringRef PrivateDiscriminator);
void finalize();
void setCurrentLoc(IRBuilder &Builder, const SILDebugScope *DS,
@@ -1664,7 +1665,8 @@ private:
IRGenDebugInfoImpl::IRGenDebugInfoImpl(const IRGenOptions &Opts,
ClangImporter &CI, IRGenModule &IGM,
llvm::Module &M,
StringRef MainOutputFilenameForDebugInfo)
StringRef MainOutputFilenameForDebugInfo,
StringRef PD)
: Opts(Opts), CI(CI), SM(IGM.Context.SourceMgr), M(M), DBuilder(M),
IGM(IGM), DebugPrefixMap(Opts.DebugPrefixMap) {
assert(Opts.DebugInfoLevel > IRGenDebugInfoLevel::None &&
@@ -1678,7 +1680,6 @@ IRGenDebugInfoImpl::IRGenDebugInfoImpl(const IRGenOptions &Opts,
unsigned Lang = llvm::dwarf::DW_LANG_Swift;
std::string Producer = version::getSwiftFullVersion(
IGM.Context.LangOpts.EffectiveLanguageVersion);
StringRef Flags = Opts.DebugFlags;
unsigned Major, Minor;
std::tie(Major, Minor) = version::getSwiftNumericVersion();
unsigned MajorRuntimeVersion = Major;
@@ -1693,7 +1694,8 @@ IRGenDebugInfoImpl::IRGenDebugInfoImpl(const IRGenOptions &Opts,
TheCU = DBuilder.createCompileUnit(
Lang, MainFile,
Producer, Opts.shouldOptimize(), Flags, MajorRuntimeVersion, SplitName,
Producer, Opts.shouldOptimize(), Opts.getDebugFlags(PD),
MajorRuntimeVersion, SplitName,
Opts.DebugInfoLevel > IRGenDebugInfoLevel::LineTables
? llvm::DICompileUnit::FullDebug
: llvm::DICompileUnit::LineTablesOnly);
@@ -2355,9 +2357,11 @@ SILLocation::DebugLoc IRGenDebugInfoImpl::decodeSourceLoc(SourceLoc SL) {
std::unique_ptr<IRGenDebugInfo> IRGenDebugInfo::createIRGenDebugInfo(
const IRGenOptions &Opts, ClangImporter &CI, IRGenModule &IGM,
llvm::Module &M, StringRef MainOutputFilenameForDebugInfo) {
llvm::Module &M, StringRef MainOutputFilenameForDebugInfo,
StringRef PrivateDiscriminator) {
return llvm::make_unique<IRGenDebugInfoImpl>(Opts, CI, IGM, M,
MainOutputFilenameForDebugInfo);
MainOutputFilenameForDebugInfo,
PrivateDiscriminator);
}

View File

@@ -49,7 +49,8 @@ public:
static std::unique_ptr<IRGenDebugInfo>
createIRGenDebugInfo(const IRGenOptions &Opts, ClangImporter &CI,
IRGenModule &IGM, llvm::Module &M,
StringRef MainOutputFilenameForDebugInfo);
StringRef MainOutputFilenameForDebugInfo,
StringRef PrivateDiscriminator);
virtual ~IRGenDebugInfo();
/// Finalize the llvm::DIBuilder owned by this object.

View File

@@ -88,7 +88,8 @@ static llvm::PointerType *createStructPointerType(IRGenModule &IGM,
static clang::CodeGenerator *createClangCodeGenerator(ASTContext &Context,
llvm::LLVMContext &LLVMContext,
IRGenOptions &Opts,
StringRef ModuleName) {
StringRef ModuleName,
StringRef PD) {
auto Loader = Context.getClangModuleLoader();
auto *Importer = static_cast<ClangImporter*>(&*Loader);
assert(Importer && "No clang module loader!");
@@ -119,13 +120,13 @@ static clang::CodeGenerator *createClangCodeGenerator(ASTContext &Context,
case IRGenDebugInfoFormat::DWARF:
CGO.DebugCompilationDir = Opts.DebugCompilationDir;
CGO.DwarfVersion = Opts.DWARFVersion;
CGO.DwarfDebugFlags = Opts.DebugFlags;
CGO.DwarfDebugFlags = Opts.getDebugFlags(PD);
break;
case IRGenDebugInfoFormat::CodeView:
CGO.EmitCodeView = true;
CGO.DebugCompilationDir = Opts.DebugCompilationDir;
// This actually contains the debug flags for codeview.
CGO.DwarfDebugFlags = Opts.DebugFlags;
CGO.DwarfDebugFlags = Opts.getDebugFlags(PD);
break;
}
@@ -144,10 +145,11 @@ IRGenModule::IRGenModule(IRGenerator &irgen,
std::unique_ptr<llvm::TargetMachine> &&target,
SourceFile *SF, llvm::LLVMContext &LLVMContext,
StringRef ModuleName, StringRef OutputFilename,
StringRef MainInputFilenameForDebugInfo)
StringRef MainInputFilenameForDebugInfo,
StringRef PrivateDiscriminator)
: IRGen(irgen), Context(irgen.SIL.getASTContext()),
ClangCodeGen(createClangCodeGenerator(Context, LLVMContext, irgen.Opts,
ModuleName)),
ModuleName, PrivateDiscriminator)),
Module(*ClangCodeGen->GetModule()), LLVMContext(Module.getContext()),
DataLayout(irgen.getClangDataLayout()),
Triple(irgen.getEffectiveClangTriple()), TargetMachine(std::move(target)),
@@ -491,7 +493,8 @@ IRGenModule::IRGenModule(IRGenerator &irgen,
if (opts.DebugInfoLevel > IRGenDebugInfoLevel::None)
DebugInfo = IRGenDebugInfo::createIRGenDebugInfo(IRGen.Opts, *CI, *this,
Module,
MainInputFilenameForDebugInfo);
MainInputFilenameForDebugInfo,
PrivateDiscriminator);
initClangTypeConverter();

View File

@@ -1225,14 +1225,15 @@ public:
IRGenModule(IRGenerator &irgen, std::unique_ptr<llvm::TargetMachine> &&target,
SourceFile *SF, llvm::LLVMContext &LLVMContext,
StringRef ModuleName, StringRef OutputFilename,
StringRef MainInputFilenameForDebugInfo);
StringRef MainInputFilenameForDebugInfo,
StringRef PrivateDiscriminator);
/// The constructor used when we just need an IRGenModule for type lowering.
IRGenModule(IRGenerator &irgen, std::unique_ptr<llvm::TargetMachine> &&target,
llvm::LLVMContext &LLVMContext)
: IRGenModule(irgen, std::move(target), /*SF=*/nullptr, LLVMContext,
"<fake module name>", "<fake output filename>",
"<fake main input filename>") {}
"<fake main input filename>", "") {}
~IRGenModule();

View File

@@ -450,7 +450,7 @@ int main(int argc, char **argv) {
auto T = irgen::createIRGenModule(
SILMod, Invocation.getOutputFilenameForAtMostOnePrimary(),
Invocation.getMainInputFilenameForDebugInfoForAtMostOnePrimary(),
getGlobalLLVMContext());
"", getGlobalLLVMContext());
runCommandLineSelectedPasses(SILMod, T.second);
irgen::deleteIRGenModule(T);
}