VNCoercion.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- VNCoercion.h - Value Numbering Coercion 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. /// \file / This file provides routines used by LLVM's value numbering passes to
  14. /// perform various forms of value extraction from memory when the types are not
  15. /// identical. For example, given
  16. ///
  17. /// store i32 8, i32 *%foo
  18. /// %a = bitcast i32 *%foo to i16
  19. /// %val = load i16, i16 *%a
  20. ///
  21. /// It possible to extract the value of the load of %a from the store to %foo.
  22. /// These routines know how to tell whether they can do that (the analyze*
  23. /// routines), and can also insert the necessary IR to do it (the get*
  24. /// routines).
  25. #ifndef LLVM_TRANSFORMS_UTILS_VNCOERCION_H
  26. #define LLVM_TRANSFORMS_UTILS_VNCOERCION_H
  27. namespace llvm {
  28. class Constant;
  29. class StoreInst;
  30. class LoadInst;
  31. class MemIntrinsic;
  32. class Instruction;
  33. class IRBuilderBase;
  34. class Value;
  35. class Type;
  36. class DataLayout;
  37. namespace VNCoercion {
  38. /// Return true if CoerceAvailableValueToLoadType would succeed if it was
  39. /// called.
  40. bool canCoerceMustAliasedValueToLoad(Value *StoredVal, Type *LoadTy,
  41. const DataLayout &DL);
  42. /// If we saw a store of a value to memory, and then a load from a must-aliased
  43. /// pointer of a different type, try to coerce the stored value to the loaded
  44. /// type. LoadedTy is the type of the load we want to replace. IRB is
  45. /// IRBuilder used to insert new instructions.
  46. ///
  47. /// If we can't do it, return null.
  48. Value *coerceAvailableValueToLoadType(Value *StoredVal, Type *LoadedTy,
  49. IRBuilderBase &IRB, const DataLayout &DL);
  50. /// This function determines whether a value for the pointer LoadPtr can be
  51. /// extracted from the store at DepSI.
  52. ///
  53. /// On success, it returns the offset into DepSI that extraction would start.
  54. /// On failure, it returns -1.
  55. int analyzeLoadFromClobberingStore(Type *LoadTy, Value *LoadPtr,
  56. StoreInst *DepSI, const DataLayout &DL);
  57. /// This function determines whether a value for the pointer LoadPtr can be
  58. /// extracted from the load at DepLI.
  59. ///
  60. /// On success, it returns the offset into DepLI that extraction would start.
  61. /// On failure, it returns -1.
  62. int analyzeLoadFromClobberingLoad(Type *LoadTy, Value *LoadPtr, LoadInst *DepLI,
  63. const DataLayout &DL);
  64. /// This function determines whether a value for the pointer LoadPtr can be
  65. /// extracted from the memory intrinsic at DepMI.
  66. ///
  67. /// On success, it returns the offset into DepMI that extraction would start.
  68. /// On failure, it returns -1.
  69. int analyzeLoadFromClobberingMemInst(Type *LoadTy, Value *LoadPtr,
  70. MemIntrinsic *DepMI, const DataLayout &DL);
  71. /// If analyzeLoadFromClobberingStore returned an offset, this function can be
  72. /// used to actually perform the extraction of the bits from the store. It
  73. /// inserts instructions to do so at InsertPt, and returns the extracted value.
  74. Value *getStoreValueForLoad(Value *SrcVal, unsigned Offset, Type *LoadTy,
  75. Instruction *InsertPt, const DataLayout &DL);
  76. // This is the same as getStoreValueForLoad, except it performs no insertion
  77. // It only allows constant inputs.
  78. Constant *getConstantStoreValueForLoad(Constant *SrcVal, unsigned Offset,
  79. Type *LoadTy, const DataLayout &DL);
  80. /// If analyzeLoadFromClobberingLoad returned an offset, this function can be
  81. /// used to actually perform the extraction of the bits from the load, including
  82. /// any necessary load widening. It inserts instructions to do so at InsertPt,
  83. /// and returns the extracted value.
  84. Value *getLoadValueForLoad(LoadInst *SrcVal, unsigned Offset, Type *LoadTy,
  85. Instruction *InsertPt, const DataLayout &DL);
  86. // This is the same as getLoadValueForLoad, except it is given the load value as
  87. // a constant. It returns nullptr if it would require widening the load.
  88. Constant *getConstantLoadValueForLoad(Constant *SrcVal, unsigned Offset,
  89. Type *LoadTy, const DataLayout &DL);
  90. /// If analyzeLoadFromClobberingMemInst returned an offset, this function can be
  91. /// used to actually perform the extraction of the bits from the memory
  92. /// intrinsic. It inserts instructions to do so at InsertPt, and returns the
  93. /// extracted value.
  94. Value *getMemInstValueForLoad(MemIntrinsic *SrcInst, unsigned Offset,
  95. Type *LoadTy, Instruction *InsertPt,
  96. const DataLayout &DL);
  97. // This is the same as getStoreValueForLoad, except it performs no insertion.
  98. // It returns nullptr if it cannot produce a constant.
  99. Constant *getConstantMemInstValueForLoad(MemIntrinsic *SrcInst, unsigned Offset,
  100. Type *LoadTy, const DataLayout &DL);
  101. }
  102. }
  103. #endif
  104. #ifdef __GNUC__
  105. #pragma GCC diagnostic pop
  106. #endif