Skip to content

Commit

Permalink
Use a simple SmallVector
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Symalla committed Dec 3, 2024
1 parent d838ec7 commit deaefdb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions lib/TableGen/Operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "llvm-dialects/TableGen/Format.h"

#include "llvm/TableGen/Record.h"
#include <map>

using namespace llvm;
using namespace llvm_dialects;
Expand Down Expand Up @@ -160,7 +159,8 @@ unsigned OperationBase::getNumFullArguments() const {

void OperationBase::emitArgumentAccessorDeclarations(llvm::raw_ostream &out,
FmtContext &fmt) const {
std::map<std::string, uint32_t> argIndexMap;
llvm::SmallVector<std::string> argNames;

unsigned numSuperclassArgs = 0;
if (m_superclass)
numSuperclassArgs = m_superclass->getNumFullArguments();
Expand All @@ -172,7 +172,7 @@ void OperationBase::emitArgumentAccessorDeclarations(llvm::raw_ostream &out,
const bool isVarArg = arg.type->isVarArgList();

if (!isVarArg)
argIndexMap[capitalizedArgName] = numSuperclassArgs + index;
argNames.push_back(capitalizedArgName);

std::string defaultDeclaration = "$0 get$1() $2;";

Expand All @@ -194,10 +194,10 @@ void OperationBase::emitArgumentAccessorDeclarations(llvm::raw_ostream &out,
capitalizedArgName, !isVarArg ? "const" : "", arg.name);
}

if (!argIndexMap.empty()) {
if (!argNames.empty()) {
out << "enum class ArgumentIndex: uint32_t {\n";
for (auto &[argName, index] : argIndexMap)
out << tgfmt("$0 = $1,\n", &fmt, argName, index);
for (const auto &[index, argName] : llvm::enumerate(argNames))
out << tgfmt("$0 = $1,\n", &fmt, argName, numSuperclassArgs + index);
out << "};";
}
}
Expand Down
10 changes: 5 additions & 5 deletions test/example/generated/ExampleDialect.h.inc
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ uint32_t getNumElements() const;
::llvm::Value * getInitial() const;
void setInitial(::llvm::Value * initial);
enum class ArgumentIndex: uint32_t {
Ptr = 0,
Count = 1,
Initial = 2,
Ptr = 0,
};
};

Expand All @@ -133,9 +133,9 @@ bool verifier(::llvm::raw_ostream &errs);
uint32_t getExtra() const;
void setExtra(uint32_t extra);
enum class ArgumentIndex: uint32_t {
Extra = 2,
Lhs = 0,
Rhs = 1,
Extra = 2,
};
::llvm::Value * getResult();

Expand Down Expand Up @@ -190,8 +190,8 @@ bool verifier(::llvm::raw_ostream &errs);
::llvm::Value * getIndex() const;
void setIndex(::llvm::Value * index);
enum class ArgumentIndex: uint32_t {
Index = 1,
Vector = 0,
Index = 1,
};
::llvm::Value * getResult();

Expand Down Expand Up @@ -338,9 +338,9 @@ bool verifier(::llvm::raw_ostream &errs);
::llvm::Value * getIndex() const;
void setIndex(::llvm::Value * index);
enum class ArgumentIndex: uint32_t {
Index = 2,
Value = 1,
Vector = 0,
Value = 1,
Index = 2,
};
::llvm::Value * getResult();

Expand Down

0 comments on commit deaefdb

Please sign in to comment.