MergedLoadStoreMotion.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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/ADT/STLFunctionalExtras.h"
  30. #include "llvm/IR/PassManager.h"
  31. namespace llvm {
  32. class Function;
  33. struct MergedLoadStoreMotionOptions {
  34. bool SplitFooterBB;
  35. MergedLoadStoreMotionOptions(bool SplitFooterBB = false)
  36. : SplitFooterBB(SplitFooterBB) {}
  37. MergedLoadStoreMotionOptions &splitFooterBB(bool SFBB) {
  38. SplitFooterBB = SFBB;
  39. return *this;
  40. }
  41. };
  42. class MergedLoadStoreMotionPass
  43. : public PassInfoMixin<MergedLoadStoreMotionPass> {
  44. MergedLoadStoreMotionOptions Options;
  45. public:
  46. MergedLoadStoreMotionPass()
  47. : MergedLoadStoreMotionPass(MergedLoadStoreMotionOptions()) {}
  48. MergedLoadStoreMotionPass(const MergedLoadStoreMotionOptions &PassOptions)
  49. : Options(PassOptions) {}
  50. PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
  51. void printPipeline(raw_ostream &OS,
  52. function_ref<StringRef(StringRef)> MapClassName2PassName);
  53. };
  54. }
  55. #endif // LLVM_TRANSFORMS_SCALAR_MERGEDLOADSTOREMOTION_H
  56. #ifdef __GNUC__
  57. #pragma GCC diagnostic pop
  58. #endif