Analysis.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //===- CodeGen/Analysis.h - CodeGen LLVM IR Analysis Utilities --*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file declares several CodeGen-specific LLVM IR analysis utilities.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_CODEGEN_ANALYSIS_H
  14. #define LLVM_CODEGEN_ANALYSIS_H
  15. #include "llvm/ADT/ArrayRef.h"
  16. #include "llvm/ADT/SmallVector.h"
  17. #include "llvm/CodeGen/ISDOpcodes.h"
  18. #include "llvm/IR/CallSite.h"
  19. #include "llvm/IR/InlineAsm.h"
  20. #include "llvm/IR/Instructions.h"
  21. namespace llvm {
  22. class GlobalValue;
  23. class TargetLoweringBase;
  24. class TargetLowering;
  25. class TargetMachine;
  26. class SDNode;
  27. class SDValue;
  28. class SelectionDAG;
  29. struct EVT;
  30. /// \brief Compute the linearized index of a member in a nested
  31. /// aggregate/struct/array.
  32. ///
  33. /// Given an LLVM IR aggregate type and a sequence of insertvalue or
  34. /// extractvalue indices that identify a member, return the linearized index of
  35. /// the start of the member, i.e the number of element in memory before the
  36. /// seeked one. This is disconnected from the number of bytes.
  37. ///
  38. /// \param Ty is the type indexed by \p Indices.
  39. /// \param Indices is an optional pointer in the indices list to the current
  40. /// index.
  41. /// \param IndicesEnd is the end of the indices list.
  42. /// \param CurIndex is the current index in the recursion.
  43. ///
  44. /// \returns \p CurIndex plus the linear index in \p Ty the indices list.
  45. unsigned ComputeLinearIndex(Type *Ty,
  46. const unsigned *Indices,
  47. const unsigned *IndicesEnd,
  48. unsigned CurIndex = 0);
  49. inline unsigned ComputeLinearIndex(Type *Ty,
  50. ArrayRef<unsigned> Indices,
  51. unsigned CurIndex = 0) {
  52. return ComputeLinearIndex(Ty, Indices.begin(), Indices.end(), CurIndex);
  53. }
  54. /// ComputeValueVTs - Given an LLVM IR type, compute a sequence of
  55. /// EVTs that represent all the individual underlying
  56. /// non-aggregate types that comprise it.
  57. ///
  58. /// If Offsets is non-null, it points to a vector to be filled in
  59. /// with the in-memory offsets of each of the individual values.
  60. ///
  61. void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty,
  62. SmallVectorImpl<EVT> &ValueVTs,
  63. SmallVectorImpl<uint64_t> *Offsets = nullptr,
  64. uint64_t StartingOffset = 0);
  65. /// ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.
  66. GlobalValue *ExtractTypeInfo(Value *V);
  67. /// hasInlineAsmMemConstraint - Return true if the inline asm instruction being
  68. /// processed uses a memory 'm' constraint.
  69. bool hasInlineAsmMemConstraint(InlineAsm::ConstraintInfoVector &CInfos,
  70. const TargetLowering &TLI);
  71. /// getFCmpCondCode - Return the ISD condition code corresponding to
  72. /// the given LLVM IR floating-point condition code. This includes
  73. /// consideration of global floating-point math flags.
  74. ///
  75. ISD::CondCode getFCmpCondCode(FCmpInst::Predicate Pred);
  76. /// getFCmpCodeWithoutNaN - Given an ISD condition code comparing floats,
  77. /// return the equivalent code if we're allowed to assume that NaNs won't occur.
  78. ISD::CondCode getFCmpCodeWithoutNaN(ISD::CondCode CC);
  79. /// getICmpCondCode - Return the ISD condition code corresponding to
  80. /// the given LLVM IR integer condition code.
  81. ///
  82. ISD::CondCode getICmpCondCode(ICmpInst::Predicate Pred);
  83. /// Test if the given instruction is in a position to be optimized
  84. /// with a tail-call. This roughly means that it's in a block with
  85. /// a return and there's nothing that needs to be scheduled
  86. /// between it and the return.
  87. ///
  88. /// This function only tests target-independent requirements.
  89. bool isInTailCallPosition(ImmutableCallSite CS, const TargetMachine &TM);
  90. /// Test if given that the input instruction is in the tail call position if the
  91. /// return type or any attributes of the function will inhibit tail call
  92. /// optimization.
  93. bool returnTypeIsEligibleForTailCall(const Function *F,
  94. const Instruction *I,
  95. const ReturnInst *Ret,
  96. const TargetLoweringBase &TLI);
  97. // True if GV can be left out of the object symbol table. This is the case
  98. // for linkonce_odr values whose address is not significant. While legal, it is
  99. // not normally profitable to omit them from the .o symbol table. Using this
  100. // analysis makes sense when the information can be passed down to the linker
  101. // or we are in LTO.
  102. bool canBeOmittedFromSymbolTable(const GlobalValue *GV);
  103. } // End llvm namespace
  104. #endif