1 //===- CodeGen/Analysis.h - CodeGen LLVM IR Analysis Utilities --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares several CodeGen-specific LLVM IR analysis utilities.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CODEGEN_ANALYSIS_H
15 #define LLVM_CODEGEN_ANALYSIS_H
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"
27 class MachineBasicBlock;
28 class MachineFunction;
29 class TargetLoweringBase;
37 /// \brief Compute the linearized index of a member in a nested
38 /// aggregate/struct/array.
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.
45 /// \param Ty is the type indexed by \p Indices.
46 /// \param Indices is an optional pointer in the indices list to the current
48 /// \param IndicesEnd is the end of the indices list.
49 /// \param CurIndex is the current index in the recursion.
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);
57 inline unsigned ComputeLinearIndex(Type *Ty,
58 ArrayRef<unsigned> Indices,
59 unsigned CurIndex = 0) {
60 return ComputeLinearIndex(Ty, Indices.begin(), Indices.end(), CurIndex);
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.
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.
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);
75 /// ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.
76 GlobalValue *ExtractTypeInfo(Value *V);
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);
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.
87 ISD::CondCode getFCmpCondCode(FCmpInst::Predicate Pred);
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);
93 /// getICmpCondCode - Return the ISD condition code corresponding to
94 /// the given LLVM IR integer condition code.
96 ISD::CondCode getICmpCondCode(ICmpInst::Predicate Pred);
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.
103 /// This function only tests target-independent requirements.
104 bool isInTailCallPosition(ImmutableCallSite CS, const TargetMachine &TM);
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
109 bool returnTypeIsEligibleForTailCall(const Function *F,
110 const Instruction *I,
111 const ReturnInst *Ret,
112 const TargetLoweringBase &TLI);
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
119 bool canBeOmittedFromSymbolTable(const GlobalValue *GV);
121 DenseMap<const MachineBasicBlock *, int>
122 getFuncletMembership(const MachineFunction &MF);
124 } // End llvm namespace