Coverage Report

Created: 2020-06-26 05:44

/home/arjun/llvm-project/mlir/lib/IR/Location.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- Location.cpp - MLIR Location Classes -------------------------------===//
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
#include "mlir/IR/Location.h"
10
#include "LocationDetail.h"
11
#include "llvm/ADT/SetVector.h"
12
13
using namespace mlir;
14
using namespace mlir::detail;
15
16
//===----------------------------------------------------------------------===//
17
// CallSiteLoc
18
//===----------------------------------------------------------------------===//
19
20
0
Location CallSiteLoc::get(Location callee, Location caller) {
21
0
  return Base::get(callee->getContext(), StandardAttributes::CallSiteLocation,
22
0
                   callee, caller);
23
0
}
24
25
Location CallSiteLoc::get(Location name, ArrayRef<Location> frames) {
26
  assert(!frames.empty() && "required at least 1 call frame");
27
  Location caller = frames.back();
28
  for (auto frame : llvm::reverse(frames.drop_back()))
29
    caller = CallSiteLoc::get(frame, caller);
30
  return CallSiteLoc::get(name, caller);
31
}
32
33
0
Location CallSiteLoc::getCallee() const { return getImpl()->callee; }
34
35
0
Location CallSiteLoc::getCaller() const { return getImpl()->caller; }
36
37
//===----------------------------------------------------------------------===//
38
// FileLineColLoc
39
//===----------------------------------------------------------------------===//
40
41
Location FileLineColLoc::get(Identifier filename, unsigned line,
42
0
                             unsigned column, MLIRContext *context) {
43
0
  return Base::get(context, StandardAttributes::FileLineColLocation, filename,
44
0
                   line, column);
45
0
}
46
47
Location FileLineColLoc::get(StringRef filename, unsigned line, unsigned column,
48
0
                             MLIRContext *context) {
49
0
  return get(Identifier::get(filename.empty() ? "-" : filename, context), line,
50
0
             column, context);
51
0
}
52
53
0
StringRef FileLineColLoc::getFilename() const { return getImpl()->filename; }
54
0
unsigned FileLineColLoc::getLine() const { return getImpl()->line; }
55
0
unsigned FileLineColLoc::getColumn() const { return getImpl()->column; }
56
57
//===----------------------------------------------------------------------===//
58
// FusedLoc
59
//===----------------------------------------------------------------------===//
60
61
Location FusedLoc::get(ArrayRef<Location> locs, Attribute metadata,
62
0
                       MLIRContext *context) {
63
0
  // Unique the set of locations to be fused.
64
0
  llvm::SmallSetVector<Location, 4> decomposedLocs;
65
0
  for (auto loc : locs) {
66
0
    // If the location is a fused location we decompose it if it has no
67
0
    // metadata or the metadata is the same as the top level metadata.
68
0
    if (auto fusedLoc = loc.dyn_cast<FusedLoc>()) {
69
0
      if (fusedLoc.getMetadata() == metadata) {
70
0
        // UnknownLoc's have already been removed from FusedLocs so we can
71
0
        // simply add all of the internal locations.
72
0
        decomposedLocs.insert(fusedLoc.getLocations().begin(),
73
0
                              fusedLoc.getLocations().end());
74
0
        continue;
75
0
      }
76
0
    }
77
0
    // Otherwise, only add known locations to the set.
78
0
    if (!loc.isa<UnknownLoc>())
79
0
      decomposedLocs.insert(loc);
80
0
  }
81
0
  locs = decomposedLocs.getArrayRef();
82
0
83
0
  // Handle the simple cases of less than two locations.
84
0
  if (locs.empty())
85
0
    return UnknownLoc::get(context);
86
0
  if (locs.size() == 1)
87
0
    return locs.front();
88
0
  return Base::get(context, StandardAttributes::FusedLocation, locs, metadata);
89
0
}
90
91
0
ArrayRef<Location> FusedLoc::getLocations() const {
92
0
  return getImpl()->getLocations();
93
0
}
94
95
0
Attribute FusedLoc::getMetadata() const { return getImpl()->metadata; }
96
97
//===----------------------------------------------------------------------===//
98
// NameLoc
99
//===----------------------------------------------------------------------===//
100
101
0
Location NameLoc::get(Identifier name, Location child) {
102
0
  assert(!child.isa<NameLoc>() &&
103
0
         "a NameLoc cannot be used as a child of another NameLoc");
104
0
  return Base::get(child->getContext(), StandardAttributes::NameLocation, name,
105
0
                   child);
106
0
}
107
108
0
Location NameLoc::get(Identifier name, MLIRContext *context) {
109
0
  return get(name, UnknownLoc::get(context));
110
0
}
111
112
/// Return the name identifier.
113
0
Identifier NameLoc::getName() const { return getImpl()->name; }
114
115
/// Return the child location.
116
0
Location NameLoc::getChildLoc() const { return getImpl()->child; }
117
118
//===----------------------------------------------------------------------===//
119
// OpaqueLoc
120
//===----------------------------------------------------------------------===//
121
122
Location OpaqueLoc::get(uintptr_t underlyingLocation, TypeID typeID,
123
0
                        Location fallbackLocation) {
124
0
  return Base::get(fallbackLocation->getContext(),
125
0
                   StandardAttributes::OpaqueLocation, underlyingLocation,
126
0
                   typeID, fallbackLocation);
127
0
}
128
129
0
uintptr_t OpaqueLoc::getUnderlyingLocation() const {
130
0
  return Base::getImpl()->underlyingLocation;
131
0
}
132
133
0
TypeID OpaqueLoc::getUnderlyingTypeID() const { return getImpl()->typeID; }
134
135
0
Location OpaqueLoc::getFallbackLocation() const {
136
0
  return Base::getImpl()->fallbackLocation;
137
0
}