[llvm] Metadata: Optimize metadata queries (PR #70700)
Duncan P. N. Exon Smith via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 30 12:57:24 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);
----------------
dexonsmith wrote:
Note that `Value::hasMetadata()` is a protected member, accessing a bit stored on Value that caches whether anything is in the DenseMap stored in the LLVMContext.
https://github.com/llvm/llvm-project/pull/70700
More information about the llvm-commits
mailing list