LLVM 17.0.0git
SSAContext.cpp
Go to the documentation of this file.
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"
22
23using namespace llvm;
24
26
28
30 return &F.getEntryBlock();
31}
32
34 return &F.getEntryBlock();
35}
36
39 for (auto &instr : block.instructionsWithoutDebug(/*SkipPseudoOp=*/true)) {
40 if (instr.isTerminator())
41 break;
42 if (instr.getType()->isVoidTy())
43 continue;
44 auto *def = &instr;
45 defs.push_back(def);
46 }
47}
48
50 const BasicBlock &block) {
51 for (auto &instr : block) {
52 if (instr.isTerminator())
53 break;
54 defs.push_back(&instr);
55 }
56}
57
60 terms.push_back(block.getTerminator());
61}
62
64 const BasicBlock &block) {
65 terms.push_back(block.getTerminator());
66}
67
69 if (const auto *instruction = dyn_cast<Instruction>(value))
70 return instruction->getParent();
71 return nullptr;
72}
73
74bool SSAContext::comesBefore(const Instruction *lhs, const Instruction *rhs) {
75 return lhs->comesBefore(rhs);
76}
77
79 if (auto *Phi = dyn_cast<PHINode>(&Instr))
80 return Phi->hasConstantOrUndefValue();
81 return false;
82}
83
85 return Printable([V](raw_ostream &Out) { V->print(Out); });
86}
87
89 return print(cast<Value>(Inst));
90}
91
93 if (!BB)
94 return Printable([](raw_ostream &Out) { Out << "<nullptr>"; });
95 if (BB->hasName())
96 return Printable([BB](raw_ostream &Out) { Out << BB->getName(); });
97
98 return Printable([BB](raw_ostream &Out) {
99 ModuleSlotTracker MST{BB->getParent()->getParent(), false};
100 MST.incorporateFunction(*BB->getParent());
101 Out << MST.getLocalSlot(BB);
102 });
103}
static const Function * getParent(const Value *V)
Given that RA is a live value
#define F(x, y, z)
Definition: MD5.cpp:55
This file declares a specialization of the GenericSSAContext<X> class template for LLVM IR.
unify loop Fixup each natural loop to have a single exit block
LLVM Basic Block Representation.
Definition: BasicBlock.h:56
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:112
static BasicBlock * getEntryBlock(Function &F)
Definition: SSAContext.cpp:29
static bool comesBefore(const Instruction *lhs, const Instruction *rhs)
Definition: SSAContext.cpp:74
static bool isConstantOrUndefValuePhi(const Instruction &Instr)
Definition: SSAContext.cpp:78
const BasicBlock * getDefBlock(const Value *value) const
Definition: SSAContext.cpp:68
static void appendBlockDefs(SmallVectorImpl< Value * > &defs, BasicBlock &block)
Definition: SSAContext.cpp:37
static void appendBlockTerms(SmallVectorImpl< Instruction * > &terms, BasicBlock &block)
Definition: SSAContext.cpp:58
Printable print(const BasicBlock *Block) const
Definition: SSAContext.cpp:92
bool comesBefore(const Instruction *Other) const
Given an instruction Other in the same basic block as this instruction, return true if this instructi...
Manage lifetime of a slot tracker for printing IR.
Simple wrapper around std::function<void(raw_ostream&)>.
Definition: Printable.h:38
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:577
void push_back(const T &Elt)
Definition: SmallVector.h:416
LLVM Value Representation.
Definition: Value.h:74
bool hasName() const
Definition: Value.h:261
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:309
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr)