Skip to content

Commit

Permalink
Make non-vararg dialect ops getter const
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Symalla authored and tsymalla-AMD committed Jul 11, 2024
1 parent 9806a24 commit 8ae2128
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 59 deletions.
13 changes: 8 additions & 5 deletions lib/TableGen/Operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,17 @@ unsigned OperationBase::getNumFullArguments() const {
void OperationBase::emitArgumentAccessorDeclarations(llvm::raw_ostream &out,
FmtContext &fmt) const {
for (const auto &arg : m_arguments) {
std::string defaultDeclaration = "$0 get$1();";
if (!arg.type->isVarArgList() && !arg.type->isImmutable()) {
const bool isVarArg = arg.type->isVarArgList();
std::string defaultDeclaration = "$0 get$1() $2;";

if (!isVarArg && !arg.type->isImmutable()) {
defaultDeclaration += R"(
void set$1($0 $2);
void set$1($0 $3);
)";
}

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

Expand Down Expand Up @@ -196,9 +198,10 @@ void AccessorBuilder::emitGetterDefinition() const {
}

m_fmt.addSubst("fromLlvm", fromLlvm);
m_fmt.addSubst("const", !m_arg.type->isVarArgList() ? "const" : "");

m_os << tgfmt(R"(
$cppType $_op::get$Name() {
$cppType $_op::get$Name() $const {
return $fromLlvm;
})",
&m_fmt);
Expand Down
54 changes: 27 additions & 27 deletions test/example/generated/ExampleDialect.cpp.inc
Original file line number Diff line number Diff line change
Expand Up @@ -320,21 +320,21 @@ return true;
}


::llvm::Value * StreamReduceOp::getPtr() {
::llvm::Value * StreamReduceOp::getPtr() const {
return getArgOperand(0);
}

void StreamReduceOp::setPtr(::llvm::Value * ptr) {
setArgOperand(0, ptr);
}
::llvm::Value * StreamReduceOp::getCount() {
::llvm::Value * StreamReduceOp::getCount() const {
return getArgOperand(1);
}

void StreamReduceOp::setCount(::llvm::Value * count) {
setArgOperand(1, count);
}
::llvm::Value * StreamReduceOp::getInitial() {
::llvm::Value * StreamReduceOp::getInitial() const {
return getArgOperand(2);
}

Expand Down Expand Up @@ -439,21 +439,21 @@ uint32_t const extra = getExtra();
}


::llvm::Value * Add32Op::getLhs() {
::llvm::Value * Add32Op::getLhs() const {
return getArgOperand(0);
}

void Add32Op::setLhs(::llvm::Value * lhs) {
setArgOperand(0, lhs);
}
::llvm::Value * Add32Op::getRhs() {
::llvm::Value * Add32Op::getRhs() const {
return getArgOperand(1);
}

void Add32Op::setRhs(::llvm::Value * rhs) {
setArgOperand(1, rhs);
}
uint32_t Add32Op::getExtra() {
uint32_t Add32Op::getExtra() const {
return ::llvm::cast<::llvm::ConstantInt>(getArgOperand(2))->getZExtValue() ;
}

Expand Down Expand Up @@ -541,14 +541,14 @@ rhs
}


::llvm::Value * CombineOp::getLhs() {
::llvm::Value * CombineOp::getLhs() const {
return getArgOperand(0);
}

void CombineOp::setLhs(::llvm::Value * lhs) {
setArgOperand(0, lhs);
}
::llvm::Value * CombineOp::getRhs() {
::llvm::Value * CombineOp::getRhs() const {
return getArgOperand(1);
}

Expand Down Expand Up @@ -645,14 +645,14 @@ index
}


::llvm::Value * ExtractElementOp::getVector() {
::llvm::Value * ExtractElementOp::getVector() const {
return getArgOperand(0);
}

void ExtractElementOp::setVector(::llvm::Value * vector) {
setArgOperand(0, vector);
}
::llvm::Value * ExtractElementOp::getIndex() {
::llvm::Value * ExtractElementOp::getIndex() const {
return getArgOperand(1);
}

Expand Down Expand Up @@ -822,7 +822,7 @@ source
}


::llvm::Value * FromFixedVectorOp::getSource() {
::llvm::Value * FromFixedVectorOp::getSource() const {
return getArgOperand(0);
}

Expand Down Expand Up @@ -982,7 +982,7 @@ source
}


::llvm::Value * IExtOp::getSource() {
::llvm::Value * IExtOp::getSource() const {
return getArgOperand(0);
}

Expand Down Expand Up @@ -1080,7 +1080,7 @@ source
}


::llvm::Value * ITruncOp::getSource() {
::llvm::Value * ITruncOp::getSource() const {
return getArgOperand(0);
}

Expand Down Expand Up @@ -1154,7 +1154,7 @@ source
}


bool ImmutableOp::getVal() {
bool ImmutableOp::getVal() const {
return ::llvm::cast<::llvm::ConstantInt>(getArgOperand(0))->getZExtValue() ;
}

Expand Down Expand Up @@ -1257,21 +1257,21 @@ index
}


::llvm::Value * InsertElementOp::getVector() {
::llvm::Value * InsertElementOp::getVector() const {
return getArgOperand(0);
}

void InsertElementOp::setVector(::llvm::Value * vector) {
setArgOperand(0, vector);
}
::llvm::Value * InsertElementOp::getValue() {
::llvm::Value * InsertElementOp::getValue() const {
return getArgOperand(1);
}

void InsertElementOp::setValue(::llvm::Value * value) {
setArgOperand(1, value);
}
::llvm::Value * InsertElementOp::getIndex() {
::llvm::Value * InsertElementOp::getIndex() const {
return getArgOperand(2);
}

Expand Down Expand Up @@ -1348,14 +1348,14 @@ instName_0
}


::llvm::Value * InstNameConflictDoubleOp::getInstName() {
::llvm::Value * InstNameConflictDoubleOp::getInstName() const {
return getArgOperand(0);
}

void InstNameConflictDoubleOp::setInstName(::llvm::Value * instName) {
setArgOperand(0, instName);
}
::llvm::Value * InstNameConflictDoubleOp::getInstName_0() {
::llvm::Value * InstNameConflictDoubleOp::getInstName_0() const {
return getArgOperand(1);
}

Expand Down Expand Up @@ -1429,7 +1429,7 @@ instName
}


::llvm::Value * InstNameConflictOp::getInstName() {
::llvm::Value * InstNameConflictOp::getInstName() const {
return getArgOperand(0);
}

Expand Down Expand Up @@ -1497,7 +1497,7 @@ instName
}


::llvm::iterator_range<::llvm::User::value_op_iterator> InstNameConflictVarargsOp::getInstName_0() {
::llvm::iterator_range<::llvm::User::value_op_iterator> InstNameConflictVarargsOp::getInstName_0() {
return ::llvm::make_range(
value_op_iterator(arg_begin() + 0),
value_op_iterator(arg_end()));
Expand Down Expand Up @@ -1673,7 +1673,7 @@ data
}


::llvm::Value * SetWriteOp::getData() {
::llvm::Value * SetWriteOp::getData() const {
return getArgOperand(0);
}

Expand Down Expand Up @@ -1746,7 +1746,7 @@ data
}


::llvm::Type * SizeOfOp::getSizeofType() {
::llvm::Type * SizeOfOp::getSizeofType() const {
return getArgOperand(0)->getType();
}

Expand Down Expand Up @@ -2096,7 +2096,7 @@ initial
}


::llvm::StringRef StringAttrOp::getVal() {
::llvm::StringRef StringAttrOp::getVal() const {
return ::llvm::cast<::llvm::ConstantDataArray>(::llvm::cast<::llvm::GlobalVariable>(getArgOperand(0))->getInitializer())->getAsString() ;
}

Expand Down Expand Up @@ -2155,7 +2155,7 @@ data
}


::llvm::Value * WriteOp::getData() {
::llvm::Value * WriteOp::getData() const {
return getArgOperand(0);
}

Expand Down Expand Up @@ -2220,14 +2220,14 @@ data
}


::llvm::Value * WriteVarArgOp::getData() {
::llvm::Value * WriteVarArgOp::getData() const {
return getArgOperand(0);
}

void WriteVarArgOp::setData(::llvm::Value * data) {
setArgOperand(0, data);
}
::llvm::iterator_range<::llvm::User::value_op_iterator> WriteVarArgOp::getArgs() {
::llvm::iterator_range<::llvm::User::value_op_iterator> WriteVarArgOp::getArgs() {
return ::llvm::make_range(
value_op_iterator(arg_begin() + 1),
value_op_iterator(arg_end()));
Expand Down
Loading

0 comments on commit 8ae2128

Please sign in to comment.