My Project
LocationDetail.h
Go to the documentation of this file.
1 //===- LocationDetail.h - MLIR Location storage details ---------*- C++ -*-===//
2 //
3 // Part of the MLIR 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 
27  : callee(callee), caller(caller) {}
28 
30  using KeyTy = std::pair<Location, Location>;
31  bool operator==(const KeyTy &key) const {
32  return key == KeyTy(callee, caller);
33  }
34 
37  construct(AttributeStorageAllocator &allocator, const KeyTy &key) {
38  return new (allocator.allocate<CallSiteLocationStorage>())
39  CallSiteLocationStorage(key.first, key.second);
40  }
41 
43 };
44 
46  FileLineColLocationStorage(Identifier filename, unsigned line,
47  unsigned column)
48  : filename(filename), line(line), column(column) {}
49 
51  using KeyTy = std::tuple<Identifier, unsigned, unsigned>;
52  bool operator==(const KeyTy &key) const {
53  return key == KeyTy(filename, line, column);
54  }
55 
58  construct(AttributeStorageAllocator &allocator, const KeyTy &key) {
59  return new (allocator.allocate<FileLineColLocationStorage>())
60  FileLineColLocationStorage(std::get<0>(key), std::get<1>(key),
61  std::get<2>(key));
62  }
63 
65  unsigned line, column;
66 };
67 
69  : public AttributeStorage,
70  public llvm::TrailingObjects<FusedLocationStorage, Location> {
71  FusedLocationStorage(unsigned numLocs, Attribute metadata)
72  : numLocs(numLocs), metadata(metadata) {}
73 
75  return ArrayRef<Location>(getTrailingObjects<Location>(), numLocs);
76  }
77 
79  using KeyTy = std::pair<ArrayRef<Location>, Attribute>;
80  bool operator==(const KeyTy &key) const {
81  return key == KeyTy(getLocations(), metadata);
82  }
83 
86  const KeyTy &key) {
87  ArrayRef<Location> locs = key.first;
88 
89  auto byteSize = totalSizeToAlloc<Location>(locs.size());
90  auto rawMem = allocator.allocate(byteSize, alignof(FusedLocationStorage));
91  auto result = new (rawMem) FusedLocationStorage(locs.size(), key.second);
92 
93  std::uninitialized_copy(locs.begin(), locs.end(),
94  result->getTrailingObjects<Location>());
95  return result;
96  }
97 
98  // This stuff is used by the TrailingObjects template.
99  friend llvm::TrailingObjects<FusedLocationStorage, Location>;
100  size_t numTrailingObjects(OverloadToken<Location>) const { return numLocs; }
101 
103  unsigned numLocs;
104 
106  Attribute metadata;
107 };
108 
111  : name(name), child(child) {}
112 
114  using KeyTy = std::pair<Identifier, Location>;
115  bool operator==(const KeyTy &key) const { return key == KeyTy(name, child); }
116 
119  const KeyTy &key) {
120  return new (allocator.allocate<NameLocationStorage>())
121  NameLocationStorage(key.first, key.second);
122  }
123 
126 };
127 
129  OpaqueLocationStorage(uintptr_t underlyingLocation, ClassID *classId,
130  Location fallbackLocation)
131  : underlyingLocation(underlyingLocation), classId(classId),
132  fallbackLocation(fallbackLocation) {}
133 
135  using KeyTy = std::tuple<uintptr_t, ClassID *, Location>;
136  bool operator==(const KeyTy &key) const {
137  return key == KeyTy(underlyingLocation, classId, fallbackLocation);
138  }
139 
142  const KeyTy &key) {
143  return new (allocator.allocate<OpaqueLocationStorage>())
144  OpaqueLocationStorage(std::get<0>(key), std::get<1>(key),
145  std::get<2>(key));
146  }
147 
150 
153 
157 };
158 
159 } // end namespace detail
160 } // end namespace mlir
161 
162 #endif // MLIR_IR_LOCATIONDETAIL_H_
Definition: InferTypeOpInterface.cpp:20
std::pair< Identifier, Location > KeyTy
The hash key used for uniquing.
Definition: LocationDetail.h:114
bool operator==(const KeyTy &key) const
Definition: LocationDetail.h:52
Location fallbackLocation
Definition: LocationDetail.h:156
Definition: STLExtras.h:95
static OpaqueLocationStorage * construct(AttributeStorageAllocator &allocator, const KeyTy &key)
Construct a new storage instance.
Definition: LocationDetail.h:141
std::pair< ArrayRef< Location >, Attribute > KeyTy
The hash key used for uniquing.
Definition: LocationDetail.h:79
Attribute metadata
Metadata used to reason about the generation of this fused location.
Definition: LocationDetail.h:106
Identifier filename
Definition: LocationDetail.h:64
Definition: StorageUniquer.h:89
Definition: LocationDetail.h:25
bool operator==(const KeyTy &key) const
Definition: LocationDetail.h:136
Definition: Identifier.h:26
FileLineColLocationStorage(Identifier filename, unsigned line, unsigned column)
Definition: LocationDetail.h:46
Definition: Location.h:52
bool operator==(const KeyTy &key) const
Definition: LocationDetail.h:115
Definition: LocationDetail.h:45
OpaqueLocationStorage(uintptr_t underlyingLocation, ClassID *classId, Location fallbackLocation)
Definition: LocationDetail.h:129
T * allocate()
Allocate an instance of the provided type.
Definition: StorageUniquer.h:109
Identifier name
Definition: LocationDetail.h:124
Definition: LLVM.h:37
CallSiteLocationStorage(Location callee, Location caller)
Definition: LocationDetail.h:26
Location callee
Definition: LocationDetail.h:42
FusedLocationStorage(unsigned numLocs, Attribute metadata)
Definition: LocationDetail.h:71
Definition: Attributes.h:53
static CallSiteLocationStorage * construct(AttributeStorageAllocator &allocator, const KeyTy &key)
Construct a new storage instance.
Definition: LocationDetail.h:37
static FusedLocationStorage * construct(AttributeStorageAllocator &allocator, const KeyTy &key)
Construct a new storage instance.
Definition: LocationDetail.h:85
static FileLineColLocationStorage * construct(AttributeStorageAllocator &allocator, const KeyTy &key)
Construct a new storage instance.
Definition: LocationDetail.h:58
size_t numTrailingObjects(OverloadToken< Location >) const
Definition: LocationDetail.h:100
Definition: LocationDetail.h:109
std::pair< Location, Location > KeyTy
The hash key used for uniquing.
Definition: LocationDetail.h:30
std::tuple< uintptr_t, ClassID *, Location > KeyTy
The hash key used for uniquing.
Definition: LocationDetail.h:135
unsigned line
Definition: LocationDetail.h:65
Definition: LocationDetail.h:128
ClassID * classId
A unique pointer for each type of underlyingLocation.
Definition: LocationDetail.h:152
Definition: LocationDetail.h:68
bool operator==(const KeyTy &key) const
Definition: LocationDetail.h:80
Location caller
Definition: LocationDetail.h:42
NameLocationStorage(Identifier name, Location child)
Definition: LocationDetail.h:110
Definition: AttributeSupport.h:34
unsigned numLocs
Number of trailing location objects.
Definition: LocationDetail.h:103
ArrayRef< Location > getLocations() const
Definition: LocationDetail.h:74
uintptr_t underlyingLocation
Pointer to the corresponding object.
Definition: LocationDetail.h:149
static NameLocationStorage * construct(AttributeStorageAllocator &allocator, const KeyTy &key)
Construct a new storage instance.
Definition: LocationDetail.h:118
bool operator==(const KeyTy &key) const
Definition: LocationDetail.h:31
Location child
Definition: LocationDetail.h:125
std::tuple< Identifier, unsigned, unsigned > KeyTy
The hash key used for uniquing.
Definition: LocationDetail.h:51