RegisterUsageInfo.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //==- RegisterUsageInfo.h - Register Usage Informartion Storage --*- C++ -*-==//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. /// \file
  9. /// This pass is required to take advantage of the interprocedural register
  10. /// allocation infrastructure.
  11. ///
  12. /// This pass is simple immutable pass which keeps RegMasks (calculated based on
  13. /// actual register allocation) for functions in a module and provides simple
  14. /// API to query this information.
  15. ///
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_CODEGEN_REGISTERUSAGEINFO_H
  18. #define LLVM_CODEGEN_REGISTERUSAGEINFO_H
  19. #include "llvm/ADT/ArrayRef.h"
  20. #include "llvm/ADT/DenseMap.h"
  21. #include "llvm/IR/Instructions.h"
  22. #include "llvm/InitializePasses.h"
  23. #include "llvm/Pass.h"
  24. #include <cstdint>
  25. #include <vector>
  26. namespace llvm {
  27. class Function;
  28. class LLVMTargetMachine;
  29. class PhysicalRegisterUsageInfo : public ImmutablePass {
  30. public:
  31. static char ID;
  32. PhysicalRegisterUsageInfo() : ImmutablePass(ID) {
  33. PassRegistry &Registry = *PassRegistry::getPassRegistry();
  34. initializePhysicalRegisterUsageInfoPass(Registry);
  35. }
  36. /// Set TargetMachine which is used to print analysis.
  37. void setTargetMachine(const LLVMTargetMachine &TM);
  38. bool doInitialization(Module &M) override;
  39. bool doFinalization(Module &M) override;
  40. /// To store RegMask for given Function *.
  41. void storeUpdateRegUsageInfo(const Function &FP,
  42. ArrayRef<uint32_t> RegMask);
  43. /// To query stored RegMask for given Function *, it will returns ane empty
  44. /// array if function is not known.
  45. ArrayRef<uint32_t> getRegUsageInfo(const Function &FP);
  46. void print(raw_ostream &OS, const Module *M = nullptr) const override;
  47. private:
  48. /// A Dense map from Function * to RegMask.
  49. /// In RegMask 0 means register used (clobbered) by function.
  50. /// and 1 means content of register will be preserved around function call.
  51. DenseMap<const Function *, std::vector<uint32_t>> RegMasks;
  52. const LLVMTargetMachine *TM;
  53. };
  54. } // end namespace llvm
  55. #endif // LLVM_CODEGEN_REGISTERUSAGEINFO_H