brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.2 KiB · 44a0348 Raw
78 lines · cpp
1//===- TBAAForest.cpp - Per-functon TBAA Trees ----------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "flang/Optimizer/Analysis/TBAAForest.h"10#include <mlir/Dialect/LLVMIR/LLVMAttrs.h>11 12mlir::LLVM::TBAATagAttr13fir::TBAATree::SubtreeState::getTag(llvm::StringRef uniqueName) const {14  std::string id = (parentId + '/' + uniqueName).str();15  mlir::LLVM::TBAATypeDescriptorAttr type =16      mlir::LLVM::TBAATypeDescriptorAttr::get(17          context, id, mlir::LLVM::TBAAMemberAttr::get(parent, 0));18  return mlir::LLVM::TBAATagAttr::get(type, type, 0);19}20 21fir::TBAATree::SubtreeState &22fir::TBAATree::SubtreeState::getOrCreateNamedSubtree(mlir::StringAttr name) {23  auto it = namedSubtrees.find(name);24  if (it != namedSubtrees.end())25    return it->second;26 27  return namedSubtrees28      .insert(29          {name, SubtreeState(context, parentId + '/' + name.str(), parent)})30      .first->second;31}32 33mlir::LLVM::TBAATagAttr fir::TBAATree::SubtreeState::getTag() const {34  return mlir::LLVM::TBAATagAttr::get(parent, parent, 0);35}36 37fir::TBAATree fir::TBAATree::buildTree(mlir::StringAttr func) {38  llvm::StringRef funcName = func.getValue();39  std::string rootId = ("Flang function root " + funcName).str();40  mlir::MLIRContext *ctx = func.getContext();41  mlir::LLVM::TBAARootAttr funcRoot =42      mlir::LLVM::TBAARootAttr::get(ctx, mlir::StringAttr::get(ctx, rootId));43 44  static constexpr llvm::StringRef anyAccessTypeDescId = "any access";45  mlir::LLVM::TBAATypeDescriptorAttr anyAccess =46      mlir::LLVM::TBAATypeDescriptorAttr::get(47          ctx, anyAccessTypeDescId,48          mlir::LLVM::TBAAMemberAttr::get(funcRoot, 0));49 50  static constexpr llvm::StringRef anyDataAccessTypeDescId = "any data access";51  mlir::LLVM::TBAATypeDescriptorAttr dataRoot =52      mlir::LLVM::TBAATypeDescriptorAttr::get(53          ctx, anyDataAccessTypeDescId,54          mlir::LLVM::TBAAMemberAttr::get(anyAccess, 0));55 56  static constexpr llvm::StringRef boxMemberTypeDescId = "descriptor member";57  mlir::LLVM::TBAATypeDescriptorAttr boxMemberTypeDesc =58      mlir::LLVM::TBAATypeDescriptorAttr::get(59          ctx, boxMemberTypeDescId,60          mlir::LLVM::TBAAMemberAttr::get(anyAccess, 0));61 62  return TBAATree{anyAccess, dataRoot, boxMemberTypeDesc};63}64 65fir::TBAATree::TBAATree(mlir::LLVM::TBAATypeDescriptorAttr anyAccess,66                        mlir::LLVM::TBAATypeDescriptorAttr dataRoot,67                        mlir::LLVM::TBAATypeDescriptorAttr boxMemberTypeDesc)68    : targetDataTree(dataRoot.getContext(), "target data", dataRoot),69      globalDataTree(dataRoot.getContext(), "global data",70                     targetDataTree.getRoot()),71      allocatedDataTree(dataRoot.getContext(), "allocated data",72                        targetDataTree.getRoot()),73      dummyArgDataTree(dataRoot.getContext(), "dummy arg data", dataRoot),74      directDataTree(dataRoot.getContext(), "direct data",75                     targetDataTree.getRoot()),76      anyAccessDesc(anyAccess), boxMemberTypeDesc(boxMemberTypeDesc),77      anyDataTypeDesc(dataRoot) {}78