This is part of the RFC for a better fold API: https://discourse.llvm.org/t/rfc-a-better-fold-api-using-more-generic-adaptors/67374
This patch implements the required foldHook changes and the TableGen machinery for generating fold method signatures using FoldAdaptor for ops, based on the value of useFoldAPI. It may be one of 2 values, with convenient named constants to create a quasi enum. The new fold method will then be generated if kEmitFoldAdaptorFolder is used.
Since the new FoldAdaptor approach is strictly better than the old signature, part of this patch updates the documentation and all example to encourage use of the new fold signature.
Included are also tests exercising the new API, ensuring proper construction of the FoldAdaptor and proper generation by TableGen.
I'd honestly prefer this to be a dialect setting instead of a per-operation setting.