forked from OSchip/llvm-project
Refactor generic op printing: extract a public printFunctionalType() on OpAsmPrinter (NFC)
PiperOrigin-RevId: 253674584
This commit is contained in:
parent
980bf61b4b
commit
74df13fdda
|
@ -98,6 +98,23 @@ public:
|
|||
os << ')';
|
||||
}
|
||||
|
||||
/// Print the complete type of an operation in functional form.
|
||||
void printFunctionalType(Operation *op) {
|
||||
auto &os = getStream();
|
||||
os << "(";
|
||||
interleaveComma(op->getNonSuccessorOperands(), os,
|
||||
[&](Value *operand) { printType(operand->getType()); });
|
||||
os << ") -> ";
|
||||
if (op->getNumResults() == 1 &&
|
||||
!op->getResult(0)->getType().isa<FunctionType>()) {
|
||||
printType(op->getResult(0)->getType());
|
||||
} else {
|
||||
os << '(';
|
||||
interleaveComma(op->getResultTypes(), os);
|
||||
os << ')';
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
OpAsmPrinter(const OpAsmPrinter &) = delete;
|
||||
void operator=(const OpAsmPrinter &) = delete;
|
||||
|
|
|
@ -320,6 +320,7 @@ public:
|
|||
return getOperand(getSuccessorOperandIndex(succIndex) + opIndex);
|
||||
}
|
||||
|
||||
bool hasSuccessors() { return numSuccs != 0; }
|
||||
unsigned getNumSuccessors() { return numSuccs; }
|
||||
unsigned getNumSuccessorOperands(unsigned index) {
|
||||
assert(!isKnownNonTerminator() && "only terminators may have successors");
|
||||
|
|
|
@ -1575,20 +1575,8 @@ void FunctionPrinter::printGenericOp(Operation *op) {
|
|||
printOptionalAttrDict(attrs);
|
||||
|
||||
// Print the type signature of the operation.
|
||||
os << " : (";
|
||||
interleaveComma(properOperands,
|
||||
[&](Value *value) { printType(value->getType()); });
|
||||
os << ") -> ";
|
||||
|
||||
if (op->getNumResults() == 1 &&
|
||||
!op->getResult(0)->getType().isa<FunctionType>()) {
|
||||
printType(op->getResult(0)->getType());
|
||||
} else {
|
||||
os << '(';
|
||||
interleaveComma(op->getResults(),
|
||||
[&](Value *result) { printType(result->getType()); });
|
||||
os << ')';
|
||||
}
|
||||
os << " : ";
|
||||
printFunctionalType(op);
|
||||
}
|
||||
|
||||
void FunctionPrinter::printSuccessorAndUseList(Operation *term,
|
||||
|
|
|
@ -495,7 +495,8 @@ void Operation::setSuccessor(Block *block, unsigned index) {
|
|||
|
||||
auto Operation::getNonSuccessorOperands() -> operand_range {
|
||||
return {operand_iterator(this, 0),
|
||||
operand_iterator(this, getSuccessorOperandIndex(0))};
|
||||
operand_iterator(this, hasSuccessors() ? getSuccessorOperandIndex(0)
|
||||
: getNumOperands())};
|
||||
}
|
||||
|
||||
/// Get the index of the first operand of the successor at the provided
|
||||
|
|
Loading…
Reference in New Issue