|
| 1 | +// SPDX-FileCopyrightText : © 2026 TU Wien <vadl@tuwien.ac.at> |
| 2 | +// SPDX-License-Identifier: GPL-3.0-or-later |
| 3 | +// |
| 4 | +// This program is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | +// |
| 9 | +// This program is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU General Public License |
| 15 | +// along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +package vadl.iss.passes; |
| 18 | + |
| 19 | +import static java.util.Objects.requireNonNull; |
| 20 | +import static vadl.iss.passes.TcgPassUtils.regInfo; |
| 21 | + |
| 22 | +import java.io.IOException; |
| 23 | +import java.util.List; |
| 24 | +import java.util.Set; |
| 25 | +import javax.annotation.CheckForNull; |
| 26 | +import vadl.configuration.IssConfiguration; |
| 27 | +import vadl.iss.passes.extensions.RegInfo; |
| 28 | +import vadl.pass.PassName; |
| 29 | +import vadl.pass.PassResults; |
| 30 | +import vadl.utils.ViamUtils; |
| 31 | +import vadl.viam.Specification; |
| 32 | +import vadl.viam.graph.Graph; |
| 33 | +import vadl.viam.graph.dependency.ReadRegTensorNode; |
| 34 | +import vadl.viam.graph.dependency.WriteRegTensorNode; |
| 35 | + |
| 36 | +public class IssRegisterAccessInfoRetrievalPass extends AbstractIssPass { |
| 37 | + public IssRegisterAccessInfoRetrievalPass(IssConfiguration config) { |
| 38 | + super(config); |
| 39 | + } |
| 40 | + |
| 41 | + @Override |
| 42 | + public PassName getName() { |
| 43 | + return PassName.of("ISS Register Access Info Retrieval"); |
| 44 | + } |
| 45 | + |
| 46 | + @CheckForNull |
| 47 | + @Override |
| 48 | + public Object execute(PassResults passResults, Specification viam) throws IOException { |
| 49 | + ViamUtils.findAllBehaviors(viam).forEach(this::collectRegisterAccessPatterns); |
| 50 | + |
| 51 | + // add custom one for program counter |
| 52 | + var pc = requireNonNull(viam.isa().get().pc()); |
| 53 | + var info = regInfo(pc.registerTensor()); |
| 54 | + info.accessPatterns.add(new RegInfo.AccessPattern( |
| 55 | + info, RegInfo.AccessType.READ, List.of(), pc.resultType().bitWidth(), pc |
| 56 | + )); |
| 57 | + info.accessPatterns.add(new RegInfo.AccessPattern( |
| 58 | + info, RegInfo.AccessType.WRITE, List.of(), pc.resultType().bitWidth(), pc |
| 59 | + )); |
| 60 | + |
| 61 | + return null; |
| 62 | + } |
| 63 | + |
| 64 | + private void collectRegisterAccessPatterns(Graph behavior) { |
| 65 | + behavior.getNodes(Set.of(ReadRegTensorNode.class, WriteRegTensorNode.class)) |
| 66 | + .forEach((n) -> { |
| 67 | + if (n instanceof ReadRegTensorNode readRegTensorNode) { |
| 68 | + collectRegisterAccessPattern(readRegTensorNode); |
| 69 | + } else { |
| 70 | + collectRegisterAccessPattern((WriteRegTensorNode) n); |
| 71 | + } |
| 72 | + }); |
| 73 | + } |
| 74 | + |
| 75 | + private void collectRegisterAccessPattern(ReadRegTensorNode node) { |
| 76 | + var info = regInfo(node.regTensor()); |
| 77 | + info.accessPatterns.add(RegInfo.AccessPattern.of(node)); |
| 78 | + } |
| 79 | + |
| 80 | + private void collectRegisterAccessPattern(WriteRegTensorNode node) { |
| 81 | + var info = regInfo(node.regTensor()); |
| 82 | + info.accessPatterns.add(RegInfo.AccessPattern.of(node)); |
| 83 | + } |
| 84 | +} |
0 commit comments