aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMichael Ilseman <milseman@apple.com>2012-11-27 00:42:44 +0000
committerMichael Ilseman <milseman@apple.com>2012-11-27 00:42:44 +0000
commit15c13d3e63d7745bccad74d547af4e3482193eaa (patch)
tree7f27560aaf6fc5c3698d8a3a574545745350b98d /lib
parent4d265332341360a7cb5b15e2c2f0c675a7fed766 (diff)
downloadexternal_llvm-15c13d3e63d7745bccad74d547af4e3482193eaa.zip
external_llvm-15c13d3e63d7745bccad74d547af4e3482193eaa.tar.gz
external_llvm-15c13d3e63d7745bccad74d547af4e3482193eaa.tar.bz2
Fast-math flags for LLVM IR parsing and printing
Added in the ability to read LLVM IR text that contains fast-math flags as a sequence of capital letters separated by spaces in any order. Added in the printing of the fast-math flags in a canonical order, and don't print the other flags when 'fast' is specified, as 'fast' implies all the others. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168645 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/AsmParser/LLLexer.cpp7
-rw-r--r--lib/AsmParser/LLParser.cpp14
-rw-r--r--lib/AsmParser/LLParser.h16
-rw-r--r--lib/AsmParser/LLToken.h5
-rw-r--r--lib/VMCore/AsmWriter.cpp16
5 files changed, 54 insertions, 4 deletions
diff --git a/lib/AsmParser/LLLexer.cpp b/lib/AsmParser/LLLexer.cpp
index d8ffe8f..eb176ae 100644
--- a/lib/AsmParser/LLLexer.cpp
+++ b/lib/AsmParser/LLLexer.cpp
@@ -402,7 +402,7 @@ lltok::Kind LLLexer::LexExclaim() {
}
return lltok::exclaim;
}
-
+
/// LexIdentifier: Handle several related productions:
/// Label [-a-zA-Z$._0-9]+:
/// IntegerType i[0-9]+
@@ -498,6 +498,11 @@ lltok::Kind LLLexer::LexIdentifier() {
KEYWORD(seq_cst);
KEYWORD(singlethread);
+ KEYWORD(nnan)
+ KEYWORD(ninf)
+ KEYWORD(nsz)
+ KEYWORD(arcp)
+ KEYWORD(fast)
KEYWORD(nuw);
KEYWORD(nsw);
KEYWORD(exact);
diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp
index 41cca68..65f4245 100644
--- a/lib/AsmParser/LLParser.cpp
+++ b/lib/AsmParser/LLParser.cpp
@@ -3012,7 +3012,17 @@ int LLParser::ParseInstruction(Instruction *&Inst, BasicBlock *BB,
}
case lltok::kw_fadd:
case lltok::kw_fsub:
- case lltok::kw_fmul: return ParseArithmetic(Inst, PFS, KeywordVal, 2);
+ case lltok::kw_fmul:
+ case lltok::kw_fdiv:
+ case lltok::kw_frem: {
+ FastMathFlags FMF = EatFastMathFlagsIfPresent();
+ int Res = ParseArithmetic(Inst, PFS, KeywordVal, 2);
+ if (Res != 0)
+ return Res;
+ if (FMF.any())
+ Inst->setFastMathFlags(FMF);
+ return 0;
+ }
case lltok::kw_sdiv:
case lltok::kw_udiv:
@@ -3027,8 +3037,6 @@ int LLParser::ParseInstruction(Instruction *&Inst, BasicBlock *BB,
case lltok::kw_urem:
case lltok::kw_srem: return ParseArithmetic(Inst, PFS, KeywordVal, 1);
- case lltok::kw_fdiv:
- case lltok::kw_frem: return ParseArithmetic(Inst, PFS, KeywordVal, 2);
case lltok::kw_and:
case lltok::kw_or:
case lltok::kw_xor: return ParseLogical(Inst, PFS, KeywordVal);
diff --git a/lib/AsmParser/LLParser.h b/lib/AsmParser/LLParser.h
index 9f9672d..8e04705 100644
--- a/lib/AsmParser/LLParser.h
+++ b/lib/AsmParser/LLParser.h
@@ -18,6 +18,7 @@
#include "llvm/Attributes.h"
#include "llvm/Instructions.h"
#include "llvm/Module.h"
+#include "llvm/Operator.h"
#include "llvm/Type.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringMap.h"
@@ -154,6 +155,21 @@ namespace llvm {
Lex.Lex();
return true;
}
+
+ FastMathFlags EatFastMathFlagsIfPresent() {
+ FastMathFlags FMF;
+ while (true)
+ switch (Lex.getKind()) {
+ case lltok::kw_fast: FMF.UnsafeAlgebra = true; Lex.Lex(); continue;
+ case lltok::kw_nnan: FMF.NoNaNs = true; Lex.Lex(); continue;
+ case lltok::kw_ninf: FMF.NoInfs = true; Lex.Lex(); continue;
+ case lltok::kw_nsz: FMF.NoSignedZeros = true; Lex.Lex(); continue;
+ case lltok::kw_arcp: FMF.AllowReciprocal = true; Lex.Lex(); continue;
+ default: return FMF;
+ }
+ return FMF;
+ }
+
bool ParseOptionalToken(lltok::Kind T, bool &Present, LocTy *Loc = 0) {
if (Lex.getKind() != T) {
Present = false;
diff --git a/lib/AsmParser/LLToken.h b/lib/AsmParser/LLToken.h
index 036686d..1ec1b1e 100644
--- a/lib/AsmParser/LLToken.h
+++ b/lib/AsmParser/LLToken.h
@@ -60,6 +60,11 @@ namespace lltok {
kw_atomic,
kw_unordered, kw_monotonic, kw_acquire, kw_release, kw_acq_rel, kw_seq_cst,
kw_singlethread,
+ kw_nnan,
+ kw_ninf,
+ kw_nsz,
+ kw_arcp,
+ kw_fast,
kw_nuw,
kw_nsw,
kw_exact,
diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp
index c45a04f..433f3e0 100644
--- a/lib/VMCore/AsmWriter.cpp
+++ b/lib/VMCore/AsmWriter.cpp
@@ -703,6 +703,22 @@ static void writeAtomicRMWOperation(raw_ostream &Out,
}
static void WriteOptimizationInfo(raw_ostream &Out, const User *U) {
+ if (const FPMathOperator *FPO = dyn_cast<const FPMathOperator>(U)) {
+ // Unsafe algebra implies all the others, no need to write them all out
+ if (FPO->hasUnsafeAlgebra())
+ Out << " fast";
+ else {
+ if (FPO->hasNoNaNs())
+ Out << " nnan";
+ if (FPO->hasNoInfs())
+ Out << " ninf";
+ if (FPO->hasNoSignedZeros())
+ Out << " nsz";
+ if (FPO->hasAllowReciprocal())
+ Out << " arcp";
+ }
+ }
+
if (const OverflowingBinaryOperator *OBO =
dyn_cast<OverflowingBinaryOperator>(U)) {
if (OBO->hasNoUnsignedWrap())