Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into tir-in-const
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Fedotov committed Feb 18, 2024
2 parents e6fe44a + ab683a8 commit 1d621d2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions compiler/hash-link/src/linker/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Defines a generic linker interface and functions that create
//! an instance of a [Linker] with the provided compiler settings
//! and target options.
#![allow(dead_code)] // @@Temporary: remove when all linker methods are used.

use std::{
ffi::{OsStr, OsString},
Expand Down
6 changes: 5 additions & 1 deletion compiler/hash-lower/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl<Ctx: LoweringCtxQuery> CompilerStage<Ctx> for IrOptimiser {
let bodies = &mut icx.bodies;
let body_data = &icx.ctx;

self.time_item("optimise", |_| {
self.time_item("optimise", |this| {
// @@Todo: think about making optimisation passes in parallel...
// pool.scope(|scope| {
// for body in &mut icx.generated_bodies {
Expand All @@ -218,6 +218,10 @@ impl<Ctx: LoweringCtxQuery> CompilerStage<Ctx> for IrOptimiser {
for body in bodies.iter_mut() {
let optimiser = Optimiser::new(body_data, settings);
optimiser.optimise(body);

// Collect metrics on the stages.
let metrics = optimiser.into_metrics().into();
this.metrics().merge(&metrics);
}
});

Expand Down
2 changes: 1 addition & 1 deletion compiler/hash-lower/src/optimise/cleanup_locals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct CleanupLocalPass;

impl IrOptimisationPass for CleanupLocalPass {
fn name(&self) -> &'static str {
"cleanup_locals"
"optimise::cleanup_locals"
}

/// Pass [CleanupLocalPass] is always enabled since it performs
Expand Down
19 changes: 18 additions & 1 deletion compiler/hash-lower/src/optimise/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use hash_ir::{ir::Body, IrCtx};
use hash_pipeline::settings::{CompilerSettings, OptimisationLevel};
use hash_utils::timing::{CellStageMetrics, HasMetrics};

// Various passes that are used to optimise the generated IR bodies.
mod cleanup_locals;
Expand Down Expand Up @@ -40,6 +41,9 @@ pub struct Optimiser<'ir> {
/// The various passes that have been added to the optimisation
/// pipeline.
passes: Vec<Box<dyn IrOptimisationPass + Send>>,

/// Metrics for each of the passes.
metrics: CellStageMetrics,
}

impl<'ir> Optimiser<'ir> {
Expand All @@ -51,6 +55,7 @@ impl<'ir> Optimiser<'ir> {
Box::new(simplify_graph::SimplifyGraphPass),
Box::new(cleanup_locals::CleanupLocalPass),
],
metrics: CellStageMetrics::default(),
}
}

Expand All @@ -59,8 +64,20 @@ impl<'ir> Optimiser<'ir> {
pub fn optimise(&self, body: &mut Body) {
for pass in self.passes.iter() {
if pass.enabled(self.settings) {
pass.optimise(body, self.store);
self.time_item(pass.name(), |this| {
pass.optimise(body, this.store);
})
}
}
}

pub fn into_metrics(self) -> CellStageMetrics {
self.metrics
}
}

impl HasMetrics for Optimiser<'_> {
fn metrics(&self) -> &CellStageMetrics {
&self.metrics
}
}
2 changes: 1 addition & 1 deletion compiler/hash-lower/src/optimise/simplify_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub struct SimplifyGraphPass;

impl IrOptimisationPass for SimplifyGraphPass {
fn name(&self) -> &'static str {
"simplify-graph"
"optimise::simplify_graph"
}

fn enabled(&self, settings: &CompilerSettings) -> bool {
Expand Down

0 comments on commit 1d621d2

Please sign in to comment.