mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
Add support for running LLVM optimizer. (#6225)
Adds a flag `--optimize=<mode>` that specifies what to optimize for: * `--optimize=none` turns off the optimizer as much as possible, but still respects always_inline. * `--optimize=debug` aims to be the equivalent of `-Og` / `-O1`, and provides optimizations that don't affect the ability to debug the program. This is the default. * `--optimize=size` optimizes for the size of the produced program, and aims to be the equivalent of `-Oz`. * `--optimize=speed` optimizes for the execution time of the produced program, and aims to be the equivalent of `-O3`. Following the approach taken by Clang, the optimization level feeds into both the configuration of the LLVM pass pipeline and the attributes added to function definitions generated by the frontend. Optimization is performed in a new phase, `optimize`, which runs between `lower` and `codegen`. --------- Co-authored-by: Dana Jansens <danakj@orodu.net> Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
This commit is contained in:
co-authored by
Dana Jansens
Chandler Carruth
parent
db150ffc5c
commit
aa69a484eb
@@ -17,27 +17,6 @@
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
auto CodeGen::Make(llvm::Module* module, llvm::StringRef target_triple_str,
|
||||
Diagnostics::Consumer* consumer) -> std::optional<CodeGen> {
|
||||
llvm::Triple target_triple(target_triple_str);
|
||||
std::string error;
|
||||
const llvm::Target* target =
|
||||
llvm::TargetRegistry::lookupTarget(target_triple, error);
|
||||
CARBON_CHECK(target, "Target should be validated before codegen: {0}", error);
|
||||
|
||||
module->setTargetTriple(target_triple);
|
||||
|
||||
constexpr llvm::StringLiteral CPU = "generic";
|
||||
constexpr llvm::StringLiteral Features = "";
|
||||
|
||||
llvm::TargetOptions target_opts;
|
||||
CodeGen codegen(module,
|
||||
consumer ? consumer : &Diagnostics::ConsoleConsumer());
|
||||
codegen.target_machine_.reset(target->createTargetMachine(
|
||||
target_triple, CPU, Features, target_opts, llvm::Reloc::PIC_));
|
||||
return codegen;
|
||||
}
|
||||
|
||||
auto CodeGen::EmitAssembly(llvm::raw_pwrite_stream& out) -> bool {
|
||||
return EmitCode(out, llvm::CodeGenFileType::AssemblyFile);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user