Main entry point for calculating metadata offsets. */
| 441 | |
| 442 | /* Main entry point for calculating metadata offsets. */ |
| 443 | int Pipeline::ComputeMetadataOffsets() { |
| 444 | int ret; |
| 445 | |
| 446 | ret = PrepareMetadataComputation(); |
| 447 | |
| 448 | if (ret) { |
| 449 | CleanupMetadataComputation(); |
| 450 | return ret; |
| 451 | } |
| 452 | |
| 453 | for (const auto &it : ModuleGraph::GetAllModules()) { |
| 454 | Module *m = it.second; |
| 455 | if (!m) { |
| 456 | break; |
| 457 | } |
| 458 | |
| 459 | size_t i = 0; |
| 460 | for (const auto &attr : m->all_attrs()) { |
| 461 | if (attr.mode == Attribute::AccessMode::kRead || |
| 462 | attr.mode == Attribute::AccessMode::kUpdate) { |
| 463 | m->set_attr_offset(i, kMetadataOffsetNoRead); |
| 464 | } else if (attr.mode == Attribute::AccessMode::kWrite) { |
| 465 | m->set_attr_offset(i, kMetadataOffsetNoWrite); |
| 466 | if (attr.scope_id == -1) { |
| 467 | IdentifySingleScopeComponent(m, &attr); |
| 468 | } |
| 469 | } |
| 470 | i++; |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | ComputeScopeDegrees(); |
| 475 | std::sort(scope_components_.begin(), scope_components_.end(), DegreeComp); |
| 476 | AssignOffsets(); |
| 477 | |
| 478 | if (VLOG_IS_ON(1)) { |
| 479 | LogAllScopes(); |
| 480 | } |
| 481 | |
| 482 | CheckOrphanReaders(); |
| 483 | |
| 484 | CleanupMetadataComputation(); |
| 485 | return 0; |
| 486 | } |
| 487 | |
| 488 | int Pipeline::RegisterAttribute(const std::string &attr_name, size_t size) { |
| 489 | const auto &it = registered_attrs_.find(attr_name); |