-
Notifications
You must be signed in to change notification settings - Fork 13.5k
CodeGen: Remove UsesMSVCFloatingPoint from MachineModuleInfo #100368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CodeGen: Remove UsesMSVCFloatingPoint from MachineModuleInfo #100368
Conversation
@llvm/pr-subscribers-llvm-selectiondag @llvm/pr-subscribers-platform-windows Author: Matt Arsenault (arsenm) ChangesThis is only used by x86 and only used in the AsmPrinter module pass. I This is https://reviews.llvm.org/D123933 resurrected. I still don't know what the point of emitting _fltused is, but this The last review mentioned the ARMs might want to emit this, but I'm Full diff: https://github.com/llvm/llvm-project/pull/100368.diff 4 Files Affected:
diff --git a/llvm/include/llvm/CodeGen/MachineModuleInfo.h b/llvm/include/llvm/CodeGen/MachineModuleInfo.h
index b39db93b021b5..f69be67ee9f17 100644
--- a/llvm/include/llvm/CodeGen/MachineModuleInfo.h
+++ b/llvm/include/llvm/CodeGen/MachineModuleInfo.h
@@ -113,10 +113,6 @@ class MachineModuleInfo {
// -g. At this moment, there's no way to specify that some CFI directives
// go into .eh_frame only, while others go into .debug_frame only.
- /// True if this module is being built for windows/msvc, and uses floating
- /// point. This is used to emit an undefined reference to _fltused.
- bool UsesMSVCFloatingPoint = false;
-
/// Maps IR Functions to their corresponding MachineFunctions.
DenseMap<const Function*, std::unique_ptr<MachineFunction>> MachineFunctions;
/// Next unique number available for a MachineFunction.
@@ -183,10 +179,6 @@ class MachineModuleInfo {
return const_cast<MachineModuleInfo*>(this)->getObjFileInfo<Ty>();
}
- bool usesMSVCFloatingPoint() const { return UsesMSVCFloatingPoint; }
-
- void setUsesMSVCFloatingPoint(bool b) { UsesMSVCFloatingPoint = b; }
-
/// \name Exception Handling
/// \{
diff --git a/llvm/lib/CodeGen/MachineModuleInfo.cpp b/llvm/lib/CodeGen/MachineModuleInfo.cpp
index 12dec288b3ce2..23de726a2ab97 100644
--- a/llvm/lib/CodeGen/MachineModuleInfo.cpp
+++ b/llvm/lib/CodeGen/MachineModuleInfo.cpp
@@ -38,7 +38,6 @@ void MachineModuleInfo::initialize() {
ObjFileMMI = nullptr;
CurCallSite = 0;
NextFnNum = 0;
- UsesMSVCFloatingPoint = false;
}
void MachineModuleInfo::finalize() {
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
index 401d23b22adcd..84331d257a3d0 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -417,30 +417,6 @@ void SelectionDAGISelLegacy::getAnalysisUsage(AnalysisUsage &AU) const {
MachineFunctionPass::getAnalysisUsage(AU);
}
-static void computeUsesMSVCFloatingPoint(const Triple &TT, const Function &F,
- MachineModuleInfo &MMI) {
- // Only needed for MSVC
- if (!TT.isWindowsMSVCEnvironment())
- return;
-
- // If it's already set, nothing to do.
- if (MMI.usesMSVCFloatingPoint())
- return;
-
- for (const Instruction &I : instructions(F)) {
- if (I.getType()->isFPOrFPVectorTy()) {
- MMI.setUsesMSVCFloatingPoint(true);
- return;
- }
- for (const auto &Op : I.operands()) {
- if (Op->getType()->isFPOrFPVectorTy()) {
- MMI.setUsesMSVCFloatingPoint(true);
- return;
- }
- }
- }
-}
-
PreservedAnalyses
SelectionDAGISelPass::run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM) {
@@ -802,9 +778,6 @@ bool SelectionDAGISel::runOnMachineFunction(MachineFunction &mf) {
}
}
- // Determine if floating point is used for msvc
- computeUsesMSVCFloatingPoint(TM.getTargetTriple(), Fn, *CurDAG->getMMI());
-
// Release function-specific state. SDB and CurDAG are already cleared
// at this point.
FuncInfo->clear();
diff --git a/llvm/lib/Target/X86/X86AsmPrinter.cpp b/llvm/lib/Target/X86/X86AsmPrinter.cpp
index 0c2c6bf7f8b70..9d86a9c9d1609 100644
--- a/llvm/lib/Target/X86/X86AsmPrinter.cpp
+++ b/llvm/lib/Target/X86/X86AsmPrinter.cpp
@@ -28,6 +28,7 @@
#include "llvm/CodeGenTypes/MachineValueType.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/InlineAsm.h"
+#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Mangler.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
@@ -975,6 +976,28 @@ static void emitNonLazyStubs(MachineModuleInfo *MMI, MCStreamer &OutStreamer) {
}
}
+/// True if this module is being built for windows/msvc, and uses floating
+/// point. This is used to emit an undefined reference to _fltused.
+static bool usesMSVCFloatingPoint(const Triple &TT, const Module &M) {
+ // Only needed for MSVC
+ if (!TT.isWindowsMSVCEnvironment())
+ return false;
+
+ for (const Function &F : M) {
+ for (const Instruction &I : instructions(F)) {
+ if (I.getType()->isFPOrFPVectorTy())
+ return true;
+
+ for (const auto &Op : I.operands()) {
+ if (Op->getType()->isFPOrFPVectorTy())
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
void X86AsmPrinter::emitEndOfAsmFile(Module &M) {
const Triple &TT = TM.getTargetTriple();
@@ -993,7 +1016,7 @@ void X86AsmPrinter::emitEndOfAsmFile(Module &M) {
// safe to set.
OutStreamer->emitAssemblerFlag(MCAF_SubsectionsViaSymbols);
} else if (TT.isOSBinFormatCOFF()) {
- if (MMI->usesMSVCFloatingPoint()) {
+ if (usesMSVCFloatingPoint(TT, M)) {
// In Windows' libcmt.lib, there is a file which is linked in only if the
// symbol _fltused is referenced. Linking this in causes some
// side-effects:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - cheers
284f0ef
to
aa152df
Compare
|
So really it should be looking for post-legalize calls to specific runtime libcalls |
Not entirely - |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @jyknight touched this last, and I may have advised him to simply use MMI to store this, since historically it has been used as a side channel for passing information along the code generation pipeline. It's good to avoid that, but it was what we were doing at the time. :)
I think the reason the existing scan was done as part of SDISel is that it is a scan over the IR, and ISel is the point at which we walk the IR to build the mostly-standalone MIR representation. Moving this scan to AsmPrinting is a bit distasteful, but it works and is less code. You could also make a cache-locality argument that walking the IR again during AsmPrinting is slow, but that's pretty weak.
Scanning the IR for FP types is obviously a gross approximation of _fltused
. If we want to try to implement this properly, maybe we could scan all MachineInstrs during AsmPrinting for usage of vector or x87 FP operands. We can leave that out of scope, though.
In conclusion, we should land this as is, but I wanted to share some context.
It's been a while since I looked at this, but its purpose, at least back then (2c36240) is very different than what was discussed above. It had two effects:
|
aa152df
to
35d1a90
Compare
9c6daa3
to
f1c93f2
Compare
In particular, I think it would be incorrect to just look at floating-point operations at the MIR level, because calling printf with a constant floating point argument doesn't necessarily use any floating point instructions. |
35d1a90
to
896e8c5
Compare
f1c93f2
to
9b8483a
Compare
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.
9b8483a
to
2774571
Compare
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.