Float2Int.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-- Float2Int.h - Demote floating point ops to work on integers -------===//
  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. // This file provides the Float2Int pass, which aims to demote floating
  15. // point operations to work on integers, where that is losslessly possible.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_TRANSFORMS_SCALAR_FLOAT2INT_H
  19. #define LLVM_TRANSFORMS_SCALAR_FLOAT2INT_H
  20. #include "llvm/ADT/EquivalenceClasses.h"
  21. #include "llvm/ADT/MapVector.h"
  22. #include "llvm/ADT/SetVector.h"
  23. #include "llvm/IR/ConstantRange.h"
  24. #include "llvm/IR/PassManager.h"
  25. namespace llvm {
  26. class DominatorTree;
  27. class Function;
  28. class Instruction;
  29. class LLVMContext;
  30. class Type;
  31. class Value;
  32. class Float2IntPass : public PassInfoMixin<Float2IntPass> {
  33. public:
  34. PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
  35. // Glue for old PM.
  36. bool runImpl(Function &F, const DominatorTree &DT);
  37. private:
  38. void findRoots(Function &F, const DominatorTree &DT);
  39. void seen(Instruction *I, ConstantRange R);
  40. ConstantRange badRange();
  41. ConstantRange unknownRange();
  42. ConstantRange validateRange(ConstantRange R);
  43. std::optional<ConstantRange> calcRange(Instruction *I);
  44. void walkBackwards();
  45. void walkForwards();
  46. bool validateAndTransform();
  47. Value *convert(Instruction *I, Type *ToTy);
  48. void cleanup();
  49. MapVector<Instruction *, ConstantRange> SeenInsts;
  50. SmallSetVector<Instruction *, 8> Roots;
  51. EquivalenceClasses<Instruction *> ECs;
  52. MapVector<Instruction *, Value *> ConvertedInsts;
  53. LLVMContext *Ctx;
  54. };
  55. }
  56. #endif // LLVM_TRANSFORMS_SCALAR_FLOAT2INT_H
  57. #ifdef __GNUC__
  58. #pragma GCC diagnostic pop
  59. #endif