The current representation of TBAA is the very last in-tree user of the `llvm.metadata` operation. Using ops to model metadata has a few disadvantages: * Building a graph has to be done through some weakly typed indirection mechanism such as `SymbolRefAttr` * Creating the metadata has to be done through a builder within a metadata op. * It is not multithreading safe as operation insertion into the same block is not thread-safe This patch therefore converts TBAA metadata into an attribute representation, in a similar manner as it has been done for alias groups and access groups in previous patches. This additionally has the large benefit of giving us more "correctness by construction" as it makes things like cycles in a TBAA graph, or references to an incorrectly typed metadata node impossible. Differential Revision: https://reviews.llvm.org/D155444
112 lines
4.1 KiB
C++
112 lines
4.1 KiB
C++
//===- LLVMAttrs.cpp - LLVM Attributes registration -----------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file defines the attribute details for the LLVM IR dialect in MLIR.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "mlir/Dialect/LLVMIR/LLVMAttrs.h"
|
|
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
|
|
#include "mlir/IR/Builders.h"
|
|
#include "mlir/IR/DialectImplementation.h"
|
|
#include "llvm/ADT/StringExtras.h"
|
|
#include "llvm/ADT/TypeSwitch.h"
|
|
#include "llvm/BinaryFormat/Dwarf.h"
|
|
#include <optional>
|
|
|
|
using namespace mlir;
|
|
using namespace mlir::LLVM;
|
|
|
|
#include "mlir/Dialect/LLVMIR/LLVMOpsEnums.cpp.inc"
|
|
#define GET_ATTRDEF_CLASSES
|
|
#include "mlir/Dialect/LLVMIR/LLVMOpsAttrDefs.cpp.inc"
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// LLVMDialect registration
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
void LLVMDialect::registerAttributes() {
|
|
addAttributes<
|
|
#define GET_ATTRDEF_LIST
|
|
#include "mlir/Dialect/LLVMIR/LLVMOpsAttrDefs.cpp.inc"
|
|
>();
|
|
}
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// DINodeAttr
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
bool DINodeAttr::classof(Attribute attr) {
|
|
return llvm::isa<DIBasicTypeAttr, DICompileUnitAttr, DICompositeTypeAttr,
|
|
DIDerivedTypeAttr, DIFileAttr, DILabelAttr,
|
|
DILexicalBlockAttr, DILexicalBlockFileAttr,
|
|
DILocalVariableAttr, DINamespaceAttr, DINullTypeAttr,
|
|
DISubprogramAttr, DISubrangeAttr, DISubroutineTypeAttr>(
|
|
attr);
|
|
}
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// DIScopeAttr
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
bool DIScopeAttr::classof(Attribute attr) {
|
|
return llvm::isa<DICompileUnitAttr, DICompositeTypeAttr, DIFileAttr,
|
|
DILocalScopeAttr, DINamespaceAttr>(attr);
|
|
}
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// DILocalScopeAttr
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
bool DILocalScopeAttr::classof(Attribute attr) {
|
|
return llvm::isa<DILexicalBlockAttr, DILexicalBlockFileAttr,
|
|
DISubprogramAttr>(attr);
|
|
}
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// DITypeAttr
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
bool DITypeAttr::classof(Attribute attr) {
|
|
return llvm::isa<DINullTypeAttr, DIBasicTypeAttr, DICompositeTypeAttr,
|
|
DIDerivedTypeAttr, DISubroutineTypeAttr>(attr);
|
|
}
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// TBAANodeAttr
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
bool TBAANodeAttr::classof(Attribute attr) {
|
|
return llvm::isa<TBAATypeDescriptorAttr, TBAARootAttr>(attr);
|
|
}
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// MemoryEffectsAttr
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
MemoryEffectsAttr MemoryEffectsAttr::get(MLIRContext *context,
|
|
ArrayRef<ModRefInfo> memInfoArgs) {
|
|
if (memInfoArgs.empty())
|
|
return MemoryEffectsAttr::get(context, ModRefInfo::ModRef,
|
|
ModRefInfo::ModRef, ModRefInfo::ModRef);
|
|
if (memInfoArgs.size() == 3)
|
|
return MemoryEffectsAttr::get(context, memInfoArgs[0], memInfoArgs[1],
|
|
memInfoArgs[2]);
|
|
return {};
|
|
}
|
|
|
|
bool MemoryEffectsAttr::isReadWrite() {
|
|
if (this->getArgMem() != ModRefInfo::ModRef)
|
|
return false;
|
|
if (this->getInaccessibleMem() != ModRefInfo::ModRef)
|
|
return false;
|
|
if (this->getOther() != ModRefInfo::ModRef)
|
|
return false;
|
|
return true;
|
|
}
|