LLVM  13.0.0git
TypeFinder.h
Go to the documentation of this file.
1 //===- llvm/IR/TypeFinder.h - Class to find used struct types ---*- 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 //
9 // This file contains the declaration of the TypeFinder class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_IR_TYPEFINDER_H
14 #define LLVM_IR_TYPEFINDER_H
15 
16 #include "llvm/ADT/DenseSet.h"
17 #include <cstddef>
18 #include <vector>
19 
20 namespace llvm {
21 
22 class MDNode;
23 class Module;
24 class StructType;
25 class Type;
26 class Value;
27 
28 /// TypeFinder - Walk over a module, identifying all of the types that are
29 /// used by the module.
30 class TypeFinder {
31  // To avoid walking constant expressions multiple times and other IR
32  // objects, we keep several helper maps.
33  DenseSet<const Value*> VisitedConstants;
34  DenseSet<const MDNode *> VisitedMetadata;
35  DenseSet<Type*> VisitedTypes;
36 
37  std::vector<StructType*> StructTypes;
38  bool OnlyNamed = false;
39 
40 public:
41  TypeFinder() = default;
42 
43  void run(const Module &M, bool onlyNamed);
44  void clear();
45 
46  using iterator = std::vector<StructType*>::iterator;
47  using const_iterator = std::vector<StructType*>::const_iterator;
48 
49  iterator begin() { return StructTypes.begin(); }
50  iterator end() { return StructTypes.end(); }
51 
52  const_iterator begin() const { return StructTypes.begin(); }
53  const_iterator end() const { return StructTypes.end(); }
54 
55  bool empty() const { return StructTypes.empty(); }
56  size_t size() const { return StructTypes.size(); }
57  iterator erase(iterator I, iterator E) { return StructTypes.erase(I, E); }
58 
59  StructType *&operator[](unsigned Idx) { return StructTypes[Idx]; }
60 
61  DenseSet<const MDNode *> &getVisitedMetadata() { return VisitedMetadata; }
62 
63 private:
64  /// incorporateType - This method adds the type to the list of used
65  /// structures if it's not in there already.
66  void incorporateType(Type *Ty);
67 
68  /// incorporateValue - This method is used to walk operand lists finding types
69  /// hiding in constant expressions and other operands that won't be walked in
70  /// other ways. GlobalValues, basic blocks, instructions, and inst operands
71  /// are all explicitly enumerated.
72  void incorporateValue(const Value *V);
73 
74  /// incorporateMDNode - This method is used to walk the operands of an MDNode
75  /// to find types hiding within.
76  void incorporateMDNode(const MDNode *V);
77 };
78 
79 } // end namespace llvm
80 
81 #endif // LLVM_IR_TYPEFINDER_H
llvm
Definition: AllocatorList.h:23
llvm::TypeFinder::end
const_iterator end() const
Definition: TypeFinder.h:53
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::TypeFinder::size
size_t size() const
Definition: TypeFinder.h:56
llvm::TypeFinder::end
iterator end()
Definition: TypeFinder.h:50
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:46
llvm::TypeFinder::begin
iterator begin()
Definition: TypeFinder.h:49
llvm::TypeFinder::empty
bool empty() const
Definition: TypeFinder.h:55
llvm::TypeFinder::clear
void clear()
Definition: TypeFinder.cpp:85
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
DenseSet.h
llvm::TypeFinder::TypeFinder
TypeFinder()=default
llvm::TypeFinder::operator[]
StructType *& operator[](unsigned Idx)
Definition: TypeFinder.h:59
llvm::DenseSet< const Value * >
I
#define I(x, y, z)
Definition: MD5.cpp:59
TemplateParamKind::Type
@ Type
llvm::TypeFinder::const_iterator
std::vector< StructType * >::const_iterator const_iterator
Definition: TypeFinder.h:47
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::MDNode
Metadata node.
Definition: Metadata.h:897
llvm::TypeFinder::getVisitedMetadata
DenseSet< const MDNode * > & getVisitedMetadata()
Definition: TypeFinder.h:61
llvm::StructType
Class to represent struct types.
Definition: DerivedTypes.h:212
llvm::TypeFinder::run
void run(const Module &M, bool onlyNamed)
Definition: TypeFinder.cpp:32
llvm::TypeFinder
TypeFinder - Walk over a module, identifying all of the types that are used by the module.
Definition: TypeFinder.h:30
llvm::TypeFinder::iterator
std::vector< StructType * >::iterator iterator
Definition: TypeFinder.h:46
Module
Machine Check Debug Module
Definition: MachineCheckDebugify.cpp:122
llvm::TypeFinder::erase
iterator erase(iterator I, iterator E)
Definition: TypeFinder.h:57
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::TypeFinder::begin
const_iterator begin() const
Definition: TypeFinder.h:52