diff options
Diffstat (limited to 'llvm/lib/Transforms/Scalar/Float2Int.cpp')
-rw-r--r-- | llvm/lib/Transforms/Scalar/Float2Int.cpp | 47 |
1 files changed, 6 insertions, 41 deletions
diff --git a/llvm/lib/Transforms/Scalar/Float2Int.cpp b/llvm/lib/Transforms/Scalar/Float2Int.cpp index f66d1b914b0b..ccca8bcc1a56 100644 --- a/llvm/lib/Transforms/Scalar/Float2Int.cpp +++ b/llvm/lib/Transforms/Scalar/Float2Int.cpp @@ -20,12 +20,9 @@ #include "llvm/IR/Dominators.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/Module.h" -#include "llvm/InitializePasses.h" -#include "llvm/Pass.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/Transforms/Scalar.h" #include <deque> #define DEBUG_TYPE "float2int" @@ -49,35 +46,6 @@ MaxIntegerBW("float2int-max-integer-bw", cl::init(64), cl::Hidden, cl::desc("Max integer bitwidth to consider in float2int" "(default=64)")); -namespace { - struct Float2IntLegacyPass : public FunctionPass { - static char ID; // Pass identification, replacement for typeid - Float2IntLegacyPass() : FunctionPass(ID) { - initializeFloat2IntLegacyPassPass(*PassRegistry::getPassRegistry()); - } - - bool runOnFunction(Function &F) override { - if (skipFunction(F)) - return false; - - const DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree(); - return Impl.runImpl(F, DT); - } - - void getAnalysisUsage(AnalysisUsage &AU) const override { - AU.setPreservesCFG(); - AU.addRequired<DominatorTreeWrapperPass>(); - AU.addPreserved<GlobalsAAWrapperPass>(); - } - - private: - Float2IntPass Impl; - }; -} - -char Float2IntLegacyPass::ID = 0; -INITIALIZE_PASS(Float2IntLegacyPass, "float2int", "Float to int", false, false) - // Given a FCmp predicate, return a matching ICmp predicate if one // exists, otherwise return BAD_ICMP_PREDICATE. static CmpInst::Predicate mapFCmpPred(CmpInst::Predicate P) { @@ -187,7 +155,7 @@ void Float2IntPass::walkBackwards() { Instruction *I = Worklist.back(); Worklist.pop_back(); - if (SeenInsts.find(I) != SeenInsts.end()) + if (SeenInsts.contains(I)) // Seen already. continue; @@ -371,7 +339,7 @@ bool Float2IntPass::validateAndTransform() { ConvertedToTy = I->getType(); for (User *U : I->users()) { Instruction *UI = dyn_cast<Instruction>(U); - if (!UI || SeenInsts.find(UI) == SeenInsts.end()) { + if (!UI || !SeenInsts.contains(UI)) { LLVM_DEBUG(dbgs() << "F2I: Failing because of " << *U << "\n"); Fail = true; break; @@ -391,8 +359,9 @@ bool Float2IntPass::validateAndTransform() { // The number of bits required is the maximum of the upper and // lower limits, plus one so it can be signed. - unsigned MinBW = std::max(R.getLower().getMinSignedBits(), - R.getUpper().getMinSignedBits()) + 1; + unsigned MinBW = std::max(R.getLower().getSignificantBits(), + R.getUpper().getSignificantBits()) + + 1; LLVM_DEBUG(dbgs() << "F2I: MinBitwidth=" << MinBW << ", R: " << R << "\n"); // If we've run off the realms of the exactly representable integers, @@ -427,7 +396,7 @@ bool Float2IntPass::validateAndTransform() { } Value *Float2IntPass::convert(Instruction *I, Type *ToTy) { - if (ConvertedInsts.find(I) != ConvertedInsts.end()) + if (ConvertedInsts.contains(I)) // Already converted this instruction. return ConvertedInsts[I]; @@ -528,9 +497,6 @@ bool Float2IntPass::runImpl(Function &F, const DominatorTree &DT) { return Modified; } -namespace llvm { -FunctionPass *createFloat2IntPass() { return new Float2IntLegacyPass(); } - PreservedAnalyses Float2IntPass::run(Function &F, FunctionAnalysisManager &AM) { const DominatorTree &DT = AM.getResult<DominatorTreeAnalysis>(F); if (!runImpl(F, DT)) @@ -540,4 +506,3 @@ PreservedAnalyses Float2IntPass::run(Function &F, FunctionAnalysisManager &AM) { PA.preserveSet<CFGAnalyses>(); return PA; } -} // End namespace llvm |