xref: /freebsd-src/contrib/llvm-project/llvm/lib/IR/SSAContext.cpp (revision 0eae32dcef82f6f06de6419a0d623d7def0cc8f6)
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 
15 #include "llvm/IR/SSAContext.h"
16 #include "llvm/IR/Argument.h"
17 #include "llvm/IR/BasicBlock.h"
18 #include "llvm/IR/Function.h"
19 #include "llvm/IR/Instruction.h"
20 #include "llvm/Support/raw_ostream.h"
21 
22 using namespace llvm;
23 
24 BasicBlock *SSAContext::getEntryBlock(Function &F) {
25   return &F.getEntryBlock();
26 }
27 
28 void SSAContext::setFunction(Function &Fn) { F = &Fn; }
29 
30 Printable SSAContext::print(Value *V) const {
31   return Printable([V](raw_ostream &Out) { V->print(Out); });
32 }
33 
34 Printable SSAContext::print(Instruction *Inst) const {
35   return print(cast<Value>(Inst));
36 }
37 
38 Printable SSAContext::print(BasicBlock *BB) const {
39   if (BB->hasName())
40     return Printable([BB](raw_ostream &Out) { Out << BB->getName(); });
41 
42   return Printable([BB](raw_ostream &Out) {
43     ModuleSlotTracker MST{BB->getParent()->getParent(), false};
44     MST.incorporateFunction(*BB->getParent());
45     Out << MST.getLocalSlot(BB);
46   });
47 }
48