mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +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
@@ -14,11 +14,10 @@ namespace Carbon {
|
||||
|
||||
class CodeGen {
|
||||
public:
|
||||
// `module` and `errors` must not be null. `consumer` may be null, in which
|
||||
// case diagnostics go to stderr.
|
||||
static auto Make(llvm::Module* module, llvm::StringRef target_triple_str,
|
||||
Diagnostics::Consumer* consumer = nullptr)
|
||||
-> std::optional<CodeGen>;
|
||||
// `module`, `target_machine`, and `consumer` must not be null.
|
||||
explicit CodeGen(llvm::Module* module, llvm::TargetMachine* target_machine,
|
||||
Diagnostics::Consumer* consumer)
|
||||
: module_(module), target_machine_(target_machine), emitter_(consumer) {}
|
||||
|
||||
// Generates the object code file.
|
||||
// Returns false in case of failure, and any information about the failure is
|
||||
@@ -35,10 +34,6 @@ class CodeGen {
|
||||
auto EmitAssembly(llvm::raw_pwrite_stream& out) -> bool;
|
||||
|
||||
private:
|
||||
// `module` and `consumer` must not be null.
|
||||
explicit CodeGen(llvm::Module* module, Diagnostics::Consumer* consumer)
|
||||
: module_(module), emitter_(consumer) {}
|
||||
|
||||
// Using the llvm pass emits either assembly or object code to dest.
|
||||
// Returns false in case of failure, and any information about the failure is
|
||||
// printed to the error stream.
|
||||
@@ -47,10 +42,10 @@ class CodeGen {
|
||||
|
||||
llvm::Module* module_;
|
||||
|
||||
llvm::TargetMachine* target_machine_;
|
||||
|
||||
// The emitter for diagnostics.
|
||||
Diagnostics::FileEmitter emitter_;
|
||||
|
||||
std::unique_ptr<llvm::TargetMachine> target_machine_;
|
||||
};
|
||||
|
||||
} // namespace Carbon
|
||||
|
||||
Reference in New Issue
Block a user