1894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===- CodeGen/Analysis.h - CodeGen LLVM IR Analysis Utilities --*- C++ -*-===//
2894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
3894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//                     The LLVM Compiler Infrastructure
4894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
5894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This file is distributed under the University of Illinois Open Source
6894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// License. See LICENSE.TXT for details.
7894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
8894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===//
9894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
10894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This file declares several CodeGen-specific LLVM IR analysis utilties.
11894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
12894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===//
13894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
14894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#ifndef LLVM_CODEGEN_ANALYSIS_H
15894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#define LLVM_CODEGEN_ANALYSIS_H
16894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
17894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/Instructions.h"
18894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/InlineAsm.h"
1919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman#include "llvm/ADT/ArrayRef.h"
20894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/ADT/SmallVector.h"
21894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/CodeGen/ValueTypes.h"
22894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/CodeGen/ISDOpcodes.h"
23894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/Support/CallSite.h"
24894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
25894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumannamespace llvm {
26894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
27894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass GlobalVariable;
2819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Baumanclass TargetLowering;
2919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Baumanclass SDNode;
3019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Baumanclass SelectionDAG;
31894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
32894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// ComputeLinearIndex - Given an LLVM IR aggregate type and a sequence
33894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// of insertvalue or extractvalue indices that identify a member, return
34894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// the linearized index of the start of the member.
35894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman///
3619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Baumanunsigned ComputeLinearIndex(Type *Ty,
37894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                            const unsigned *Indices,
38894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                            const unsigned *IndicesEnd,
39894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                            unsigned CurIndex = 0);
40894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
4119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Baumaninline unsigned ComputeLinearIndex(Type *Ty,
4219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman                                   ArrayRef<unsigned> Indices,
4319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman                                   unsigned CurIndex = 0) {
4419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  return ComputeLinearIndex(Ty, Indices.begin(), Indices.end(), CurIndex);
4519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman}
4619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
47894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// ComputeValueVTs - Given an LLVM IR type, compute a sequence of
48894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// EVTs that represent all the individual underlying
49894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// non-aggregate types that comprise it.
50894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman///
51894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// If Offsets is non-null, it points to a vector to be filled in
52894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// with the in-memory offsets of each of the individual values.
53894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman///
5419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Baumanvoid ComputeValueVTs(const TargetLowering &TLI, Type *Ty,
55894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                     SmallVectorImpl<EVT> &ValueVTs,
56894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                     SmallVectorImpl<uint64_t> *Offsets = 0,
57894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                     uint64_t StartingOffset = 0);
58894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
59894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.
60894018228b0e0bdbd7aa7e8f47d4a9458789ca82John BaumanGlobalVariable *ExtractTypeInfo(Value *V);
61894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
62894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// hasInlineAsmMemConstraint - Return true if the inline asm instruction being
63894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// processed uses a memory 'm' constraint.
6419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Baumanbool hasInlineAsmMemConstraint(InlineAsm::ConstraintInfoVector &CInfos,
65894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                               const TargetLowering &TLI);
66894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
67894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// getFCmpCondCode - Return the ISD condition code corresponding to
68894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// the given LLVM IR floating-point condition code.  This includes
69894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// consideration of global floating-point math flags.
70894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman///
71894018228b0e0bdbd7aa7e8f47d4a9458789ca82John BaumanISD::CondCode getFCmpCondCode(FCmpInst::Predicate Pred);
72894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
73894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// getICmpCondCode - Return the ISD condition code corresponding to
74894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// the given LLVM IR integer condition code.
75894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman///
76894018228b0e0bdbd7aa7e8f47d4a9458789ca82John BaumanISD::CondCode getICmpCondCode(ICmpInst::Predicate Pred);
77894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
78894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// Test if the given instruction is in a position to be optimized
79894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// with a tail-call. This roughly means that it's in a block with
80894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// a return and there's nothing that needs to be scheduled
81894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// between it and the return.
82894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman///
83894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// This function only tests target-independent requirements.
84894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanbool isInTailCallPosition(ImmutableCallSite CS, Attributes CalleeRetAttr,
85894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                          const TargetLowering &TLI);
86894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
8719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Baumanbool isInTailCallPosition(SelectionDAG &DAG, SDNode *Node,
8819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman                          const TargetLowering &TLI);
8919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
90894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman} // End llvm namespace
91894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
92894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#endif
93