|
|
|||
File indexing completed on 2026-05-10 08:43:05
0001 //===- GenericSSAContext.h --------------------------------------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 /// \file 0009 /// 0010 /// This file defines the little GenericSSAContext<X> template class 0011 /// that can be used to implement IR analyses as templates. 0012 /// Specializing these templates allows the analyses to be used over 0013 /// both LLVM IR and Machine IR. 0014 /// 0015 //===----------------------------------------------------------------------===// 0016 0017 #ifndef LLVM_ADT_GENERICSSACONTEXT_H 0018 #define LLVM_ADT_GENERICSSACONTEXT_H 0019 0020 #include "llvm/Support/Printable.h" 0021 0022 namespace llvm { 0023 0024 template <typename, bool> class DominatorTreeBase; 0025 template <typename> class SmallVectorImpl; 0026 0027 namespace Intrinsic { 0028 typedef unsigned ID; 0029 } 0030 0031 // Specializations of this template should provide the types used by the 0032 // template GenericSSAContext below. 0033 template <typename _FunctionT> struct GenericSSATraits; 0034 0035 // Ideally this should have been a stateless traits class. But the print methods 0036 // for Machine IR need access to the owning function. So we track that state in 0037 // the template itself. 0038 // 0039 // We use FunctionT as a template argument and not GenericSSATraits to allow 0040 // forward declarations using well-known typenames. 0041 template <typename _FunctionT> class GenericSSAContext { 0042 using SSATraits = GenericSSATraits<_FunctionT>; 0043 const typename SSATraits::FunctionT *F; 0044 0045 public: 0046 // The smallest unit of the IR is a ValueT. The SSA context uses a ValueRefT, 0047 // which is a pointer to a ValueT, since Machine IR does not have the 0048 // equivalent of a ValueT. 0049 using ValueRefT = typename SSATraits::ValueRefT; 0050 0051 // The ConstValueRefT is needed to work with "const Value *", where const 0052 // needs to bind to the pointee and not the pointer. 0053 using ConstValueRefT = typename SSATraits::ConstValueRefT; 0054 0055 // The null value for ValueRefT. For LLVM IR and MIR, this is simply the 0056 // default constructed value. 0057 static constexpr ValueRefT *ValueRefNull = {}; 0058 0059 // An InstructionT usually defines one or more ValueT objects. 0060 using InstructionT = typename SSATraits::InstructionT; 0061 0062 // A UseT represents a data-edge from the defining instruction to the using 0063 // instruction. 0064 using UseT = typename SSATraits::UseT; 0065 0066 // A BlockT is a sequence of InstructionT, and forms a node of the CFG. It 0067 // has global methods predecessors() and successors() that return 0068 // the list of incoming CFG edges and outgoing CFG edges 0069 // respectively. 0070 using BlockT = typename SSATraits::BlockT; 0071 0072 // A FunctionT represents a CFG along with arguments and return values. It is 0073 // the smallest complete unit of code in a Module. 0074 using FunctionT = typename SSATraits::FunctionT; 0075 0076 // A dominator tree provides the dominance relation between basic blocks in 0077 // a given funciton. 0078 using DominatorTreeT = DominatorTreeBase<BlockT, false>; 0079 0080 GenericSSAContext() = default; 0081 GenericSSAContext(const FunctionT *F) : F(F) {} 0082 0083 const FunctionT *getFunction() const { return F; } 0084 0085 static Intrinsic::ID getIntrinsicID(const InstructionT &I); 0086 0087 static void appendBlockDefs(SmallVectorImpl<ValueRefT> &defs, BlockT &block); 0088 static void appendBlockDefs(SmallVectorImpl<ConstValueRefT> &defs, 0089 const BlockT &block); 0090 0091 static void appendBlockTerms(SmallVectorImpl<InstructionT *> &terms, 0092 BlockT &block); 0093 static void appendBlockTerms(SmallVectorImpl<const InstructionT *> &terms, 0094 const BlockT &block); 0095 0096 static bool isConstantOrUndefValuePhi(const InstructionT &Instr); 0097 const BlockT *getDefBlock(ConstValueRefT value) const; 0098 0099 Printable print(const BlockT *block) const; 0100 Printable printAsOperand(const BlockT *BB) const; 0101 Printable print(const InstructionT *inst) const; 0102 Printable print(ConstValueRefT value) const; 0103 }; 0104 } // namespace llvm 0105 0106 #endif // LLVM_ADT_GENERICSSACONTEXT_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|