1 //===-- Float2Int.h - Demote floating point ops to work on integers -------===//
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 //
9 // This file provides the Float2Int pass, which aims to demote floating
10 // point operations to work on integers, where that is losslessly possible.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_TRANSFORMS_SCALAR_FLOAT2INT_H
15 #define LLVM_TRANSFORMS_SCALAR_FLOAT2INT_H
16 
17 #include "llvm/ADT/EquivalenceClasses.h"
18 #include "llvm/ADT/MapVector.h"
19 #include "llvm/ADT/SetVector.h"
20 #include "llvm/IR/ConstantRange.h"
21 #include "llvm/IR/Dominators.h"
22 #include "llvm/IR/Function.h"
23 #include "llvm/IR/PassManager.h"
24 
25 namespace llvm {
26 class Float2IntPass : public PassInfoMixin<Float2IntPass> {
27 public:
28   PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
29 
30   // Glue for old PM.
31   bool runImpl(Function &F, const DominatorTree &DT);
32 
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 
45   MapVector<Instruction *, ConstantRange> SeenInsts;
46   SmallSetVector<Instruction *, 8> Roots;
47   EquivalenceClasses<Instruction *> ECs;
48   MapVector<Instruction *, Value *> ConvertedInsts;
49   LLVMContext *Ctx;
50 };
51 }
52 #endif // LLVM_TRANSFORMS_SCALAR_FLOAT2INT_H
53