mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 21:30:12 +01:00
Some module metadata changed - because rather than linking one module with one module metadata value (eg: PIC Level 0, or unspecified) and one module with a different one (PIC level 2, in clang) - we use Clang's Module as-is, no merging required, so Clang's module metadata sticks rather than being merged with default values from Carbon. Also tweaked the name we use for Clang's module name so it matches the carbon file name. Otherwise the IR changes seem to be just reorderings - C++ interop goes first, then Carbon, rather than the other way around.
52 lines
1.7 KiB
C++
52 lines
1.7 KiB
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#include "toolchain/lower/lower.h"
|
|
|
|
#include <memory>
|
|
#include <optional>
|
|
|
|
#include "common/vlog.h"
|
|
#include "llvm/IR/Verifier.h"
|
|
#include "toolchain/lower/context.h"
|
|
#include "toolchain/lower/file_context.h"
|
|
|
|
namespace Carbon::Lower {
|
|
|
|
auto LowerToLLVM(
|
|
llvm::LLVMContext& llvm_context,
|
|
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs,
|
|
const Parse::GetTreeAndSubtreesStore& tree_and_subtrees_getters,
|
|
const SemIR::File& sem_ir, int total_ir_count,
|
|
const LowerToLLVMOptions& options) -> std::unique_ptr<llvm::Module> {
|
|
Context context(
|
|
&llvm_context, std::move(fs), options.want_debug_info,
|
|
&tree_and_subtrees_getters,
|
|
sem_ir.cpp_file() ? sem_ir.cpp_file()->GetCodeGenerator() : nullptr,
|
|
sem_ir.filename(), total_ir_count, options.opt_level,
|
|
options.vlog_stream);
|
|
|
|
// TODO: Consider disabling instruction naming by default if we're not
|
|
// producing textual LLVM IR.
|
|
SemIR::InstNamer inst_namer(&sem_ir, total_ir_count);
|
|
context.GetFileContext(&sem_ir, &inst_namer).LowerDefinitions();
|
|
|
|
std::unique_ptr<llvm::Module> module = std::move(context).Finalize();
|
|
|
|
if (options.vlog_stream) {
|
|
CARBON_VLOG_TO(options.vlog_stream, "*** llvm::Module ***\n");
|
|
module->print(*options.vlog_stream, /*AAW=*/nullptr,
|
|
/*ShouldPreserveUseListOrder=*/false,
|
|
/*IsForDebug=*/true);
|
|
}
|
|
|
|
if (options.llvm_verifier_stream) {
|
|
CARBON_CHECK(!llvm::verifyModule(*module, options.llvm_verifier_stream));
|
|
}
|
|
|
|
return module;
|
|
}
|
|
|
|
} // namespace Carbon::Lower
|