SSAContext.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //===- SSAContext.cpp -------------------------------------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. /// \file
  9. ///
  10. /// This file defines a specialization of the GenericSSAContext<X>
  11. /// template class for LLVM IR.
  12. ///
  13. //===----------------------------------------------------------------------===//
  14. #include "llvm/IR/SSAContext.h"
  15. #include "llvm/IR/BasicBlock.h"
  16. #include "llvm/IR/Function.h"
  17. #include "llvm/IR/Instruction.h"
  18. #include "llvm/IR/ModuleSlotTracker.h"
  19. #include "llvm/IR/Value.h"
  20. #include "llvm/Support/raw_ostream.h"
  21. using namespace llvm;
  22. BasicBlock *SSAContext::getEntryBlock(Function &F) {
  23. return &F.getEntryBlock();
  24. }
  25. void SSAContext::setFunction(Function &Fn) { F = &Fn; }
  26. Printable SSAContext::print(Value *V) const {
  27. return Printable([V](raw_ostream &Out) { V->print(Out); });
  28. }
  29. Printable SSAContext::print(Instruction *Inst) const {
  30. return print(cast<Value>(Inst));
  31. }
  32. Printable SSAContext::print(BasicBlock *BB) const {
  33. if (BB->hasName())
  34. return Printable([BB](raw_ostream &Out) { Out << BB->getName(); });
  35. return Printable([BB](raw_ostream &Out) {
  36. ModuleSlotTracker MST{BB->getParent()->getParent(), false};
  37. MST.incorporateFunction(*BB->getParent());
  38. Out << MST.getLocalSlot(BB);
  39. });
  40. }