================
@@ -2808,10 +2806,10 @@ RecordRecTy *Record::getType() {
   return RecordRecTy::get(TrackedRecords, DirectSCs);
 }
 
-DefInit *Record::getDefInit() {
+DefInit *Record::getDefInit() const {
   if (!CorrespondingDefInit) {
-    CorrespondingDefInit =
-        new (TrackedRecords.getImpl().Allocator) DefInit(this);
+    CorrespondingDefInit = new (TrackedRecords.getImpl().Allocator)
+        DefInit(const_cast<Record *>(this));
----------------
jurahul wrote:

I did look into making the Def pointer in DefInit const. It's possible, but 
will spawn a bunch of other changes, so best done as a separate PR. I also 
checked if we can always instantiate the `CorrespondingDefInit` when a new 
Record is added to the `RecordKeeper` when parsing, it seems only a small 
fraction of Records have CorrespondingDefInit set to non-null (measured in 
RecordKeeper destructor) so unconditionally populating CorrespondingDefInit 
will likely cause memory footprint increase. So this seems like a reasonable 
thing, and will be followed by removing the const_cast<> (but 
CorrespondingDefInit will stay mutable, its like a cache).

https://github.com/llvm/llvm-project/pull/107692
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to