inst_fingerprinter.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. private:
  18. // The fingerprint for each instruction that has had its fingerprint computed,
  19. // indexed by the InstId's index.
  20. //
  21. // TODO: Experiment with also caching fingerprints for instruction blocks once
  22. // we can get realistic performance measurements for this. This would simplify
  23. // the `GetOrCompute` overload for `InstBlockId`s, and may save some work if
  24. // the same canonical inst block is used by multiple instructions, for example
  25. // as a specific argument list.
  26. Map<std::pair<const File*, InstId>, uint64_t> fingerprints_;
  27. };
  28. } // namespace Carbon::SemIR
  29. #endif // CARBON_TOOLCHAIN_SEM_IR_INST_FINGERPRINTER_H_