Replace gimple_code() == GIMPLE_ASSIGN checks with dyn_cast<gassign*>.
GCC compiler refactoring uses safer dynamic casting for GIMPLE assignments, improving internal type checking.
This commit systematically replaces checks like gimple_code() == GIMPLE_ASSIGN with dyn_cast<gassign*>() across numerous GCC passes. This change leverages C++’s dynamic casting mechanism to safely determine if a gimple* pointer refers to an assignment statement, then casts it to the more specific gassign* type. This improves internal type safety, code clarity, and robustness in various optimization and analysis passes.
In Details
This patch targets numerous files within GCC's GIMPLE processing infrastructure, including analysis (gimple-predicate-analysis.cc, tree-ssa-dom.cc), optimization (gimple-range-fold.cc, ipa-split.cc, tree-ssa-loop-ch.cc), and code generation (omp-expand.cc, predict.cc). It replaces explicit checks for the GIMPLE statement code being GIMPLE_ASSIGN with safe_dyn_cast<gassign*> or dyn_cast<gassign*>. This is a standard C++ idiom for safely downcasting pointers in an inheritance hierarchy and improves type safety and expressiveness within the compiler's intermediate representat…
- dyn_cast
- A C++ RTTI (Run-Time Type Information) operator used for safe downcasting of pointers within a class hierarchy. It returns a pointer to the target type if the cast is valid, or nullptr otherwise.
- gassign*
- A pointer to a GIMPLE assignment statement (GIMPLE_ASSIGN) in GCC's intermediate representation.
- gimple*
- A pointer to a GIMPLE statement in GCC's intermediate representation. GIMPLE is a three-address code representation used after the initial parsing and high-level optimization stages.
- GIMPLE_ASSIGN
- An enumeration value representing a GIMPLE assignment statement in GCC's intermediate representation.
- GIMPLE
- GCC's internal three-address code representation.