MergedLoadStoreMotion.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- MergedLoadStoreMotion.h - merge and hoist/sink load/stores ---------===//
  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. //! \file
  15. //! This pass performs merges of loads and stores on both sides of a
  16. // diamond (hammock). It hoists the loads and sinks the stores.
  17. //
  18. // The algorithm iteratively hoists two loads to the same address out of a
  19. // diamond (hammock) and merges them into a single load in the header. Similar
  20. // it sinks and merges two stores to the tail block (footer). The algorithm
  21. // iterates over the instructions of one side of the diamond and attempts to
  22. // find a matching load/store on the other side. It hoists / sinks when it
  23. // thinks it safe to do so. This optimization helps with eg. hiding load
  24. // latencies, triggering if-conversion, and reducing static code size.
  25. //
  26. //===----------------------------------------------------------------------===//
  27. #ifndef LLVM_TRANSFORMS_SCALAR_MERGEDLOADSTOREMOTION_H
  28. #define LLVM_TRANSFORMS_SCALAR_MERGEDLOADSTOREMOTION_H
  29. #include "llvm/IR/Module.h"
  30. #include "llvm/IR/PassManager.h"
  31. namespace llvm {
  32. struct MergedLoadStoreMotionOptions {
  33. bool SplitFooterBB;
  34. MergedLoadStoreMotionOptions(bool SplitFooterBB = false)
  35. : SplitFooterBB(SplitFooterBB) {}
  36. MergedLoadStoreMotionOptions &splitFooterBB(bool SFBB) {
  37. SplitFooterBB = SFBB;
  38. return *this;
  39. }
  40. };
  41. class MergedLoadStoreMotionPass
  42. : public PassInfoMixin<MergedLoadStoreMotionPass> {
  43. MergedLoadStoreMotionOptions Options;
  44. public:
  45. MergedLoadStoreMotionPass()
  46. : MergedLoadStoreMotionPass(MergedLoadStoreMotionOptions()) {}
  47. MergedLoadStoreMotionPass(const MergedLoadStoreMotionOptions &PassOptions)
  48. : Options(PassOptions) {}
  49. PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
  50. void printPipeline(raw_ostream &OS,
  51. function_ref<StringRef(StringRef)> MapClassName2PassName);
  52. };
  53. }
  54. #endif // LLVM_TRANSFORMS_SCALAR_MERGEDLOADSTOREMOTION_H
  55. #ifdef __GNUC__
  56. #pragma GCC diagnostic pop
  57. #endif