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