15eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman//===- CodeGen/Analysis.h - CodeGen LLVM IR Analysis Utilities --*- C++ -*-===//
25eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman//
35eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman//                     The LLVM Compiler Infrastructure
45eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman//
55eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman// This file is distributed under the University of Illinois Open Source
65eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman// License. See LICENSE.TXT for details.
75eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman//
85eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman//===----------------------------------------------------------------------===//
95eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman//
10cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines// This file declares several CodeGen-specific LLVM IR analysis utilities.
115eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman//
125eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman//===----------------------------------------------------------------------===//
135eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman
145eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman#ifndef LLVM_CODEGEN_ANALYSIS_H
155eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman#define LLVM_CODEGEN_ANALYSIS_H
165eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman
17fc6d3a49867cd38954dc40936a88f1907252c6d2Jay Foad#include "llvm/ADT/ArrayRef.h"
185eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman#include "llvm/ADT/SmallVector.h"
195eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman#include "llvm/CodeGen/ISDOpcodes.h"
2036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#include "llvm/IR/CallSite.h"
210b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/InlineAsm.h"
220b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/Instructions.h"
235eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman
245eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohmannamespace llvm {
255eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohmanclass GlobalVariable;
269d6852cf98dd1e6a939b3469ea49ff7cbc15ad73Michael Gottesmanclass TargetLoweringBase;
273d2125c9dbac695c93f42c0f59fd040e413fd711Evan Chengclass SDNode;
28bf010eb9110009d745382bf15131fbe556562ffeEvan Chengclass SDValue;
293d2125c9dbac695c93f42c0f59fd040e413fd711Evan Chengclass SelectionDAG;
3036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesclass TargetLowering;
3136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstruct EVT;
325eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman
335eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman/// ComputeLinearIndex - Given an LLVM IR aggregate type and a sequence
345eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman/// of insertvalue or extractvalue indices that identify a member, return
355eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman/// the linearized index of the start of the member.
365eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman///
37db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattnerunsigned ComputeLinearIndex(Type *Ty,
385eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman                            const unsigned *Indices,
395eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman                            const unsigned *IndicesEnd,
405eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman                            unsigned CurIndex = 0);
415eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman
42db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattnerinline unsigned ComputeLinearIndex(Type *Ty,
43fc6d3a49867cd38954dc40936a88f1907252c6d2Jay Foad                                   ArrayRef<unsigned> Indices,
44fc6d3a49867cd38954dc40936a88f1907252c6d2Jay Foad                                   unsigned CurIndex = 0) {
45fc6d3a49867cd38954dc40936a88f1907252c6d2Jay Foad  return ComputeLinearIndex(Ty, Indices.begin(), Indices.end(), CurIndex);
46fc6d3a49867cd38954dc40936a88f1907252c6d2Jay Foad}
47fc6d3a49867cd38954dc40936a88f1907252c6d2Jay Foad
485eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman/// ComputeValueVTs - Given an LLVM IR type, compute a sequence of
495eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman/// EVTs that represent all the individual underlying
505eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman/// non-aggregate types that comprise it.
515eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman///
525eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman/// If Offsets is non-null, it points to a vector to be filled in
535eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman/// with the in-memory offsets of each of the individual values.
545eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman///
55db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattnervoid ComputeValueVTs(const TargetLowering &TLI, Type *Ty,
565eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman                     SmallVectorImpl<EVT> &ValueVTs,
57dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines                     SmallVectorImpl<uint64_t> *Offsets = nullptr,
585eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman                     uint64_t StartingOffset = 0);
595eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman
605eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman/// ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.
615eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan GohmanGlobalVariable *ExtractTypeInfo(Value *V);
625eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman
635eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman/// hasInlineAsmMemConstraint - Return true if the inline asm instruction being
645eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman/// processed uses a memory 'm' constraint.
6544ab89eb376af838d1123293a79975aede501464John Thompsonbool hasInlineAsmMemConstraint(InlineAsm::ConstraintInfoVector &CInfos,
665eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman                               const TargetLowering &TLI);
675eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman
685eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman/// getFCmpCondCode - Return the ISD condition code corresponding to
695eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman/// the given LLVM IR floating-point condition code.  This includes
705eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman/// consideration of global floating-point math flags.
715eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman///
725eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan GohmanISD::CondCode getFCmpCondCode(FCmpInst::Predicate Pred);
735eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman
748a8d479214745c82ef00f08d4e4f1c173b5f9ce2Nick Lewycky/// getFCmpCodeWithoutNaN - Given an ISD condition code comparing floats,
758a8d479214745c82ef00f08d4e4f1c173b5f9ce2Nick Lewycky/// return the equivalent code if we're allowed to assume that NaNs won't occur.
768a8d479214745c82ef00f08d4e4f1c173b5f9ce2Nick LewyckyISD::CondCode getFCmpCodeWithoutNaN(ISD::CondCode CC);
778a8d479214745c82ef00f08d4e4f1c173b5f9ce2Nick Lewycky
785eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman/// getICmpCondCode - Return the ISD condition code corresponding to
795eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman/// the given LLVM IR integer condition code.
805eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman///
815eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan GohmanISD::CondCode getICmpCondCode(ICmpInst::Predicate Pred);
825eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman
835eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman/// Test if the given instruction is in a position to be optimized
845eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman/// with a tail-call. This roughly means that it's in a block with
855eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman/// a return and there's nothing that needs to be scheduled
865eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman/// between it and the return.
875eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman///
885eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman/// This function only tests target-independent requirements.
89cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesbool isInTailCallPosition(ImmutableCallSite CS, const SelectionDAG &DAG);
905eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman
919d6852cf98dd1e6a939b3469ea49ff7cbc15ad73Michael Gottesman/// Test if given that the input instruction is in the tail call position if the
929d6852cf98dd1e6a939b3469ea49ff7cbc15ad73Michael Gottesman/// return type or any attributes of the function will inhibit tail call
939d6852cf98dd1e6a939b3469ea49ff7cbc15ad73Michael Gottesman/// optimization.
949d6852cf98dd1e6a939b3469ea49ff7cbc15ad73Michael Gottesmanbool returnTypeIsEligibleForTailCall(const Function *F,
959d6852cf98dd1e6a939b3469ea49ff7cbc15ad73Michael Gottesman                                     const Instruction *I,
969d6852cf98dd1e6a939b3469ea49ff7cbc15ad73Michael Gottesman                                     const ReturnInst *Ret,
979d6852cf98dd1e6a939b3469ea49ff7cbc15ad73Michael Gottesman                                     const TargetLoweringBase &TLI);
989d6852cf98dd1e6a939b3469ea49ff7cbc15ad73Michael Gottesman
995eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman} // End llvm namespace
1005eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman
1015eb6d65a27fd77a0bf10bd49f5cccb9f1796d98bDan Gohman#endif
102