From fbe7ae9e3c3b1adf9c053d898d023338568475f3 Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Mon, 8 Jan 2007 08:00:00 +0000 Subject: [PATCH] For PR1090: Clean up the definitions of the helper functions per Chris' review suggestions so they are easier to read. For PR1091: Print minimum signed integer values as unsigned so that we get no warnings from the C compiler about constant ranges and value comparisons. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33010 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/CBackend/CBackend.cpp | 59 +++++++++++++++++--------------- lib/Target/CBackend/Writer.cpp | 59 +++++++++++++++++--------------- 2 files changed, 62 insertions(+), 56 deletions(-) diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index c59dd60adc5..ff87be77584 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -826,23 +826,26 @@ void CWriter::printConstant(Constant *CPV) { return; } - switch (CPV->getType()->getTypeID()) { - case Type::BoolTyID: - Out << (cast(CPV)->getValue() ? '1' : '0'); - break; - case Type::Int8TyID: - Out << "((char)" << cast(CPV)->getSExtValue() << ")"; - break; - case Type::Int16TyID: - Out << "((short)" << cast(CPV)->getSExtValue() << ")"; - break; - case Type::Int32TyID: - Out << "((int)" << cast(CPV)->getSExtValue() << ")"; - break; - case Type::Int64TyID: - Out << "((long long)" << cast(CPV)->getSExtValue() << "ll)"; - break; + if (ConstantBool *CB = dyn_cast(CPV)) { + Out << (CB->getValue() ? '1' : '0') ; + return; + } + if (ConstantInt *CI = dyn_cast(CPV)) { + const Type* Ty = CI->getType(); + Out << "(("; + printPrimitiveType(Out, Ty, true) << ')'; + if (CI->isMinValue(true)) + Out << CI->getZExtValue() << 'u'; + else + Out << CI->getSExtValue(); + if (Ty->getPrimitiveSizeInBits() > 32) + Out << "ll"; + Out << ')'; + return; + } + + switch (CPV->getType()->getTypeID()) { case Type::FloatTyID: case Type::DoubleTyID: { ConstantFP *FPC = cast(CPV); @@ -1586,29 +1589,29 @@ bool CWriter::doInitialization(Module &M) { Out << "static inline int llvm_fcmp_uno(double X, double Y) { "; Out << "return X != X || Y != Y; }\n"; Out << "static inline int llvm_fcmp_ueq(double X, double Y) { "; - Out << "return X == Y || X != X || Y != Y; }\n"; + Out << "return X == Y || llvm_fcmp_uno(X, Y); }\n"; Out << "static inline int llvm_fcmp_une(double X, double Y) { "; - Out << "return X != Y || X != X || Y != Y; }\n"; + Out << "return X != Y; }\n"; Out << "static inline int llvm_fcmp_ult(double X, double Y) { "; - Out << "return X < Y || X != X || Y != Y; }\n"; + Out << "return X < Y || llvm_fcmp_uno(X, Y); }\n"; Out << "static inline int llvm_fcmp_ugt(double X, double Y) { "; - Out << "return X > Y || X != X || Y != Y; }\n"; + Out << "return X > Y || llvm_fcmp_uno(X, Y); }\n"; Out << "static inline int llvm_fcmp_ule(double X, double Y) { "; - Out << "return X <= Y || X != X || Y != Y; }\n"; + Out << "return X <= Y || llvm_fcmp_uno(X, Y); }\n"; Out << "static inline int llvm_fcmp_uge(double X, double Y) { "; - Out << "return X >= Y || X != X || Y != Y; }\n"; + Out << "return X >= Y || llvm_fcmp_uno(X, Y); }\n"; Out << "static inline int llvm_fcmp_oeq(double X, double Y) { "; - Out << "return X == Y && X == X && Y == Y; }\n"; + Out << "return X == Y ; }\n"; Out << "static inline int llvm_fcmp_one(double X, double Y) { "; - Out << "return X != Y && X == X && Y == Y; }\n"; + Out << "return X != Y && llvm_fcmp_ord(X, Y); }\n"; Out << "static inline int llvm_fcmp_olt(double X, double Y) { "; - Out << "return X < Y && X == X && Y == Y; }\n"; + Out << "return X < Y ; }\n"; Out << "static inline int llvm_fcmp_ogt(double X, double Y) { "; - Out << "return X > Y && X == X && Y == Y; }\n"; + Out << "return X > Y ; }\n"; Out << "static inline int llvm_fcmp_ole(double X, double Y) { "; - Out << "return X <= Y && X == X && Y == Y; }\n"; + Out << "return X <= Y ; }\n"; Out << "static inline int llvm_fcmp_oge(double X, double Y) { "; - Out << "return X >= Y && X == X && Y == Y; }\n"; + Out << "return X >= Y ; }\n"; return false; } diff --git a/lib/Target/CBackend/Writer.cpp b/lib/Target/CBackend/Writer.cpp index c59dd60adc5..ff87be77584 100644 --- a/lib/Target/CBackend/Writer.cpp +++ b/lib/Target/CBackend/Writer.cpp @@ -826,23 +826,26 @@ void CWriter::printConstant(Constant *CPV) { return; } - switch (CPV->getType()->getTypeID()) { - case Type::BoolTyID: - Out << (cast(CPV)->getValue() ? '1' : '0'); - break; - case Type::Int8TyID: - Out << "((char)" << cast(CPV)->getSExtValue() << ")"; - break; - case Type::Int16TyID: - Out << "((short)" << cast(CPV)->getSExtValue() << ")"; - break; - case Type::Int32TyID: - Out << "((int)" << cast(CPV)->getSExtValue() << ")"; - break; - case Type::Int64TyID: - Out << "((long long)" << cast(CPV)->getSExtValue() << "ll)"; - break; + if (ConstantBool *CB = dyn_cast(CPV)) { + Out << (CB->getValue() ? '1' : '0') ; + return; + } + if (ConstantInt *CI = dyn_cast(CPV)) { + const Type* Ty = CI->getType(); + Out << "(("; + printPrimitiveType(Out, Ty, true) << ')'; + if (CI->isMinValue(true)) + Out << CI->getZExtValue() << 'u'; + else + Out << CI->getSExtValue(); + if (Ty->getPrimitiveSizeInBits() > 32) + Out << "ll"; + Out << ')'; + return; + } + + switch (CPV->getType()->getTypeID()) { case Type::FloatTyID: case Type::DoubleTyID: { ConstantFP *FPC = cast(CPV); @@ -1586,29 +1589,29 @@ bool CWriter::doInitialization(Module &M) { Out << "static inline int llvm_fcmp_uno(double X, double Y) { "; Out << "return X != X || Y != Y; }\n"; Out << "static inline int llvm_fcmp_ueq(double X, double Y) { "; - Out << "return X == Y || X != X || Y != Y; }\n"; + Out << "return X == Y || llvm_fcmp_uno(X, Y); }\n"; Out << "static inline int llvm_fcmp_une(double X, double Y) { "; - Out << "return X != Y || X != X || Y != Y; }\n"; + Out << "return X != Y; }\n"; Out << "static inline int llvm_fcmp_ult(double X, double Y) { "; - Out << "return X < Y || X != X || Y != Y; }\n"; + Out << "return X < Y || llvm_fcmp_uno(X, Y); }\n"; Out << "static inline int llvm_fcmp_ugt(double X, double Y) { "; - Out << "return X > Y || X != X || Y != Y; }\n"; + Out << "return X > Y || llvm_fcmp_uno(X, Y); }\n"; Out << "static inline int llvm_fcmp_ule(double X, double Y) { "; - Out << "return X <= Y || X != X || Y != Y; }\n"; + Out << "return X <= Y || llvm_fcmp_uno(X, Y); }\n"; Out << "static inline int llvm_fcmp_uge(double X, double Y) { "; - Out << "return X >= Y || X != X || Y != Y; }\n"; + Out << "return X >= Y || llvm_fcmp_uno(X, Y); }\n"; Out << "static inline int llvm_fcmp_oeq(double X, double Y) { "; - Out << "return X == Y && X == X && Y == Y; }\n"; + Out << "return X == Y ; }\n"; Out << "static inline int llvm_fcmp_one(double X, double Y) { "; - Out << "return X != Y && X == X && Y == Y; }\n"; + Out << "return X != Y && llvm_fcmp_ord(X, Y); }\n"; Out << "static inline int llvm_fcmp_olt(double X, double Y) { "; - Out << "return X < Y && X == X && Y == Y; }\n"; + Out << "return X < Y ; }\n"; Out << "static inline int llvm_fcmp_ogt(double X, double Y) { "; - Out << "return X > Y && X == X && Y == Y; }\n"; + Out << "return X > Y ; }\n"; Out << "static inline int llvm_fcmp_ole(double X, double Y) { "; - Out << "return X <= Y && X == X && Y == Y; }\n"; + Out << "return X <= Y ; }\n"; Out << "static inline int llvm_fcmp_oge(double X, double Y) { "; - Out << "return X >= Y && X == X && Y == Y; }\n"; + Out << "return X >= Y ; }\n"; return false; } -- 2.34.1