[llvm] [TableGen] Use const getter to implement non-const getter instead of the other way around. NFC (PR #123452)

Sergei Barannikov via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 17 23:43:45 PST 2025


================
@@ -495,13 +495,14 @@ class CodeGenSchedModels {
     return ProcModels[I->second];
   }
 
-  CodeGenProcModel &getProcModel(const Record *ModelDef) {
+  const CodeGenProcModel &getProcModel(const Record *ModelDef) const {
     ProcModelMapTy::const_iterator I = ProcModelMap.find(ModelDef);
     assert(I != ProcModelMap.end() && "missing machine model");
     return ProcModels[I->second];
   }
-  const CodeGenProcModel &getProcModel(const Record *ModelDef) const {
-    return const_cast<CodeGenSchedModels *>(this)->getProcModel(ModelDef);
+  CodeGenProcModel &getProcModel(const Record *ModelDef) {
+    return const_cast<CodeGenProcModel &>(
+        static_cast<const CodeGenSchedModels &>(*this).getProcModel(ModelDef));
----------------
s-barannikov wrote:

(note) Some argue that `cost_cast` is better suited for adding `const`.


https://github.com/llvm/llvm-project/pull/123452


More information about the llvm-commits mailing list