//===- Location.h - MLIR Location Classes -----------------------*- C++ -*-===// // // 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 // //===----------------------------------------------------------------------===// // // These classes provide the ability to relate MLIR objects back to source // location position information. // //===----------------------------------------------------------------------===// #ifndef MLIR_IR_LOCATION_H #define MLIR_IR_LOCATION_H #include "mlir/IR/Attributes.h" #include "llvm/Support/PointerLikeTypeTraits.h" namespace mlir { class Location; class WalkResult; //===----------------------------------------------------------------------===// // LocationAttr //===----------------------------------------------------------------------===// /// Location objects represent source locations information in MLIR. /// LocationAttr acts as the anchor for all Location based attributes. class LocationAttr : public Attribute { … }; //===----------------------------------------------------------------------===// // Location //===----------------------------------------------------------------------===// /// This class defines the main interface for locations in MLIR and acts as a /// non-nullable wrapper around a LocationAttr. class Location { … }; inline raw_ostream &operator<<(raw_ostream &os, const Location &loc) { … } // Make Location hashable. inline ::llvm::hash_code hash_value(Location arg) { … } } // namespace mlir //===----------------------------------------------------------------------===// // Tablegen Attribute Declarations //===----------------------------------------------------------------------===// #define GET_ATTRDEF_CLASSES #include "mlir/IR/BuiltinLocationAttributes.h.inc" namespace mlir { //===----------------------------------------------------------------------===// // FusedLoc //===----------------------------------------------------------------------===// /// This class represents a fused location whose metadata is known to be an /// instance of the given type. template <typename MetadataT> class FusedLocWith : public FusedLoc { … }; //===----------------------------------------------------------------------===// // OpaqueLoc //===----------------------------------------------------------------------===// /// Returns an instance of opaque location which contains a given pointer to /// an object. The corresponding MLIR location is set to UnknownLoc. template <typename T> inline OpaqueLoc OpaqueLoc::get(T underlyingLocation, MLIRContext *context) { … } //===----------------------------------------------------------------------===// // SubElements //===----------------------------------------------------------------------===// /// Enable locations to be introspected as sub-elements. template <> struct AttrTypeSubElementHandler<Location> { … }; } // namespace mlir //===----------------------------------------------------------------------===// // LLVM Utilities //===----------------------------------------------------------------------===// namespace llvm { // Type hash just like pointers. template <> struct DenseMapInfo<mlir::Location> { … }; /// We align LocationStorage by 8, so allow LLVM to steal the low bits. template <> struct PointerLikeTypeTraits<mlir::Location> { … }; /// The constructors in mlir::Location ensure that the class is a non-nullable /// wrapper around mlir::LocationAttr. Override default behavior and always /// return true for isPresent(). template <> struct ValueIsPresent<mlir::Location> { … }; /// Add support for llvm style casts. We provide a cast between To and From if /// From is mlir::Location or derives from it. CastInfo<To, From, std::enable_if_t<std::is_same_v<mlir::Location, std::remove_const_t<From>> || std::is_base_of_v<mlir::Location, From>>>; } // namespace llvm #endif