[llvm] [LLVM][TableGen] Use const Record pointers in PredicateExpander (PR #109365)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 19 20:05:41 PDT 2024
https://github.com/jurahul created https://github.com/llvm/llvm-project/pull/109365
Use const Record pointers in PredicateExpander.
>From 7d787b2cbbf1eb608207efb8095802b4bf009da2 Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Thu, 19 Sep 2024 20:04:15 -0700
Subject: [PATCH] [LLVM][TableGen] Use const Record pointers in
PredicateExpander
---
.../TableGen/Common/PredicateExpander.cpp | 23 ++++++++-----------
.../utils/TableGen/Common/PredicateExpander.h | 13 ++++++-----
2 files changed, 17 insertions(+), 19 deletions(-)
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);
};
More information about the llvm-commits
mailing list