Analysis.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- CodeGen/Analysis.h - CodeGen LLVM IR Analysis Utilities --*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file declares several CodeGen-specific LLVM IR analysis utilities.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_CODEGEN_ANALYSIS_H
  18. #define LLVM_CODEGEN_ANALYSIS_H
  19. #include "llvm/ADT/ArrayRef.h"
  20. #include "llvm/ADT/DenseMap.h"
  21. #include "llvm/CodeGen/ISDOpcodes.h"
  22. #include "llvm/IR/Instructions.h"
  23. namespace llvm {
  24. template <typename T> class SmallVectorImpl;
  25. class GlobalValue;
  26. class LLT;
  27. class MachineBasicBlock;
  28. class MachineFunction;
  29. class TargetLoweringBase;
  30. class TargetLowering;
  31. class TargetMachine;
  32. struct EVT;
  33. /// Compute the linearized index of a member in a nested
  34. /// aggregate/struct/array.
  35. ///
  36. /// Given an LLVM IR aggregate type and a sequence of insertvalue or
  37. /// extractvalue indices that identify a member, return the linearized index of
  38. /// the start of the member, i.e the number of element in memory before the
  39. /// sought one. This is disconnected from the number of bytes.
  40. ///
  41. /// \param Ty is the type indexed by \p Indices.
  42. /// \param Indices is an optional pointer in the indices list to the current
  43. /// index.
  44. /// \param IndicesEnd is the end of the indices list.
  45. /// \param CurIndex is the current index in the recursion.
  46. ///
  47. /// \returns \p CurIndex plus the linear index in \p Ty the indices list.
  48. unsigned ComputeLinearIndex(Type *Ty,
  49. const unsigned *Indices,
  50. const unsigned *IndicesEnd,
  51. unsigned CurIndex = 0);
  52. inline unsigned ComputeLinearIndex(Type *Ty,
  53. ArrayRef<unsigned> Indices,
  54. unsigned CurIndex = 0) {
  55. return ComputeLinearIndex(Ty, Indices.begin(), Indices.end(), CurIndex);
  56. }
  57. /// ComputeValueVTs - Given an LLVM IR type, compute a sequence of
  58. /// EVTs that represent all the individual underlying
  59. /// non-aggregate types that comprise it.
  60. ///
  61. /// If Offsets is non-null, it points to a vector to be filled in
  62. /// with the in-memory offsets of each of the individual values.
  63. ///
  64. void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty,
  65. SmallVectorImpl<EVT> &ValueVTs,
  66. SmallVectorImpl<uint64_t> *Offsets = nullptr,
  67. uint64_t StartingOffset = 0);
  68. /// Variant of ComputeValueVTs that also produces the memory VTs.
  69. void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty,
  70. SmallVectorImpl<EVT> &ValueVTs,
  71. SmallVectorImpl<EVT> *MemVTs,
  72. SmallVectorImpl<uint64_t> *Offsets = nullptr,
  73. uint64_t StartingOffset = 0);
  74. /// computeValueLLTs - Given an LLVM IR type, compute a sequence of
  75. /// LLTs that represent all the individual underlying
  76. /// non-aggregate types that comprise it.
  77. ///
  78. /// If Offsets is non-null, it points to a vector to be filled in
  79. /// with the in-memory offsets of each of the individual values.
  80. ///
  81. void computeValueLLTs(const DataLayout &DL, Type &Ty,
  82. SmallVectorImpl<LLT> &ValueTys,
  83. SmallVectorImpl<uint64_t> *Offsets = nullptr,
  84. uint64_t StartingOffset = 0);
  85. /// ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.
  86. GlobalValue *ExtractTypeInfo(Value *V);
  87. /// getFCmpCondCode - Return the ISD condition code corresponding to
  88. /// the given LLVM IR floating-point condition code. This includes
  89. /// consideration of global floating-point math flags.
  90. ///
  91. ISD::CondCode getFCmpCondCode(FCmpInst::Predicate Pred);
  92. /// getFCmpCodeWithoutNaN - Given an ISD condition code comparing floats,
  93. /// return the equivalent code if we're allowed to assume that NaNs won't occur.
  94. ISD::CondCode getFCmpCodeWithoutNaN(ISD::CondCode CC);
  95. /// getICmpCondCode - Return the ISD condition code corresponding to
  96. /// the given LLVM IR integer condition code.
  97. ISD::CondCode getICmpCondCode(ICmpInst::Predicate Pred);
  98. /// getICmpCondCode - Return the LLVM IR integer condition code
  99. /// corresponding to the given ISD integer condition code.
  100. ICmpInst::Predicate getICmpCondCode(ISD::CondCode Pred);
  101. /// Test if the given instruction is in a position to be optimized
  102. /// with a tail-call. This roughly means that it's in a block with
  103. /// a return and there's nothing that needs to be scheduled
  104. /// between it and the return.
  105. ///
  106. /// This function only tests target-independent requirements.
  107. bool isInTailCallPosition(const CallBase &Call, const TargetMachine &TM);
  108. /// Test if given that the input instruction is in the tail call position, if
  109. /// there is an attribute mismatch between the caller and the callee that will
  110. /// inhibit tail call optimizations.
  111. /// \p AllowDifferingSizes is an output parameter which, if forming a tail call
  112. /// is permitted, determines whether it's permitted only if the size of the
  113. /// caller's and callee's return types match exactly.
  114. bool attributesPermitTailCall(const Function *F, const Instruction *I,
  115. const ReturnInst *Ret,
  116. const TargetLoweringBase &TLI,
  117. bool *AllowDifferingSizes = nullptr);
  118. /// Test if given that the input instruction is in the tail call position if the
  119. /// return type or any attributes of the function will inhibit tail call
  120. /// optimization.
  121. bool returnTypeIsEligibleForTailCall(const Function *F, const Instruction *I,
  122. const ReturnInst *Ret,
  123. const TargetLoweringBase &TLI);
  124. DenseMap<const MachineBasicBlock *, int>
  125. getEHScopeMembership(const MachineFunction &MF);
  126. } // End llvm namespace
  127. #endif
  128. #ifdef __GNUC__
  129. #pragma GCC diagnostic pop
  130. #endif