[llvm] 2a4c4b5 - [TableGen] Use const getter to implement non-const getter instead of the other way around. NFC (#123452)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 18 08:36:03 PST 2025
Author: Craig Topper
Date: 2025-01-18T08:35:59-08:00
New Revision: 2a4c4b554b23f2a7180502c1a635d8aae4dca027
URL: https://github.com/llvm/llvm-project/commit/2a4c4b554b23f2a7180502c1a635d8aae4dca027
DIFF: https://github.com/llvm/llvm-project/commit/2a4c4b554b23f2a7180502c1a635d8aae4dca027.diff
LOG: [TableGen] Use const getter to implement non-const getter instead of the other way around. NFC (#123452)
It's better to cast away constness on the reference being returned than
to cast away constness on the this pointer.
Added:
Modified:
llvm/utils/TableGen/Common/CodeGenSchedule.h
Removed:
################################################################################
diff --git a/llvm/utils/TableGen/Common/CodeGenSchedule.h b/llvm/utils/TableGen/Common/CodeGenSchedule.h
index 01f267ae55fad0..fed8b3e1ccb8a6 100644
--- a/llvm/utils/TableGen/Common/CodeGenSchedule.h
+++ b/llvm/utils/TableGen/Common/CodeGenSchedule.h
@@ -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));
}
// Iterate over the unique processor models.
@@ -529,14 +530,14 @@ class CodeGenSchedModels {
const CodeGenSchedRW &getSchedRW(unsigned Idx, bool IsRead) const {
return IsRead ? getSchedRead(Idx) : getSchedWrite(Idx);
}
- CodeGenSchedRW &getSchedRW(const Record *Def) {
+ const CodeGenSchedRW &getSchedRW(const Record *Def) const {
bool IsRead = Def->isSubClassOf("SchedRead");
unsigned Idx = getSchedRWIdx(Def, IsRead);
- return const_cast<CodeGenSchedRW &>(IsRead ? getSchedRead(Idx)
- : getSchedWrite(Idx));
+ return IsRead ? getSchedRead(Idx) : getSchedWrite(Idx);
}
- const CodeGenSchedRW &getSchedRW(const Record *Def) const {
- return const_cast<CodeGenSchedModels &>(*this).getSchedRW(Def);
+ CodeGenSchedRW &getSchedRW(const Record *Def) {
+ return const_cast<CodeGenSchedRW &>(
+ static_cast<const CodeGenSchedModels &>(*this).getSchedRW(Def));
}
unsigned getSchedRWIdx(const Record *Def, bool IsRead) const;
More information about the llvm-commits
mailing list