diff --git a/lib/TableGen/Operations.cpp b/lib/TableGen/Operations.cpp index d10f3b7..2b0bf56 100644 --- a/lib/TableGen/Operations.cpp +++ b/lib/TableGen/Operations.cpp @@ -194,10 +194,10 @@ void OperationBase::emitArgumentAccessorDeclarations(llvm::raw_ostream &out, } if (!argNames.empty()) { - out << "enum class ArgumentIndex: uint32_t {\n"; + out << "struct ArgumentIndex { enum Enum : uint32_t {\n"; for (const auto &[index, argName] : llvm::enumerate(argNames)) out << tgfmt("$0 = $1,\n", &fmt, argName, numSuperclassArgs + index); - out << "};"; + out << "};};"; } } @@ -215,7 +215,8 @@ void AccessorBuilder::emitGetterDefinition() const { std::string fromLlvm; if (!m_arg.type->isVarArgList()) { - fromLlvm = tgfmt("getArgOperand($index)", &m_fmt); + fromLlvm = tgfmt( + "getArgOperand(ArgumentIndex::$Name)", &m_fmt); if (auto *attr = dyn_cast(m_arg.type)) fromLlvm = tgfmt(attr->getFromLlvmValue(), &m_fmt, fromLlvm); else if (m_arg.type->isTypeArg()) @@ -223,9 +224,9 @@ void AccessorBuilder::emitGetterDefinition() const { } else { fromLlvm = tgfmt( R"(::llvm::make_range( - value_op_iterator(arg_begin() + $index), + value_op_iterator(arg_begin() + ArgumentIndex::$Name$0), value_op_iterator(arg_end())))", - &m_fmt); + &m_fmt, "Start"); } m_fmt.addSubst("fromLlvm", fromLlvm); @@ -251,7 +252,7 @@ void AccessorBuilder::emitSetterDefinition() const { m_os << tgfmt(R"( void $_op::set$Name($cppType $name) { - setArgOperand($index, $toLlvm); + setArgOperand(ArgumentIndex::$Name, $toLlvm); })", &m_fmt); } @@ -263,8 +264,8 @@ void AccessorBuilder::emitVarArgReplacementDefinition() const { $_op *$_op::replace$Name(::llvm::ArrayRef $name) { ::llvm::SmallVector newArgs; - if ($index > 0) - newArgs.append(arg_begin(), arg_begin() + $index); + if (ArgumentIndex::$Name$0 > 0) + newArgs.append(arg_begin(), arg_begin() + ArgumentIndex::$Name$0); newArgs.append($name.begin(), $name.end()); $_op *newOp = ::llvm::cast<$_op>(::llvm::CallInst::Create(getCalledFunction(), newArgs, this->getName(), this->getIterator())); newOp->copyMetadata(*this); @@ -272,15 +273,11 @@ void AccessorBuilder::emitVarArgReplacementDefinition() const { this->eraseFromParent(); return newOp; })", - &m_fmt); + &m_fmt, "Start"); } void OperationBase::emitArgumentAccessorDefinitions(llvm::raw_ostream &out, FmtContext &fmt) const { - unsigned numSuperclassArgs = 0; - if (m_superclass) - numSuperclassArgs = m_superclass->getNumFullArguments(); - for (const auto &indexedArg : llvm::enumerate(m_arguments)) { FmtContextScope scope(fmt); @@ -288,7 +285,6 @@ void OperationBase::emitArgumentAccessorDefinitions(llvm::raw_ostream &out, AccessorBuilder builder{fmt, out, arg, m_attrTypes[indexedArg.index()]}; fmt.withContext("getContext()"); - fmt.addSubst("index", Twine(numSuperclassArgs + indexedArg.index())); fmt.addSubst("cppType", arg.type->getGetterCppType()); fmt.addSubst("name", arg.name); fmt.addSubst("Name", convertToCamelFromSnakeCase(arg.name, true)); diff --git a/test/example/generated/ExampleDialect.cpp.inc b/test/example/generated/ExampleDialect.cpp.inc index db08dec..3c2d603 100644 --- a/test/example/generated/ExampleDialect.cpp.inc +++ b/test/example/generated/ExampleDialect.cpp.inc @@ -322,25 +322,25 @@ return true; ::llvm::Value * StreamReduceOp::getPtr() const { - return getArgOperand(0); + return getArgOperand(ArgumentIndex::Ptr); } void StreamReduceOp::setPtr(::llvm::Value * ptr) { - setArgOperand(0, ptr); + setArgOperand(ArgumentIndex::Ptr, ptr); } ::llvm::Value * StreamReduceOp::getCount() const { - return getArgOperand(1); + return getArgOperand(ArgumentIndex::Count); } void StreamReduceOp::setCount(::llvm::Value * count) { - setArgOperand(1, count); + setArgOperand(ArgumentIndex::Count, count); } ::llvm::Value * StreamReduceOp::getInitial() const { - return getArgOperand(2); + return getArgOperand(ArgumentIndex::Initial); } void StreamReduceOp::setInitial(::llvm::Value * initial) { - setArgOperand(2, initial); + setArgOperand(ArgumentIndex::Initial, initial); } const ::llvm::StringLiteral Add32Op::s_name{"xd.ir.add32"}; @@ -441,25 +441,25 @@ uint32_t const extra = getExtra(); ::llvm::Value * Add32Op::getLhs() const { - return getArgOperand(0); + return getArgOperand(ArgumentIndex::Lhs); } void Add32Op::setLhs(::llvm::Value * lhs) { - setArgOperand(0, lhs); + setArgOperand(ArgumentIndex::Lhs, lhs); } ::llvm::Value * Add32Op::getRhs() const { - return getArgOperand(1); + return getArgOperand(ArgumentIndex::Rhs); } void Add32Op::setRhs(::llvm::Value * rhs) { - setArgOperand(1, rhs); + setArgOperand(ArgumentIndex::Rhs, rhs); } uint32_t Add32Op::getExtra() const { - return ::llvm::cast<::llvm::ConstantInt>(getArgOperand(2))->getZExtValue() ; + return ::llvm::cast<::llvm::ConstantInt>(getArgOperand(ArgumentIndex::Extra))->getZExtValue() ; } void Add32Op::setExtra(uint32_t extra) { - setArgOperand(2, ::llvm::ConstantInt::get(::llvm::IntegerType::get(getContext(), 32), extra) ); + setArgOperand(ArgumentIndex::Extra, ::llvm::ConstantInt::get(::llvm::IntegerType::get(getContext(), 32), extra) ); } ::llvm::Value *Add32Op::getResult() {return this;} @@ -543,18 +543,18 @@ rhs ::llvm::Value * CombineOp::getLhs() const { - return getArgOperand(0); + return getArgOperand(ArgumentIndex::Lhs); } void CombineOp::setLhs(::llvm::Value * lhs) { - setArgOperand(0, lhs); + setArgOperand(ArgumentIndex::Lhs, lhs); } ::llvm::Value * CombineOp::getRhs() const { - return getArgOperand(1); + return getArgOperand(ArgumentIndex::Rhs); } void CombineOp::setRhs(::llvm::Value * rhs) { - setArgOperand(1, rhs); + setArgOperand(ArgumentIndex::Rhs, rhs); } ::llvm::Value *CombineOp::getResult() {return this;} @@ -647,18 +647,18 @@ index ::llvm::Value * ExtractElementOp::getVector() const { - return getArgOperand(0); + return getArgOperand(ArgumentIndex::Vector); } void ExtractElementOp::setVector(::llvm::Value * vector) { - setArgOperand(0, vector); + setArgOperand(ArgumentIndex::Vector, vector); } ::llvm::Value * ExtractElementOp::getIndex() const { - return getArgOperand(1); + return getArgOperand(ArgumentIndex::Index); } void ExtractElementOp::setIndex(::llvm::Value * index) { - setArgOperand(1, index); + setArgOperand(ArgumentIndex::Index, index); } ::llvm::Value *ExtractElementOp::getResult() {return this;} @@ -824,11 +824,11 @@ source ::llvm::Value * FromFixedVectorOp::getSource() const { - return getArgOperand(0); + return getArgOperand(ArgumentIndex::Source); } void FromFixedVectorOp::setSource(::llvm::Value * source) { - setArgOperand(0, source); + setArgOperand(ArgumentIndex::Source, source); } ::llvm::Value *FromFixedVectorOp::getResult() {return this;} @@ -984,11 +984,11 @@ source ::llvm::Value * IExtOp::getSource() const { - return getArgOperand(0); + return getArgOperand(ArgumentIndex::Source); } void IExtOp::setSource(::llvm::Value * source) { - setArgOperand(0, source); + setArgOperand(ArgumentIndex::Source, source); } ::llvm::Value *IExtOp::getResult() {return this;} @@ -1082,11 +1082,11 @@ source ::llvm::Value * ITruncOp::getSource() const { - return getArgOperand(0); + return getArgOperand(ArgumentIndex::Source); } void ITruncOp::setSource(::llvm::Value * source) { - setArgOperand(0, source); + setArgOperand(ArgumentIndex::Source, source); } ::llvm::Value *ITruncOp::getResult() {return this;} @@ -1156,7 +1156,7 @@ source bool ImmutableOp::getVal() const { - return ::llvm::cast<::llvm::ConstantInt>(getArgOperand(0))->getZExtValue() ; + return ::llvm::cast<::llvm::ConstantInt>(getArgOperand(ArgumentIndex::Val))->getZExtValue() ; } @@ -1259,25 +1259,25 @@ index ::llvm::Value * InsertElementOp::getVector() const { - return getArgOperand(0); + return getArgOperand(ArgumentIndex::Vector); } void InsertElementOp::setVector(::llvm::Value * vector) { - setArgOperand(0, vector); + setArgOperand(ArgumentIndex::Vector, vector); } ::llvm::Value * InsertElementOp::getValue() const { - return getArgOperand(1); + return getArgOperand(ArgumentIndex::Value); } void InsertElementOp::setValue(::llvm::Value * value) { - setArgOperand(1, value); + setArgOperand(ArgumentIndex::Value, value); } ::llvm::Value * InsertElementOp::getIndex() const { - return getArgOperand(2); + return getArgOperand(ArgumentIndex::Index); } void InsertElementOp::setIndex(::llvm::Value * index) { - setArgOperand(2, index); + setArgOperand(ArgumentIndex::Index, index); } ::llvm::Value *InsertElementOp::getResult() {return this;} @@ -1350,18 +1350,18 @@ instName_0 ::llvm::Value * InstNameConflictDoubleOp::getInstName() const { - return getArgOperand(0); + return getArgOperand(ArgumentIndex::InstName); } void InstNameConflictDoubleOp::setInstName(::llvm::Value * instName) { - setArgOperand(0, instName); + setArgOperand(ArgumentIndex::InstName, instName); } ::llvm::Value * InstNameConflictDoubleOp::getInstName_0() const { - return getArgOperand(1); + return getArgOperand(ArgumentIndex::InstName_0); } void InstNameConflictDoubleOp::setInstName_0(::llvm::Value * instName_0) { - setArgOperand(1, instName_0); + setArgOperand(ArgumentIndex::InstName_0, instName_0); } ::llvm::Value *InstNameConflictDoubleOp::getResult() {return this;} @@ -1431,11 +1431,11 @@ instName ::llvm::Value * InstNameConflictOp::getInstName() const { - return getArgOperand(0); + return getArgOperand(ArgumentIndex::InstName); } void InstNameConflictOp::setInstName(::llvm::Value * instName) { - setArgOperand(0, instName); + setArgOperand(ArgumentIndex::InstName, instName); } ::llvm::Value *InstNameConflictOp::getResult() {return this;} @@ -1500,14 +1500,14 @@ instName ::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_begin() + ArgumentIndex::InstName_0Start), value_op_iterator(arg_end())); } InstNameConflictVarargsOp *InstNameConflictVarargsOp::replaceInstName_0(::llvm::ArrayRef instName_0) { ::llvm::SmallVector newArgs; - if (0 > 0) - newArgs.append(arg_begin(), arg_begin() + 0); + if (ArgumentIndex::InstName_0Start > 0) + newArgs.append(arg_begin(), arg_begin() + ArgumentIndex::InstName_0Start); newArgs.append(instName_0.begin(), instName_0.end()); InstNameConflictVarargsOp *newOp = ::llvm::cast(::llvm::CallInst::Create(getCalledFunction(), newArgs, this->getName(), this->getIterator())); newOp->copyMetadata(*this); @@ -1687,11 +1687,11 @@ data ::llvm::Value * SetWriteOp::getData() const { - return getArgOperand(0); + return getArgOperand(ArgumentIndex::Data); } void SetWriteOp::setData(::llvm::Value * data) { - setArgOperand(0, data); + setArgOperand(ArgumentIndex::Data, data); } @@ -1760,11 +1760,11 @@ data ::llvm::Type * SizeOfOp::getSizeofType() const { - return getArgOperand(0)->getType(); + return getArgOperand(ArgumentIndex::SizeofType)->getType(); } void SizeOfOp::setSizeofType(::llvm::Type * sizeof_type) { - setArgOperand(0, llvm::PoisonValue::get(sizeof_type)); + setArgOperand(ArgumentIndex::SizeofType, llvm::PoisonValue::get(sizeof_type)); } ::llvm::Value *SizeOfOp::getResult() {return this;} @@ -2110,7 +2110,7 @@ initial ::llvm::StringRef StringAttrOp::getVal() const { - return ::llvm::cast<::llvm::ConstantDataArray>(::llvm::cast<::llvm::GlobalVariable>(getArgOperand(0))->getInitializer())->getAsString() ; + return ::llvm::cast<::llvm::ConstantDataArray>(::llvm::cast<::llvm::GlobalVariable>(getArgOperand(ArgumentIndex::Val))->getInitializer())->getAsString() ; } @@ -2169,11 +2169,11 @@ data ::llvm::Value * WriteOp::getData() const { - return getArgOperand(0); + return getArgOperand(ArgumentIndex::Data); } void WriteOp::setData(::llvm::Value * data) { - setArgOperand(0, data); + setArgOperand(ArgumentIndex::Data, data); } @@ -2234,22 +2234,22 @@ data ::llvm::Value * WriteVarArgOp::getData() const { - return getArgOperand(0); + return getArgOperand(ArgumentIndex::Data); } void WriteVarArgOp::setData(::llvm::Value * data) { - setArgOperand(0, data); + setArgOperand(ArgumentIndex::Data, data); } ::llvm::iterator_range<::llvm::User::value_op_iterator> WriteVarArgOp::getArgs() { return ::llvm::make_range( - value_op_iterator(arg_begin() + 1), + value_op_iterator(arg_begin() + ArgumentIndex::ArgsStart), value_op_iterator(arg_end())); } WriteVarArgOp *WriteVarArgOp::replaceArgs(::llvm::ArrayRef args) { ::llvm::SmallVector newArgs; - if (1 > 0) - newArgs.append(arg_begin(), arg_begin() + 1); + if (ArgumentIndex::ArgsStart > 0) + newArgs.append(arg_begin(), arg_begin() + ArgumentIndex::ArgsStart); newArgs.append(args.begin(), args.end()); WriteVarArgOp *newOp = ::llvm::cast(::llvm::CallInst::Create(getCalledFunction(), newArgs, this->getName(), this->getIterator())); newOp->copyMetadata(*this); diff --git a/test/example/generated/ExampleDialect.h.inc b/test/example/generated/ExampleDialect.h.inc index 9e5794f..5b317a6 100644 --- a/test/example/generated/ExampleDialect.h.inc +++ b/test/example/generated/ExampleDialect.h.inc @@ -104,11 +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 { + struct ArgumentIndex { enum Enum : uint32_t { Ptr = 0, Count = 1, Initial = 2, -}; +};}; }; class Add32Op : public ::llvm::CallInst { @@ -132,11 +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 { + struct ArgumentIndex { enum Enum : uint32_t { Lhs = 0, Rhs = 1, Extra = 2, -}; +};}; ::llvm::Value * getResult(); @@ -161,10 +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 { + struct ArgumentIndex { enum Enum : uint32_t { Lhs = 0, Rhs = 1, -}; +};}; ::llvm::Value * getResult(); @@ -189,10 +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 { + struct ArgumentIndex { enum Enum : uint32_t { Vector = 0, Index = 1, -}; +};}; ::llvm::Value * getResult(); @@ -215,9 +215,9 @@ bool verifier(::llvm::raw_ostream &errs); ::llvm::Value * getSource() const; void setSource(::llvm::Value * source); - enum class ArgumentIndex: uint32_t { + struct ArgumentIndex { enum Enum : uint32_t { Source = 0, -}; +};}; ::llvm::Value * getResult(); @@ -261,9 +261,9 @@ bool verifier(::llvm::raw_ostream &errs); ::llvm::Value * getSource() const; void setSource(::llvm::Value * source); - enum class ArgumentIndex: uint32_t { + struct ArgumentIndex { enum Enum : uint32_t { Source = 0, -}; +};}; ::llvm::Value * getResult(); @@ -286,9 +286,9 @@ bool verifier(::llvm::raw_ostream &errs); ::llvm::Value * getSource() const; void setSource(::llvm::Value * source); - enum class ArgumentIndex: uint32_t { + struct ArgumentIndex { enum Enum : uint32_t { Source = 0, -}; +};}; ::llvm::Value * getResult(); @@ -309,9 +309,9 @@ Source = 0, bool verifier(::llvm::raw_ostream &errs); -bool getVal() const;enum class ArgumentIndex: uint32_t { +bool getVal() const;struct ArgumentIndex { enum Enum : uint32_t { Val = 0, -}; +};}; }; @@ -337,11 +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 { + struct ArgumentIndex { enum Enum : uint32_t { Vector = 0, Value = 1, Index = 2, -}; +};}; ::llvm::Value * getResult(); @@ -366,10 +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 { + struct ArgumentIndex { enum Enum : uint32_t { InstName = 0, InstName_0 = 1, -}; +};}; ::llvm::Value * getResult(); @@ -392,9 +392,9 @@ bool verifier(::llvm::raw_ostream &errs); ::llvm::Value * getInstName() const; void setInstName(::llvm::Value * instName); - enum class ArgumentIndex: uint32_t { + struct ArgumentIndex { enum Enum : uint32_t { InstName = 0, -}; +};}; ::llvm::Value * getResult(); @@ -419,9 +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); - enum class ArgumentIndex: uint32_t { + struct ArgumentIndex { enum Enum : uint32_t { InstName_0Start = 0, -}; +};}; ::llvm::Value * getResult(); @@ -486,9 +486,9 @@ bool verifier(::llvm::raw_ostream &errs); ::llvm::Value * getData() const; void setData(::llvm::Value * data); - enum class ArgumentIndex: uint32_t { + struct ArgumentIndex { enum Enum : uint32_t { Data = 0, -}; +};}; }; @@ -510,9 +510,9 @@ bool verifier(::llvm::raw_ostream &errs); ::llvm::Type * getSizeofType() const; void setSizeofType(::llvm::Type * sizeof_type); - enum class ArgumentIndex: uint32_t { + struct ArgumentIndex { enum Enum : uint32_t { SizeofType = 0, -}; +};}; ::llvm::Value * getResult(); @@ -596,9 +596,9 @@ bool verifier(::llvm::raw_ostream &errs); bool verifier(::llvm::raw_ostream &errs); -::llvm::StringRef getVal() const;enum class ArgumentIndex: uint32_t { +::llvm::StringRef getVal() const;struct ArgumentIndex { enum Enum : uint32_t { Val = 0, -}; +};}; }; @@ -620,9 +620,9 @@ bool verifier(::llvm::raw_ostream &errs); ::llvm::Value * getData() const; void setData(::llvm::Value * data); - enum class ArgumentIndex: uint32_t { + struct ArgumentIndex { enum Enum : uint32_t { Data = 0, -}; +};}; }; @@ -648,10 +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); - enum class ArgumentIndex: uint32_t { + struct ArgumentIndex { enum Enum : uint32_t { Data = 0, ArgsStart = 1, -}; +};}; };