cgraph.scm 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 (test-cgraph)
  19. #:use-module (gcc)
  20. #:use-module (gcc cgraph)
  21. #:use-module (gcc gimple)
  22. #:use-module (srfi srfi-1))
  23. ;; Test whether a pass can be inserted at a point where the cgraph is built,
  24. ;; whether it can traverse the cgraph, and whether it can access the
  25. ;; corresponding tree or GIMPLE nodes.
  26. (define call-graph-info-pass
  27. (make-pass "call-graph-info" GIMPLE_PASS
  28. (lambda ()
  29. (let ((n (cgraph-get-node (current-function-decl))))
  30. (and (eq? (cgraph-node-decl n) (current-function-decl))
  31. (inform (decl-source-location (cgraph-node-decl n))
  32. "~a callers, ~a callees"
  33. (length (cgraph-node-callers n))
  34. (length (cgraph-node-callees n))))
  35. (for-each (lambda (edge)
  36. (let ((call (cgraph-edge-call-statement edge)))
  37. (and (gimple? call)
  38. (= (gimple-code call) GIMPLE_CALL)
  39. (let* ((fn (gimple-call-fndecl call))
  40. (id (decl-name fn)))
  41. (inform (gimple-source-location call)
  42. "call to ~a"
  43. (identifier-string id))))))
  44. (cgraph-node-callees n)))
  45. ;; Nothing left to do.
  46. 0)))
  47. ;; Register a pass after `*build_cgraph_edges', which is the one that builds
  48. ;; the cgraph nodes.
  49. (register-pass "guile" call-graph-info-pass "*build_cgraph_edges"
  50. (pass-position after))
  51. ;; Register a callback to be called after most of the optimization passes,
  52. ;; including inlining.
  53. (register-callback "guile" PLUGIN_FINISH
  54. (lambda ()
  55. (or (pair? (cgraph-nodes))
  56. (error-at %unknown-location "no nodes"))))