/src/test/run-make-fulldeps/pgo-indirect-call-promotion/interesting.rs

https://gitlab.com/rust-lang/rust · Rust · 56 lines · 32 code · 12 blank · 12 comment · 3 complexity · 318daff168d3e177d78a96b9b2f8f362 MD5 · raw file

  1. #![crate_name="interesting"]
  2. #![crate_type="rlib"]
  3. extern crate opaque;
  4. #[no_mangle]
  5. pub fn function_called_always() {
  6. opaque::opaque_f1();
  7. }
  8. #[no_mangle]
  9. pub fn function_called_never() {
  10. opaque::opaque_f2();
  11. }
  12. #[no_mangle]
  13. pub fn call_a_bunch_of_functions(fns: &[fn()]) {
  14. // Indirect call promotion transforms the below into something like
  15. //
  16. // for f in fns {
  17. // if f == function_called_always {
  18. // function_called_always()
  19. // } else {
  20. // f();
  21. // }
  22. // }
  23. //
  24. // where `function_called_always` actually gets inlined too.
  25. for f in fns {
  26. f();
  27. }
  28. }
  29. pub trait Foo {
  30. fn foo(&self);
  31. }
  32. impl Foo for u32 {
  33. #[no_mangle]
  34. fn foo(&self) {
  35. opaque::opaque_f2();
  36. }
  37. }
  38. #[no_mangle]
  39. pub fn call_a_bunch_of_trait_methods(trait_objects: &[&dyn Foo]) {
  40. // Same as above, just with vtables in between
  41. for x in trait_objects {
  42. x.foo();
  43. }
  44. }