HLUtil.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // HLUtil.h //
  4. // Copyright (C) Microsoft Corporation. All rights reserved. //
  5. // This file is distributed under the University of Illinois Open Source //
  6. // License. See LICENSE.TXT for details. //
  7. // //
  8. // HL helper functions. //
  9. // //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #pragma once
  12. #include "llvm/ADT/SetVector.h"
  13. namespace llvm {
  14. class Function;
  15. class Value;
  16. class MemCpyInst;
  17. } // namespace llvm
  18. namespace hlsl {
  19. class DxilTypeSystem;
  20. namespace hlutil {
  21. struct PointerStatus {
  22. /// Keep track of what stores to the pointer look like.
  23. enum class StoredType {
  24. /// There is no store to this pointer. It can thus be marked constant.
  25. NotStored,
  26. /// This ptr is a global, and is stored to, but the only thing stored is the
  27. /// constant it
  28. /// was initialized with. This is only tracked for scalar globals.
  29. InitializerStored,
  30. /// This ptr is stored to, but only its initializer and one other value
  31. /// is ever stored to it. If this global isStoredOnce, we track the value
  32. /// stored to it in StoredOnceValue below. This is only tracked for scalar
  33. /// globals.
  34. StoredOnce,
  35. /// This ptr is only assigned by a memcpy.
  36. MemcopyDestOnce,
  37. /// This ptr is stored to by multiple values or something else that we
  38. /// cannot track.
  39. Stored
  40. } storedType;
  41. /// Keep track of what loaded from the pointer look like.
  42. enum class LoadedType {
  43. /// There is no load to this pointer. It can thus be marked constant.
  44. NotLoaded,
  45. /// This ptr is only used by a memcpy.
  46. MemcopySrcOnce,
  47. /// This ptr is loaded to by multiple instructions or something else that we
  48. /// cannot track.
  49. Loaded
  50. } loadedType;
  51. /// If only one value (besides the initializer constant) is ever stored to
  52. /// this global, keep track of what value it is.
  53. llvm::Value *StoredOnceValue;
  54. /// Memcpy which this ptr is used.
  55. llvm::SetVector<llvm::MemCpyInst *> memcpySet;
  56. /// Memcpy which use this ptr as dest.
  57. llvm::MemCpyInst *StoringMemcpy;
  58. /// Memcpy which use this ptr as src.
  59. llvm::MemCpyInst *LoadingMemcpy;
  60. /// These start out null/false. When the first accessing function is noticed,
  61. /// it is recorded. When a second different accessing function is noticed,
  62. /// HasMultipleAccessingFunctions is set to true.
  63. const llvm::Function *AccessingFunction;
  64. bool HasMultipleAccessingFunctions;
  65. /// Size of the ptr.
  66. unsigned Size;
  67. llvm::Value *Ptr;
  68. // Just check load store.
  69. bool bLoadStoreOnly;
  70. void analyze(DxilTypeSystem &typeSys, bool bStructElt);
  71. PointerStatus(llvm::Value *ptr, unsigned size, bool bLdStOnly);
  72. void MarkAsStored();
  73. void MarkAsLoaded();
  74. bool HasStored();
  75. bool HasLoaded();
  76. };
  77. } // namespace hlutil
  78. } // namespace hlsl