[llvm] Metadata: Optimize metadata queries (PR #70700)
Matthias Braun via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 30 13:05:19 PDT 2023
================
@@ -303,8 +303,14 @@ class Instruction : public User,
/// Get the metadata of given kind attached to this Instruction.
/// If the metadata is not found then return null.
MDNode *getMetadata(unsigned KindID) const {
- if (!hasMetadata()) return nullptr;
- return getMetadataImpl(KindID);
+ // Handle 'dbg' as a special case since it is not stored in the hash table.
+ if (KindID == LLVMContext::MD_dbg) {
+ return DbgLoc.getAsMDNode();
+ }
+ if (hasMetadataOtherThanDebugLoc()) {
+ return getMetadataImpl(KindID);
----------------
MatzeB wrote:
With my changes applied `getMetadataImpl()` will not perform any additional `hasMetadata()` checks anymore.
https://github.com/llvm/llvm-project/pull/70700
More information about the llvm-commits
mailing list