CIRCT  20.0.0git
ArcCostModel.h
Go to the documentation of this file.
1 //===- ArcCostModel.h -----------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef CIRCT_DIALECT_ARC_ARCCOSTMODEL_H
10 #define CIRCT_DIALECT_ARC_ARCCOSTMODEL_H
11 
13 #include "mlir/IR/Operation.h"
14 #include "mlir/Pass/AnalysisManager.h"
15 
16 using namespace mlir;
17 
18 namespace circt {
19 namespace arc {
20 
22  size_t normalCost{0};
23  size_t packingCost{0};
24  size_t shufflingCost{0};
25  size_t vectorizeOpsBodyCost{0};
26  size_t totalCost() const {
27  return normalCost + packingCost + shufflingCost + vectorizeOpsBodyCost;
28  }
30  this->normalCost += other.normalCost;
31  this->packingCost += other.packingCost;
32  this->shufflingCost += other.shufflingCost;
33  this->vectorizeOpsBodyCost += other.vectorizeOpsBodyCost;
34  return *this;
35  }
36 };
37 
38 class ArcCostModel {
39 public:
40  OperationCosts getCost(Operation *op);
41 
42 private:
43  OperationCosts computeOperationCost(Operation *op);
44 
45  // gets the cost to pack the vectors we have some cases we need to consider:
46  // 1: the input is scalar so we can give it a cost of 1
47  // 2: the input is a result of another vector but with no shuffling so the
48  // is 0
49  // 3: the input is a result of another vector but with some shuffling so
50  // the cost is the (number of out of order elements) * 2
51  // 4: the input is a mix of some vectors:
52  // a) same order we multiply by 2
53  // b) shuffling we multiply by 3
54  OperationCosts getInputVectorsCost(VectorizeOp vecOp);
55  size_t getShufflingCost(const ValueRange &inputVec, bool isSame = false);
56  DenseMap<Operation *, OperationCosts> opCostCache;
57 };
58 
59 } // namespace arc
60 } // namespace circt
61 
62 #endif // CIRCT_DIALECT_ARC_ARCCOSTMODEL_H
DenseMap< Operation *, OperationCosts > opCostCache
Definition: ArcCostModel.h:56
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
OperationCosts & operator+=(const OperationCosts &other)
Definition: ArcCostModel.h:29
size_t totalCost() const
Definition: ArcCostModel.h:26