Skip to content

Commit

Permalink
singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangbopd committed Nov 24, 2023
1 parent dd7b281 commit c7faa30
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
3 changes: 3 additions & 0 deletions paddle/pir/core/operation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ using detail::OpOperandImpl;
using detail::OpOutlineResultImpl;
using detail::OpResultImpl;

uint64_t Operation::uid_ = 0;

Operation *Operation::Create(OperationArgument &&argument) {
Operation *op = Create(argument.inputs,
argument.attributes,
Expand Down Expand Up @@ -130,6 +132,7 @@ Operation *Operation::Create(const std::vector<Value> &inputs,
throw e;
}
}
uid_++;
return op;
}

Expand Down
3 changes: 3 additions & 0 deletions paddle/pir/core/operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ class IR_API alignas(8) Operation final {

void Verify();

static uint64_t id() { return uid_; }

private:
DISABLE_COPY_AND_ASSIGN(Operation);
Operation(const AttributeMap &attribute,
Expand Down Expand Up @@ -216,6 +218,7 @@ class IR_API alignas(8) Operation final {
const uint32_t num_operands_ = 0;
const uint32_t num_regions_ = 0;
const uint32_t num_successors_ = 0;
static uint64_t uid_;

detail::BlockOperandImpl *block_operands_{nullptr};
Region *regions_{nullptr};
Expand Down
8 changes: 4 additions & 4 deletions paddle/pir/dialect/shape/utils/shape_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@ ShapeAnalysisManager& ShapeAnalysisManager::Instance() {
return instance;
}

ShapeConstraintIRAnalysis& ShapeAnalysisManager::GetShapeConstraintIRAnalysis(
pir::Program* program) {
auto it = tables_.find(program);
ShapeConstraintIRAnalysis& ShapeAnalysisManager::Get(pir::Program* program) {
auto it = tables_.find(program->module_op().operation()->id());

if (it == tables_.end()) {
it = tables_
.emplace(program, ShapeConstraintIRAnalysis(program->module_op()))
.emplace(program->module_op().operation()->id(),
ShapeConstraintIRAnalysis(program->module_op()))
.first;
}

Expand Down
5 changes: 2 additions & 3 deletions paddle/pir/dialect/shape/utils/shape_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,11 @@ class IR_API ShapeConstraintIRAnalysis : public ShapeAnalysis {
class IR_API ShapeAnalysisManager {
public:
static ShapeAnalysisManager& Instance();
ShapeConstraintIRAnalysis& GetShapeConstraintIRAnalysis(
pir::Program* program);
ShapeConstraintIRAnalysis& Get(pir::Program* program);

private:
ShapeAnalysisManager() {}
std::unordered_map<pir::Program*, ShapeConstraintIRAnalysis> tables_;
std::unordered_map<uint64_t, ShapeConstraintIRAnalysis> tables_;
};

} // namespace pir

0 comments on commit c7faa30

Please sign in to comment.