Analysis.h 6.1 KB

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