forked from OSchip/llvm-project
Generate another op builder with aggregated parameters
For each op, generate another builder with the following signature: static void build(Builder* builder, OperationState* result, ArrayRef<Type> resultTypes, ArrayRef<SSAValue*> args, ArrayRef<NamedAttribute> attributes); PiperOrigin-RevId: 225066007
This commit is contained in:
parent
63261aa9a8
commit
a9eb2e8ffc
|
@ -144,15 +144,20 @@ class Op<string mnemonic, list<OpProperty> props = []> {
|
|||
// Define the hooks used for building, parsing, printing, verification.
|
||||
|
||||
// Custom builder.
|
||||
// If a derived class/def does not override this, then a default builder
|
||||
// is generated, with the following signature:
|
||||
// If a derived class/def does not override this, then two default builders
|
||||
// are generated, with the following signatures:
|
||||
//
|
||||
// static void build(Builder* builder, OperationState* result,
|
||||
// Type resultType0, Type resultType1, ...,
|
||||
// SSAValue* arg0, SSAValue* arg1, ...,
|
||||
// Attribute attr0, Attribute attr1, ...);
|
||||
// Attribute <attr0-name>, Attribute <attr1-name>, ...);
|
||||
//
|
||||
// Where the attributes follow the same declaration order as in the op.
|
||||
// * where the attributes follow the same declaration order as in the op.
|
||||
//
|
||||
// static void build(Builder* builder, OperationState* result,
|
||||
// ArrayRef<Type> resultTypes,
|
||||
// ArrayRef<SSAValue*> args,
|
||||
// ArrayRef<NamedAttribute> attributes);
|
||||
code builder = ?;
|
||||
|
||||
// Custom parser.
|
||||
|
|
|
@ -231,6 +231,13 @@ void OpEmitter::emitBuilder() {
|
|||
// Otherwise, generate a default builder that requires all result type,
|
||||
// operands, and attributes as parameters.
|
||||
|
||||
// We generate two builders here, one having a stand-alone parameter for
|
||||
// each result type / operand / attribute, the other having an aggregated
|
||||
// parameter for all result types / operands / attributes, to facilitate
|
||||
// different call patterns.
|
||||
|
||||
// 1. Stand-alone parameters
|
||||
|
||||
std::vector<Record *> returnTypes = def.getValueAsListOfDefs("returnTypes");
|
||||
std::vector<Record *> operandTypes = def.getValueAsListOfDefs("operandTypes");
|
||||
|
||||
|
@ -277,6 +284,30 @@ void OpEmitter::emitBuilder() {
|
|||
}
|
||||
|
||||
os << " }\n";
|
||||
|
||||
// 2. Aggregated parameters
|
||||
|
||||
// Signature
|
||||
os << " static void build(Builder* builder, OperationState* result, "
|
||||
<< "ArrayRef<Type> resultTypes, ArrayRef<SSAValue*> args, "
|
||||
"ArrayRef<NamedAttribute> attributes) {\n";
|
||||
|
||||
// Result types
|
||||
os << " assert(resultTypes.size() == " << returnTypes.size()
|
||||
<< "u && \"mismatched number of return types\");\n"
|
||||
<< " result->addTypes(resultTypes);\n";
|
||||
|
||||
// Operands
|
||||
os << " assert(args.size() == " << operandTypes.size()
|
||||
<< "u && \"mismatched number of parameters\");\n"
|
||||
<< " result->addOperands(args);\n\n";
|
||||
|
||||
// Attributes
|
||||
os << " assert(attributes.size() >= " << attrs.size()
|
||||
<< "u && \"not enough attributes\");\n"
|
||||
<< " for (const auto& pair : attributes)\n"
|
||||
<< " result->addAttribute(pair.first, pair.second);\n"
|
||||
<< " }\n";
|
||||
}
|
||||
|
||||
void OpEmitter::emitCanonicalizationPatterns() {
|
||||
|
|
Loading…
Reference in New Issue