GenericSSAContext.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- GenericSSAContext.h --------------------------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. /// \file
  14. ///
  15. /// This file defines the little GenericSSAContext<X> template class
  16. /// that can be used to implement IR analyses as templates.
  17. /// Specializing these templates allows the analyses to be used over
  18. /// both LLVM IR and Machine IR.
  19. ///
  20. //===----------------------------------------------------------------------===//
  21. #ifndef LLVM_ADT_GENERICSSACONTEXT_H
  22. #define LLVM_ADT_GENERICSSACONTEXT_H
  23. #include "llvm/Support/Printable.h"
  24. namespace llvm {
  25. template <typename _FunctionT> class GenericSSAContext {
  26. public:
  27. // Specializations should provide the following types that are similar to how
  28. // LLVM IR is structured:
  29. // The smallest unit of the IR is a ValueT. The SSA context uses a ValueRefT,
  30. // which is a pointer to a ValueT, since Machine IR does not have the
  31. // equivalent of a ValueT.
  32. //
  33. // using ValueRefT = ...
  34. // An InstT is a subclass of ValueT that itself defines one or more ValueT
  35. // objects.
  36. //
  37. // using InstT = ... must be a subclass of Value
  38. // A BlockT is a sequence of InstT, and forms a node of the CFG. It
  39. // has global methods predecessors() and successors() that return
  40. // the list of incoming CFG edges and outgoing CFG edges
  41. // respectively.
  42. //
  43. // using BlockT = ...
  44. // A FunctionT represents a CFG along with arguments and return values. It is
  45. // the smallest complete unit of code in a Module.
  46. //
  47. // The compiler produces an error here if this class is implicitly
  48. // specialized due to an instantiation. An explicit specialization
  49. // of this template needs to be added before the instantiation point
  50. // indicated by the compiler.
  51. using FunctionT = typename _FunctionT::invalidTemplateInstanceError;
  52. // Every FunctionT has a unique BlockT marked as its entry.
  53. //
  54. // static BlockT* getEntryBlock(FunctionT &F);
  55. // Initialize the SSA context with information about the FunctionT being
  56. // processed.
  57. //
  58. // void setFunction(FunctionT &function);
  59. // FunctionT* getFunction() const;
  60. // Methods to print various objects.
  61. //
  62. // Printable print(BlockT *block) const;
  63. // Printable print(InstructionT *inst) const;
  64. // Printable print(ValueRefT value) const;
  65. };
  66. } // namespace llvm
  67. #endif // LLVM_ADT_GENERICSSACONTEXT_H
  68. #ifdef __GNUC__
  69. #pragma GCC diagnostic pop
  70. #endif