mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 10:54:49 +01:00
Remove CppGlobalVarStore (#7309)
Replace all uses of CppGlobalVarStore store with ClangDeclStore. Adding a VarStorage->VarDecl mapping to ClangDeclStore is now done with the `AddVar` method, which takes an extra `pattern_id` arg. While the corresponding `ClangDecl` is unchanged from before, the reverse mapping in `inst_id_to_clang_decl_id_` now uses the `pattern_id` as the key. This is necessary because in some places the original VarStorage instructions gets replaced (e.g. by a call to `Convert`). The `pattern_id` remains stable in those cases. --------- Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
co-authored by
Richard Smith
parent
d652cb0dfd
commit
1aa34d7642
@@ -714,10 +714,12 @@ auto FileContext::BuildDISubprogram(const SemIR::Function& function,
|
||||
|
||||
auto FileContext::BuildGlobalVariableDecl(SemIR::VarStorage var_storage)
|
||||
-> llvm::Constant* {
|
||||
// When a Carbon variable is exported and used from C++, code
|
||||
// Check if an llvm::GlobalVariable already exists and use it if so.
|
||||
//
|
||||
// This happens for C++ variables imported into Carbon. It also
|
||||
// happens when a Carbon variable is exported and used from C++; code
|
||||
// generation for the C++ code may have already created an
|
||||
// llvm::GlobalVariable. If so, return that global rather than
|
||||
// creating a new one.
|
||||
// llvm::GlobalVariable.
|
||||
auto clang_decl_id = sem_ir().clang_decls().Lookup(var_storage.pattern_id);
|
||||
if (clang_decl_id.has_value()) {
|
||||
auto* decl = sem_ir().clang_decls().Get(clang_decl_id).key.decl;
|
||||
@@ -729,21 +731,6 @@ auto FileContext::BuildGlobalVariableDecl(SemIR::VarStorage var_storage)
|
||||
}
|
||||
}
|
||||
|
||||
auto var_name_id =
|
||||
SemIR::GetFirstBindingNameFromPatternId(sem_ir(), var_storage.pattern_id);
|
||||
if (auto cpp_global_var_id =
|
||||
sem_ir().cpp_global_vars().Lookup({.entity_name_id = var_name_id});
|
||||
cpp_global_var_id.has_value()) {
|
||||
SemIR::ClangDeclId clang_decl_id =
|
||||
sem_ir().cpp_global_vars().Get(cpp_global_var_id).clang_decl_id;
|
||||
CARBON_CHECK(clang_decl_id.has_value(),
|
||||
"CppGlobalVar should have a clang_decl_id");
|
||||
return cpp_code_generator_->GetAddrOfGlobal(
|
||||
cast<clang::VarDecl>(
|
||||
sem_ir().clang_decls().Get(clang_decl_id).key.decl),
|
||||
/*isForDefinition=*/false);
|
||||
}
|
||||
|
||||
return BuildNonCppGlobalVariableDecl(var_storage);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user