include "mlir/IR/AttrTypeBase.td"
include "mlir/IR/BuiltinDialect.td"
+include "mlir/IR/SubElementInterfaces.td"
// Base class for Builtin dialect location attributes.
-class Builtin_LocationAttr<string name>
- : AttrDef<Builtin_Dialect, name, [], "::mlir::LocationAttr"> {
+class Builtin_LocationAttr<string name, list<Trait> traits = []>
+ : AttrDef<Builtin_Dialect, name, traits, "::mlir::LocationAttr"> {
let cppClassName = name;
let mnemonic = ?;
}
// CallSiteLoc
//===----------------------------------------------------------------------===//
-def CallSiteLoc : Builtin_LocationAttr<"CallSiteLoc"> {
+def CallSiteLoc : Builtin_LocationAttr<"CallSiteLoc", [
+ DeclareAttrInterfaceMethods<SubElementAttrInterface>
+ ]> {
let summary = "A callsite source location";
let description = [{
Syntax:
// FusedLoc
//===----------------------------------------------------------------------===//
-def FusedLoc : Builtin_LocationAttr<"FusedLoc"> {
+def FusedLoc : Builtin_LocationAttr<"FusedLoc", [
+ DeclareAttrInterfaceMethods<SubElementAttrInterface>
+ ]> {
let summary = "A tuple of other source locations";
let description = [{
Syntax:
// NameLoc
//===----------------------------------------------------------------------===//
-def NameLoc : Builtin_LocationAttr<"NameLoc"> {
+def NameLoc : Builtin_LocationAttr<"NameLoc", [
+ DeclareAttrInterfaceMethods<SubElementAttrInterface>
+ ]> {
let summary = "A named source location";
let description = [{
Syntax:
// OpaqueLoc
//===----------------------------------------------------------------------===//
-def OpaqueLoc : Builtin_LocationAttr<"OpaqueLoc"> {
+def OpaqueLoc : Builtin_LocationAttr<"OpaqueLoc", [
+ DeclareAttrInterfaceMethods<SubElementAttrInterface>
+ ]> {
let summary = "An opaque source location";
let description = [{
An instance of this location essentially contains a pointer to some data
return CallSiteLoc::get(name, caller);
}
+void CallSiteLoc::walkImmediateSubElements(
+ function_ref<void(Attribute)> walkAttrsFn,
+ function_ref<void(Type)> walkTypesFn) const {
+ walkAttrsFn(getCallee());
+ walkAttrsFn(getCaller());
+}
+
+Attribute
+CallSiteLoc::replaceImmediateSubElements(ArrayRef<Attribute> replAttrs,
+ ArrayRef<Type> replTypes) const {
+ return get(replAttrs[0].cast<LocationAttr>(),
+ replAttrs[1].cast<LocationAttr>());
+}
+
//===----------------------------------------------------------------------===//
// FusedLoc
//===----------------------------------------------------------------------===//
return Base::get(context, locs, metadata);
}
+
+void FusedLoc::walkImmediateSubElements(
+ function_ref<void(Attribute)> walkAttrsFn,
+ function_ref<void(Type)> walkTypesFn) const {
+ for (Attribute attr : getLocations())
+ walkAttrsFn(attr);
+ walkAttrsFn(getMetadata());
+}
+
+Attribute
+FusedLoc::replaceImmediateSubElements(ArrayRef<Attribute> replAttrs,
+ ArrayRef<Type> replTypes) const {
+ SmallVector<Location> newLocs;
+ newLocs.reserve(replAttrs.size() - 1);
+ for (Attribute attr : replAttrs.drop_back())
+ newLocs.push_back(attr.cast<LocationAttr>());
+ return get(getContext(), newLocs, replAttrs.back());
+}
+
+//===----------------------------------------------------------------------===//
+// NameLoc
+//===----------------------------------------------------------------------===//
+
+void NameLoc::walkImmediateSubElements(
+ function_ref<void(Attribute)> walkAttrsFn,
+ function_ref<void(Type)> walkTypesFn) const {
+ walkAttrsFn(getName());
+ walkAttrsFn(getChildLoc());
+}
+
+Attribute NameLoc::replaceImmediateSubElements(ArrayRef<Attribute> replAttrs,
+ ArrayRef<Type> replTypes) const {
+ return get(replAttrs[0].cast<StringAttr>(),
+ replAttrs[1].cast<LocationAttr>());
+}
+
+//===----------------------------------------------------------------------===//
+// OpaqueLoc
+//===----------------------------------------------------------------------===//
+
+void OpaqueLoc::walkImmediateSubElements(
+ function_ref<void(Attribute)> walkAttrsFn,
+ function_ref<void(Type)> walkTypesFn) const {
+ walkAttrsFn(getFallbackLocation());
+}
+
+Attribute
+OpaqueLoc::replaceImmediateSubElements(ArrayRef<Attribute> replAttrs,
+ ArrayRef<Type> replTypes) const {
+ return get(getUnderlyingLocation(), getUnderlyingTypeID(),
+ replAttrs[0].cast<LocationAttr>());
+}