private llvm::TrailingObjects<Operation, detail::OperandStorage,
BlockOperand, Region, OpOperand> {
public:
- /// Create a new Operation with the specific fields.
+ /// Create a new Operation with the specific fields. This constructor
+ /// populates the provided attribute list with default attributes if
+ /// necessary.
static Operation *create(Location location, OperationName name,
TypeRange resultTypes, ValueRange operands,
NamedAttrList &&attributes, BlockRange successors,
unsigned numRegions);
+ /// Create a new Operation with the specific fields. This constructor uses an
+ /// existing attribute dictionary to avoid uniquing a list of attributes.
+ static Operation *create(Location location, OperationName name,
+ TypeRange resultTypes, ValueRange operands,
+ DictionaryAttr attributes, BlockRange successors,
+ unsigned numRegions);
+
/// Create a new Operation from the fields stored in `state`.
static Operation *create(const OperationState &state);
/// Sets default attributes on unset attributes.
void populateDefaultAttrs() {
- NamedAttrList attrs(getAttrDictionary());
- name.populateDefaultAttrs(attrs);
- setAttrs(attrs.getDictionary(getContext()));
+ NamedAttrList attrs(getAttrDictionary());
+ name.populateDefaultAttrs(attrs);
+ setAttrs(attrs.getDictionary(getContext()));
}
//===--------------------------------------------------------------------===//
return op;
}
+/// Create a new Operation with the specific fields.
+Operation *Operation::create(Location location, OperationName name,
+ TypeRange resultTypes, ValueRange operands,
+ NamedAttrList &&attributes, BlockRange successors,
+ unsigned numRegions) {
+ // Populate default attributes.
+ name.populateDefaultAttrs(attributes);
+
+ return create(location, name, resultTypes, operands,
+ attributes.getDictionary(location.getContext()), successors,
+ numRegions);
+}
+
/// Overload of create that takes an existing DictionaryAttr to avoid
/// unnecessarily uniquing a list of attributes.
Operation *Operation::create(Location location, OperationName name,
TypeRange resultTypes, ValueRange operands,
- NamedAttrList &&attributes, BlockRange successors,
+ DictionaryAttr attributes, BlockRange successors,
unsigned numRegions) {
assert(llvm::all_of(resultTypes, [](Type t) { return t; }) &&
"unexpected null result type");
char *mallocMem = reinterpret_cast<char *>(malloc(byteSize + prefixByteSize));
void *rawMem = mallocMem + prefixByteSize;
- // Populate default attributes.
- name.populateDefaultAttrs(attributes);
-
// Create the new Operation.
- Operation *op = ::new (rawMem) Operation(
- location, name, numResults, numSuccessors, numRegions,
- attributes.getDictionary(location.getContext()), needsOperandStorage);
+ Operation *op =
+ ::new (rawMem) Operation(location, name, numResults, numSuccessors,
+ numRegions, attributes, needsOperandStorage);
assert((numSuccessors == 0 || op->mightHaveTrait<OpTrait::IsTerminator>()) &&
"unexpected successors in a non-terminator operation");