| 975 | } |
| 976 | |
| 977 | static void calculateAndInitConstants(Transform &t) { |
| 978 | if (!bits_program_pointer) |
| 979 | initBitsProgramPointer(t); |
| 980 | |
| 981 | const auto &globals_tgt = t.tgt.getGlobalVars(); |
| 982 | const auto &globals_src = t.src.getGlobalVars(); |
| 983 | num_globals_src = globals_src.size(); |
| 984 | unsigned num_globals = num_globals_src; |
| 985 | uint64_t glb_alloc_aligned_size = 0; |
| 986 | |
| 987 | num_consts_src = 0; |
| 988 | has_globals_diff_align = false; |
| 989 | |
| 990 | for (auto GV : globals_src) { |
| 991 | if (GV->isConst()) |
| 992 | ++num_consts_src; |
| 993 | glb_alloc_aligned_size |
| 994 | = add_saturate(glb_alloc_aligned_size, |
| 995 | aligned_alloc_size(GV->size(), GV->getAlignment())); |
| 996 | } |
| 997 | |
| 998 | for (auto GVT : globals_tgt) { |
| 999 | auto I = find_if(globals_src.begin(), globals_src.end(), |
| 1000 | [GVT](auto *GV) -> bool { return GVT->getName() == GV->getName(); }); |
| 1001 | if (I == globals_src.end()) { |
| 1002 | ++num_globals; |
| 1003 | } else { |
| 1004 | has_globals_diff_align |= GVT->getAlignment() != (*I)->getAlignment(); |
| 1005 | } |
| 1006 | |
| 1007 | glb_alloc_aligned_size |
| 1008 | = add_saturate(glb_alloc_aligned_size, |
| 1009 | aligned_alloc_size(GVT->size(), GVT->getAlignment())); |
| 1010 | } |
| 1011 | |
| 1012 | num_ptrinputs = 0; |
| 1013 | unsigned num_null_ptrinputs = 0; |
| 1014 | for (auto &arg : t.src.getInputs()) { |
| 1015 | auto n = num_ptrs(arg.getType()); |
| 1016 | auto in = dynamic_cast<const Input*>(&arg); |
| 1017 | if (in && in->hasAttribute(ParamAttrs::ByVal)) { |
| 1018 | num_globals_src += n; |
| 1019 | num_globals += n; |
| 1020 | } else { |
| 1021 | num_ptrinputs += n; |
| 1022 | if (!in || !in->hasAttribute(ParamAttrs::NonNull)) |
| 1023 | num_null_ptrinputs += n; |
| 1024 | } |
| 1025 | } |
| 1026 | |
| 1027 | // The number of local blocks. |
| 1028 | num_locals_src = 0; |
| 1029 | num_locals_tgt = 0; |
| 1030 | uint64_t max_gep_src = 0, max_gep_tgt = 0; |
| 1031 | uint64_t max_alloc_size = 0; |
| 1032 | uint64_t max_access_size = 0; |
| 1033 | uint64_t min_global_size = UINT64_MAX; |
| 1034 |
no test coverage detected