This commit fixes the failure in the original PR when building with shared libs. The problem is that `visitUsedValuesDefinedAbove` is defined in `MLIRTransformUtils`, but that lib depends on this lib (`MLIRAnalysis`). To fix, I dropped the use of `visitUsedValuesDefinedAbove` and use `Region::walk` to traverse values defined above. Reapplies PR https://github.com/llvm/llvm-project/pull/113478 Reverts PR https://github.com/llvm/llvm-project/pull/114432 This reverts commit a9a8351.