Use getPassManagerType() instead of dynamic_cast.