We can cast a string to a record via !cast, but we have no mechanism
to check if it is valid and TableGen will raise an error if failed to
cast. Besides, we have no semantic null in TableGen (we have ? but
different backends handle uninitialized value differently), so operator
like dyn_cast<> is hard to implement.
In this patch, when input of !isa is a string and type to check is a
record, we will treat the input string as record name and loop up all
defined records with the type to see if we can find one. We do this
check until the final resolving step is done to match what !cast has
done.
By doing these, we can write code like:
class dyn_cast_to_record<string r> { R value = !if(!isa<R>(r), !cast<R>(r), default_value); } defvar v = dyn_cast_to_record<"R0">.value; // R0 or default_value.