LLVM 20.0.0git
GenericSSAContext.h
Go to the documentation of this file.
1//===- GenericSSAContext.h --------------------------------------*- 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 the little GenericSSAContext<X> template class
11/// that can be used to implement IR analyses as templates.
12/// Specializing these templates allows the analyses to be used over
13/// both LLVM IR and Machine IR.
14///
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_ADT_GENERICSSACONTEXT_H
18#define LLVM_ADT_GENERICSSACONTEXT_H
19
21
22namespace llvm {
23
24template <typename, bool> class DominatorTreeBase;
25template <typename> class SmallVectorImpl;
26
27namespace Intrinsic {
28typedef unsigned ID;
29}
30
31// Specializations of this template should provide the types used by the
32// template GenericSSAContext below.
33template <typename _FunctionT> struct GenericSSATraits;
34
35// Ideally this should have been a stateless traits class. But the print methods
36// for Machine IR need access to the owning function. So we track that state in
37// the template itself.
38//
39// We use FunctionT as a template argument and not GenericSSATraits to allow
40// forward declarations using well-known typenames.
41template <typename _FunctionT> class GenericSSAContext {
43 const typename SSATraits::FunctionT *F;
44
45public:
46 // The smallest unit of the IR is a ValueT. The SSA context uses a ValueRefT,
47 // which is a pointer to a ValueT, since Machine IR does not have the
48 // equivalent of a ValueT.
49 using ValueRefT = typename SSATraits::ValueRefT;
50
51 // The ConstValueRefT is needed to work with "const Value *", where const
52 // needs to bind to the pointee and not the pointer.
53 using ConstValueRefT = typename SSATraits::ConstValueRefT;
54
55 // The null value for ValueRefT. For LLVM IR and MIR, this is simply the
56 // default constructed value.
57 static constexpr ValueRefT *ValueRefNull = {};
58
59 // An InstructionT usually defines one or more ValueT objects.
60 using InstructionT = typename SSATraits::InstructionT;
61
62 // A UseT represents a data-edge from the defining instruction to the using
63 // instruction.
64 using UseT = typename SSATraits::UseT;
65
66 // A BlockT is a sequence of InstructionT, and forms a node of the CFG. It
67 // has global methods predecessors() and successors() that return
68 // the list of incoming CFG edges and outgoing CFG edges
69 // respectively.
70 using BlockT = typename SSATraits::BlockT;
71
72 // A FunctionT represents a CFG along with arguments and return values. It is
73 // the smallest complete unit of code in a Module.
74 using FunctionT = typename SSATraits::FunctionT;
75
76 // A dominator tree provides the dominance relation between basic blocks in
77 // a given funciton.
79
80 GenericSSAContext() = default;
82
83 const FunctionT *getFunction() const { return F; }
84
86
89 const BlockT &block);
90
92 BlockT &block);
94 const BlockT &block);
95
96 static bool isConstantOrUndefValuePhi(const InstructionT &Instr);
98
99 Printable print(const BlockT *block) const;
101 Printable print(const InstructionT *inst) const;
103};
104} // namespace llvm
105
106#endif // LLVM_ADT_GENERICSSACONTEXT_H
Given that RA is a live value
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
unify loop Fixup each natural loop to have a single exit block
Core dominator tree base class.
typename SSATraits::InstructionT InstructionT
static void appendBlockTerms(SmallVectorImpl< const InstructionT * > &terms, const BlockT &block)
static void appendBlockDefs(SmallVectorImpl< ValueRefT > &defs, BlockT &block)
typename SSATraits::FunctionT FunctionT
const FunctionT * getFunction() const
static bool isConstantOrUndefValuePhi(const InstructionT &Instr)
static void appendBlockTerms(SmallVectorImpl< InstructionT * > &terms, BlockT &block)
static constexpr ValueRefT * ValueRefNull
static Intrinsic::ID getIntrinsicID(const InstructionT &I)
Printable print(const BlockT *block) const
typename SSATraits::ConstValueRefT ConstValueRefT
static void appendBlockDefs(SmallVectorImpl< ConstValueRefT > &defs, const BlockT &block)
Printable print(ConstValueRefT value) const
typename SSATraits::BlockT BlockT
const BlockT * getDefBlock(ConstValueRefT value) const
typename SSATraits::UseT UseT
Printable print(const InstructionT *inst) const
typename SSATraits::ValueRefT ValueRefT
Printable printAsOperand(const BlockT *BB) const
GenericSSAContext(const FunctionT *F)
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:586
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18