Skip to content
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

Add argument index enum per op #113

Merged
merged 4 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
23 changes: 21 additions & 2 deletions lib/TableGen/Operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,20 @@ unsigned OperationBase::getNumFullArguments() const {

void OperationBase::emitArgumentAccessorDeclarations(llvm::raw_ostream &out,
FmtContext &fmt) const {
for (const auto &arg : m_arguments) {
llvm::SmallVector<std::string> argNames;

unsigned numSuperclassArgs = 0;
if (m_superclass)
numSuperclassArgs = m_superclass->getNumFullArguments();

for (const auto &[index, arg] : llvm::enumerate(m_arguments)) {
tsymalla-AMD marked this conversation as resolved.
Show resolved Hide resolved
const std::string capitalizedArgName =
convertToCamelFromSnakeCase(arg.name, true);

const bool isVarArg = arg.type->isVarArgList();

argNames.push_back(capitalizedArgName + (isVarArg ? "Start" : ""));

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

if (!arg.type->isImmutable()) {
Expand All @@ -178,7 +190,14 @@ void OperationBase::emitArgumentAccessorDeclarations(llvm::raw_ostream &out,
}

out << tgfmt(defaultDeclaration, &fmt, arg.type->getGetterCppType(),
convertToCamelFromSnakeCase(arg.name, true), !isVarArg ? "const" : "", arg.name);
capitalizedArgName, !isVarArg ? "const" : "", arg.name);
}

if (!argNames.empty()) {
out << "enum class ArgumentIndex: uint32_t {\n";
for (const auto &[index, argName] : llvm::enumerate(argNames))
out << tgfmt("$0 = $1,\n", &fmt, argName, numSuperclassArgs + index);
out << "};";
}
}

Expand Down
78 changes: 61 additions & 17 deletions test/example/generated/ExampleDialect.h.inc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ uint32_t getNumElements() const;
void setCount(::llvm::Value * count);
::llvm::Value * getInitial() const;
void setInitial(::llvm::Value * initial);

enum class ArgumentIndex: uint32_t {
Ptr = 0,
Count = 1,
Initial = 2,
};
};

class Add32Op : public ::llvm::CallInst {
Expand All @@ -128,7 +132,11 @@ bool verifier(::llvm::raw_ostream &errs);
void setRhs(::llvm::Value * rhs);
uint32_t getExtra() const;
void setExtra(uint32_t extra);

enum class ArgumentIndex: uint32_t {
Lhs = 0,
Rhs = 1,
Extra = 2,
};
::llvm::Value * getResult();


Expand All @@ -153,7 +161,10 @@ bool verifier(::llvm::raw_ostream &errs);
void setLhs(::llvm::Value * lhs);
::llvm::Value * getRhs() const;
void setRhs(::llvm::Value * rhs);

enum class ArgumentIndex: uint32_t {
Lhs = 0,
Rhs = 1,
};
::llvm::Value * getResult();


Expand All @@ -178,7 +189,10 @@ bool verifier(::llvm::raw_ostream &errs);
void setVector(::llvm::Value * vector);
::llvm::Value * getIndex() const;
void setIndex(::llvm::Value * index);

enum class ArgumentIndex: uint32_t {
Vector = 0,
Index = 1,
};
::llvm::Value * getResult();


Expand All @@ -201,7 +215,9 @@ bool verifier(::llvm::raw_ostream &errs);

::llvm::Value * getSource() const;
void setSource(::llvm::Value * source);

enum class ArgumentIndex: uint32_t {
Source = 0,
};
::llvm::Value * getResult();


Expand Down Expand Up @@ -245,7 +261,9 @@ bool verifier(::llvm::raw_ostream &errs);

::llvm::Value * getSource() const;
void setSource(::llvm::Value * source);

enum class ArgumentIndex: uint32_t {
Source = 0,
};
::llvm::Value * getResult();


Expand All @@ -268,7 +286,9 @@ bool verifier(::llvm::raw_ostream &errs);

::llvm::Value * getSource() const;
void setSource(::llvm::Value * source);

enum class ArgumentIndex: uint32_t {
Source = 0,
};
::llvm::Value * getResult();


Expand All @@ -289,7 +309,9 @@ bool verifier(::llvm::raw_ostream &errs);

bool verifier(::llvm::raw_ostream &errs);

bool getVal() const;
bool getVal() const;enum class ArgumentIndex: uint32_t {
Val = 0,
};


};
Expand All @@ -315,7 +337,11 @@ bool verifier(::llvm::raw_ostream &errs);
void setValue(::llvm::Value * value);
::llvm::Value * getIndex() const;
void setIndex(::llvm::Value * index);

enum class ArgumentIndex: uint32_t {
Vector = 0,
Value = 1,
Index = 2,
};
::llvm::Value * getResult();


Expand All @@ -340,7 +366,10 @@ bool verifier(::llvm::raw_ostream &errs);
void setInstName(::llvm::Value * instName);
::llvm::Value * getInstName_0() const;
void setInstName_0(::llvm::Value * instName_0);

enum class ArgumentIndex: uint32_t {
InstName = 0,
InstName_0 = 1,
};
::llvm::Value * getResult();


Expand All @@ -363,7 +392,9 @@ bool verifier(::llvm::raw_ostream &errs);

::llvm::Value * getInstName() const;
void setInstName(::llvm::Value * instName);

enum class ArgumentIndex: uint32_t {
InstName = 0,
};
::llvm::Value * getResult();


Expand All @@ -388,7 +419,9 @@ bool verifier(::llvm::raw_ostream &errs);
/// Returns a new op with the same arguments and a new tail argument list.
/// The object on which this is called will be replaced and erased.
InstNameConflictVarargsOp *replaceInstName_0(::llvm::ArrayRef<Value *>);

enum class ArgumentIndex: uint32_t {
InstName_0Start = 0,
};
::llvm::Value * getResult();


Expand Down Expand Up @@ -453,7 +486,9 @@ bool verifier(::llvm::raw_ostream &errs);

::llvm::Value * getData() const;
void setData(::llvm::Value * data);

enum class ArgumentIndex: uint32_t {
Data = 0,
};


};
Expand All @@ -475,7 +510,9 @@ bool verifier(::llvm::raw_ostream &errs);

::llvm::Type * getSizeofType() const;
void setSizeofType(::llvm::Type * sizeof_type);

enum class ArgumentIndex: uint32_t {
SizeofType = 0,
};
::llvm::Value * getResult();


Expand Down Expand Up @@ -559,7 +596,9 @@ bool verifier(::llvm::raw_ostream &errs);

bool verifier(::llvm::raw_ostream &errs);

::llvm::StringRef getVal() const;
::llvm::StringRef getVal() const;enum class ArgumentIndex: uint32_t {
Val = 0,
};


};
Expand All @@ -581,7 +620,9 @@ bool verifier(::llvm::raw_ostream &errs);

::llvm::Value * getData() const;
void setData(::llvm::Value * data);

enum class ArgumentIndex: uint32_t {
Data = 0,
};


};
Expand All @@ -607,7 +648,10 @@ bool verifier(::llvm::raw_ostream &errs);
/// Returns a new op with the same arguments and a new tail argument list.
/// The object on which this is called will be replaced and erased.
WriteVarArgOp *replaceArgs(::llvm::ArrayRef<Value *>);

enum class ArgumentIndex: uint32_t {
Data = 0,
ArgsStart = 1,
};


};
Expand Down