forked from OSchip/llvm-project
IR: Extract macros from DILocation, NFC
`DILocation` is a lightweight wrapper. Its accessors check for null and the correct type, and then forward to `MDLocation`. Extract a couple of macros to do the `dyn_cast_or_null<>` and default return logic. I'll be using these to minimize error-prone boilerplate when I move the new hierarchy into place -- since all the other subclasses of `DIDescriptor` will similarly become lightweight wrappers. (Note that I hope to obsolete these wrappers fairly quickly, with the goal of renaming the underlying types (e.g., I'll rename `MDLocation` to `DILocation` once the name is free).) llvm-svn: 229953
This commit is contained in:
parent
301ed0c3b4
commit
f86505abdf
|
@ -252,6 +252,19 @@ public:
|
||||||
void replaceAllUsesWith(MDNode *D);
|
void replaceAllUsesWith(MDNode *D);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define RETURN_FROM_RAW(VALID, DEFAULT) \
|
||||||
|
do { \
|
||||||
|
if (auto *N = getRaw()) \
|
||||||
|
return VALID; \
|
||||||
|
return DEFAULT; \
|
||||||
|
} while (false)
|
||||||
|
#define RETURN_DESCRIPTOR_FROM_RAW(DESC, VALID) \
|
||||||
|
do { \
|
||||||
|
if (auto *N = getRaw()) \
|
||||||
|
return DESC(dyn_cast_or_null<MDNode>(VALID)); \
|
||||||
|
return DESC(static_cast<const MDNode *>(nullptr)); \
|
||||||
|
} while (false)
|
||||||
|
|
||||||
/// \brief This is used to represent ranges, for array bounds.
|
/// \brief This is used to represent ranges, for array bounds.
|
||||||
class DISubrange : public DIDescriptor {
|
class DISubrange : public DIDescriptor {
|
||||||
friend class DIDescriptor;
|
friend class DIDescriptor;
|
||||||
|
@ -933,25 +946,13 @@ class DILocation : public DIDescriptor {
|
||||||
public:
|
public:
|
||||||
explicit DILocation(const MDNode *N) : DIDescriptor(N) {}
|
explicit DILocation(const MDNode *N) : DIDescriptor(N) {}
|
||||||
|
|
||||||
unsigned getLineNumber() const {
|
unsigned getLineNumber() const { RETURN_FROM_RAW(N->getLine(), 0); }
|
||||||
if (auto *L = getRaw())
|
unsigned getColumnNumber() const { RETURN_FROM_RAW(N->getColumn(), 0); }
|
||||||
return L->getLine();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
unsigned getColumnNumber() const {
|
|
||||||
if (auto *L = getRaw())
|
|
||||||
return L->getColumn();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
DIScope getScope() const {
|
DIScope getScope() const {
|
||||||
if (auto *L = getRaw())
|
RETURN_DESCRIPTOR_FROM_RAW(DIScope, N->getScope());
|
||||||
return DIScope(dyn_cast_or_null<MDNode>(L->getScope()));
|
|
||||||
return DIScope(nullptr);
|
|
||||||
}
|
}
|
||||||
DILocation getOrigLocation() const {
|
DILocation getOrigLocation() const {
|
||||||
if (auto *L = getRaw())
|
RETURN_DESCRIPTOR_FROM_RAW(DILocation, N->getInlinedAt());
|
||||||
return DILocation(dyn_cast_or_null<MDNode>(L->getInlinedAt()));
|
|
||||||
return DILocation(nullptr);
|
|
||||||
}
|
}
|
||||||
StringRef getFilename() const { return getScope().getFilename(); }
|
StringRef getFilename() const { return getScope().getFilename(); }
|
||||||
StringRef getDirectory() const { return getScope().getDirectory(); }
|
StringRef getDirectory() const { return getScope().getDirectory(); }
|
||||||
|
@ -1042,6 +1043,9 @@ public:
|
||||||
bool Verify() const;
|
bool Verify() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#undef RETURN_FROM_RAW
|
||||||
|
#undef RETURN_DESCRIPTOR_FROM_RAW
|
||||||
|
|
||||||
/// \brief Find subprogram that is enclosing this scope.
|
/// \brief Find subprogram that is enclosing this scope.
|
||||||
DISubprogram getDISubprogram(const MDNode *Scope);
|
DISubprogram getDISubprogram(const MDNode *Scope);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue