Skip to content

Commit 8991fa2

Browse files
committed
CodeGen: Remove UsesMSVCFloatingPoint from MachineModuleInfo
This is only used by x86 and only used in the AsmPrinter module pass. I think implementing this by looking at the underlying IR types instead of the selected instructions is a pretty horrifying implementation, but it's still available in the AsmPrinter. This is https://reviews.llvm.org/D123933 resurrected. I still don't know what the point of emitting _fltused is, but this approach of looking at the IR types probably isn't the right way to do this in the first place. If the intent is report any FP instructions, this will miss any implicitly introduced ones during codegen. Also don't know why just unconditionally emitting it isn't an option. The last review mentioned the ARMs might want to emit this, but I'm not going to go fix that. If someone wants to emit this on ARM, they can move this to a common helper or analysis somewhere.
1 parent 35d1a90 commit 8991fa2

File tree

4 files changed

+24
-37
lines changed

4 files changed

+24
-37
lines changed

llvm/include/llvm/CodeGen/MachineModuleInfo.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,6 @@ class MachineModuleInfo {
113113
// -g. At this moment, there's no way to specify that some CFI directives
114114
// go into .eh_frame only, while others go into .debug_frame only.
115115

116-
/// True if this module is being built for windows/msvc, and uses floating
117-
/// point. This is used to emit an undefined reference to _fltused.
118-
bool UsesMSVCFloatingPoint = false;
119-
120116
/// Maps IR Functions to their corresponding MachineFunctions.
121117
DenseMap<const Function*, std::unique_ptr<MachineFunction>> MachineFunctions;
122118
/// Next unique number available for a MachineFunction.
@@ -183,10 +179,6 @@ class MachineModuleInfo {
183179
return const_cast<MachineModuleInfo*>(this)->getObjFileInfo<Ty>();
184180
}
185181

186-
bool usesMSVCFloatingPoint() const { return UsesMSVCFloatingPoint; }
187-
188-
void setUsesMSVCFloatingPoint(bool b) { UsesMSVCFloatingPoint = b; }
189-
190182
/// \name Exception Handling
191183
/// \{
192184

llvm/lib/CodeGen/MachineModuleInfo.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ void MachineModuleInfo::initialize() {
3838
ObjFileMMI = nullptr;
3939
CurCallSite = 0;
4040
NextFnNum = 0;
41-
UsesMSVCFloatingPoint = false;
4241
}
4342

4443
void MachineModuleInfo::finalize() {

llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -417,30 +417,6 @@ void SelectionDAGISelLegacy::getAnalysisUsage(AnalysisUsage &AU) const {
417417
MachineFunctionPass::getAnalysisUsage(AU);
418418
}
419419

420-
static void computeUsesMSVCFloatingPoint(const Triple &TT, const Function &F,
421-
MachineModuleInfo &MMI) {
422-
// Only needed for MSVC
423-
if (!TT.isWindowsMSVCEnvironment())
424-
return;
425-
426-
// If it's already set, nothing to do.
427-
if (MMI.usesMSVCFloatingPoint())
428-
return;
429-
430-
for (const Instruction &I : instructions(F)) {
431-
if (I.getType()->isFPOrFPVectorTy()) {
432-
MMI.setUsesMSVCFloatingPoint(true);
433-
return;
434-
}
435-
for (const auto &Op : I.operands()) {
436-
if (Op->getType()->isFPOrFPVectorTy()) {
437-
MMI.setUsesMSVCFloatingPoint(true);
438-
return;
439-
}
440-
}
441-
}
442-
}
443-
444420
PreservedAnalyses
445421
SelectionDAGISelPass::run(MachineFunction &MF,
446422
MachineFunctionAnalysisManager &MFAM) {
@@ -802,9 +778,6 @@ bool SelectionDAGISel::runOnMachineFunction(MachineFunction &mf) {
802778
}
803779
}
804780

805-
// Determine if floating point is used for msvc
806-
computeUsesMSVCFloatingPoint(TM.getTargetTriple(), Fn, *CurDAG->getMMI());
807-
808781
// Release function-specific state. SDB and CurDAG are already cleared
809782
// at this point.
810783
FuncInfo->clear();

llvm/lib/Target/X86/X86AsmPrinter.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "llvm/CodeGenTypes/MachineValueType.h"
2929
#include "llvm/IR/DerivedTypes.h"
3030
#include "llvm/IR/InlineAsm.h"
31+
#include "llvm/IR/InstIterator.h"
3132
#include "llvm/IR/Mangler.h"
3233
#include "llvm/IR/Module.h"
3334
#include "llvm/IR/Type.h"
@@ -975,6 +976,28 @@ static void emitNonLazyStubs(MachineModuleInfo *MMI, MCStreamer &OutStreamer) {
975976
}
976977
}
977978

979+
/// True if this module is being built for windows/msvc, and uses floating
980+
/// point. This is used to emit an undefined reference to _fltused.
981+
static bool usesMSVCFloatingPoint(const Triple &TT, const Module &M) {
982+
// Only needed for MSVC
983+
if (!TT.isWindowsMSVCEnvironment())
984+
return false;
985+
986+
for (const Function &F : M) {
987+
for (const Instruction &I : instructions(F)) {
988+
if (I.getType()->isFPOrFPVectorTy())
989+
return true;
990+
991+
for (const auto &Op : I.operands()) {
992+
if (Op->getType()->isFPOrFPVectorTy())
993+
return true;
994+
}
995+
}
996+
}
997+
998+
return false;
999+
}
1000+
9781001
void X86AsmPrinter::emitEndOfAsmFile(Module &M) {
9791002
const Triple &TT = TM.getTargetTriple();
9801003

@@ -993,7 +1016,7 @@ void X86AsmPrinter::emitEndOfAsmFile(Module &M) {
9931016
// safe to set.
9941017
OutStreamer->emitAssemblerFlag(MCAF_SubsectionsViaSymbols);
9951018
} else if (TT.isOSBinFormatCOFF()) {
996-
if (MMI->usesMSVCFloatingPoint()) {
1019+
if (usesMSVCFloatingPoint(TT, M)) {
9971020
// In Windows' libcmt.lib, there is a file which is linked in only if the
9981021
// symbol _fltused is referenced. Linking this in causes some
9991022
// side-effects:

0 commit comments

Comments
 (0)