[llvm-commits] [llvm] r116665 - in /llvm/trunk: include/llvm/CodeGen/MachineModuleInfo.h lib/CodeGen/MachineModuleInfo.cpp lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp lib/Target/X86/X86AsmPrinter.cpp test/CodeGen/X86/fltused.ll
Michael J. Spencer
bigcheesegs at gmail.com
Sat Oct 16 01:25:41 PDT 2010
Author: mspencer
Date: Sat Oct 16 03:25:41 2010
New Revision: 116665
URL: http://llvm.org/viewvc/llvm-project?rev=116665&view=rev
Log:
X86-Windows: Emit an undefined global __fltused symbol when targeting Windows
if any floating point arguments are passed to an external function.
Added:
llvm/trunk/test/CodeGen/X86/fltused.ll
Modified:
llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h
llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/trunk/lib/Target/X86/X86AsmPrinter.cpp
Modified: llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h?rev=116665&r1=116664&r2=116665&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h Sat Oct 16 03:25:41 2010
@@ -157,6 +157,11 @@
/// in this module.
bool DbgInfoAvailable;
+ /// True if this module calls an external function with floating point
+ /// arguments. This is used to emit an undefined reference to fltused on
+ /// Windows targets.
+ bool CallsExternalFunctionWithFloatingPointArguments;
+
public:
static char ID; // Pass identification, replacement for typeid
@@ -211,7 +216,15 @@
bool callsUnwindInit() const { return CallsUnwindInit; }
void setCallsUnwindInit(bool b) { CallsUnwindInit = b; }
-
+
+ bool callsExternalFunctionWithFloatingPointArguments() const {
+ return CallsExternalFunctionWithFloatingPointArguments;
+ }
+
+ void setCallsExternalFunctionWithFloatingPointArguments(bool b) {
+ CallsExternalFunctionWithFloatingPointArguments = b;
+ }
+
/// getFrameMoves - Returns a reference to a list of moves done in the current
/// function's prologue. Used to construct frame maps for debug and exception
/// handling comsumers.
Modified: llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp?rev=116665&r1=116664&r2=116665&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp Sat Oct 16 03:25:41 2010
@@ -256,7 +256,8 @@
MachineModuleInfo::MachineModuleInfo(const MCAsmInfo &MAI)
: ImmutablePass(ID), Context(MAI),
ObjFileMMI(0),
- CurCallSite(0), CallsEHReturn(0), CallsUnwindInit(0), DbgInfoAvailable(false){
+ CurCallSite(0), CallsEHReturn(0), CallsUnwindInit(0), DbgInfoAvailable(false),
+ CallsExternalFunctionWithFloatingPointArguments(false) {
// Always emit some info, by default "no personality" info.
Personalities.push_back(NULL);
AddrLabelSymbols = 0;
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp?rev=116665&r1=116664&r2=116665&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp Sat Oct 16 03:25:41 2010
@@ -15,6 +15,7 @@
#include "SDNodeDbgValue.h"
#include "SelectionDAGBuilder.h"
#include "llvm/ADT/BitVector.h"
+#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/ConstantFolding.h"
@@ -5019,6 +5020,25 @@
}
}
+ // See if any floating point values are being passed to this external
+ // function. This is used to emit an undefined reference to fltused on
+ // Windows.
+ if (!F->hasLocalLinkage() && F->hasName()) {
+ MachineModuleInfo &MMI = DAG.getMachineFunction().getMMI();
+ for (unsigned i = 0, e = I.getNumArgOperands(); i != e &&
+ !MMI.callsExternalFunctionWithFloatingPointArguments(); ++i) {
+ const Type* T = I.getArgOperand(i)->getType();
+ for (po_iterator<const Type*> i = po_begin(T),
+ e = po_end(T);
+ i != e; ++i) {
+ if (i->isFloatingPointTy()) {
+ MMI.setCallsExternalFunctionWithFloatingPointArguments(true);
+ break;
+ }
+ }
+ }
+ }
+
// Check for well-known libc/libm calls. If the function is internal, it
// can't be a library call.
if (!F->hasLocalLinkage() && F->hasName()) {
Modified: llvm/trunk/lib/Target/X86/X86AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86AsmPrinter.cpp?rev=116665&r1=116664&r2=116665&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86AsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86AsmPrinter.cpp Sat Oct 16 03:25:41 2010
@@ -580,6 +580,13 @@
OutStreamer.EmitAssemblerFlag(MCAF_SubsectionsViaSymbols);
}
+ if (Subtarget->isTargetWindows()
+ && !Subtarget->isTargetCygMing()
+ && MMI->callsExternalFunctionWithFloatingPointArguments()) {
+ MCSymbol *S = MMI->getContext().GetOrCreateSymbol(StringRef("__fltused"));
+ OutStreamer.EmitSymbolAttribute(S, MCSA_Global);
+ }
+
if (Subtarget->isTargetCOFF()) {
X86COFFMachineModuleInfo &COFFMMI =
MMI->getObjFileInfo<X86COFFMachineModuleInfo>();
Added: llvm/trunk/test/CodeGen/X86/fltused.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/fltused.ll?rev=116665&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/fltused.ll (added)
+++ llvm/trunk/test/CodeGen/X86/fltused.ll Sat Oct 16 03:25:41 2010
@@ -0,0 +1,17 @@
+; The purpose of this test to to verify that the fltused symbol is emitted when
+; any function is called with floating point arguments on Windows. And that it
+; is not emitted otherwise.
+
+; RUN: llc < %s -mtriple i686-pc-win32 | FileCheck %s
+
+ at .str = private constant [4 x i8] c"%f\0A\00"
+
+define i32 @main() nounwind {
+entry:
+ %call = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([4 x i8]* @.str, i32 0, i32 0), double 1.000000e+000) nounwind
+ ret i32 0
+}
+
+declare i32 @printf(i8* nocapture, ...) nounwind
+
+; CHECK: .globl __fltused
More information about the llvm-commits
mailing list