[TableGen] Improve algorithms for processing template arguments

Rework template argument checking so that all arguments are type-checked
and cast if necessary.

Add a test.

Differential Revision: https://reviews.llvm.org/D96416

GitOrigin-RevId: d248cce44e290b70a84495885559f41701422d2a
7 files changed