aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Semantics/mod-file.cpp
diff options
context:
space:
mode:
authorTim Keith <tkeith@nvidia.com>2020-04-22 15:39:24 -0700
committerTim Keith <tkeith@nvidia.com>2020-04-23 14:54:34 -0700
commitc353ebbfa4cb30a823fd850de97cb1ef559a05cc (patch)
tree092750eefb0ec905195f0d325a2f2046bad0c0e8 /flang/lib/Semantics/mod-file.cpp
parentfcbc613ad8b7785f710996f58726f26ad4ace50b (diff)
downloadllvm-c353ebbfa4cb30a823fd850de97cb1ef559a05cc.zip
llvm-c353ebbfa4cb30a823fd850de97cb1ef559a05cc.tar.gz
llvm-c353ebbfa4cb30a823fd850de97cb1ef559a05cc.tar.bz2
[flang] Compute sizes and offsets for symbols
Summary: Add size and offset properties to symbols, representing their byte size and offset within their enclosing scope. Add size and align properties to scopes so that they are available for scopes representing derived types. Add ComputeOffsets pass over the symbol table to fill in those fields. Compute descriptor size based on rank and length parameters. Extract DerivedTypeSpec::NumLengthParameters from DynamicType::RequiresDescriptor to share the code. Add Scope::GetSymbols to get symbols in canonical order. compute-offsets.cpp and mod-file.cpp both need to process symbols in the order in which they are declared. Move the collecting of those symbols into Scope so that it can be shared. Add symbol size and offset to output of `-fdebug-dump-symbols` and use that in some tests. Still to do: - make size and alignment rules configurable based on target - use offsets to check EQUIVALENCE statements Differential Revision: https://reviews.llvm.org/D78680
Diffstat (limited to 'flang/lib/Semantics/mod-file.cpp')
-rw-r--r--flang/lib/Semantics/mod-file.cpp35
1 files changed, 12 insertions, 23 deletions
diff --git a/flang/lib/Semantics/mod-file.cpp b/flang/lib/Semantics/mod-file.cpp
index 5dcc198..8e95b82 100644
--- a/flang/lib/Semantics/mod-file.cpp
+++ b/flang/lib/Semantics/mod-file.cpp
@@ -414,36 +414,25 @@ void ModFileWriter::PutUseExtraAttr(
// Collect the symbols of this scope sorted by their original order, not name.
// Namelists are an exception: they are sorted after other symbols.
SymbolVector CollectSymbols(const Scope &scope) {
- SymbolSet symbols; // to prevent duplicates
SymbolVector sorted;
SymbolVector namelist;
- SymbolVector common;
- sorted.reserve(scope.size() + scope.commonBlocks().size());
- for (const auto &pair : scope) {
- const Symbol &symbol{*pair.second};
- if (!symbol.test(Symbol::Flag::ParentComp)) {
- if (symbols.insert(symbol).second) {
- if (symbol.has<NamelistDetails>()) {
- namelist.push_back(symbol);
- } else {
- sorted.push_back(symbol);
- }
+ std::size_t commonSize{scope.commonBlocks().size()};
+ auto symbols{scope.GetSymbols()};
+ sorted.reserve(symbols.size() + commonSize);
+ for (SymbolRef symbol : symbols) {
+ if (!symbol->test(Symbol::Flag::ParentComp)) {
+ if (symbol->has<NamelistDetails>()) {
+ namelist.push_back(symbol);
+ } else {
+ sorted.push_back(symbol);
}
}
}
+ sorted.insert(sorted.end(), namelist.begin(), namelist.end());
for (const auto &pair : scope.commonBlocks()) {
- const Symbol &symbol{*pair.second};
- if (symbols.insert(symbol).second) {
- common.push_back(symbol);
- }
+ sorted.push_back(*pair.second);
}
- // sort normal symbols, then namelists, then common blocks:
- auto cursor{sorted.begin()};
- std::sort(cursor, sorted.end());
- cursor = sorted.insert(sorted.end(), namelist.begin(), namelist.end());
- std::sort(cursor, sorted.end());
- cursor = sorted.insert(sorted.end(), common.begin(), common.end());
- std::sort(cursor, sorted.end());
+ std::sort(sorted.end() - commonSize, sorted.end());
return sorted;
}