llvm.org GIT mirror llvm / b9c01c2
Merge from mainline. git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_24@57957 91177308-0d34-0410-b5e6-96231b3b80d8 Tanya Lattner 10 years ago
2 changed file(s) with 107 addition(s) and 47 deletion(s). Raw diff Collapse all Expand all
8787 std::map FPConstantMap;
8888 std::set intrinsicPrototypesAlreadyGenerated;
8989 std::set ByValParams;
90 unsigned FPCounter;
9091
9192 public:
9293 static char ID;
9394 explicit CWriter(raw_ostream &o)
9495 : FunctionPass(&ID), Out(o), IL(0), Mang(0), LI(0),
95 TheModule(0), TAsm(0), TD(0) {}
96 TheModule(0), TAsm(0), TD(0) {
97 FPCounter = 0;
98 }
9699
97100 virtual const char *getPassName() const { return "C backend"; }
98101
180183 void printModuleTypes(const TypeSymbolTable &ST);
181184 void printContainedStructs(const Type *Ty, std::set &);
182185 void printFloatingPointConstants(Function &F);
186 void printFloatingPointConstants(const Constant *C);
183187 void printFunctionSignature(const Function *F, bool Prototype);
184188
185189 void printFunction(Function &);
832836 //
833837 static bool isFPCSafeToPrint(const ConstantFP *CFP) {
834838 // Do long doubles in hex for now.
835 if (CFP->getType()!=Type::FloatTy && CFP->getType()!=Type::DoubleTy)
839 if (CFP->getType() != Type::FloatTy && CFP->getType() != Type::DoubleTy)
836840 return false;
837841 APFloat APF = APFloat(CFP->getValueAPF()); // copy
838 if (CFP->getType()==Type::FloatTy)
842 if (CFP->getType() == Type::FloatTy)
839843 APF.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven);
840844 #if HAVE_PRINTF_A && ENABLE_CBE_PRINTF_A
841845 char Buffer[100];
11271131 "long double")
11281132 << "*)&FPConstant" << I->second << ')';
11291133 } else {
1130 assert(FPC->getType() == Type::FloatTy ||
1131 FPC->getType() == Type::DoubleTy);
1132 double V = FPC->getType() == Type::FloatTy ?
1133 FPC->getValueAPF().convertToFloat() :
1134 FPC->getValueAPF().convertToDouble();
1134 double V;
1135 if (FPC->getType() == Type::FloatTy)
1136 V = FPC->getValueAPF().convertToFloat();
1137 else if (FPC->getType() == Type::DoubleTy)
1138 V = FPC->getValueAPF().convertToDouble();
1139 else {
1140 // Long double. Convert the number to double, discarding precision.
1141 // This is not awesome, but it at least makes the CBE output somewhat
1142 // useful.
1143 APFloat Tmp = FPC->getValueAPF();
1144 bool LosesInfo;
1145 Tmp.convert(APFloat::IEEEdouble, APFloat::rmTowardZero, &LosesInfo);
1146 V = Tmp.convertToDouble();
1147 }
1148
11351149 if (IsNAN(V)) {
11361150 // The value is NaN
11371151
20172031 // the precision of the printed form, unless the printed form preserves
20182032 // precision.
20192033 //
2020 static unsigned FPCounter = 0;
20212034 for (constant_iterator I = constant_begin(&F), E = constant_end(&F);
20222035 I != E; ++I)
2023 if (const ConstantFP *FPC = dyn_cast(*I))
2024 if (!isFPCSafeToPrint(FPC) && // Do not put in FPConstantMap if safe.
2025 !FPConstantMap.count(FPC)) {
2026 FPConstantMap[FPC] = FPCounter; // Number the FP constants
2027
2028 if (FPC->getType() == Type::DoubleTy) {
2029 double Val = FPC->getValueAPF().convertToDouble();
2030 uint64_t i = FPC->getValueAPF().convertToAPInt().getZExtValue();
2031 Out << "static const ConstantDoubleTy FPConstant" << FPCounter++
2032 << " = 0x" << utohexstr(i)
2033 << "ULL; /* " << Val << " */\n";
2034 } else if (FPC->getType() == Type::FloatTy) {
2035 float Val = FPC->getValueAPF().convertToFloat();
2036 uint32_t i = (uint32_t)FPC->getValueAPF().convertToAPInt().
2037 getZExtValue();
2038 Out << "static const ConstantFloatTy FPConstant" << FPCounter++
2039 << " = 0x" << utohexstr(i)
2040 << "U; /* " << Val << " */\n";
2041 } else if (FPC->getType() == Type::X86_FP80Ty) {
2042 // api needed to prevent premature destruction
2043 APInt api = FPC->getValueAPF().convertToAPInt();
2044 const uint64_t *p = api.getRawData();
2045 Out << "static const ConstantFP80Ty FPConstant" << FPCounter++
2046 << " = { 0x"
2047 << utohexstr((uint16_t)p[1] | (p[0] & 0xffffffffffffLL)<<16)
2048 << "ULL, 0x" << utohexstr((uint16_t)(p[0] >> 48)) << ",{0,0,0}"
2049 << "}; /* Long double constant */\n";
2050 } else if (FPC->getType() == Type::PPC_FP128Ty) {
2051 APInt api = FPC->getValueAPF().convertToAPInt();
2052 const uint64_t *p = api.getRawData();
2053 Out << "static const ConstantFP128Ty FPConstant" << FPCounter++
2054 << " = { 0x"
2055 << utohexstr(p[0]) << ", 0x" << utohexstr(p[1])
2056 << "}; /* Long double constant */\n";
2057
2058 } else
2059 assert(0 && "Unknown float type!");
2060 }
2036 printFloatingPointConstants(*I);
20612037
20622038 Out << '\n';
20632039 }
2040
2041 void CWriter::printFloatingPointConstants(const Constant *C) {
2042 // If this is a constant expression, recursively check for constant fp values.
2043 if (const ConstantExpr *CE = dyn_cast(C)) {
2044 for (unsigned i = 0, e = CE->getNumOperands(); i != e; ++i)
2045 printFloatingPointConstants(CE->getOperand(i));
2046 return;
2047 }
2048
2049 // Otherwise, check for a FP constant that we need to print.
2050 const ConstantFP *FPC = dyn_cast(C);
2051 if (FPC == 0 ||
2052 // Do not put in FPConstantMap if safe.
2053 isFPCSafeToPrint(FPC) ||
2054 // Already printed this constant?
2055 FPConstantMap.count(FPC))
2056 return;
2057
2058 FPConstantMap[FPC] = FPCounter; // Number the FP constants
2059
2060 if (FPC->getType() == Type::DoubleTy) {
2061 double Val = FPC->getValueAPF().convertToDouble();
2062 uint64_t i = FPC->getValueAPF().bitcastToAPInt().getZExtValue();
2063 Out << "static const ConstantDoubleTy FPConstant" << FPCounter++
2064 << " = 0x" << utohexstr(i)
2065 << "ULL; /* " << Val << " */\n";
2066 } else if (FPC->getType() == Type::FloatTy) {
2067 float Val = FPC->getValueAPF().convertToFloat();
2068 uint32_t i = (uint32_t)FPC->getValueAPF().bitcastToAPInt().
2069 getZExtValue();
2070 Out << "static const ConstantFloatTy FPConstant" << FPCounter++
2071 << " = 0x" << utohexstr(i)
2072 << "U; /* " << Val << " */\n";
2073 } else if (FPC->getType() == Type::X86_FP80Ty) {
2074 // api needed to prevent premature destruction
2075 APInt api = FPC->getValueAPF().bitcastToAPInt();
2076 const uint64_t *p = api.getRawData();
2077 Out << "static const ConstantFP80Ty FPConstant" << FPCounter++
2078 << " = { 0x"
2079 << utohexstr((uint16_t)p[1] | (p[0] & 0xffffffffffffLL)<<16)
2080 << "ULL, 0x" << utohexstr((uint16_t)(p[0] >> 48)) << ",{0,0,0}"
2081 << "}; /* Long double constant */\n";
2082 } else if (FPC->getType() == Type::PPC_FP128Ty) {
2083 APInt api = FPC->getValueAPF().bitcastToAPInt();
2084 const uint64_t *p = api.getRawData();
2085 Out << "static const ConstantFP128Ty FPConstant" << FPCounter++
2086 << " = { 0x"
2087 << utohexstr(p[0]) << ", 0x" << utohexstr(p[1])
2088 << "}; /* Long double constant */\n";
2089
2090 } else {
2091 assert(0 && "Unknown float type!");
2092 }
2093 }
2094
20642095
20652096
20662097 /// printSymbolTable - Run through symbol table looking for type names. If a
0 ; RUN: llvm-as < %s | llc -march=c
1 ; PR2907
2 target datalayout = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f128:64:128"
3 target triple = "powerpc-apple-darwin9.5"
4 %"struct.Point<0>" = type { %"struct.Tensor<1,0>" }
5 %"struct.QGauss2<1>" = type { %"struct.Quadrature<0>" }
6 %"struct.Quadrature<0>" = type { %struct.Subscriptor, i32, %"struct.std::vector,std::allocator > >", %"struct.std::vector >" }
7 %struct.Subscriptor = type { i32 (...)**, i32, %"struct.std::type_info"* }
8 %"struct.Tensor<1,0>" = type { [1 x double] }
9 %"struct.std::_Vector_base,std::allocator > >" = type { %"struct.std::_Vector_base,std::allocator > >::_Vector_impl" }
10 %"struct.std::_Vector_base,std::allocator > >::_Vector_impl" = type { %"struct.Point<0>"*, %"struct.Point<0>"*, %"struct.Point<0>"* }
11 %"struct.std::_Vector_base >" = type { %"struct.std::_Vector_base >::_Vector_impl" }
12 %"struct.std::_Vector_base >::_Vector_impl" = type { double*, double*, double* }
13 %"struct.std::type_info" = type { i32 (...)**, i8* }
14 %"struct.std::vector,std::allocator > >" = type { %"struct.std::_Vector_base,std::allocator > >" }
15 %"struct.std::vector >" = type { %"struct.std::_Vector_base >" }
16
17 define fastcc void @_ZN6QGaussILi1EEC1Ej(%"struct.QGauss2<1>"* %this, i32 %n) {
18 entry:
19 br label %bb4
20
21 bb4: ; preds = %bb5.split, %bb4, %entry
22 %0 = fcmp ogt ppc_fp128 0xM00000000000000000000000000000000, select (i1 fcmp olt (ppc_fp128 fpext (double 0x3C447AE147AE147B to ppc_fp128), ppc_fp128 mul (ppc_fp128 0xM00000000000000010000000000000000, ppc_fp128 0xM40140000000000000000000000000000)), ppc_fp128 mul (ppc_fp128 0xM00000000000000010000000000000000, ppc_fp128 0xM40140000000000000000000000000000), ppc_fp128 fpext (double 0x3C447AE147AE147B to ppc_fp128)) ; [#uses=1]
23 br i1 %0, label %bb4, label %bb5.split
24
25 bb5.split: ; preds = %bb4
26 %1 = getelementptr double* null, i32 0 ; [#uses=0]
27 br label %bb4
28 }