Skip to content

[Swift next] Construct DataLayout from string #38135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
2 changes: 1 addition & 1 deletion include/swift/AST/TBDGenRequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class TBDGenDescriptor final {
const TBDGenOptions &getOptions() const { return Opts; }
TBDGenOptions &getOptions() { return Opts; }

const llvm::DataLayout &getDataLayout() const;
const StringRef getDataLayoutString() const;
const llvm::Triple &getTarget() const;

bool operator==(const TBDGenDescriptor &other) const;
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/IRGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1533,7 +1533,7 @@ bool swift::performLLVM(const IRGenOptions &Opts, ASTContext &Ctx,

auto *Clang = static_cast<ClangImporter *>(Ctx.getClangModuleLoader());
// Use clang's datalayout.
Module->setDataLayout(Clang->getTargetInfo().getDataLayout());
Module->setDataLayout(Clang->getTargetInfo().getDataLayoutString());

embedBitcode(Module, Opts);
if (::performLLVM(Opts, Ctx.Diags, nullptr, nullptr, Module,
Expand Down
19 changes: 9 additions & 10 deletions lib/IRGen/IRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,18 @@ static void sanityCheckStdlib(IRGenModule &IGM) {

IRGenModule::IRGenModule(IRGenerator &irgen,
std::unique_ptr<llvm::TargetMachine> &&target,
SourceFile *SF,
StringRef ModuleName, StringRef OutputFilename,
SourceFile *SF, StringRef ModuleName,
StringRef OutputFilename,
StringRef MainInputFilenameForDebugInfo,
StringRef PrivateDiscriminator)
: LLVMContext(new llvm::LLVMContext()),
IRGen(irgen), Context(irgen.SIL.getASTContext()),
: LLVMContext(new llvm::LLVMContext()), IRGen(irgen),
Context(irgen.SIL.getASTContext()),
// The LLVMContext (and the IGM itself) will get deleted by the IGMDeleter
// as long as the IGM is registered with the IRGenerator.
ClangCodeGen(createClangCodeGenerator(Context, *LLVMContext,
irgen.Opts,
ClangCodeGen(createClangCodeGenerator(Context, *LLVMContext, irgen.Opts,
ModuleName, PrivateDiscriminator)),
Module(*ClangCodeGen->GetModule()),
DataLayout(irgen.getClangDataLayout()),
DataLayout(irgen.getClangDataLayoutString()),
Triple(irgen.getEffectiveClangTriple()), TargetMachine(std::move(target)),
silConv(irgen.SIL), OutputFilename(OutputFilename),
MainInputFilenameForDebugInfo(MainInputFilenameForDebugInfo),
Expand Down Expand Up @@ -1750,12 +1749,12 @@ llvm::Triple IRGenerator::getEffectiveClangTriple() {
return llvm::Triple(CI->getTargetInfo().getTargetOpts().Triple);
}

const llvm::DataLayout &IRGenerator::getClangDataLayout() {
const llvm::StringRef IRGenerator::getClangDataLayoutString() {
return static_cast<ClangImporter *>(
SIL.getASTContext().getClangModuleLoader())
->getTargetInfo()
.getDataLayout();
}
.getDataLayoutString();
}

TypeExpansionContext IRGenModule::getMaximalTypeExpansionContext() const {
return TypeExpansionContext::maximal(getSwiftModule(),
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/IRGenModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ class IRGenerator {
/// Return the effective triple used by clang.
llvm::Triple getEffectiveClangTriple();

const llvm::DataLayout &getClangDataLayout();
const llvm::StringRef getClangDataLayoutString();
};

class ConstantReference {
Expand Down
6 changes: 4 additions & 2 deletions lib/TBDGen/TBDGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static bool isGlobalOrStaticVar(VarDecl *VD) {

TBDGenVisitor::TBDGenVisitor(const TBDGenDescriptor &desc,
APIRecorder &recorder)
: TBDGenVisitor(desc.getTarget(), desc.getDataLayout(),
: TBDGenVisitor(desc.getTarget(), desc.getDataLayoutString(),
desc.getParentModule(), desc.getOptions(), recorder) {}

void TBDGenVisitor::addSymbolInternal(StringRef name, SymbolKind kind,
Expand Down Expand Up @@ -390,7 +390,9 @@ void TBDGenVisitor::addSymbol(StringRef name, SymbolSource source,
if (kind == SymbolKind::ObjectiveCClass) {
mangled = name;
} else {
llvm::Mangler::getNameWithPrefix(mangled, name, DataLayout);
if (!DataLayout)
DataLayout = llvm::DataLayout(DataLayoutDescription);
llvm::Mangler::getNameWithPrefix(mangled, name, *DataLayout);
}

addSymbolInternal(mangled, kind, source);
Expand Down
4 changes: 2 additions & 2 deletions lib/TBDGen/TBDGenRequests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ ModuleDecl *TBDGenDescriptor::getParentModule() const {
return Input.get<FileUnit *>()->getParentModule();
}

const llvm::DataLayout &TBDGenDescriptor::getDataLayout() const {
const StringRef TBDGenDescriptor::getDataLayoutString() const {
auto &ctx = getParentModule()->getASTContext();
auto *clang = static_cast<ClangImporter *>(ctx.getClangModuleLoader());
return clang->getTargetInfo().getDataLayout();
return llvm::StringRef(clang->getTargetInfo().getDataLayoutString());
}

const llvm::Triple &TBDGenDescriptor::getTarget() const {
Expand Down
8 changes: 5 additions & 3 deletions lib/TBDGen/TBDGenVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ class TBDGenVisitor : public ASTVisitor<TBDGenVisitor> {
llvm::StringSet<> DuplicateSymbolChecker;
#endif

const llvm::DataLayout &DataLayout;
Optional<llvm::DataLayout> DataLayout = None;
const StringRef DataLayoutDescription;

UniversalLinkageInfo UniversalLinkInfo;
ModuleDecl *SwiftModule;
const TBDGenOptions &Opts;
Expand Down Expand Up @@ -167,10 +169,10 @@ class TBDGenVisitor : public ASTVisitor<TBDGenVisitor> {
const AutoDiffConfig &config);

public:
TBDGenVisitor(const llvm::Triple &target, const llvm::DataLayout &dataLayout,
TBDGenVisitor(const llvm::Triple &target, const StringRef dataLayoutString,
ModuleDecl *swiftModule, const TBDGenOptions &opts,
APIRecorder &recorder)
: DataLayout(dataLayout),
: DataLayoutDescription(dataLayoutString),
UniversalLinkInfo(target, opts.HasMultipleIGMs, /*forcePublic*/ false),
SwiftModule(swiftModule), Opts(opts), recorder(recorder),
previousInstallNameMap(parsePreviousModuleInstallNameMap()) {}
Expand Down