SSAContext.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- SSAContext.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 declares a specialization of the GenericSSAContext<X>
  16. /// class template for LLVM IR.
  17. ///
  18. //===----------------------------------------------------------------------===//
  19. #ifndef LLVM_IR_SSACONTEXT_H
  20. #define LLVM_IR_SSACONTEXT_H
  21. #include "llvm/ADT/GenericSSAContext.h"
  22. #include "llvm/IR/BasicBlock.h"
  23. #include "llvm/IR/ModuleSlotTracker.h"
  24. #include "llvm/Support/Printable.h"
  25. #include <memory>
  26. namespace llvm {
  27. class BasicBlock;
  28. class Function;
  29. class Instruction;
  30. class Value;
  31. template <typename> class SmallVectorImpl;
  32. template <typename, bool> class DominatorTreeBase;
  33. inline auto instrs(const BasicBlock &BB) {
  34. return llvm::make_range(BB.begin(), BB.end());
  35. }
  36. template <> class GenericSSAContext<Function> {
  37. Function *F;
  38. public:
  39. using BlockT = BasicBlock;
  40. using FunctionT = Function;
  41. using InstructionT = Instruction;
  42. using ValueRefT = Value *;
  43. using ConstValueRefT = const Value *;
  44. static Value *ValueRefNull;
  45. using DominatorTreeT = DominatorTreeBase<BlockT, false>;
  46. void setFunction(Function &Fn);
  47. Function *getFunction() const { return F; }
  48. static BasicBlock *getEntryBlock(Function &F);
  49. static const BasicBlock *getEntryBlock(const Function &F);
  50. static void appendBlockDefs(SmallVectorImpl<Value *> &defs,
  51. BasicBlock &block);
  52. static void appendBlockDefs(SmallVectorImpl<const Value *> &defs,
  53. const BasicBlock &block);
  54. static void appendBlockTerms(SmallVectorImpl<Instruction *> &terms,
  55. BasicBlock &block);
  56. static void appendBlockTerms(SmallVectorImpl<const Instruction *> &terms,
  57. const BasicBlock &block);
  58. static bool comesBefore(const Instruction *lhs, const Instruction *rhs);
  59. static bool isConstantValuePhi(const Instruction &Instr);
  60. const BasicBlock *getDefBlock(const Value *value) const;
  61. Printable print(const BasicBlock *Block) const;
  62. Printable print(const Instruction *Inst) const;
  63. Printable print(const Value *Value) const;
  64. };
  65. using SSAContext = GenericSSAContext<Function>;
  66. } // namespace llvm
  67. #endif // LLVM_IR_SSACONTEXT_H
  68. #ifdef __GNUC__
  69. #pragma GCC diagnostic pop
  70. #endif