• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16// This file should be included inside each Visitor class
17public:
18void VisitGraph() override {
19    for (auto& bb : GetBlocksToVisit()) {
20        for (auto inst : bb->AllInsts()) {
21            TABLE[static_cast<unsigned>(inst->GetOpcode())](this, inst);
22        }
23    }
24}
25
26uint64_t VisitGraphAndCount() override {
27    uint64_t insts_number = 0;
28    for (auto& bb : GetBlocksToVisit()) {
29        for (auto inst : bb->AllInsts()) {
30            insts_number++;
31            TABLE[static_cast<unsigned>(inst->GetOpcode())](this, inst);
32        }
33    }
34    return insts_number;
35}
36
37void VisitBlock(BasicBlock* bb) override {
38    for (auto inst : bb->AllInsts()) {
39        TABLE[static_cast<unsigned>(inst->GetOpcode())](this, inst);
40    }
41}
42void VisitInstruction(Inst* inst) override {
43    TABLE[static_cast<unsigned>(inst->GetOpcode())](this, inst);
44}
45
46private:
47// NOLINTNEXTLINE(modernize-avoid-c-arrays)
48static constexpr VisitFunc TABLE[static_cast<unsigned>(Opcode::NUM_OPCODES)] = {
49// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
50#define INST_DEF(opcode, ...) Visit##opcode,
51    OPCODE_LIST(INST_DEF)
52#undef INST_DEF
53};
54