How to create an undefined operation from scratch in MLIR?

I know that OpBuilder::create can create operation defined in td file.
But how to create undefined operation such as "undefined.op"(%arg0, %arg1) {}:()

Yes, OpBuilder creates ops for which C++ classes with build methods have been defined. ODS (inside td files) is the most common way to do so. To create an op for which there is no C++ class, one can use OperationState directly - test was the first one I came across that shows this.

Actually, using OperationState isn’t necessary and it’d be roundabout here. Instead, the generic Operation::create(loc, name, resultTypes, operands, ...) could be used.

Operation *op = Operation::create(loc, name, resultTypes, operands, attrs);

Good point, the state immediately gets unpacked to that create.