aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-10-12 08:12:58 +0000
committerChris Lattner <sabre@nondot.org>2003-10-12 08:12:58 +0000
commit5ef6ffd6c367e23189feb5353ded501ef8b96e20 (patch)
treea1e447ebb3172917adf3e6acf31a0a1db0505647
parentdfaeb0e8b9e739b75fb9f1036f45553f8be4ef5a (diff)
downloadexternal_llvm-5ef6ffd6c367e23189feb5353ded501ef8b96e20.zip
external_llvm-5ef6ffd6c367e23189feb5353ded501ef8b96e20.tar.gz
external_llvm-5ef6ffd6c367e23189feb5353ded501ef8b96e20.tar.bz2
* Spell "necessary" correctly
* Print floating point values using C99 hexadecimal style FP if possible. This increases the number of floating point constants that may be emitted inline, and improves precision for global variable initializers which can not be emitted in integer form. This fixes the Olden/Power benchmark with the CBE!!!! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9052 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Target/CBackend/CBackend.cpp27
-rw-r--r--lib/Target/CBackend/Writer.cpp27
2 files changed, 48 insertions, 6 deletions
diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp
index d1bf849..3398124 100644
--- a/lib/Target/CBackend/CBackend.cpp
+++ b/lib/Target/CBackend/CBackend.cpp
@@ -23,6 +23,10 @@
#include <algorithm>
#include <sstream>
+
+/* FIXME: This should be autoconf'd! */
+#define HAS_C99_HEXADECIMAL_CONSTANTS 1
+
namespace {
class CWriter : public Pass, public InstVisitor<CWriter> {
std::ostream &Out;
@@ -337,6 +341,16 @@ void CWriter::printConstantArray(ConstantArray *CPA) {
// only deal in IEEE FP).
//
static bool isFPCSafeToPrint(const ConstantFP *CFP) {
+#if HAS_C99_HEXADECIMAL_CONSTANTS
+ char Buffer[100];
+ sprintf(Buffer, "%a", CFP->getValue());
+
+ if (!strncmp(Buffer, "0x", 2) ||
+ !strncmp(Buffer, "-0x", 3) ||
+ !strncmp(Buffer, "+0x", 3))
+ return atof(Buffer) == CFP->getValue();
+ return false;
+#else
std::string StrVal = ftostr(CFP->getValue());
while (StrVal[0] == ' ')
@@ -350,6 +364,7 @@ static bool isFPCSafeToPrint(const ConstantFP *CFP) {
// Reparse stringized version!
return atof(StrVal.c_str()) == CFP->getValue();
return false;
+#endif
}
// printConstant - The LLVM Constant to C Constant converter.
@@ -442,8 +457,14 @@ void CWriter::printConstant(Constant *CPV) {
Out << "(*(" << (FPC->getType() == Type::FloatTy ? "float" : "double")
<< "*)&FPConstant" << I->second << ")";
} else {
+#if HAS_C99_HEXADECIMAL_CONSTANTS
// Print out the constant as a floating point number.
+ char Buffer[100];
+ sprintf(Buffer, "%a", FPC->getValue());
+ Out << Buffer << " /*" << FPC->getValue() << "*/ ";
+#else
Out << ftostr(FPC->getValue());
+#endif
}
break;
}
@@ -1018,7 +1039,7 @@ void CWriter::visitUnwindInst(UnwindInst &I) {
emittedInvoke = true;
}
-static bool isGotoCodeNeccessary(BasicBlock *From, BasicBlock *To) {
+static bool isGotoCodeNecessary(BasicBlock *From, BasicBlock *To) {
// If PHI nodes need copies, we need the copy code...
if (isa<PHINode>(To->front()) ||
From->getNext() != To) // Not directly successor, need goto
@@ -1051,14 +1072,14 @@ void CWriter::printBranchToBlock(BasicBlock *CurBB, BasicBlock *Succ,
//
void CWriter::visitBranchInst(BranchInst &I) {
if (I.isConditional()) {
- if (isGotoCodeNeccessary(I.getParent(), I.getSuccessor(0))) {
+ if (isGotoCodeNecessary(I.getParent(), I.getSuccessor(0))) {
Out << " if (";
writeOperand(I.getCondition());
Out << ") {\n";
printBranchToBlock(I.getParent(), I.getSuccessor(0), 2);
- if (isGotoCodeNeccessary(I.getParent(), I.getSuccessor(1))) {
+ if (isGotoCodeNecessary(I.getParent(), I.getSuccessor(1))) {
Out << " } else {\n";
printBranchToBlock(I.getParent(), I.getSuccessor(1), 2);
}
diff --git a/lib/Target/CBackend/Writer.cpp b/lib/Target/CBackend/Writer.cpp
index d1bf849..3398124 100644
--- a/lib/Target/CBackend/Writer.cpp
+++ b/lib/Target/CBackend/Writer.cpp
@@ -23,6 +23,10 @@
#include <algorithm>
#include <sstream>
+
+/* FIXME: This should be autoconf'd! */
+#define HAS_C99_HEXADECIMAL_CONSTANTS 1
+
namespace {
class CWriter : public Pass, public InstVisitor<CWriter> {
std::ostream &Out;
@@ -337,6 +341,16 @@ void CWriter::printConstantArray(ConstantArray *CPA) {
// only deal in IEEE FP).
//
static bool isFPCSafeToPrint(const ConstantFP *CFP) {
+#if HAS_C99_HEXADECIMAL_CONSTANTS
+ char Buffer[100];
+ sprintf(Buffer, "%a", CFP->getValue());
+
+ if (!strncmp(Buffer, "0x", 2) ||
+ !strncmp(Buffer, "-0x", 3) ||
+ !strncmp(Buffer, "+0x", 3))
+ return atof(Buffer) == CFP->getValue();
+ return false;
+#else
std::string StrVal = ftostr(CFP->getValue());
while (StrVal[0] == ' ')
@@ -350,6 +364,7 @@ static bool isFPCSafeToPrint(const ConstantFP *CFP) {
// Reparse stringized version!
return atof(StrVal.c_str()) == CFP->getValue();
return false;
+#endif
}
// printConstant - The LLVM Constant to C Constant converter.
@@ -442,8 +457,14 @@ void CWriter::printConstant(Constant *CPV) {
Out << "(*(" << (FPC->getType() == Type::FloatTy ? "float" : "double")
<< "*)&FPConstant" << I->second << ")";
} else {
+#if HAS_C99_HEXADECIMAL_CONSTANTS
// Print out the constant as a floating point number.
+ char Buffer[100];
+ sprintf(Buffer, "%a", FPC->getValue());
+ Out << Buffer << " /*" << FPC->getValue() << "*/ ";
+#else
Out << ftostr(FPC->getValue());
+#endif
}
break;
}
@@ -1018,7 +1039,7 @@ void CWriter::visitUnwindInst(UnwindInst &I) {
emittedInvoke = true;
}
-static bool isGotoCodeNeccessary(BasicBlock *From, BasicBlock *To) {
+static bool isGotoCodeNecessary(BasicBlock *From, BasicBlock *To) {
// If PHI nodes need copies, we need the copy code...
if (isa<PHINode>(To->front()) ||
From->getNext() != To) // Not directly successor, need goto
@@ -1051,14 +1072,14 @@ void CWriter::printBranchToBlock(BasicBlock *CurBB, BasicBlock *Succ,
//
void CWriter::visitBranchInst(BranchInst &I) {
if (I.isConditional()) {
- if (isGotoCodeNeccessary(I.getParent(), I.getSuccessor(0))) {
+ if (isGotoCodeNecessary(I.getParent(), I.getSuccessor(0))) {
Out << " if (";
writeOperand(I.getCondition());
Out << ") {\n";
printBranchToBlock(I.getParent(), I.getSuccessor(0), 2);
- if (isGotoCodeNeccessary(I.getParent(), I.getSuccessor(1))) {
+ if (isGotoCodeNecessary(I.getParent(), I.getSuccessor(1))) {
Out << " } else {\n";
printBranchToBlock(I.getParent(), I.getSuccessor(1), 2);
}