Skip to content

Commit 3921900

Browse files
authored
CodeGen: Remove UsesMSVCFloatingPoint from MachineModuleInfo (#100368)
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 9482a83 commit 3921900

File tree

4 files changed

+29
-37
lines changed

4 files changed

+29
-37
lines changed

llvm/include/llvm/CodeGen/MachineModuleInfo.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,6 @@ class MachineModuleInfo {
116116
/// True if debugging information is available in this module.
117117
bool DbgInfoAvailable = false;
118118

119-
/// True if this module is being built for windows/msvc, and uses floating
120-
/// point. This is used to emit an undefined reference to _fltused.
121-
bool UsesMSVCFloatingPoint = false;
122-
123119
/// Maps IR Functions to their corresponding MachineFunctions.
124120
DenseMap<const Function*, std::unique_ptr<MachineFunction>> MachineFunctions;
125121
/// Next unique number available for a MachineFunction.
@@ -189,10 +185,6 @@ class MachineModuleInfo {
189185
/// Returns true if valid debug info is present.
190186
bool hasDebugInfo() const { return DbgInfoAvailable; }
191187

192-
bool usesMSVCFloatingPoint() const { return UsesMSVCFloatingPoint; }
193-
194-
void setUsesMSVCFloatingPoint(bool b) { UsesMSVCFloatingPoint = b; }
195-
196188
/// \name Exception Handling
197189
/// \{
198190

llvm/lib/CodeGen/MachineModuleInfo.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ void MachineModuleInfo::initialize() {
2828
ObjFileMMI = nullptr;
2929
CurCallSite = 0;
3030
NextFnNum = 0;
31-
UsesMSVCFloatingPoint = false;
3231
DbgInfoAvailable = false;
3332
}
3433

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: 29 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,33 @@ 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. This is
981+
/// needed in Windows kernel or driver contexts to find and prevent code from
982+
/// modifying non-GPR registers.
983+
///
984+
/// TODO: It would be better if this was computed from MIR by looking for
985+
/// selected floating-point instructions.
986+
static bool usesMSVCFloatingPoint(const Triple &TT, const Module &M) {
987+
// Only needed for MSVC
988+
if (!TT.isWindowsMSVCEnvironment())
989+
return false;
990+
991+
for (const Function &F : M) {
992+
for (const Instruction &I : instructions(F)) {
993+
if (I.getType()->isFPOrFPVectorTy())
994+
return true;
995+
996+
for (const auto &Op : I.operands()) {
997+
if (Op->getType()->isFPOrFPVectorTy())
998+
return true;
999+
}
1000+
}
1001+
}
1002+
1003+
return false;
1004+
}
1005+
9781006
void X86AsmPrinter::emitEndOfAsmFile(Module &M) {
9791007
const Triple &TT = TM.getTargetTriple();
9801008

@@ -993,7 +1021,7 @@ void X86AsmPrinter::emitEndOfAsmFile(Module &M) {
9931021
// safe to set.
9941022
OutStreamer->emitAssemblerFlag(MCAF_SubsectionsViaSymbols);
9951023
} else if (TT.isOSBinFormatCOFF()) {
996-
if (MMI->usesMSVCFloatingPoint()) {
1024+
if (usesMSVCFloatingPoint(TT, M)) {
9971025
// In Windows' libcmt.lib, there is a file which is linked in only if the
9981026
// symbol _fltused is referenced. Linking this in causes some
9991027
// side-effects:

0 commit comments

Comments
 (0)