-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[LLVM][TableGen] Use const Record pointers in PredicateExpander #109365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arsenm
approved these changes
Sep 20, 2024
@llvm/pr-subscribers-tablegen Author: Rahul Joshi (jurahul) ChangesUse const Record pointers in PredicateExpander. This is a part of effort to have better const correctness in TableGen backends: Full diff: https://github.com/llvm/llvm-project/pull/109365.diff 2 Files Affected:
diff --git a/llvm/utils/TableGen/Common/PredicateExpander.cpp b/llvm/utils/TableGen/Common/PredicateExpander.cpp
index d0a35ff82df649..456c4cf5d92279 100644
--- a/llvm/utils/TableGen/Common/PredicateExpander.cpp
+++ b/llvm/utils/TableGen/Common/PredicateExpander.cpp
@@ -139,7 +139,7 @@ void PredicateExpander::expandCheckOpcode(raw_ostream &OS, const Record *Inst) {
}
void PredicateExpander::expandCheckOpcode(raw_ostream &OS,
- const RecVec &Opcodes) {
+ ArrayRef<const Record *> Opcodes) {
assert(!Opcodes.empty() && "Expected at least one opcode to check!");
bool First = true;
@@ -169,16 +169,15 @@ void PredicateExpander::expandCheckOpcode(raw_ostream &OS,
}
void PredicateExpander::expandCheckPseudo(raw_ostream &OS,
- const RecVec &Opcodes) {
+ ArrayRef<const Record *> Opcodes) {
if (shouldExpandForMC())
expandFalse(OS);
else
expandCheckOpcode(OS, Opcodes);
}
-void PredicateExpander::expandPredicateSequence(raw_ostream &OS,
- const RecVec &Sequence,
- bool IsCheckAll) {
+void PredicateExpander::expandPredicateSequence(
+ raw_ostream &OS, ArrayRef<const Record *> Sequence, bool IsCheckAll) {
assert(!Sequence.empty() && "Found an invalid empty predicate set!");
if (Sequence.size() == 1)
return expandPredicate(OS, Sequence[0]);
@@ -267,8 +266,7 @@ void PredicateExpander::expandReturnStatement(raw_ostream &OS,
void PredicateExpander::expandOpcodeSwitchCase(raw_ostream &OS,
const Record *Rec) {
- const RecVec &Opcodes = Rec->getValueAsListOfDefs("Opcodes");
- for (const Record *Opcode : Opcodes) {
+ for (const Record *Opcode : Rec->getValueAsListOfDefs("Opcodes")) {
OS.indent(getIndentLevel() * 2);
OS << "case " << Opcode->getValueAsString("Namespace")
<< "::" << Opcode->getName() << ":\n";
@@ -280,9 +278,8 @@ void PredicateExpander::expandOpcodeSwitchCase(raw_ostream &OS,
decreaseIndentLevel();
}
-void PredicateExpander::expandOpcodeSwitchStatement(raw_ostream &OS,
- const RecVec &Cases,
- const Record *Default) {
+void PredicateExpander::expandOpcodeSwitchStatement(
+ raw_ostream &OS, ArrayRef<const Record *> Cases, const Record *Default) {
std::string Buffer;
raw_string_ostream SS(Buffer);
@@ -310,7 +307,7 @@ void PredicateExpander::expandOpcodeSwitchStatement(raw_ostream &OS,
void PredicateExpander::expandStatement(raw_ostream &OS, const Record *Rec) {
// Assume that padding has been added by the caller.
if (Rec->isSubClassOf("MCOpcodeSwitchStatement")) {
- expandOpcodeSwitchStatement(OS, Rec->getValueAsListOfDefs("Cases"),
+ expandOpcodeSwitchStatement(OS, Rec->getValueAsListOfConstDefs("Cases"),
Rec->getValueAsDef("DefaultCase"));
return;
}
@@ -461,13 +458,13 @@ void STIPredicateExpander::expandHeader(raw_ostream &OS,
void STIPredicateExpander::expandPrologue(raw_ostream &OS,
const STIPredicateFunction &Fn) {
- RecVec Delegates = Fn.getDeclaration()->getValueAsListOfDefs("Delegates");
bool UpdatesOpcodeMask =
Fn.getDeclaration()->getValueAsBit("UpdatesOpcodeMask");
increaseIndentLevel();
unsigned IndentLevel = getIndentLevel();
- for (const Record *Delegate : Delegates) {
+ for (const Record *Delegate :
+ Fn.getDeclaration()->getValueAsListOfDefs("Delegates")) {
OS.indent(IndentLevel * 2);
OS << "if (" << Delegate->getValueAsString("Name") << "(MI";
if (UpdatesOpcodeMask)
diff --git a/llvm/utils/TableGen/Common/PredicateExpander.h b/llvm/utils/TableGen/Common/PredicateExpander.h
index 333d1c561f9701..c0cd69e3cb1f85 100644
--- a/llvm/utils/TableGen/Common/PredicateExpander.h
+++ b/llvm/utils/TableGen/Common/PredicateExpander.h
@@ -16,8 +16,8 @@
#ifndef LLVM_UTILS_TABLEGEN_COMMON_PREDICATEEXPANDER_H
#define LLVM_UTILS_TABLEGEN_COMMON_PREDICATEEXPANDER_H
+#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
-#include <vector>
namespace llvm {
@@ -52,7 +52,6 @@ class PredicateExpander {
void increaseIndentLevel() { ++IndentLevel; }
void decreaseIndentLevel() { --IndentLevel; }
- using RecVec = std::vector<Record *>;
void expandTrue(raw_ostream &OS);
void expandFalse(raw_ostream &OS);
void expandCheckImmOperand(raw_ostream &OS, int OpIndex, int ImmVal,
@@ -73,9 +72,10 @@ class PredicateExpander {
void expandCheckNumOperands(raw_ostream &OS, int NumOps);
void expandCheckOpcode(raw_ostream &OS, const Record *Inst);
- void expandCheckPseudo(raw_ostream &OS, const RecVec &Opcodes);
- void expandCheckOpcode(raw_ostream &OS, const RecVec &Opcodes);
- void expandPredicateSequence(raw_ostream &OS, const RecVec &Sequence,
+ void expandCheckPseudo(raw_ostream &OS, ArrayRef<const Record *> Opcodes);
+ void expandCheckOpcode(raw_ostream &OS, ArrayRef<const Record *> Opcodes);
+ void expandPredicateSequence(raw_ostream &OS,
+ ArrayRef<const Record *> Sequence,
bool IsCheckAll);
void expandTIIFunctionCall(raw_ostream &OS, StringRef MethodName);
void expandCheckIsRegOperand(raw_ostream &OS, int OpIndex);
@@ -91,7 +91,8 @@ class PredicateExpander {
void expandPredicate(raw_ostream &OS, const Record *Rec);
void expandReturnStatement(raw_ostream &OS, const Record *Rec);
void expandOpcodeSwitchCase(raw_ostream &OS, const Record *Rec);
- void expandOpcodeSwitchStatement(raw_ostream &OS, const RecVec &Cases,
+ void expandOpcodeSwitchStatement(raw_ostream &OS,
+ ArrayRef<const Record *> Cases,
const Record *Default);
void expandStatement(raw_ostream &OS, const Record *Rec);
};
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Use const Record pointers in PredicateExpander.
This is a part of effort to have better const correctness in TableGen backends:
https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089