1- // ===--- ExpandLargeFpConvert .cpp - Expand large fp convert ----------------===//
1+ // ===--- ExpandFp .cpp - Expand fp instructions ------------ ----------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
55// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66//
77// ===----------------------------------------------------------------------===//
8+ // This pass expands certain floating point instructions at the IR level.
89//
9-
10- // This pass expands ‘fptoui .. to’, ‘fptosi .. to’, ‘uitofp .. to’,
11- // ‘sitofp .. to’ instructions with a bitwidth above a threshold into
12- // auto-generated functions. This is useful for targets like x86_64 that cannot
13- // lower fp convertions with more than 128 bits.
10+ // It expands ‘fptoui .. to’, ‘fptosi .. to’, ‘uitofp .. to’, ‘sitofp
11+ // .. to’ instructions with a bitwidth above a threshold. This is
12+ // useful for targets like x86_64 that cannot lower fp convertions
13+ // with more than 128 bits.
1414//
1515// ===----------------------------------------------------------------------===//
1616
17- #include " llvm/CodeGen/ExpandLargeFpConvert .h"
17+ #include " llvm/CodeGen/ExpandFp .h"
1818#include " llvm/ADT/SmallVector.h"
1919#include " llvm/Analysis/GlobalsModRef.h"
2020#include " llvm/CodeGen/Passes.h"
@@ -33,9 +33,11 @@ using namespace llvm;
3333
3434static cl::opt<unsigned >
3535 ExpandFpConvertBits (" expand-fp-convert-bits" , cl::Hidden,
36- cl::init (llvm::IntegerType::MAX_INT_BITS),
37- cl::desc(" fp convert instructions on integers with "
38- " more than <N> bits are expanded." ));
36+ cl::init (llvm::IntegerType::MAX_INT_BITS),
37+ cl::desc(" fp convert instructions on integers with "
38+ " more than <N> bits are expanded." ));
39+
40+ // clang-format off: preserve formatting of the following example
3941
4042// / Generate code to convert a fp number to integer, replacing FPToS(U)I with
4143// / the generated code. This currently generates code similarly to compiler-rt's
@@ -88,6 +90,7 @@ static cl::opt<unsigned>
8890// /
8991// / Replace fp to integer with generated code.
9092static void expandFPToI (Instruction *FPToI) {
93+ // clang-format on
9194 IRBuilder<> Builder (FPToI);
9295 auto *FloatVal = FPToI->getOperand (0 );
9396 IntegerType *IntTy = cast<IntegerType>(FPToI->getType ());
@@ -224,6 +227,8 @@ static void expandFPToI(Instruction *FPToI) {
224227 FPToI->eraseFromParent ();
225228}
226229
230+ // clang-format off: preserve formatting of the following example
231+
227232// / Generate code to convert a fp number to integer, replacing S(U)IToFP with
228233// / the generated code. This currently generates code similarly to compiler-rt's
229234// / implementations. This implementation has an implicit assumption that integer
@@ -307,6 +312,7 @@ static void expandFPToI(Instruction *FPToI) {
307312// /
308313// / Replace integer to fp with generated code.
309314static void expandIToFP (Instruction *IToFP) {
315+ // clang-format on
310316 IRBuilder<> Builder (IToFP);
311317 auto *IntVal = IToFP->getOperand (0 );
312318 IntegerType *IntTy = cast<IntegerType>(IntVal->getType ());
@@ -666,13 +672,12 @@ static bool runImpl(Function &F, const TargetLowering &TLI) {
666672}
667673
668674namespace {
669- class ExpandLargeFpConvertLegacyPass : public FunctionPass {
675+ class ExpandFpLegacyPass : public FunctionPass {
670676public:
671677 static char ID;
672678
673- ExpandLargeFpConvertLegacyPass () : FunctionPass(ID) {
674- initializeExpandLargeFpConvertLegacyPassPass (
675- *PassRegistry::getPassRegistry ());
679+ ExpandFpLegacyPass () : FunctionPass(ID) {
680+ initializeExpandFpLegacyPassPass (*PassRegistry::getPassRegistry ());
676681 }
677682
678683 bool runOnFunction (Function &F) override {
@@ -689,19 +694,15 @@ class ExpandLargeFpConvertLegacyPass : public FunctionPass {
689694};
690695} // namespace
691696
692- PreservedAnalyses ExpandLargeFpConvertPass::run (Function &F,
693- FunctionAnalysisManager &FAM) {
697+ PreservedAnalyses ExpandFpPass::run (Function &F, FunctionAnalysisManager &FAM) {
694698 const TargetSubtargetInfo *STI = TM->getSubtargetImpl (F);
695699 return runImpl (F, *STI->getTargetLowering ()) ? PreservedAnalyses::none ()
696700 : PreservedAnalyses::all ();
697701}
698702
699- char ExpandLargeFpConvertLegacyPass::ID = 0 ;
700- INITIALIZE_PASS_BEGIN (ExpandLargeFpConvertLegacyPass, " expand-large-fp-convert" ,
701- " Expand large fp convert" , false , false )
702- INITIALIZE_PASS_END(ExpandLargeFpConvertLegacyPass, " expand-large-fp-convert" ,
703- " Expand large fp convert" , false , false )
703+ char ExpandFpLegacyPass::ID = 0 ;
704+ INITIALIZE_PASS_BEGIN (ExpandFpLegacyPass, " expand-fp" ,
705+ " Expand certain fp instructions" , false , false )
706+ INITIALIZE_PASS_END(ExpandFpLegacyPass, " expand-fp" , " Expand fp" , false , false )
704707
705- FunctionPass *llvm::createExpandLargeFpConvertPass() {
706- return new ExpandLargeFpConvertLegacyPass ();
707- }
708+ FunctionPass *llvm::createExpandFpPass() { return new ExpandFpLegacyPass (); }
0 commit comments