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

Use ArgumentIndex enum #114

Merged
merged 3 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 8 additions & 12 deletions lib/TableGen/Operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,18 @@ void AccessorBuilder::emitGetterDefinition() const {
std::string fromLlvm;

if (!m_arg.type->isVarArgList()) {
fromLlvm = tgfmt("getArgOperand($index)", &m_fmt);
fromLlvm = tgfmt(
"getArgOperand(static_cast<uint32_t>(ArgumentIndex::$Name))", &m_fmt);
if (auto *attr = dyn_cast<Attr>(m_arg.type))
fromLlvm = tgfmt(attr->getFromLlvmValue(), &m_fmt, fromLlvm);
else if (m_arg.type->isTypeArg())
fromLlvm += "->getType()";
} else {
fromLlvm = tgfmt(
R"(::llvm::make_range(
value_op_iterator(arg_begin() + $index),
value_op_iterator(arg_begin() + static_cast<uint32_t>(ArgumentIndex::$Name$0)),
value_op_iterator(arg_end())))",
&m_fmt);
&m_fmt, "Start");
}

m_fmt.addSubst("fromLlvm", fromLlvm);
Expand All @@ -251,7 +252,7 @@ void AccessorBuilder::emitSetterDefinition() const {
m_os << tgfmt(R"(

void $_op::set$Name($cppType $name) {
setArgOperand($index, $toLlvm);
setArgOperand(static_cast<uint32_t>(ArgumentIndex::$Name), $toLlvm);
})",
&m_fmt);
}
Expand All @@ -263,32 +264,27 @@ void AccessorBuilder::emitVarArgReplacementDefinition() const {

$_op *$_op::replace$Name(::llvm::ArrayRef<Value *> $name) {
::llvm::SmallVector<Value *> newArgs;
if ($index > 0)
newArgs.append(arg_begin(), arg_begin() + $index);
if (static_cast<uint32_t>(ArgumentIndex::$Name$0) > 0)
newArgs.append(arg_begin(), arg_begin() + static_cast<uint32_t>(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);
this->replaceAllUsesWith(newOp);
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);

const NamedValue &arg = indexedArg.value();
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));
Expand Down
108 changes: 54 additions & 54 deletions test/example/generated/ExampleDialect.cpp.inc
Original file line number Diff line number Diff line change
Expand Up @@ -322,25 +322,25 @@ return true;


::llvm::Value * StreamReduceOp::getPtr() const {
return getArgOperand(0);
return getArgOperand(static_cast<uint32_t>(ArgumentIndex::Ptr));
tsymalla-AMD marked this conversation as resolved.
Show resolved Hide resolved
}

void StreamReduceOp::setPtr(::llvm::Value * ptr) {
setArgOperand(0, ptr);
setArgOperand(static_cast<uint32_t>(ArgumentIndex::Ptr), ptr);
}
::llvm::Value * StreamReduceOp::getCount() const {
return getArgOperand(1);
return getArgOperand(static_cast<uint32_t>(ArgumentIndex::Count));
}

void StreamReduceOp::setCount(::llvm::Value * count) {
setArgOperand(1, count);
setArgOperand(static_cast<uint32_t>(ArgumentIndex::Count), count);
}
::llvm::Value * StreamReduceOp::getInitial() const {
return getArgOperand(2);
return getArgOperand(static_cast<uint32_t>(ArgumentIndex::Initial));
}

void StreamReduceOp::setInitial(::llvm::Value * initial) {
setArgOperand(2, initial);
setArgOperand(static_cast<uint32_t>(ArgumentIndex::Initial), initial);
}

const ::llvm::StringLiteral Add32Op::s_name{"xd.ir.add32"};
Expand Down Expand Up @@ -441,25 +441,25 @@ uint32_t const extra = getExtra();


::llvm::Value * Add32Op::getLhs() const {
return getArgOperand(0);
return getArgOperand(static_cast<uint32_t>(ArgumentIndex::Lhs));
}

void Add32Op::setLhs(::llvm::Value * lhs) {
setArgOperand(0, lhs);
setArgOperand(static_cast<uint32_t>(ArgumentIndex::Lhs), lhs);
}
::llvm::Value * Add32Op::getRhs() const {
return getArgOperand(1);
return getArgOperand(static_cast<uint32_t>(ArgumentIndex::Rhs));
}

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

void Add32Op::setExtra(uint32_t extra) {
setArgOperand(2, ::llvm::ConstantInt::get(::llvm::IntegerType::get(getContext(), 32), extra) );
setArgOperand(static_cast<uint32_t>(ArgumentIndex::Extra), ::llvm::ConstantInt::get(::llvm::IntegerType::get(getContext(), 32), extra) );
}
::llvm::Value *Add32Op::getResult() {return this;}

Expand Down Expand Up @@ -543,18 +543,18 @@ rhs


::llvm::Value * CombineOp::getLhs() const {
return getArgOperand(0);
return getArgOperand(static_cast<uint32_t>(ArgumentIndex::Lhs));
}

void CombineOp::setLhs(::llvm::Value * lhs) {
setArgOperand(0, lhs);
setArgOperand(static_cast<uint32_t>(ArgumentIndex::Lhs), lhs);
}
::llvm::Value * CombineOp::getRhs() const {
return getArgOperand(1);
return getArgOperand(static_cast<uint32_t>(ArgumentIndex::Rhs));
}

void CombineOp::setRhs(::llvm::Value * rhs) {
setArgOperand(1, rhs);
setArgOperand(static_cast<uint32_t>(ArgumentIndex::Rhs), rhs);
}
::llvm::Value *CombineOp::getResult() {return this;}

Expand Down Expand Up @@ -647,18 +647,18 @@ index


::llvm::Value * ExtractElementOp::getVector() const {
return getArgOperand(0);
return getArgOperand(static_cast<uint32_t>(ArgumentIndex::Vector));
}

void ExtractElementOp::setVector(::llvm::Value * vector) {
setArgOperand(0, vector);
setArgOperand(static_cast<uint32_t>(ArgumentIndex::Vector), vector);
}
::llvm::Value * ExtractElementOp::getIndex() const {
return getArgOperand(1);
return getArgOperand(static_cast<uint32_t>(ArgumentIndex::Index));
}

void ExtractElementOp::setIndex(::llvm::Value * index) {
setArgOperand(1, index);
setArgOperand(static_cast<uint32_t>(ArgumentIndex::Index), index);
}
::llvm::Value *ExtractElementOp::getResult() {return this;}

Expand Down Expand Up @@ -824,11 +824,11 @@ source


::llvm::Value * FromFixedVectorOp::getSource() const {
return getArgOperand(0);
return getArgOperand(static_cast<uint32_t>(ArgumentIndex::Source));
}

void FromFixedVectorOp::setSource(::llvm::Value * source) {
setArgOperand(0, source);
setArgOperand(static_cast<uint32_t>(ArgumentIndex::Source), source);
}
::llvm::Value *FromFixedVectorOp::getResult() {return this;}

Expand Down Expand Up @@ -984,11 +984,11 @@ source


::llvm::Value * IExtOp::getSource() const {
return getArgOperand(0);
return getArgOperand(static_cast<uint32_t>(ArgumentIndex::Source));
}

void IExtOp::setSource(::llvm::Value * source) {
setArgOperand(0, source);
setArgOperand(static_cast<uint32_t>(ArgumentIndex::Source), source);
}
::llvm::Value *IExtOp::getResult() {return this;}

Expand Down Expand Up @@ -1082,11 +1082,11 @@ source


::llvm::Value * ITruncOp::getSource() const {
return getArgOperand(0);
return getArgOperand(static_cast<uint32_t>(ArgumentIndex::Source));
}

void ITruncOp::setSource(::llvm::Value * source) {
setArgOperand(0, source);
setArgOperand(static_cast<uint32_t>(ArgumentIndex::Source), source);
}
::llvm::Value *ITruncOp::getResult() {return this;}

Expand Down Expand Up @@ -1156,7 +1156,7 @@ source


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


Expand Down Expand Up @@ -1259,25 +1259,25 @@ index


::llvm::Value * InsertElementOp::getVector() const {
return getArgOperand(0);
return getArgOperand(static_cast<uint32_t>(ArgumentIndex::Vector));
}

void InsertElementOp::setVector(::llvm::Value * vector) {
setArgOperand(0, vector);
setArgOperand(static_cast<uint32_t>(ArgumentIndex::Vector), vector);
}
::llvm::Value * InsertElementOp::getValue() const {
return getArgOperand(1);
return getArgOperand(static_cast<uint32_t>(ArgumentIndex::Value));
}

void InsertElementOp::setValue(::llvm::Value * value) {
setArgOperand(1, value);
setArgOperand(static_cast<uint32_t>(ArgumentIndex::Value), value);
}
::llvm::Value * InsertElementOp::getIndex() const {
return getArgOperand(2);
return getArgOperand(static_cast<uint32_t>(ArgumentIndex::Index));
}

void InsertElementOp::setIndex(::llvm::Value * index) {
setArgOperand(2, index);
setArgOperand(static_cast<uint32_t>(ArgumentIndex::Index), index);
}
::llvm::Value *InsertElementOp::getResult() {return this;}

Expand Down Expand Up @@ -1350,18 +1350,18 @@ instName_0


::llvm::Value * InstNameConflictDoubleOp::getInstName() const {
return getArgOperand(0);
return getArgOperand(static_cast<uint32_t>(ArgumentIndex::InstName));
}

void InstNameConflictDoubleOp::setInstName(::llvm::Value * instName) {
setArgOperand(0, instName);
setArgOperand(static_cast<uint32_t>(ArgumentIndex::InstName), instName);
}
::llvm::Value * InstNameConflictDoubleOp::getInstName_0() const {
return getArgOperand(1);
return getArgOperand(static_cast<uint32_t>(ArgumentIndex::InstName_0));
}

void InstNameConflictDoubleOp::setInstName_0(::llvm::Value * instName_0) {
setArgOperand(1, instName_0);
setArgOperand(static_cast<uint32_t>(ArgumentIndex::InstName_0), instName_0);
}
::llvm::Value *InstNameConflictDoubleOp::getResult() {return this;}

Expand Down Expand Up @@ -1431,11 +1431,11 @@ instName


::llvm::Value * InstNameConflictOp::getInstName() const {
return getArgOperand(0);
return getArgOperand(static_cast<uint32_t>(ArgumentIndex::InstName));
}

void InstNameConflictOp::setInstName(::llvm::Value * instName) {
setArgOperand(0, instName);
setArgOperand(static_cast<uint32_t>(ArgumentIndex::InstName), instName);
}
::llvm::Value *InstNameConflictOp::getResult() {return this;}

Expand Down Expand Up @@ -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() + static_cast<uint32_t>(ArgumentIndex::InstName_0Start)),
value_op_iterator(arg_end()));
}

InstNameConflictVarargsOp *InstNameConflictVarargsOp::replaceInstName_0(::llvm::ArrayRef<Value *> instName_0) {
::llvm::SmallVector<Value *> newArgs;
if (0 > 0)
newArgs.append(arg_begin(), arg_begin() + 0);
if (static_cast<uint32_t>(ArgumentIndex::InstName_0Start) > 0)
newArgs.append(arg_begin(), arg_begin() + static_cast<uint32_t>(ArgumentIndex::InstName_0Start));
newArgs.append(instName_0.begin(), instName_0.end());
InstNameConflictVarargsOp *newOp = ::llvm::cast<InstNameConflictVarargsOp>(::llvm::CallInst::Create(getCalledFunction(), newArgs, this->getName(), this->getIterator()));
newOp->copyMetadata(*this);
Expand Down Expand Up @@ -1687,11 +1687,11 @@ data


::llvm::Value * SetWriteOp::getData() const {
return getArgOperand(0);
return getArgOperand(static_cast<uint32_t>(ArgumentIndex::Data));
}

void SetWriteOp::setData(::llvm::Value * data) {
setArgOperand(0, data);
setArgOperand(static_cast<uint32_t>(ArgumentIndex::Data), data);
}


Expand Down Expand Up @@ -1760,11 +1760,11 @@ data


::llvm::Type * SizeOfOp::getSizeofType() const {
return getArgOperand(0)->getType();
return getArgOperand(static_cast<uint32_t>(ArgumentIndex::SizeofType))->getType();
}

void SizeOfOp::setSizeofType(::llvm::Type * sizeof_type) {
setArgOperand(0, llvm::PoisonValue::get(sizeof_type));
setArgOperand(static_cast<uint32_t>(ArgumentIndex::SizeofType), llvm::PoisonValue::get(sizeof_type));
}
::llvm::Value *SizeOfOp::getResult() {return this;}

Expand Down Expand Up @@ -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(static_cast<uint32_t>(ArgumentIndex::Val)))->getInitializer())->getAsString() ;
}


Expand Down Expand Up @@ -2169,11 +2169,11 @@ data


::llvm::Value * WriteOp::getData() const {
return getArgOperand(0);
return getArgOperand(static_cast<uint32_t>(ArgumentIndex::Data));
}

void WriteOp::setData(::llvm::Value * data) {
setArgOperand(0, data);
setArgOperand(static_cast<uint32_t>(ArgumentIndex::Data), data);
}


Expand Down Expand Up @@ -2234,22 +2234,22 @@ data


::llvm::Value * WriteVarArgOp::getData() const {
return getArgOperand(0);
return getArgOperand(static_cast<uint32_t>(ArgumentIndex::Data));
}

void WriteVarArgOp::setData(::llvm::Value * data) {
setArgOperand(0, data);
setArgOperand(static_cast<uint32_t>(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() + static_cast<uint32_t>(ArgumentIndex::ArgsStart)),
value_op_iterator(arg_end()));
}

WriteVarArgOp *WriteVarArgOp::replaceArgs(::llvm::ArrayRef<Value *> args) {
::llvm::SmallVector<Value *> newArgs;
if (1 > 0)
newArgs.append(arg_begin(), arg_begin() + 1);
if (static_cast<uint32_t>(ArgumentIndex::ArgsStart) > 0)
newArgs.append(arg_begin(), arg_begin() + static_cast<uint32_t>(ArgumentIndex::ArgsStart));
newArgs.append(args.begin(), args.end());
WriteVarArgOp *newOp = ::llvm::cast<WriteVarArgOp>(::llvm::CallInst::Create(getCalledFunction(), newArgs, this->getName(), this->getIterator()));
newOp->copyMetadata(*this);
Expand Down