Skip to content

Commit

Permalink
Add const getter for non-vararg dialect ops
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Symalla committed Jul 9, 2024
1 parent 9806a24 commit 7292254
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 2 deletions.
4 changes: 3 additions & 1 deletion example/ExampleMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ void createFunctionExample(Module &module, const Twine &name) {
Value *x2 = b.create<xd::Add32Op>(x1, sizeOf32, 11);
Value *x3 = b.create<xd::CombineOp>(x2, x1);
Value *x4 = b.create<xd::IExtOp>(b.getInt64Ty(), x3);
b.create<xd::WriteOp>(x4);
[[maybe_unused]] const xd::WriteOp *x5 = b.create<xd::WriteOp>(x4);
static_assert(!std::is_invocable_v<decltype(&xd::WriteOp::setData),
xd::WriteOp *, decltype(x5)>);

cast<xd::SizeOfOp>(sizeOf)->setSizeofType(b.getDoubleTy());
cast<xd::Add32Op>(x2)->setExtra(7);
Expand Down
16 changes: 15 additions & 1 deletion lib/TableGen/Operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,17 @@ 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()) {

if (!arg.type->isVarArgList()) {
defaultDeclaration += R"(
$0 get$1() const;
)";

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

out << tgfmt(defaultDeclaration, &fmt, arg.type->getGetterCppType(),
Expand Down Expand Up @@ -202,6 +209,13 @@ void AccessorBuilder::emitGetterDefinition() const {
return $fromLlvm;
})",
&m_fmt);
if (!m_arg.type->isVarArgList()) {
m_os << tgfmt(R"(
$cppType $_op::get$Name() const {
return $fromLlvm;
})",
&m_fmt);
}
}

void AccessorBuilder::emitSetterDefinition() const {
Expand Down
75 changes: 75 additions & 0 deletions test/example/generated/ExampleDialect.cpp.inc
Original file line number Diff line number Diff line change
Expand Up @@ -323,20 +323,29 @@ return true;
::llvm::Value * StreamReduceOp::getPtr() {
return getArgOperand(0);
}
::llvm::Value * StreamReduceOp::getPtr() const {
return getArgOperand(0);
}

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

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

void StreamReduceOp::setInitial(::llvm::Value * initial) {
setArgOperand(2, initial);
Expand Down Expand Up @@ -442,20 +451,29 @@ uint32_t const extra = getExtra();
::llvm::Value * Add32Op::getLhs() {
return getArgOperand(0);
}
::llvm::Value * Add32Op::getLhs() const {
return getArgOperand(0);
}

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

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

void Add32Op::setExtra(uint32_t extra) {
setArgOperand(2, ::llvm::ConstantInt::get(::llvm::IntegerType::get(getContext(), 32), extra) );
Expand Down Expand Up @@ -544,13 +562,19 @@ rhs
::llvm::Value * CombineOp::getLhs() {
return getArgOperand(0);
}
::llvm::Value * CombineOp::getLhs() const {
return getArgOperand(0);
}

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

void CombineOp::setRhs(::llvm::Value * rhs) {
setArgOperand(1, rhs);
Expand Down Expand Up @@ -648,13 +672,19 @@ index
::llvm::Value * ExtractElementOp::getVector() {
return getArgOperand(0);
}
::llvm::Value * ExtractElementOp::getVector() const {
return getArgOperand(0);
}

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

void ExtractElementOp::setIndex(::llvm::Value * index) {
setArgOperand(1, index);
Expand Down Expand Up @@ -825,6 +855,9 @@ source
::llvm::Value * FromFixedVectorOp::getSource() {
return getArgOperand(0);
}
::llvm::Value * FromFixedVectorOp::getSource() const {
return getArgOperand(0);
}

void FromFixedVectorOp::setSource(::llvm::Value * source) {
setArgOperand(0, source);
Expand Down Expand Up @@ -985,6 +1018,9 @@ source
::llvm::Value * IExtOp::getSource() {
return getArgOperand(0);
}
::llvm::Value * IExtOp::getSource() const {
return getArgOperand(0);
}

void IExtOp::setSource(::llvm::Value * source) {
setArgOperand(0, source);
Expand Down Expand Up @@ -1083,6 +1119,9 @@ source
::llvm::Value * ITruncOp::getSource() {
return getArgOperand(0);
}
::llvm::Value * ITruncOp::getSource() const {
return getArgOperand(0);
}

void ITruncOp::setSource(::llvm::Value * source) {
setArgOperand(0, source);
Expand Down Expand Up @@ -1157,6 +1196,9 @@ source
bool ImmutableOp::getVal() {
return ::llvm::cast<::llvm::ConstantInt>(getArgOperand(0))->getZExtValue() ;
}
bool ImmutableOp::getVal() const {
return ::llvm::cast<::llvm::ConstantInt>(getArgOperand(0))->getZExtValue() ;
}



Expand Down Expand Up @@ -1260,20 +1302,29 @@ index
::llvm::Value * InsertElementOp::getVector() {
return getArgOperand(0);
}
::llvm::Value * InsertElementOp::getVector() const {
return getArgOperand(0);
}

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

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

void InsertElementOp::setIndex(::llvm::Value * index) {
setArgOperand(2, index);
Expand Down Expand Up @@ -1351,13 +1402,19 @@ instName_0
::llvm::Value * InstNameConflictDoubleOp::getInstName() {
return getArgOperand(0);
}
::llvm::Value * InstNameConflictDoubleOp::getInstName() const {
return getArgOperand(0);
}

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

void InstNameConflictDoubleOp::setInstName_0(::llvm::Value * instName_0) {
setArgOperand(1, instName_0);
Expand Down Expand Up @@ -1432,6 +1489,9 @@ instName
::llvm::Value * InstNameConflictOp::getInstName() {
return getArgOperand(0);
}
::llvm::Value * InstNameConflictOp::getInstName() const {
return getArgOperand(0);
}

void InstNameConflictOp::setInstName(::llvm::Value * instName) {
setArgOperand(0, instName);
Expand Down Expand Up @@ -1676,6 +1736,9 @@ data
::llvm::Value * SetWriteOp::getData() {
return getArgOperand(0);
}
::llvm::Value * SetWriteOp::getData() const {
return getArgOperand(0);
}

void SetWriteOp::setData(::llvm::Value * data) {
setArgOperand(0, data);
Expand Down Expand Up @@ -1749,6 +1812,9 @@ data
::llvm::Type * SizeOfOp::getSizeofType() {
return getArgOperand(0)->getType();
}
::llvm::Type * SizeOfOp::getSizeofType() const {
return getArgOperand(0)->getType();
}

void SizeOfOp::setSizeofType(::llvm::Type * sizeof_type) {
setArgOperand(0, llvm::PoisonValue::get(sizeof_type));
Expand Down Expand Up @@ -2099,6 +2165,9 @@ initial
::llvm::StringRef StringAttrOp::getVal() {
return ::llvm::cast<::llvm::ConstantDataArray>(::llvm::cast<::llvm::GlobalVariable>(getArgOperand(0))->getInitializer())->getAsString() ;
}
::llvm::StringRef StringAttrOp::getVal() const {
return ::llvm::cast<::llvm::ConstantDataArray>(::llvm::cast<::llvm::GlobalVariable>(getArgOperand(0))->getInitializer())->getAsString() ;
}



Expand Down Expand Up @@ -2158,6 +2227,9 @@ data
::llvm::Value * WriteOp::getData() {
return getArgOperand(0);
}
::llvm::Value * WriteOp::getData() const {
return getArgOperand(0);
}

void WriteOp::setData(::llvm::Value * data) {
setArgOperand(0, data);
Expand Down Expand Up @@ -2223,6 +2295,9 @@ data
::llvm::Value * WriteVarArgOp::getData() {
return getArgOperand(0);
}
::llvm::Value * WriteVarArgOp::getData() const {
return getArgOperand(0);
}

void WriteVarArgOp::setData(::llvm::Value * data) {
setArgOperand(0, data);
Expand Down
Loading

0 comments on commit 7292254

Please sign in to comment.