Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions flang/include/flang/Optimizer/Analysis/TBAAForest.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ struct TBAATree {

mlir::LLVM::TBAATypeDescriptorAttr getRoot() const { return parent; }

/// For the given name, get or create a subtree in the current
/// subtree. For example, this is used for creating subtrees
/// inside the "global data" subtree for the COMMON block variables
/// belonging to the same COMMON block.
SubtreeState &getOrCreateNamedSubtree(mlir::StringAttr name);

private:
SubtreeState(mlir::MLIRContext *ctx, std::string name,
mlir::LLVM::TBAANodeAttr grandParent)
Expand All @@ -57,6 +63,9 @@ struct TBAATree {
const std::string parentId;
mlir::MLIRContext *const context;
mlir::LLVM::TBAATypeDescriptorAttr parent;
// A map of named sub-trees, e.g. sub-trees of the COMMON blocks
// placed under the "global data" root.
llvm::DenseMap<mlir::StringAttr, SubtreeState> namedSubtrees;
};

/// A subtree for POINTER/TARGET variables data.
Expand Down Expand Up @@ -131,22 +140,29 @@ class TBAAForrest {
// responsibility to provide unique name for the scope.
// If the scope string is empty, returns the TBAA tree for the
// "root" scope of the given function.
inline const TBAATree &getFuncTreeWithScope(mlir::func::FuncOp func,
llvm::StringRef scope) {
inline TBAATree &getMutableFuncTreeWithScope(mlir::func::FuncOp func,
llvm::StringRef scope) {
mlir::StringAttr name = func.getSymNameAttr();
if (!scope.empty())
name = mlir::StringAttr::get(name.getContext(),
llvm::Twine(name) + " - " + scope);
return getFuncTree(name);
}

inline const TBAATree &getFuncTreeWithScope(mlir::func::FuncOp func,
llvm::StringRef scope) {
return getMutableFuncTreeWithScope(func, scope);
}

private:
const TBAATree &getFuncTree(mlir::StringAttr symName) {
TBAATree &getFuncTree(mlir::StringAttr symName) {
if (!separatePerFunction)
symName = mlir::StringAttr::get(symName.getContext(), "");
if (!trees.contains(symName))
trees.insert({symName, TBAATree::buildTree(symName)});
return trees.at(symName);
auto it = trees.find(symName);
assert(it != trees.end());
return it->second;
}

// Should each function use a different tree?
Expand Down
7 changes: 6 additions & 1 deletion flang/include/flang/Optimizer/Builder/FIRBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,12 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener {
// Linkage helpers (inline). The default linkage is external.
//===--------------------------------------------------------------------===//

mlir::StringAttr createCommonLinkage() { return getStringAttr("common"); }
static mlir::StringAttr createCommonLinkage(mlir::MLIRContext *context) {
return mlir::StringAttr::get(context, "common");
}
mlir::StringAttr createCommonLinkage() {
return createCommonLinkage(getContext());
}

mlir::StringAttr createInternalLinkage() { return getStringAttr("internal"); }

Expand Down
2 changes: 2 additions & 0 deletions flang/include/flang/Optimizer/Dialect/FIRType.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
namespace fir {
class FIROpsDialect;
class KindMapping;
class LLVMTypeConverter;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why do you need this change, it does not seem to be used in the header.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching it! It is a leftover.

using KindTy = unsigned;

namespace detail {
Expand Down Expand Up @@ -551,6 +552,7 @@ std::optional<std::pair<uint64_t, unsigned short>>
getTypeSizeAndAlignment(mlir::Location loc, mlir::Type ty,
const mlir::DataLayout &dl,
const fir::KindMapping &kindMap);

} // namespace fir

#endif // FORTRAN_OPTIMIZER_DIALECT_FIRTYPE_H
3 changes: 2 additions & 1 deletion flang/include/flang/Optimizer/Transforms/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ def AddAliasTags : Pass<"fir-add-alias-tags", "mlir::ModuleOp"> {
theory, each operation could be considered in prallel, so long as there
aren't races adding new tags to the mlir context.
}];
let dependentDialects = [ "fir::FIROpsDialect" ];
// The pass inserts TBAA attributes from LLVM dialect.
let dependentDialects = ["mlir::LLVM::LLVMDialect"];
}

def SimplifyRegionLite : Pass<"simplify-region-lite", "mlir::ModuleOp"> {
Expand Down
13 changes: 11 additions & 2 deletions flang/lib/Optimizer/Analysis/TBAAForest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,21 @@

mlir::LLVM::TBAATagAttr
fir::TBAATree::SubtreeState::getTag(llvm::StringRef uniqueName) const {
std::string id = (parentId + "/" + uniqueName).str();
std::string id = (parentId + '/' + uniqueName).str();
mlir::LLVM::TBAATypeDescriptorAttr type =
mlir::LLVM::TBAATypeDescriptorAttr::get(
context, id, mlir::LLVM::TBAAMemberAttr::get(parent, 0));
return mlir::LLVM::TBAATagAttr::get(type, type, 0);
// return tag;
}

fir::TBAATree::SubtreeState &
fir::TBAATree::SubtreeState::getOrCreateNamedSubtree(mlir::StringAttr name) {
if (!namedSubtrees.contains(name))
namedSubtrees.insert(
{name, SubtreeState(context, parentId + '/' + name.str(), parent)});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: could return the insert iterator result here instead of doing a new search afterwards.

auto it = namedSubtrees.find(name);
assert(it != namedSubtrees.end());
return it->second;
}

mlir::LLVM::TBAATagAttr fir::TBAATree::SubtreeState::getTag() const {
Expand Down
Loading
Loading