1207618Srdivacky//===- CodeGen/Analysis.h - CodeGen LLVM IR Analysis Utilities --*- C++ -*-===// 2207618Srdivacky// 3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4353358Sdim// See https://llvm.org/LICENSE.txt for license information. 5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6207618Srdivacky// 7207618Srdivacky//===----------------------------------------------------------------------===// 8207618Srdivacky// 9276479Sdim// This file declares several CodeGen-specific LLVM IR analysis utilities. 10207618Srdivacky// 11207618Srdivacky//===----------------------------------------------------------------------===// 12207618Srdivacky 13207618Srdivacky#ifndef LLVM_CODEGEN_ANALYSIS_H 14207618Srdivacky#define LLVM_CODEGEN_ANALYSIS_H 15207618Srdivacky 16224145Sdim#include "llvm/ADT/ArrayRef.h" 17296417Sdim#include "llvm/ADT/DenseMap.h" 18207618Srdivacky#include "llvm/ADT/SmallVector.h" 19309124Sdim#include "llvm/ADT/Triple.h" 20249423Sdim#include "llvm/CodeGen/ISDOpcodes.h" 21276479Sdim#include "llvm/IR/CallSite.h" 22249423Sdim#include "llvm/IR/InlineAsm.h" 23249423Sdim#include "llvm/IR/Instructions.h" 24309124Sdim#include "llvm/Support/CodeGen.h" 25207618Srdivacky 26207618Srdivackynamespace llvm { 27280031Sdimclass GlobalValue; 28353358Sdimclass LLT; 29296417Sdimclass MachineBasicBlock; 30296417Sdimclass MachineFunction; 31276479Sdimclass TargetLoweringBase; 32207618Srdivackyclass TargetLowering; 33276479Sdimclass TargetMachine; 34218893Sdimclass SDNode; 35234353Sdimclass SDValue; 36218893Sdimclass SelectionDAG; 37276479Sdimstruct EVT; 38207618Srdivacky 39341825Sdim/// Compute the linearized index of a member in a nested 40280031Sdim/// aggregate/struct/array. 41207618Srdivacky/// 42280031Sdim/// Given an LLVM IR aggregate type and a sequence of insertvalue or 43280031Sdim/// extractvalue indices that identify a member, return the linearized index of 44280031Sdim/// the start of the member, i.e the number of element in memory before the 45296417Sdim/// sought one. This is disconnected from the number of bytes. 46280031Sdim/// 47280031Sdim/// \param Ty is the type indexed by \p Indices. 48280031Sdim/// \param Indices is an optional pointer in the indices list to the current 49280031Sdim/// index. 50280031Sdim/// \param IndicesEnd is the end of the indices list. 51280031Sdim/// \param CurIndex is the current index in the recursion. 52280031Sdim/// 53280031Sdim/// \returns \p CurIndex plus the linear index in \p Ty the indices list. 54226633Sdimunsigned ComputeLinearIndex(Type *Ty, 55207618Srdivacky const unsigned *Indices, 56207618Srdivacky const unsigned *IndicesEnd, 57207618Srdivacky unsigned CurIndex = 0); 58207618Srdivacky 59226633Sdiminline unsigned ComputeLinearIndex(Type *Ty, 60224145Sdim ArrayRef<unsigned> Indices, 61224145Sdim unsigned CurIndex = 0) { 62224145Sdim return ComputeLinearIndex(Ty, Indices.begin(), Indices.end(), CurIndex); 63224145Sdim} 64224145Sdim 65207618Srdivacky/// ComputeValueVTs - Given an LLVM IR type, compute a sequence of 66207618Srdivacky/// EVTs that represent all the individual underlying 67207618Srdivacky/// non-aggregate types that comprise it. 68207618Srdivacky/// 69207618Srdivacky/// If Offsets is non-null, it points to a vector to be filled in 70207618Srdivacky/// with the in-memory offsets of each of the individual values. 71207618Srdivacky/// 72288943Sdimvoid ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty, 73207618Srdivacky SmallVectorImpl<EVT> &ValueVTs, 74276479Sdim SmallVectorImpl<uint64_t> *Offsets = nullptr, 75207618Srdivacky uint64_t StartingOffset = 0); 76207618Srdivacky 77353358Sdim/// Variant of ComputeValueVTs that also produces the memory VTs. 78353358Sdimvoid ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty, 79353358Sdim SmallVectorImpl<EVT> &ValueVTs, 80353358Sdim SmallVectorImpl<EVT> *MemVTs, 81353358Sdim SmallVectorImpl<uint64_t> *Offsets = nullptr, 82353358Sdim uint64_t StartingOffset = 0); 83353358Sdim 84353358Sdim/// computeValueLLTs - Given an LLVM IR type, compute a sequence of 85353358Sdim/// LLTs that represent all the individual underlying 86353358Sdim/// non-aggregate types that comprise it. 87353358Sdim/// 88353358Sdim/// If Offsets is non-null, it points to a vector to be filled in 89353358Sdim/// with the in-memory offsets of each of the individual values. 90353358Sdim/// 91353358Sdimvoid computeValueLLTs(const DataLayout &DL, Type &Ty, 92353358Sdim SmallVectorImpl<LLT> &ValueTys, 93353358Sdim SmallVectorImpl<uint64_t> *Offsets = nullptr, 94353358Sdim uint64_t StartingOffset = 0); 95353358Sdim 96207618Srdivacky/// ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V. 97280031SdimGlobalValue *ExtractTypeInfo(Value *V); 98207618Srdivacky 99207618Srdivacky/// hasInlineAsmMemConstraint - Return true if the inline asm instruction being 100207618Srdivacky/// processed uses a memory 'm' constraint. 101218893Sdimbool hasInlineAsmMemConstraint(InlineAsm::ConstraintInfoVector &CInfos, 102207618Srdivacky const TargetLowering &TLI); 103207618Srdivacky 104207618Srdivacky/// getFCmpCondCode - Return the ISD condition code corresponding to 105207618Srdivacky/// the given LLVM IR floating-point condition code. This includes 106207618Srdivacky/// consideration of global floating-point math flags. 107207618Srdivacky/// 108207618SrdivackyISD::CondCode getFCmpCondCode(FCmpInst::Predicate Pred); 109207618Srdivacky 110234353Sdim/// getFCmpCodeWithoutNaN - Given an ISD condition code comparing floats, 111234353Sdim/// return the equivalent code if we're allowed to assume that NaNs won't occur. 112234353SdimISD::CondCode getFCmpCodeWithoutNaN(ISD::CondCode CC); 113234353Sdim 114207618Srdivacky/// getICmpCondCode - Return the ISD condition code corresponding to 115207618Srdivacky/// the given LLVM IR integer condition code. 116207618Srdivacky/// 117207618SrdivackyISD::CondCode getICmpCondCode(ICmpInst::Predicate Pred); 118207618Srdivacky 119207618Srdivacky/// Test if the given instruction is in a position to be optimized 120207618Srdivacky/// with a tail-call. This roughly means that it's in a block with 121207618Srdivacky/// a return and there's nothing that needs to be scheduled 122207618Srdivacky/// between it and the return. 123207618Srdivacky/// 124207618Srdivacky/// This function only tests target-independent requirements. 125276479Sdimbool isInTailCallPosition(ImmutableCallSite CS, const TargetMachine &TM); 126207618Srdivacky 127314564Sdim/// Test if given that the input instruction is in the tail call position, if 128314564Sdim/// there is an attribute mismatch between the caller and the callee that will 129314564Sdim/// inhibit tail call optimizations. 130314564Sdim/// \p AllowDifferingSizes is an output parameter which, if forming a tail call 131314564Sdim/// is permitted, determines whether it's permitted only if the size of the 132314564Sdim/// caller's and callee's return types match exactly. 133314564Sdimbool attributesPermitTailCall(const Function *F, const Instruction *I, 134314564Sdim const ReturnInst *Ret, 135314564Sdim const TargetLoweringBase &TLI, 136314564Sdim bool *AllowDifferingSizes = nullptr); 137314564Sdim 138261991Sdim/// Test if given that the input instruction is in the tail call position if the 139261991Sdim/// return type or any attributes of the function will inhibit tail call 140261991Sdim/// optimization. 141314564Sdimbool returnTypeIsEligibleForTailCall(const Function *F, const Instruction *I, 142261991Sdim const ReturnInst *Ret, 143261991Sdim const TargetLoweringBase &TLI); 144261991Sdim 145296417SdimDenseMap<const MachineBasicBlock *, int> 146341825SdimgetEHScopeMembership(const MachineFunction &MF); 147296417Sdim 148207618Srdivacky} // End llvm namespace 149207618Srdivacky 150207618Srdivacky#endif 151