3132999dde4656cb3fa3e6eddfe54e5ebe625a77
[oota-llvm.git] / include / llvm / CodeGen / Analysis.h
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/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"
23
24 namespace llvm {
25 class GlobalValue;
26 class TargetLoweringBase;
27 class TargetLowering;
28 class TargetMachine;
29 class SDNode;
30 class SDValue;
31 class SelectionDAG;
32 struct EVT;
33
34 /// ComputeLinearIndex - Given an LLVM IR aggregate type and a sequence
35 /// of insertvalue or extractvalue indices that identify a member, return
36 /// the linearized index of the start of the member.
37 ///
38 unsigned ComputeLinearIndex(Type *Ty,
39                             const unsigned *Indices,
40                             const unsigned *IndicesEnd,
41                             unsigned CurIndex = 0);
42
43 inline unsigned ComputeLinearIndex(Type *Ty,
44                                    ArrayRef<unsigned> Indices,
45                                    unsigned CurIndex = 0) {
46   return ComputeLinearIndex(Ty, Indices.begin(), Indices.end(), CurIndex);
47 }
48
49 /// ComputeValueVTs - Given an LLVM IR type, compute a sequence of
50 /// EVTs that represent all the individual underlying
51 /// non-aggregate types that comprise it.
52 ///
53 /// If Offsets is non-null, it points to a vector to be filled in
54 /// with the in-memory offsets of each of the individual values.
55 ///
56 void ComputeValueVTs(const TargetLowering &TLI, Type *Ty,
57                      SmallVectorImpl<EVT> &ValueVTs,
58                      SmallVectorImpl<uint64_t> *Offsets = nullptr,
59                      uint64_t StartingOffset = 0);
60
61 /// ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.
62 GlobalValue *ExtractTypeInfo(Value *V);
63
64 /// hasInlineAsmMemConstraint - Return true if the inline asm instruction being
65 /// processed uses a memory 'm' constraint.
66 bool hasInlineAsmMemConstraint(InlineAsm::ConstraintInfoVector &CInfos,
67                                const TargetLowering &TLI);
68
69 /// getFCmpCondCode - Return the ISD condition code corresponding to
70 /// the given LLVM IR floating-point condition code.  This includes
71 /// consideration of global floating-point math flags.
72 ///
73 ISD::CondCode getFCmpCondCode(FCmpInst::Predicate Pred);
74
75 /// getFCmpCodeWithoutNaN - Given an ISD condition code comparing floats,
76 /// return the equivalent code if we're allowed to assume that NaNs won't occur.
77 ISD::CondCode getFCmpCodeWithoutNaN(ISD::CondCode CC);
78
79 /// getICmpCondCode - Return the ISD condition code corresponding to
80 /// the given LLVM IR integer condition code.
81 ///
82 ISD::CondCode getICmpCondCode(ICmpInst::Predicate Pred);
83
84 /// Test if the given instruction is in a position to be optimized
85 /// with a tail-call. This roughly means that it's in a block with
86 /// a return and there's nothing that needs to be scheduled
87 /// between it and the return.
88 ///
89 /// This function only tests target-independent requirements.
90 bool isInTailCallPosition(ImmutableCallSite CS, const TargetMachine &TM);
91
92 /// Test if given that the input instruction is in the tail call position if the
93 /// return type or any attributes of the function will inhibit tail call
94 /// optimization.
95 bool returnTypeIsEligibleForTailCall(const Function *F,
96                                      const Instruction *I,
97                                      const ReturnInst *Ret,
98                                      const TargetLoweringBase &TLI);
99
100 // True if GV can be left out of the object symbol table. This is the case
101 // for linkonce_odr values whose address is not significant. While legal, it is
102 // not normally profitable to omit them from the .o symbol table. Using this
103 // analysis makes sense when the information can be passed down to the linker
104 // or we are in LTO.
105 bool canBeOmittedFromSymbolTable(const GlobalValue *GV);
106
107 } // End llvm namespace
108
109 #endif