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 
20 #include "llvm/Support/Printable.h"
21 
22 namespace llvm {
23 
24 template <typename _FunctionT> class GenericSSAContext {
25 public:
26   // Specializations should provide the following types that are similar to how
27   // LLVM IR is structured:
28 
29   // The smallest unit of the IR is a ValueT. The SSA context uses a ValueRefT,
30   // which is a pointer to a ValueT, since Machine IR does not have the
31   // equivalent of a ValueT.
32   //
33   // using ValueRefT = ...
34   //
35   // The ConstValueRefT is needed to work with "const Value *", where const
36   // needs to bind to the pointee and not the pointer.
37   //
38   // using ConstValueRefT = ...
39   //
40   // The null value for ValueRefT.
41   //
42   // static constexpr ValueRefT ValueRefNull;
43 
44   // An InstructionT usually defines one or more ValueT objects.
45   //
46   // using InstructionT = ... must be a subclass of Value
47 
48   // A UseT represents a data-edge from the defining instruction to the using
49   // instruction.
50   //
51   // using UseT = ...
52 
53   // A BlockT is a sequence of InstructionT, and forms a node of the CFG. It
54   // has global methods predecessors() and successors() that return
55   // the list of incoming CFG edges and outgoing CFG edges
56   // respectively.
57   //
58   // using BlockT = ...
59 
60   // A FunctionT represents a CFG along with arguments and return values. It is
61   // the smallest complete unit of code in a Module.
62   //
63   // The compiler produces an error here if this class is implicitly
64   // specialized due to an instantiation. An explicit specialization
65   // of this template needs to be added before the instantiation point
66   // indicated by the compiler.
67   using FunctionT = typename _FunctionT::invalidTemplateInstanceError;
68 
69   // A dominator tree provides the dominance relation between basic blocks in
70   // a given funciton.
71   //
72   // using DominatorTreeT = ...
73 
74   // Initialize the SSA context with information about the FunctionT being
75   // processed.
76   //
77   // void setFunction(FunctionT &function);
78   // FunctionT* getFunction() const;
79 
80   // Every FunctionT has a unique BlockT marked as its entry.
81   //
82   // static BlockT* getEntryBlock(FunctionT &F);
83 
84   // Methods to examine basic blocks and values
85   //
86   // static void appendBlockDefs(SmallVectorImpl<ValueRefT> &defs,
87   //                             BlockT &block);
88   // static void appendBlockDefs(SmallVectorImpl<const ValueRefT> &defs,
89   //                             const BlockT &block);
90 
91   // static void appendBlockTerms(SmallVectorImpl<InstructionT *> &terms,
92   //                              BlockT &block);
93   // static void appendBlockTerms(SmallVectorImpl<const InstructionT *> &terms,
94   //                              const BlockT &block);
95   //
96   // static bool comesBefore(const InstructionT *lhs, const InstructionT *rhs);
97   // static bool isConstantOrUndefValuePhi(const InstructionT &Instr);
98   // const BlockT *getDefBlock(const ValueRefT value) const;
99 
100   // Methods to print various objects.
101   //
102   // Printable print(BlockT *block) const;
103   // Printable print(InstructionT *inst) const;
104   // Printable print(ValueRefT value) const;
105 };
106 } // namespace llvm
107 
108 #endif // LLVM_ADT_GENERICSSACONTEXT_H
109