inst_fingerprinter.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #ifndef CARBON_TOOLCHAIN_SEM_IR_INST_FINGERPRINTER_H_
  5. #define CARBON_TOOLCHAIN_SEM_IR_INST_FINGERPRINTER_H_
  6. #include "toolchain/sem_ir/file.h"
  7. #include "toolchain/sem_ir/ids.h"
  8. namespace Carbon::SemIR {
  9. // Computes fingerprints for instructions. These fingerprints are intended to be
  10. // stable across compilations and across minor changes to the compiler.
  11. class InstFingerprinter {
  12. public:
  13. // Gets or computes a fingerprint for the given instruction.
  14. auto GetOrCompute(const File* file, InstId inst_id) -> uint64_t;
  15. // Gets or computes a fingerprint for the given instruction block.
  16. auto GetOrCompute(const File* file, InstBlockId inst_block_id) -> uint64_t;
  17. // Gets or computes a fingerprint for the given impl.
  18. auto GetOrCompute(const File* file, ImplId impl_id) -> uint64_t;
  19. private:
  20. // The fingerprint for each instruction that has had its fingerprint computed,
  21. // indexed by the InstId's index.
  22. //
  23. // TODO: Experiment with also caching fingerprints for instruction blocks once
  24. // we can get realistic performance measurements for this. This would simplify
  25. // the `GetOrCompute` overload for `InstBlockId`s, and may save some work if
  26. // the same canonical inst block is used by multiple instructions, for example
  27. // as a specific argument list.
  28. Map<std::pair<const File*, InstId>, uint64_t> fingerprints_;
  29. };
  30. } // namespace Carbon::SemIR
  31. #endif // CARBON_TOOLCHAIN_SEM_IR_INST_FINGERPRINTER_H_