Skip to content
Open
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
33 changes: 33 additions & 0 deletions vadl/main/vadl/dump/infoEnrichers/ViamEnricherCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import vadl.dump.InfoEnricher;
import vadl.dump.InfoUtils;
import vadl.dump.entities.DefinitionEntity;
import vadl.iss.passes.extensions.InstrExecPlan;
import vadl.iss.passes.extensions.InstrInfo;
import vadl.utils.SourceLocation;
import vadl.viam.DefProp;
import vadl.viam.Encoding;
Expand Down Expand Up @@ -295,6 +297,36 @@ private static String sourceHeader(SourceLocation location) {
entity.addInfo(info);
});

public static InfoEnricher VECTOR_TCG_PLAN_SUPPLIER_TAGS =
forType(DefinitionEntity.class, (entity, passResult) -> {
if (!(entity.origin() instanceof Instruction instruction)) {
return;
}

var info = instruction.extension(InstrInfo.class);
if (info == null || info.executionPlan() == null) {
return;
}

var executionPlan = info.executionPlan();
entity.addInfo(Info.Tag.of("SelectedExecutionStrategy",
executionPlan.selectedStrategy().name()));

var directGvec = executionPlan.evaluation(
InstrExecPlan.StrategyKind.DIRECT_GVEC);
if (directGvec == null) {
return;
}

entity.addInfo(Info.Tag.of("DirectGvecStatus", directGvec.status().name()));
entity.addInfo(Info.Tag.of("DirectGvecIssues",
directGvec.issues().isEmpty()
? "-"
: directGvec.issues().stream()
.map(issue -> issue.code())
.collect(Collectors.joining(", "))));
});


public static InfoEnricher BEHAVIOR_NO_LOCATION_EXPANDABLE =
forType(DefinitionEntity.class, (entity, passResult) -> {
Expand Down Expand Up @@ -405,6 +437,7 @@ private static String sourceHeader(SourceLocation location) {
VERIFY_SUPPLIER_EXPANDABLE,
SOURCE_CODE_SUPPLIER_EXPANDABLE,
RESOURCE_ACCESS_SUPPLIER_EXPANDABLE,
VECTOR_TCG_PLAN_SUPPLIER_TAGS,
BEHAVIOR_NO_LOCATION_EXPANDABLE,
STAGE_ORDER_SUPPLIER,
OPERATION_INSTRUCTIONS_SUPPLIER_EXPANDABLE,
Expand Down
80 changes: 0 additions & 80 deletions vadl/main/vadl/iss/passes/common/IssExecStrategyPass.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// SPDX-FileCopyrightText : © 2026 TU Wien <vadl@tuwien.ac.at>
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

package vadl.iss.passes.common.planning;

import java.util.Comparator;
import java.util.List;
import vadl.iss.passes.extensions.InstrExecPlan;
import vadl.iss.passes.extensions.InstrExecPlan.StrategyEvaluation;
import vadl.iss.passes.extensions.InstrExecPlan.StrategyKind;
import vadl.viam.Instruction;

/**
* Evaluates all configured execution strategies and selects the best viable one.
*/
final class InstructionExecutionPlanner {

private final List<StrategyEvaluator> evaluators;

InstructionExecutionPlanner(List<StrategyEvaluator> evaluators) {
this.evaluators = List.copyOf(evaluators);
}

/**
* Plans instruction execution by evaluating all strategies and selecting the best viable one.
*/
InstrExecPlan plan(Instruction instruction) {
var evaluations = evaluators.stream()
.map(evaluator -> evaluator.evaluate(instruction))
.toList();
var selected = evaluations.stream()
.filter(StrategyEvaluation::isViable)
.min(Comparator
.comparingInt(StrategyEvaluation::estimatedCost)
.thenComparingInt(evaluation -> strategyPriority(evaluation.strategy())))
.orElseThrow(() -> new IllegalStateException(
"Expected at least one viable execution strategy for " + instruction.simpleName()));
return new InstrExecPlan(evaluations, selected);
}

private int strategyPriority(StrategyKind strategy) {
return switch (strategy) {
case DIRECT_GVEC -> 0;
case TCG_SCALAR -> 1;
case HELPER_CALL -> 2;
};
}
}
74 changes: 74 additions & 0 deletions vadl/main/vadl/iss/passes/common/planning/IssExecStrategyPass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// SPDX-FileCopyrightText : © 2026 TU Wien <vadl@tuwien.ac.at>
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

package vadl.iss.passes.common.planning;

import static vadl.iss.passes.TcgPassUtils.instrInfo;

import java.io.IOException;
import java.util.List;
import javax.annotation.Nullable;
import vadl.configuration.IssConfiguration;
import vadl.iss.passes.AbstractIssPass;
import vadl.iss.passes.common.planning.evaluators.DirectGvecStrategyEvaluator;
import vadl.iss.passes.common.planning.evaluators.HelperCallStrategyEvaluator;
import vadl.iss.passes.common.planning.evaluators.TcgScalarStrategyEvaluator;
import vadl.pass.PassName;
import vadl.pass.PassResults;
import vadl.viam.Specification;

/**
* Computes and stores instruction execution plans plus the currently supported backend strategy.
*
* <p>The selected execution plan is the backend-independent source of truth. The legacy
* {@link vadl.iss.passes.extensions.InstrInfo.ExecStrategy} is derived from the selected plan so
* existing code generation can keep treating unsupported non-scalar strategies as helper calls.</p>
*/
public class IssExecStrategyPass extends AbstractIssPass {

private final InstructionExecutionPlanner executionPlanner;

public IssExecStrategyPass(IssConfiguration configuration) {
super(configuration);
this.executionPlanner = new InstructionExecutionPlanner(defaultEvaluators());
}

@Override
public PassName getName() {
return PassName.of("ISS Exec Strategy Classification");
}

@Override
public @Nullable Object execute(PassResults passResults, Specification viam) throws IOException {
if (viam.isa().isEmpty()) {
return null;
}

var isa = viam.isa().get();
isa.ownInstructions().forEach(
instr -> instrInfo(instr).setExecutionPlan(executionPlanner.plan(instr))
);
return null;
}

private List<StrategyEvaluator> defaultEvaluators() {
return List.of(
new DirectGvecStrategyEvaluator(),
new TcgScalarStrategyEvaluator(),
new HelperCallStrategyEvaluator()
);
}
}
31 changes: 31 additions & 0 deletions vadl/main/vadl/iss/passes/common/planning/StrategyEvaluator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-FileCopyrightText : © 2026 TU Wien <vadl@tuwien.ac.at>
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

package vadl.iss.passes.common.planning;

import vadl.iss.passes.extensions.InstrExecPlan.StrategyEvaluation;
import vadl.viam.Instruction;

/**
* Evaluates whether one execution strategy can implement a given instruction.
*/
public interface StrategyEvaluator {

/**
* Evaluates the strategy for the given instruction.
*/
StrategyEvaluation evaluate(Instruction instruction);
}
Loading
Loading