forked from OSchip/llvm-project
[flang][NFC] Add accessors to equivalence and common blocks
Add a way to get mutable equivalence sets to Scope so that they can have sizes and offsets assigned to them. Change CommonBlockDetails to have mutable symbols so that they can have sizes and offets assigned to them. This also allows the removal of some `const_cast`s. Add MutableSymbolRef and MutableSymbolVector as mutable analogs to SymbolRef and SymbolVector. Replace uses of equivalent types with those names. Differential Revision: https://reviews.llvm.org/D79346
This commit is contained in:
parent
947f78ac27
commit
d5c05ced82
|
@ -52,7 +52,7 @@ struct EquivalenceObject {
|
|||
using EquivalenceSet = std::vector<EquivalenceObject>;
|
||||
|
||||
class Scope {
|
||||
using mapType = std::map<SourceName, common::Reference<Symbol>>;
|
||||
using mapType = std::map<SourceName, MutableSymbolRef>;
|
||||
|
||||
public:
|
||||
ENUM_CLASS(Kind, Global, Module, MainProgram, Subprogram, BlockData,
|
||||
|
@ -110,7 +110,7 @@ public:
|
|||
|
||||
// Return symbols in declaration order (the iterators above are in name order)
|
||||
SymbolVector GetSymbols() const;
|
||||
std::vector<common::Reference<Symbol>> GetSymbols();
|
||||
MutableSymbolVector GetSymbols();
|
||||
|
||||
iterator find(const SourceName &name);
|
||||
const_iterator find(const SourceName &name) const {
|
||||
|
@ -147,7 +147,10 @@ public:
|
|||
// Make a copy of a symbol in this scope; nullptr if one is already there
|
||||
Symbol *CopySymbol(const Symbol &);
|
||||
|
||||
const std::list<EquivalenceSet> &equivalenceSets() const;
|
||||
std::list<EquivalenceSet> &equivalenceSets() { return equivalenceSets_; }
|
||||
const std::list<EquivalenceSet> &equivalenceSets() const {
|
||||
return equivalenceSets_;
|
||||
}
|
||||
void add_equivalenceSet(EquivalenceSet &&);
|
||||
// Cray pointers are saved as map of pointee name -> pointer symbol
|
||||
const mapType &crayPointers() const { return crayPointers_; }
|
||||
|
|
|
@ -35,6 +35,8 @@ class ProgramTree;
|
|||
|
||||
using SymbolRef = common::Reference<const Symbol>;
|
||||
using SymbolVector = std::vector<SymbolRef>;
|
||||
using MutableSymbolRef = common::Reference<Symbol>;
|
||||
using MutableSymbolVector = std::vector<MutableSymbolRef>;
|
||||
|
||||
// A module or submodule.
|
||||
class ModuleDetails {
|
||||
|
@ -299,15 +301,16 @@ private:
|
|||
|
||||
class CommonBlockDetails {
|
||||
public:
|
||||
const SymbolVector &objects() const { return objects_; }
|
||||
void add_object(const Symbol &object) { objects_.emplace_back(object); }
|
||||
MutableSymbolVector &objects() { return objects_; }
|
||||
const MutableSymbolVector &objects() const { return objects_; }
|
||||
void add_object(Symbol &object) { objects_.emplace_back(object); }
|
||||
MaybeExpr bindName() const { return bindName_; }
|
||||
void set_bindName(MaybeExpr &&expr) { bindName_ = std::move(expr); }
|
||||
std::size_t align() const { return align_; }
|
||||
void set_align(std::size_t align) { align_ = align; }
|
||||
|
||||
private:
|
||||
SymbolVector objects_;
|
||||
MutableSymbolVector objects_;
|
||||
MaybeExpr bindName_;
|
||||
std::size_t align_{0}; // required alignment in bytes
|
||||
};
|
||||
|
@ -739,8 +742,7 @@ inline bool ProcEntityDetails::HasExplicitInterface() const {
|
|||
}
|
||||
|
||||
inline bool operator<(SymbolRef x, SymbolRef y) { return *x < *y; }
|
||||
inline bool operator<(
|
||||
common::Reference<Symbol> x, common::Reference<Symbol> y) {
|
||||
inline bool operator<(MutableSymbolRef x, MutableSymbolRef y) {
|
||||
return *x < *y;
|
||||
}
|
||||
using SymbolSet = std::set<SymbolRef>;
|
||||
|
|
|
@ -243,8 +243,8 @@ void ModFileWriter::PutSymbol(
|
|||
[&](const CommonBlockDetails &x) {
|
||||
decls_ << "common/" << symbol.name();
|
||||
char sep = '/';
|
||||
for (const Symbol &object : x.objects()) {
|
||||
decls_ << sep << object.name();
|
||||
for (const auto &object : x.objects()) {
|
||||
decls_ << sep << object->name();
|
||||
sep = ',';
|
||||
}
|
||||
decls_ << '\n';
|
||||
|
@ -875,8 +875,8 @@ void SubprogramSymbolCollector::DoSymbol(
|
|||
}
|
||||
},
|
||||
[this](const CommonBlockDetails &details) {
|
||||
for (const Symbol &object : details.objects()) {
|
||||
DoSymbol(object);
|
||||
for (const auto &object : details.objects()) {
|
||||
DoSymbol(*object);
|
||||
}
|
||||
},
|
||||
[](const auto &) {},
|
||||
|
|
|
@ -4376,9 +4376,8 @@ void DeclarationVisitor::CheckSaveStmts() {
|
|||
" common block name '%s'"_err_en_US);
|
||||
}
|
||||
} else {
|
||||
for (const Symbol &object :
|
||||
symbol->get<CommonBlockDetails>().objects()) {
|
||||
SetSaveAttr(*const_cast<Symbol *>(&object));
|
||||
for (auto &object : symbol->get<CommonBlockDetails>().objects()) {
|
||||
SetSaveAttr(*object);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6692,11 +6691,9 @@ void OmpAttributeVisitor::ResolveOmpObject(
|
|||
// 2.15.3 When a named common block appears in a list, it has the
|
||||
// same meaning as if every explicit member of the common block
|
||||
// appeared in the list
|
||||
for (const Symbol &object :
|
||||
symbol->get<CommonBlockDetails>().objects()) {
|
||||
Symbol &mutableObject{const_cast<Symbol &>(object)};
|
||||
for (auto &object : symbol->get<CommonBlockDetails>().objects()) {
|
||||
if (auto *resolvedObject{
|
||||
ResolveOmp(mutableObject, ompFlag, currScope())}) {
|
||||
ResolveOmp(*object, ompFlag, currScope())}) {
|
||||
AddToContextObjectWithDSA(*resolvedObject, ompFlag);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ Scope &Scope::MakeScope(Kind kind, Symbol *symbol) {
|
|||
|
||||
template <typename T>
|
||||
static std::vector<common::Reference<T>> GetSortedSymbols(
|
||||
std::map<SourceName, common::Reference<Symbol>> symbols) {
|
||||
std::map<SourceName, MutableSymbolRef> symbols) {
|
||||
std::vector<common::Reference<T>> result;
|
||||
result.reserve(symbols.size());
|
||||
for (auto &pair : symbols) {
|
||||
|
@ -72,7 +72,7 @@ static std::vector<common::Reference<T>> GetSortedSymbols(
|
|||
return result;
|
||||
}
|
||||
|
||||
std::vector<common::Reference<Symbol>> Scope::GetSymbols() {
|
||||
MutableSymbolVector Scope::GetSymbols() {
|
||||
return GetSortedSymbols<Symbol>(symbols_);
|
||||
}
|
||||
SymbolVector Scope::GetSymbols() const {
|
||||
|
@ -145,9 +145,6 @@ Symbol *Scope::CopySymbol(const Symbol &symbol) {
|
|||
}
|
||||
}
|
||||
|
||||
const std::list<EquivalenceSet> &Scope::equivalenceSets() const {
|
||||
return equivalenceSets_;
|
||||
}
|
||||
void Scope::add_equivalenceSet(EquivalenceSet &&set) {
|
||||
equivalenceSets_.emplace_back(std::move(set));
|
||||
}
|
||||
|
|
|
@ -438,8 +438,8 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const Details &details) {
|
|||
os << " align=" << x.align();
|
||||
}
|
||||
os << ':';
|
||||
for (const Symbol &object : x.objects()) {
|
||||
os << ' ' << object.name();
|
||||
for (const auto &object : x.objects()) {
|
||||
os << ' ' << object->name();
|
||||
}
|
||||
},
|
||||
[&](const FinalProcDetails &) {},
|
||||
|
|
Loading…
Reference in New Issue