Get rid of dynamic casts

Use llvm::dyn_cast instead of dynamic_cast. This prevents llvm from
needing to be recompiled with rtti enabled.
Fix up remaining test cases
Use dyn_cast_or_null where needed