[cfe-commits] r154835 - in /cfe/trunk: lib/CodeGen/CodeGenFunction.cpp test/CodeGen/2012-04-16-FastMath.c

Duncan Sands baldrick at free.fr
Mon Apr 16 10:24:32 PDT 2012


Author: baldrick
Date: Mon Apr 16 12:24:31 2012
New Revision: 154835

URL: http://llvm.org/viewvc/llvm-project?rev=154835&view=rev
Log:
Generate fpmath metadata when -ffast-math. Note that no optimizations are hooked
up to this yet.

Added:
    cfe/trunk/test/CodeGen/2012-04-16-FastMath.c
Modified:
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=154835&r1=154834&r2=154835&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Mon Apr 16 12:24:31 2012
@@ -22,8 +22,9 @@
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/StmtCXX.h"
 #include "clang/Frontend/CodeGenOptions.h"
-#include "llvm/Target/TargetData.h"
 #include "llvm/Intrinsics.h"
+#include "llvm/Support/MDBuilder.h"
+#include "llvm/Target/TargetData.h"
 using namespace clang;
 using namespace CodeGen;
 
@@ -41,6 +42,10 @@
     TerminateHandler(0), TrapBB(0) {
 
   CatchUndefined = getContext().getLangOpts().CatchUndefined;
+  if (getContext().getLangOpts().FastMath) {
+    llvm::MDBuilder MDHelper(Builder.getContext());
+    Builder.SetDefaultFPMathTag(MDHelper.createFastFPMath());
+  }
   CGM.getCXXABI().getMangleContext().startNewFunction();
 }
 

Added: cfe/trunk/test/CodeGen/2012-04-16-FastMath.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/2012-04-16-FastMath.c?rev=154835&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/2012-04-16-FastMath.c (added)
+++ cfe/trunk/test/CodeGen/2012-04-16-FastMath.c Mon Apr 16 12:24:31 2012
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 %s -ffast-math -emit-llvm -o - | FileCheck %s
+
+double add(double x, double y) {
+// CHECK: @add
+  return x + y;
+// CHECK: fadd double %{{.}}, %{{.}}, !fpmath !0
+}
+// CHECK: !0 = metadata !{metadata !"fast"}





More information about the cfe-commits mailing list