Float2Int.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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/Dominators.h"
  25. #include "llvm/IR/Function.h"
  26. #include "llvm/IR/PassManager.h"
  27. namespace llvm {
  28. class Float2IntPass : public PassInfoMixin<Float2IntPass> {
  29. public:
  30. PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
  31. // Glue for old PM.
  32. bool runImpl(Function &F, const DominatorTree &DT);
  33. private:
  34. void findRoots(Function &F, const DominatorTree &DT);
  35. void seen(Instruction *I, ConstantRange R);
  36. ConstantRange badRange();
  37. ConstantRange unknownRange();
  38. ConstantRange validateRange(ConstantRange R);
  39. void walkBackwards();
  40. void walkForwards();
  41. bool validateAndTransform();
  42. Value *convert(Instruction *I, Type *ToTy);
  43. void cleanup();
  44. MapVector<Instruction *, ConstantRange> SeenInsts;
  45. SmallSetVector<Instruction *, 8> Roots;
  46. EquivalenceClasses<Instruction *> ECs;
  47. MapVector<Instruction *, Value *> ConvertedInsts;
  48. LLVMContext *Ctx;
  49. };
  50. }
  51. #endif // LLVM_TRANSFORMS_SCALAR_FLOAT2INT_H
  52. #ifdef __GNUC__
  53. #pragma GCC diagnostic pop
  54. #endif