call-graph.scm 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. ;;; Guile-GCC --- Guile extension to GCC. -*- coding: utf-8 -*-
  2. ;;; Copyright (C) 2012 Ludovic Courtès
  3. ;;;
  4. ;;; This file is part of Guile-GCC.
  5. ;;;
  6. ;;; Guile-GCC is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; Guile-GCC is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with Guile-GCC. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (call-graph)
  19. #:use-module (gcc)
  20. #:use-module (gcc cgraph)
  21. #:use-module (srfi srfi-1))
  22. (define call-graph-info-pass
  23. (make-pass "call-graph-info" GIMPLE_PASS
  24. (lambda ()
  25. (let ((n (cgraph-get-node (current-function-decl))))
  26. (inform (decl-source-location (cgraph-node-decl n))
  27. "~a callers, ~a callees"
  28. (length (cgraph-node-callers n))
  29. (length (cgraph-node-callees n))))
  30. ;; Nothing left to do.
  31. 0)))
  32. ;; Register a pass after `*build_cgraph_edges', which is the one that builds
  33. ;; the cgraph nodes.
  34. (register-pass "guile" call-graph-info-pass "*build_cgraph_edges"
  35. (pass-position after))
  36. (define %output-file-name
  37. ;; Name of the file to store the `dot' output. Honor
  38. ;; `-fplugin-arg-guile-dot-file'.
  39. (or (assoc-ref %plugin-arguments "dot-file")
  40. "call-graph.dot"))
  41. ;; Register a callback to be called after most of the optimization passes,
  42. ;; including inlining.
  43. (register-callback "guile" PLUGIN_FINISH
  44. (lambda ()
  45. (call-with-output-file %output-file-name
  46. (lambda (port)
  47. (inform %unknown-location
  48. "dot output written to `~a'"
  49. %output-file-name)
  50. (cgraph-nodes->dot (cgraph-nodes) port)))))