Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions flang/include/flang/Optimizer/Dialect/FIRType.h
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,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
15 changes: 13 additions & 2 deletions flang/lib/Optimizer/Analysis/TBAAForest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,23 @@

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) {
auto it = namedSubtrees.find(name);
if (it != namedSubtrees.end())
return it->second;

return namedSubtrees
.insert(
{name, SubtreeState(context, parentId + '/' + name.str(), parent)})
.first->second;
}

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