/home/arjun/llvm-project/mlir/lib/IR/LocationDetail.h
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | //===- LocationDetail.h - MLIR Location storage details ---------*- C++ -*-===// | 
| 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-exception | 
| 6 |  | // | 
| 7 |  | //===----------------------------------------------------------------------===// | 
| 8 |  | // | 
| 9 |  | // This holds implementation details of the location attributes. | 
| 10 |  | // | 
| 11 |  | //===----------------------------------------------------------------------===// | 
| 12 |  | #ifndef MLIR_IR_LOCATIONDETAIL_H_ | 
| 13 |  | #define MLIR_IR_LOCATIONDETAIL_H_ | 
| 14 |  |  | 
| 15 |  | #include "mlir/IR/Attributes.h" | 
| 16 |  | #include "mlir/IR/Identifier.h" | 
| 17 |  | #include "mlir/IR/Location.h" | 
| 18 |  | #include "llvm/ADT/StringRef.h" | 
| 19 |  | #include "llvm/Support/TrailingObjects.h" | 
| 20 |  |  | 
| 21 |  | namespace mlir { | 
| 22 |  |  | 
| 23 |  | namespace detail { | 
| 24 |  |  | 
| 25 |  | struct CallSiteLocationStorage : public AttributeStorage { | 
| 26 |  |   CallSiteLocationStorage(Location callee, Location caller) | 
| 27 | 0 |       : callee(callee), caller(caller) {} | 
| 28 |  |  | 
| 29 |  |   /// The hash key used for uniquing. | 
| 30 |  |   using KeyTy = std::pair<Location, Location>; | 
| 31 | 0 |   bool operator==(const KeyTy &key) const { | 
| 32 | 0 |     return key == KeyTy(callee, caller); | 
| 33 | 0 |   } | 
| 34 |  |  | 
| 35 |  |   /// Construct a new storage instance. | 
| 36 |  |   static CallSiteLocationStorage * | 
| 37 | 0 |   construct(AttributeStorageAllocator &allocator, const KeyTy &key) { | 
| 38 | 0 |     return new (allocator.allocate<CallSiteLocationStorage>()) | 
| 39 | 0 |         CallSiteLocationStorage(key.first, key.second); | 
| 40 | 0 |   } | 
| 41 |  |  | 
| 42 |  |   Location callee, caller; | 
| 43 |  | }; | 
| 44 |  |  | 
| 45 |  | struct FileLineColLocationStorage : public AttributeStorage { | 
| 46 |  |   FileLineColLocationStorage(Identifier filename, unsigned line, | 
| 47 |  |                              unsigned column) | 
| 48 | 0 |       : filename(filename), line(line), column(column) {} | 
| 49 |  |  | 
| 50 |  |   /// The hash key used for uniquing. | 
| 51 |  |   using KeyTy = std::tuple<Identifier, unsigned, unsigned>; | 
| 52 | 0 |   bool operator==(const KeyTy &key) const { | 
| 53 | 0 |     return key == KeyTy(filename, line, column); | 
| 54 | 0 |   } | 
| 55 |  |  | 
| 56 |  |   /// Construct a new storage instance. | 
| 57 |  |   static FileLineColLocationStorage * | 
| 58 | 0 |   construct(AttributeStorageAllocator &allocator, const KeyTy &key) { | 
| 59 | 0 |     return new (allocator.allocate<FileLineColLocationStorage>()) | 
| 60 | 0 |         FileLineColLocationStorage(std::get<0>(key), std::get<1>(key), | 
| 61 | 0 |                                    std::get<2>(key)); | 
| 62 | 0 |   } | 
| 63 |  |  | 
| 64 |  |   Identifier filename; | 
| 65 |  |   unsigned line, column; | 
| 66 |  | }; | 
| 67 |  |  | 
| 68 |  | struct FusedLocationStorage final | 
| 69 |  |     : public AttributeStorage, | 
| 70 |  |       public llvm::TrailingObjects<FusedLocationStorage, Location> { | 
| 71 |  |   FusedLocationStorage(unsigned numLocs, Attribute metadata) | 
| 72 | 0 |       : numLocs(numLocs), metadata(metadata) {} | 
| 73 |  |  | 
| 74 | 0 |   ArrayRef<Location> getLocations() const { | 
| 75 | 0 |     return ArrayRef<Location>(getTrailingObjects<Location>(), numLocs); | 
| 76 | 0 |   } | 
| 77 |  |  | 
| 78 |  |   /// The hash key used for uniquing. | 
| 79 |  |   using KeyTy = std::pair<ArrayRef<Location>, Attribute>; | 
| 80 | 0 |   bool operator==(const KeyTy &key) const { | 
| 81 | 0 |     return key == KeyTy(getLocations(), metadata); | 
| 82 | 0 |   } | 
| 83 |  |  | 
| 84 |  |   /// Construct a new storage instance. | 
| 85 |  |   static FusedLocationStorage *construct(AttributeStorageAllocator &allocator, | 
| 86 | 0 |                                          const KeyTy &key) { | 
| 87 | 0 |     ArrayRef<Location> locs = key.first; | 
| 88 | 0 | 
 | 
| 89 | 0 |     auto byteSize = totalSizeToAlloc<Location>(locs.size()); | 
| 90 | 0 |     auto rawMem = allocator.allocate(byteSize, alignof(FusedLocationStorage)); | 
| 91 | 0 |     auto result = new (rawMem) FusedLocationStorage(locs.size(), key.second); | 
| 92 | 0 | 
 | 
| 93 | 0 |     std::uninitialized_copy(locs.begin(), locs.end(), | 
| 94 | 0 |                             result->getTrailingObjects<Location>()); | 
| 95 | 0 |     return result; | 
| 96 | 0 |   } | 
| 97 |  |  | 
| 98 |  |   // This stuff is used by the TrailingObjects template. | 
| 99 |  |   friend llvm::TrailingObjects<FusedLocationStorage, Location>; | 
| 100 | 0 |   size_t numTrailingObjects(OverloadToken<Location>) const { return numLocs; } | 
| 101 |  |  | 
| 102 |  |   /// Number of trailing location objects. | 
| 103 |  |   unsigned numLocs; | 
| 104 |  |  | 
| 105 |  |   /// Metadata used to reason about the generation of this fused location. | 
| 106 |  |   Attribute metadata; | 
| 107 |  | }; | 
| 108 |  |  | 
| 109 |  | struct NameLocationStorage : public AttributeStorage { | 
| 110 |  |   NameLocationStorage(Identifier name, Location child) | 
| 111 | 0 |       : name(name), child(child) {} | 
| 112 |  |  | 
| 113 |  |   /// The hash key used for uniquing. | 
| 114 |  |   using KeyTy = std::pair<Identifier, Location>; | 
| 115 | 0 |   bool operator==(const KeyTy &key) const { return key == KeyTy(name, child); } | 
| 116 |  |  | 
| 117 |  |   /// Construct a new storage instance. | 
| 118 |  |   static NameLocationStorage *construct(AttributeStorageAllocator &allocator, | 
| 119 | 0 |                                         const KeyTy &key) { | 
| 120 | 0 |     return new (allocator.allocate<NameLocationStorage>()) | 
| 121 | 0 |         NameLocationStorage(key.first, key.second); | 
| 122 | 0 |   } | 
| 123 |  |  | 
| 124 |  |   Identifier name; | 
| 125 |  |   Location child; | 
| 126 |  | }; | 
| 127 |  |  | 
| 128 |  | struct OpaqueLocationStorage : public AttributeStorage { | 
| 129 |  |   OpaqueLocationStorage(uintptr_t underlyingLocation, TypeID typeID, | 
| 130 |  |                         Location fallbackLocation) | 
| 131 |  |       : underlyingLocation(underlyingLocation), typeID(typeID), | 
| 132 | 0 |         fallbackLocation(fallbackLocation) {} | 
| 133 |  |  | 
| 134 |  |   /// The hash key used for uniquing. | 
| 135 |  |   using KeyTy = std::tuple<uintptr_t, TypeID, Location>; | 
| 136 | 0 |   bool operator==(const KeyTy &key) const { | 
| 137 | 0 |     return key == KeyTy(underlyingLocation, typeID, fallbackLocation); | 
| 138 | 0 |   } | 
| 139 |  |  | 
| 140 |  |   /// Construct a new storage instance. | 
| 141 |  |   static OpaqueLocationStorage *construct(AttributeStorageAllocator &allocator, | 
| 142 | 0 |                                           const KeyTy &key) { | 
| 143 | 0 |     return new (allocator.allocate<OpaqueLocationStorage>()) | 
| 144 | 0 |         OpaqueLocationStorage(std::get<0>(key), std::get<1>(key), | 
| 145 | 0 |                               std::get<2>(key)); | 
| 146 | 0 |   } | 
| 147 |  |  | 
| 148 |  |   /// Pointer to the corresponding object. | 
| 149 |  |   uintptr_t underlyingLocation; | 
| 150 |  |  | 
| 151 |  |   /// A unique pointer for each type of underlyingLocation. | 
| 152 |  |   TypeID typeID; | 
| 153 |  |  | 
| 154 |  |   /// An additional location that can be used if the external one is not | 
| 155 |  |   /// suitable. | 
| 156 |  |   Location fallbackLocation; | 
| 157 |  | }; | 
| 158 |  |  | 
| 159 |  | } // end namespace detail | 
| 160 |  | } // end namespace mlir | 
| 161 |  |  | 
| 162 |  | #endif // MLIR_IR_LOCATIONDETAIL_H_ |