[clang] [llvm] [TableGen] Change SetTheory set/vec to use const Record * (PR #107692)

Rahul Joshi via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 8 10:43:48 PDT 2024


================
@@ -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


More information about the cfe-commits mailing list