================
@@ -335,6 +335,67 @@ Metadata
*BitcodeReaderMetadataList::resolveTypeArray(Metadata *MaybeTuple) {
return MDTuple::get(Context, Ops);
}
+/// Rebuild \p Old with \p Ops, keeping its identity: a self reference has to
+/// point at the replacement, and a distinct node must not be uniqued.
+static MDNode *rebuildAliasScopeNode(MDNode *Old,
+ SmallVectorImpl<Metadata *> &Ops) {
+ LLVMContext &Context = Old->getContext();
+ if (Ops[0] != Old)
+ return Old->isDistinct() ? MDNode::getDistinct(Context, Ops)
+ : MDNode::get(Context, Ops);
+
+ Ops[0] = nullptr;
+ MDNode *New = MDNode::getDistinct(Context, Ops);
+ New->replaceOperandWith(0, New);
+ return New;
+}
+
+static MDNode *upgradeAliasScopeDomain(MDNode *Domain,
+ DenseMap<MDNode *, MDNode *> &Upgraded)
{
+ unsigned NumOperands = Domain->getNumOperands();
+ bool HadDescription = NumOperands == 2;
+ // Already upgraded, or invalid and left to the verifier.
+ if (NumOperands == 0 || NumOperands > 2 ||
+ (HadDescription && mdconst::hasa<ConstantInt>(Domain->getOperand(1))))
+ return Domain;
+
+ if (MDNode *Upgrade = Upgraded.lookup(Domain))
+ return Upgrade;
----------------
brunodf-gf wrote:
Here, you can avoid looking up the same key in `Upgraded` twice, because
`Upgraded` is not modified in between. For example (since the value cannot be a
null pointer):
```suggestion
MDNode *&Upgrade = Upgraded[Domain];
if (Upgrade)
return Upgrade;
```
Then just assign to `Upgrade` further in the function.
https://github.com/llvm/llvm-project/pull/218768
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits