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/SmallVector.h"
19 #include "llvm/CodeGen/ISDOpcodes.h"
20 #include "llvm/IR/CallSite.h"
21 #include "llvm/IR/InlineAsm.h"
22 #include "llvm/IR/Instructions.h"
26 class TargetLoweringBase;
34 /// \brief Compute the linearized index of a member in a nested
35 /// aggregate/struct/array.
37 /// Given an LLVM IR aggregate type and a sequence of insertvalue or
38 /// extractvalue indices that identify a member, return the linearized index of
39 /// the start of the member, i.e the number of element in memory before the
40 /// seeked one. This is disconnected from the number of bytes.
42 /// \param Ty is the type indexed by \p Indices.
43 /// \param Indices is an optional pointer in the indices list to the current
45 /// \param IndicesEnd is the end of the indices list.
46 /// \param CurIndex is the current index in the recursion.
48 /// \returns \p CurIndex plus the linear index in \p Ty the indices list.
49 unsigned ComputeLinearIndex(Type *Ty,
50 const unsigned *Indices,
51 const unsigned *IndicesEnd,
52 unsigned CurIndex = 0);
54 inline unsigned ComputeLinearIndex(Type *Ty,
55 ArrayRef<unsigned> Indices,
56 unsigned CurIndex = 0) {
57 return ComputeLinearIndex(Ty, Indices.begin(), Indices.end(), CurIndex);
60 /// ComputeValueVTs - Given an LLVM IR type, compute a sequence of
61 /// EVTs that represent all the individual underlying
62 /// non-aggregate types that comprise it.
64 /// If Offsets is non-null, it points to a vector to be filled in
65 /// with the in-memory offsets of each of the individual values.
67 void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty,
68 SmallVectorImpl<EVT> &ValueVTs,
69 SmallVectorImpl<uint64_t> *Offsets = nullptr,
70 uint64_t StartingOffset = 0);
72 /// ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.
73 GlobalValue *ExtractTypeInfo(Value *V);
75 /// hasInlineAsmMemConstraint - Return true if the inline asm instruction being
76 /// processed uses a memory 'm' constraint.
77 bool hasInlineAsmMemConstraint(InlineAsm::ConstraintInfoVector &CInfos,
78 const TargetLowering &TLI);
80 /// getFCmpCondCode - Return the ISD condition code corresponding to
81 /// the given LLVM IR floating-point condition code. This includes
82 /// consideration of global floating-point math flags.
84 ISD::CondCode getFCmpCondCode(FCmpInst::Predicate Pred);
86 /// getFCmpCodeWithoutNaN - Given an ISD condition code comparing floats,
87 /// return the equivalent code if we're allowed to assume that NaNs won't occur.
88 ISD::CondCode getFCmpCodeWithoutNaN(ISD::CondCode CC);
90 /// getICmpCondCode - Return the ISD condition code corresponding to
91 /// the given LLVM IR integer condition code.
93 ISD::CondCode getICmpCondCode(ICmpInst::Predicate Pred);
95 /// Test if the given instruction is in a position to be optimized
96 /// with a tail-call. This roughly means that it's in a block with
97 /// a return and there's nothing that needs to be scheduled
98 /// between it and the return.
100 /// This function only tests target-independent requirements.
101 bool isInTailCallPosition(ImmutableCallSite CS, const TargetMachine &TM);
103 /// Test if given that the input instruction is in the tail call position if the
104 /// return type or any attributes of the function will inhibit tail call
106 bool returnTypeIsEligibleForTailCall(const Function *F,
107 const Instruction *I,
108 const ReturnInst *Ret,
109 const TargetLoweringBase &TLI);
111 // True if GV can be left out of the object symbol table. This is the case
112 // for linkonce_odr values whose address is not significant. While legal, it is
113 // not normally profitable to omit them from the .o symbol table. Using this
114 // analysis makes sense when the information can be passed down to the linker
116 bool canBeOmittedFromSymbolTable(const GlobalValue *GV);
118 } // End llvm namespace