• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- CodeGen/Analysis.h - CodeGen LLVM IR Analysis Utilities --*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares several CodeGen-specific LLVM IR analysis utilities.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CODEGEN_ANALYSIS_H
15 #define LLVM_CODEGEN_ANALYSIS_H
16 
17 #include "llvm/ADT/ArrayRef.h"
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/CodeGen/ISDOpcodes.h"
21 #include "llvm/IR/CallSite.h"
22 #include "llvm/IR/InlineAsm.h"
23 #include "llvm/IR/Instructions.h"
24 
25 namespace llvm {
26 class GlobalValue;
27 class MachineBasicBlock;
28 class MachineFunction;
29 class TargetLoweringBase;
30 class TargetLowering;
31 class TargetMachine;
32 class SDNode;
33 class SDValue;
34 class SelectionDAG;
35 struct EVT;
36 
37 /// \brief Compute the linearized index of a member in a nested
38 /// aggregate/struct/array.
39 ///
40 /// Given an LLVM IR aggregate type and a sequence of insertvalue or
41 /// extractvalue indices that identify a member, return the linearized index of
42 /// the start of the member, i.e the number of element in memory before the
43 /// sought one. This is disconnected from the number of bytes.
44 ///
45 /// \param Ty is the type indexed by \p Indices.
46 /// \param Indices is an optional pointer in the indices list to the current
47 /// index.
48 /// \param IndicesEnd is the end of the indices list.
49 /// \param CurIndex is the current index in the recursion.
50 ///
51 /// \returns \p CurIndex plus the linear index in \p Ty  the indices list.
52 unsigned ComputeLinearIndex(Type *Ty,
53                             const unsigned *Indices,
54                             const unsigned *IndicesEnd,
55                             unsigned CurIndex = 0);
56 
57 inline unsigned ComputeLinearIndex(Type *Ty,
58                                    ArrayRef<unsigned> Indices,
59                                    unsigned CurIndex = 0) {
60   return ComputeLinearIndex(Ty, Indices.begin(), Indices.end(), CurIndex);
61 }
62 
63 /// ComputeValueVTs - Given an LLVM IR type, compute a sequence of
64 /// EVTs that represent all the individual underlying
65 /// non-aggregate types that comprise it.
66 ///
67 /// If Offsets is non-null, it points to a vector to be filled in
68 /// with the in-memory offsets of each of the individual values.
69 ///
70 void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty,
71                      SmallVectorImpl<EVT> &ValueVTs,
72                      SmallVectorImpl<uint64_t> *Offsets = nullptr,
73                      uint64_t StartingOffset = 0);
74 
75 /// ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.
76 GlobalValue *ExtractTypeInfo(Value *V);
77 
78 /// hasInlineAsmMemConstraint - Return true if the inline asm instruction being
79 /// processed uses a memory 'm' constraint.
80 bool hasInlineAsmMemConstraint(InlineAsm::ConstraintInfoVector &CInfos,
81                                const TargetLowering &TLI);
82 
83 /// getFCmpCondCode - Return the ISD condition code corresponding to
84 /// the given LLVM IR floating-point condition code.  This includes
85 /// consideration of global floating-point math flags.
86 ///
87 ISD::CondCode getFCmpCondCode(FCmpInst::Predicate Pred);
88 
89 /// getFCmpCodeWithoutNaN - Given an ISD condition code comparing floats,
90 /// return the equivalent code if we're allowed to assume that NaNs won't occur.
91 ISD::CondCode getFCmpCodeWithoutNaN(ISD::CondCode CC);
92 
93 /// getICmpCondCode - Return the ISD condition code corresponding to
94 /// the given LLVM IR integer condition code.
95 ///
96 ISD::CondCode getICmpCondCode(ICmpInst::Predicate Pred);
97 
98 /// Test if the given instruction is in a position to be optimized
99 /// with a tail-call. This roughly means that it's in a block with
100 /// a return and there's nothing that needs to be scheduled
101 /// between it and the return.
102 ///
103 /// This function only tests target-independent requirements.
104 bool isInTailCallPosition(ImmutableCallSite CS, const TargetMachine &TM);
105 
106 /// Test if given that the input instruction is in the tail call position if the
107 /// return type or any attributes of the function will inhibit tail call
108 /// optimization.
109 bool returnTypeIsEligibleForTailCall(const Function *F,
110                                      const Instruction *I,
111                                      const ReturnInst *Ret,
112                                      const TargetLoweringBase &TLI);
113 
114 // True if GV can be left out of the object symbol table. This is the case
115 // for linkonce_odr values whose address is not significant. While legal, it is
116 // not normally profitable to omit them from the .o symbol table. Using this
117 // analysis makes sense when the information can be passed down to the linker
118 // or we are in LTO.
119 bool canBeOmittedFromSymbolTable(const GlobalValue *GV);
120 
121 DenseMap<const MachineBasicBlock *, int>
122 getFuncletMembership(const MachineFunction &MF);
123 
124 } // End llvm namespace
125 
126 #endif
127