Skip to content

[NFC][TableGen] Rename CodeGenTarget instruction accessors #146767

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/utils/TableGen/AsmMatcherEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1541,7 +1541,7 @@ void AsmMatcherInfo::buildInfo() {
Variant.Name = AsmVariant->getValueAsString("Name");
Variant.AsmVariantNo = AsmVariant->getValueAsInt("Variant");

for (const CodeGenInstruction *CGI : Target.getInstructionsByEnumValue()) {
for (const CodeGenInstruction *CGI : Target.getInstructions()) {

// If the tblgen -match-prefix option is specified (for tblgen hackers),
// filter the set of instructions we consider.
Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/TableGen/AsmWriterEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ AsmWriterEmitter::AsmWriterEmitter(const RecordKeeper &R)
unsigned Variant = AsmWriter->getValueAsInt("Variant");

// Get the instruction numbering.
NumberedInstructions = Target.getInstructionsByEnumValue();
NumberedInstructions = Target.getInstructions();

for (const auto &[Idx, I] : enumerate(NumberedInstructions)) {
if (!I->AsmString.empty() && I->TheDef->getName() != "PHI")
Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/TableGen/CodeEmitterGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ void CodeEmitterGen::run(raw_ostream &O) {
Target.reverseBitsForLittleEndianEncoding();

ArrayRef<const CodeGenInstruction *> NumberedInstructions =
Target.getInstructionsByEnumValue();
Target.getInstructions();

if (Target.hasVariableLengthEncodings()) {
emitVarLenCodeEmitter(Records, O);
Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/TableGen/CodeGenMapTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ const Record *MapTableEmitter::getInstrForColumn(const Record *KeyInstr,

unsigned MapTableEmitter::emitBinSearchTable(raw_ostream &OS) {
ArrayRef<const CodeGenInstruction *> NumberedInstructions =
Target.getInstructionsByEnumValue();
Target.getInstructions();
StringRef Namespace = Target.getInstNamespace();
ArrayRef<const ListInit *> ValueCols = InstrMapDesc.getValueCols();
unsigned NumCol = ValueCols.size();
Expand Down
3 changes: 1 addition & 2 deletions llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4122,8 +4122,7 @@ void CodeGenDAGPatterns::AddPatternToMatch(TreePattern *Pattern,
}

void CodeGenDAGPatterns::InferInstructionFlags() {
ArrayRef<const CodeGenInstruction *> Instructions =
Target.getInstructionsByEnumValue();
ArrayRef<const CodeGenInstruction *> Instructions = Target.getInstructions();

unsigned Errors = 0;

Expand Down
14 changes: 7 additions & 7 deletions llvm/utils/TableGen/Common/CodeGenSchedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ struct InstRegexOp : public SetTheory::Operator {
void apply(SetTheory &ST, const DagInit *Expr, SetTheory::RecSet &Elts,
ArrayRef<SMLoc> Loc) override {
ArrayRef<const CodeGenInstruction *> Generics =
Target.getGenericInstructionsByEnumValue();
Target.getGenericInstructions();
ArrayRef<const CodeGenInstruction *> Pseudos =
Target.getTargetPseudoInstructionsByEnumValue();
Target.getTargetPseudoInstructions();
ArrayRef<const CodeGenInstruction *> NonPseudos =
Target.getTargetNonPseudoInstructionsByEnumValue();
Target.getTargetNonPseudoInstructions();

for (const Init *Arg : Expr->getArgs()) {
const StringInit *SI = dyn_cast<StringInit>(Arg);
Expand Down Expand Up @@ -587,7 +587,7 @@ void CodeGenSchedModels::collectSchedRW() {

// Find all SchedReadWrites referenced by instruction defs.
ConstRecVec SWDefs, SRDefs;
for (const CodeGenInstruction *Inst : Target.getInstructionsByEnumValue()) {
for (const CodeGenInstruction *Inst : Target.getInstructions()) {
const Record *SchedDef = Inst->TheDef;
if (SchedDef->isValueUnset("SchedRW"))
continue;
Expand Down Expand Up @@ -836,7 +836,7 @@ void CodeGenSchedModels::collectSchedClasses() {

// Create a SchedClass for each unique combination of itinerary class and
// SchedRW list.
for (const CodeGenInstruction *Inst : Target.getInstructionsByEnumValue()) {
for (const CodeGenInstruction *Inst : Target.getInstructions()) {
const Record *ItinDef = Inst->TheDef->getValueAsDef("Itinerary");
IdxVec Writes, Reads;
if (!Inst->TheDef->isValueUnset("SchedRW"))
Expand All @@ -861,7 +861,7 @@ void CodeGenSchedModels::collectSchedClasses() {
LLVM_DEBUG(
dbgs()
<< "\n+++ ITINERARIES and/or MACHINE MODELS (collectSchedClasses) +++\n");
for (const CodeGenInstruction *Inst : Target.getInstructionsByEnumValue()) {
for (const CodeGenInstruction *Inst : Target.getInstructions()) {
StringRef InstName = Inst->TheDef->getName();
unsigned SCIdx = getSchedClassIdx(*Inst);
if (!SCIdx) {
Expand Down Expand Up @@ -1922,7 +1922,7 @@ void CodeGenSchedModels::checkCompleteness() {
const bool HasItineraries = ProcModel.hasItineraries();
if (!ProcModel.ModelDef->getValueAsBit("CompleteModel"))
continue;
for (const CodeGenInstruction *Inst : Target.getInstructionsByEnumValue()) {
for (const CodeGenInstruction *Inst : Target.getInstructions()) {
if (Inst->hasNoSchedulingInfo)
continue;
if (ProcModel.isUnsupported(*Inst))
Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/TableGen/Common/CodeGenTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ StringRef CodeGenTarget::getName() const { return TargetRec->getName(); }
/// namespace. The namespace is cached because it is requested multiple times.
StringRef CodeGenTarget::getInstNamespace() const {
if (InstNamespace.empty()) {
for (const CodeGenInstruction *Inst : getInstructionsByEnumValue()) {
for (const CodeGenInstruction *Inst : getInstructions()) {
// We are not interested in the "TargetOpcode" namespace.
if (Inst->Namespace != "TargetOpcode") {
InstNamespace = Inst->Namespace;
Expand Down
25 changes: 11 additions & 14 deletions llvm/utils/TableGen/Common/CodeGenTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,31 +176,28 @@ class CodeGenTarget {
/// - fixed / generic instructions as declared in TargetOpcodes.def, in order;
/// - pseudo instructions in lexicographical order sorted by name;
/// - other instructions in lexicographical order sorted by name.
ArrayRef<const CodeGenInstruction *> getInstructionsByEnumValue() const {
ArrayRef<const CodeGenInstruction *> getInstructions() const {
if (InstrsByEnum.empty())
ComputeInstrsByEnum();
return InstrsByEnum;
}

// Functions that return various slices of `getInstructionsByEnumValue`.
ArrayRef<const CodeGenInstruction *>
getGenericInstructionsByEnumValue() const {
return getInstructionsByEnumValue().take_front(getNumFixedInstructions());
// Functions that return various slices of `getInstructions`, ordered by
// their enum values.
ArrayRef<const CodeGenInstruction *> getGenericInstructions() const {
return getInstructions().take_front(getNumFixedInstructions());
}

ArrayRef<const CodeGenInstruction *>
getTargetInstructionsByEnumValue() const {
return getInstructionsByEnumValue().drop_front(getNumFixedInstructions());
ArrayRef<const CodeGenInstruction *> getTargetInstructions() const {
return getInstructions().drop_front(getNumFixedInstructions());
}

ArrayRef<const CodeGenInstruction *>
getTargetPseudoInstructionsByEnumValue() const {
return getTargetInstructionsByEnumValue().take_front(NumPseudoInstructions);
ArrayRef<const CodeGenInstruction *> getTargetPseudoInstructions() const {
return getTargetInstructions().take_front(NumPseudoInstructions);
}

ArrayRef<const CodeGenInstruction *>
getTargetNonPseudoInstructionsByEnumValue() const {
return getTargetInstructionsByEnumValue().drop_front(NumPseudoInstructions);
ArrayRef<const CodeGenInstruction *> getTargetNonPseudoInstructions() const {
return getTargetInstructions().drop_front(NumPseudoInstructions);
}

/// Return the integer enum value corresponding to this instruction record.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,7 @@ void InstructionOpcodeMatcher::initOpcodeValuesMap(
const CodeGenTarget &Target) {
OpcodeValues.clear();

for (const CodeGenInstruction *I : Target.getInstructionsByEnumValue())
for (const CodeGenInstruction *I : Target.getInstructions())
OpcodeValues[I] = Target.getInstrIntValue(I->TheDef);
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/TableGen/Common/VarLenCodeEmitterGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void VarLenInst::buildRec(const DagInit *DI) {
void VarLenCodeEmitterGen::run(raw_ostream &OS) {
CodeGenTarget Target(Records);

auto NumberedInstructions = Target.getInstructionsByEnumValue();
auto NumberedInstructions = Target.getInstructions();

for (const CodeGenInstruction *CGI : NumberedInstructions) {
const Record *R = CGI->TheDef;
Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/TableGen/DecoderEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2572,7 +2572,7 @@ namespace {
if (HwModeNames.empty())
HwModeNames.push_back("");

const auto &NumberedInstructions = Target.getInstructionsByEnumValue();
const auto &NumberedInstructions = Target.getInstructions();
NumberedEncodings.reserve(NumberedInstructions.size());
for (const auto &NumberedInstruction : NumberedInstructions) {
const Record *InstDef = NumberedInstruction->TheDef;
Expand Down
5 changes: 2 additions & 3 deletions llvm/utils/TableGen/DisassemblerEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ static void emitDisassembler(const RecordKeeper &Records, raw_ostream &OS) {
if (Target.getName() == "X86") {
DisassemblerTables Tables;

for (const auto &[Idx, NumberedInst] :
enumerate(Target.getInstructionsByEnumValue()))
for (const auto &[Idx, NumberedInst] : enumerate(Target.getInstructions()))
RecognizableInstr::processInstr(Tables, *NumberedInst, Idx);

if (Tables.hasConflicts()) {
Expand All @@ -120,7 +119,7 @@ static void emitDisassembler(const RecordKeeper &Records, raw_ostream &OS) {
// below (which depends on a Size table-gen Record), and also uses a custom
// disassembler.
if (Target.getName() == "WebAssembly") {
emitWebAssemblyDisassemblerTables(OS, Target.getInstructionsByEnumValue());
emitWebAssemblyDisassemblerTables(OS, Target.getInstructions());
return;
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/TableGen/InstrDocsEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static void EmitInstrDocs(const RecordKeeper &RK, raw_ostream &OS) {
writeTitle(Title, OS);
OS << "\n";

for (const CodeGenInstruction *II : Target.getInstructionsByEnumValue()) {
for (const CodeGenInstruction *II : Target.getInstructions()) {
const Record *Inst = II->TheDef;

// Don't print the target-independent instructions.
Expand Down
10 changes: 5 additions & 5 deletions llvm/utils/TableGen/InstrInfoEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ InstrInfoEmitter::CollectOperandInfo(OperandInfoListTy &OperandInfoList,
OperandInfoMapTy &OperandInfoMap) {
const CodeGenTarget &Target = CDP.getTargetInfo();
unsigned Offset = 0;
for (const CodeGenInstruction *Inst : Target.getInstructionsByEnumValue()) {
for (const CodeGenInstruction *Inst : Target.getInstructions()) {
OperandInfoTy OperandInfo = GetOperandInfo(*Inst);
if (OperandInfoMap.try_emplace(OperandInfo, Offset).second) {
OperandInfoList.push_back(OperandInfo);
Expand Down Expand Up @@ -645,7 +645,7 @@ void InstrInfoEmitter::emitFeatureVerifier(raw_ostream &OS,
Target.getName(), "", "computeAvailableFeatures", SubtargetFeatures, OS);

std::vector<std::vector<const Record *>> FeatureBitsets;
for (const CodeGenInstruction *Inst : Target.getInstructionsByEnumValue()) {
for (const CodeGenInstruction *Inst : Target.getInstructions()) {
FeatureBitsets.emplace_back();
for (const Record *Predicate :
Inst->TheDef->getValueAsListOfDefs("Predicates")) {
Expand Down Expand Up @@ -696,7 +696,7 @@ void InstrInfoEmitter::emitFeatureVerifier(raw_ostream &OS,
<< " static constexpr " << getMinimalTypeForRange(FeatureBitsets.size())
<< " RequiredFeaturesRefs[] = {\n";
unsigned InstIdx = 0;
for (const CodeGenInstruction *Inst : Target.getInstructionsByEnumValue()) {
for (const CodeGenInstruction *Inst : Target.getInstructions()) {
OS << " CEFBS";
unsigned NumPredicates = 0;
for (const Record *Predicate :
Expand Down Expand Up @@ -818,7 +818,7 @@ void InstrInfoEmitter::run(raw_ostream &OS) {

const CodeGenTarget &Target = CDP.getTargetInfo();
ArrayRef<const CodeGenInstruction *> NumberedInstructions =
Target.getInstructionsByEnumValue();
Target.getInstructions();

emitEnums(OS, NumberedInstructions);

Expand Down Expand Up @@ -1058,7 +1058,7 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
OS << "#endif // GET_INSTRINFO_CTOR_DTOR\n\n";

ArrayRef<const CodeGenInstruction *> TargetInstructions =
Target.getTargetInstructionsByEnumValue();
Target.getTargetInstructions();

if (HasUseNamedOperandTable) {
Timer.startTimer("Emit operand name mappings");
Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/TableGen/X86FoldTablesEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ void X86FoldTablesEmitter::run(raw_ostream &OS) {
std::map<uint8_t, std::vector<const CodeGenInstruction *>> RegInsts;

ArrayRef<const CodeGenInstruction *> NumberedInstructions =
Target.getInstructionsByEnumValue();
Target.getInstructions();

for (const CodeGenInstruction *Inst : NumberedInstructions) {
const Record *Rec = Inst->TheDef;
Expand Down
3 changes: 1 addition & 2 deletions llvm/utils/TableGen/X86InstrMappingEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,7 @@ void X86InstrMappingEmitter::emitSSE2AVXTable(
void X86InstrMappingEmitter::run(raw_ostream &OS) {
emitSourceFileHeader("X86 instruction mapping", OS);

ArrayRef<const CodeGenInstruction *> Insts =
Target.getInstructionsByEnumValue();
ArrayRef<const CodeGenInstruction *> Insts = Target.getInstructions();
printClassDef(OS);
emitCompressEVEXTable(Insts, OS);
emitNFTransformTable(Insts, OS);
Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/TableGen/X86MnemonicTables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void X86MnemonicTablesEmitter::run(raw_ostream &OS) {
// Hold all instructions grouped by mnemonic
StringMap<SmallVector<const CodeGenInstruction *, 0>> MnemonicToCGInstrMap;

for (const CodeGenInstruction *I : Target.getInstructionsByEnumValue()) {
for (const CodeGenInstruction *I : Target.getInstructions()) {
const Record *Def = I->TheDef;
// Filter non-X86 instructions.
if (!Def->isSubClassOf("X86Inst"))
Expand Down
Loading