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