From 72922547b65fab46385c65bdb12a1cdc7a8ac796 Mon Sep 17 00:00:00 2001 From: Thomas Symalla Date: Tue, 9 Jul 2024 10:35:26 +0200 Subject: [PATCH] Add const getter for non-vararg dialect ops --- example/ExampleMain.cpp | 4 +- lib/TableGen/Operations.cpp | 16 +++- test/example/generated/ExampleDialect.cpp.inc | 75 +++++++++++++++++++ test/example/generated/ExampleDialect.h.inc | 50 +++++++++++++ 4 files changed, 143 insertions(+), 2 deletions(-) diff --git a/example/ExampleMain.cpp b/example/ExampleMain.cpp index bc20d42..c6e3a30 100644 --- a/example/ExampleMain.cpp +++ b/example/ExampleMain.cpp @@ -91,7 +91,9 @@ void createFunctionExample(Module &module, const Twine &name) { Value *x2 = b.create(x1, sizeOf32, 11); Value *x3 = b.create(x2, x1); Value *x4 = b.create(b.getInt64Ty(), x3); - b.create(x4); + [[maybe_unused]] const xd::WriteOp *x5 = b.create(x4); + static_assert(!std::is_invocable_v); cast(sizeOf)->setSizeofType(b.getDoubleTy()); cast(x2)->setExtra(7); diff --git a/lib/TableGen/Operations.cpp b/lib/TableGen/Operations.cpp index 5463bec..3f9f5ad 100644 --- a/lib/TableGen/Operations.cpp +++ b/lib/TableGen/Operations.cpp @@ -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(), @@ -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 { diff --git a/test/example/generated/ExampleDialect.cpp.inc b/test/example/generated/ExampleDialect.cpp.inc index 13f57dd..276e830 100644 --- a/test/example/generated/ExampleDialect.cpp.inc +++ b/test/example/generated/ExampleDialect.cpp.inc @@ -323,6 +323,9 @@ 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); @@ -330,6 +333,9 @@ return true; ::llvm::Value * StreamReduceOp::getCount() { return getArgOperand(1); } + ::llvm::Value * StreamReduceOp::getCount() const { + return getArgOperand(1); + } void StreamReduceOp::setCount(::llvm::Value * count) { setArgOperand(1, count); @@ -337,6 +343,9 @@ return true; ::llvm::Value * StreamReduceOp::getInitial() { return getArgOperand(2); } + ::llvm::Value * StreamReduceOp::getInitial() const { + return getArgOperand(2); + } void StreamReduceOp::setInitial(::llvm::Value * initial) { setArgOperand(2, initial); @@ -442,6 +451,9 @@ 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); @@ -449,6 +461,9 @@ uint32_t const extra = getExtra(); ::llvm::Value * Add32Op::getRhs() { return getArgOperand(1); } + ::llvm::Value * Add32Op::getRhs() const { + return getArgOperand(1); + } void Add32Op::setRhs(::llvm::Value * rhs) { setArgOperand(1, rhs); @@ -456,6 +471,9 @@ uint32_t const extra = getExtra(); 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) ); @@ -544,6 +562,9 @@ 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); @@ -551,6 +572,9 @@ rhs ::llvm::Value * CombineOp::getRhs() { return getArgOperand(1); } + ::llvm::Value * CombineOp::getRhs() const { + return getArgOperand(1); + } void CombineOp::setRhs(::llvm::Value * rhs) { setArgOperand(1, rhs); @@ -648,6 +672,9 @@ 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); @@ -655,6 +682,9 @@ index ::llvm::Value * ExtractElementOp::getIndex() { return getArgOperand(1); } + ::llvm::Value * ExtractElementOp::getIndex() const { + return getArgOperand(1); + } void ExtractElementOp::setIndex(::llvm::Value * index) { setArgOperand(1, index); @@ -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); @@ -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); @@ -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); @@ -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() ; + } @@ -1260,6 +1302,9 @@ 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); @@ -1267,6 +1312,9 @@ index ::llvm::Value * InsertElementOp::getValue() { return getArgOperand(1); } + ::llvm::Value * InsertElementOp::getValue() const { + return getArgOperand(1); + } void InsertElementOp::setValue(::llvm::Value * value) { setArgOperand(1, value); @@ -1274,6 +1322,9 @@ index ::llvm::Value * InsertElementOp::getIndex() { return getArgOperand(2); } + ::llvm::Value * InsertElementOp::getIndex() const { + return getArgOperand(2); + } void InsertElementOp::setIndex(::llvm::Value * index) { setArgOperand(2, index); @@ -1351,6 +1402,9 @@ 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); @@ -1358,6 +1412,9 @@ instName_0 ::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); @@ -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); @@ -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); @@ -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)); @@ -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() ; + } @@ -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); @@ -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); diff --git a/test/example/generated/ExampleDialect.h.inc b/test/example/generated/ExampleDialect.h.inc index 1918a5e..aa3e2ac 100644 --- a/test/example/generated/ExampleDialect.h.inc +++ b/test/example/generated/ExampleDialect.h.inc @@ -99,10 +99,16 @@ uint32_t getNumElements() const; classof(::llvm::cast<::llvm::CallInst>(v)); } ::llvm::Value * getPtr(); + ::llvm::Value * getPtr() const; + void setPtr(::llvm::Value * ptr); ::llvm::Value * getCount(); + ::llvm::Value * getCount() const; + void setCount(::llvm::Value * count); ::llvm::Value * getInitial(); + ::llvm::Value * getInitial() const; + void setInitial(::llvm::Value * initial); }; @@ -123,10 +129,16 @@ uint32_t getNumElements() const; bool verifier(::llvm::raw_ostream &errs); ::llvm::Value * getLhs(); + ::llvm::Value * getLhs() const; + void setLhs(::llvm::Value * lhs); ::llvm::Value * getRhs(); + ::llvm::Value * getRhs() const; + void setRhs(::llvm::Value * rhs); uint32_t getExtra(); + uint32_t getExtra() const; + void setExtra(uint32_t extra); ::llvm::Value * getResult(); @@ -150,8 +162,12 @@ bool verifier(::llvm::raw_ostream &errs); bool verifier(::llvm::raw_ostream &errs); ::llvm::Value * getLhs(); + ::llvm::Value * getLhs() const; + void setLhs(::llvm::Value * lhs); ::llvm::Value * getRhs(); + ::llvm::Value * getRhs() const; + void setRhs(::llvm::Value * rhs); ::llvm::Value * getResult(); @@ -175,8 +191,12 @@ bool verifier(::llvm::raw_ostream &errs); bool verifier(::llvm::raw_ostream &errs); ::llvm::Value * getVector(); + ::llvm::Value * getVector() const; + void setVector(::llvm::Value * vector); ::llvm::Value * getIndex(); + ::llvm::Value * getIndex() const; + void setIndex(::llvm::Value * index); ::llvm::Value * getResult(); @@ -200,6 +220,8 @@ bool verifier(::llvm::raw_ostream &errs); bool verifier(::llvm::raw_ostream &errs); ::llvm::Value * getSource(); + ::llvm::Value * getSource() const; + void setSource(::llvm::Value * source); ::llvm::Value * getResult(); @@ -244,6 +266,8 @@ bool verifier(::llvm::raw_ostream &errs); bool verifier(::llvm::raw_ostream &errs); ::llvm::Value * getSource(); + ::llvm::Value * getSource() const; + void setSource(::llvm::Value * source); ::llvm::Value * getResult(); @@ -267,6 +291,8 @@ bool verifier(::llvm::raw_ostream &errs); bool verifier(::llvm::raw_ostream &errs); ::llvm::Value * getSource(); + ::llvm::Value * getSource() const; + void setSource(::llvm::Value * source); ::llvm::Value * getResult(); @@ -290,6 +316,8 @@ bool verifier(::llvm::raw_ostream &errs); bool verifier(::llvm::raw_ostream &errs); bool getVal(); + bool getVal() const; + }; @@ -310,10 +338,16 @@ bool getVal(); bool verifier(::llvm::raw_ostream &errs); ::llvm::Value * getVector(); + ::llvm::Value * getVector() const; + void setVector(::llvm::Value * vector); ::llvm::Value * getValue(); + ::llvm::Value * getValue() const; + void setValue(::llvm::Value * value); ::llvm::Value * getIndex(); + ::llvm::Value * getIndex() const; + void setIndex(::llvm::Value * index); ::llvm::Value * getResult(); @@ -337,8 +371,12 @@ bool verifier(::llvm::raw_ostream &errs); bool verifier(::llvm::raw_ostream &errs); ::llvm::Value * getInstName(); + ::llvm::Value * getInstName() const; + void setInstName(::llvm::Value * instName); ::llvm::Value * getInstName_0(); + ::llvm::Value * getInstName_0() const; + void setInstName_0(::llvm::Value * instName_0); ::llvm::Value * getResult(); @@ -362,6 +400,8 @@ bool verifier(::llvm::raw_ostream &errs); bool verifier(::llvm::raw_ostream &errs); ::llvm::Value * getInstName(); + ::llvm::Value * getInstName() const; + void setInstName(::llvm::Value * instName); ::llvm::Value * getResult(); @@ -448,6 +488,8 @@ bool verifier(::llvm::raw_ostream &errs); bool verifier(::llvm::raw_ostream &errs); ::llvm::Value * getData(); + ::llvm::Value * getData() const; + void setData(::llvm::Value * data); @@ -470,6 +512,8 @@ bool verifier(::llvm::raw_ostream &errs); bool verifier(::llvm::raw_ostream &errs); ::llvm::Type * getSizeofType(); + ::llvm::Type * getSizeofType() const; + void setSizeofType(::llvm::Type * sizeof_type); ::llvm::Value * getResult(); @@ -556,6 +600,8 @@ bool verifier(::llvm::raw_ostream &errs); bool verifier(::llvm::raw_ostream &errs); ::llvm::StringRef getVal(); + ::llvm::StringRef getVal() const; + }; @@ -576,6 +622,8 @@ bool verifier(::llvm::raw_ostream &errs); bool verifier(::llvm::raw_ostream &errs); ::llvm::Value * getData(); + ::llvm::Value * getData() const; + void setData(::llvm::Value * data); @@ -598,6 +646,8 @@ bool verifier(::llvm::raw_ostream &errs); bool verifier(::llvm::raw_ostream &errs); ::llvm::Value * getData(); + ::llvm::Value * getData() const; + void setData(::llvm::Value * data); ::llvm::iterator_range<::llvm::User::value_op_iterator> getArgs();