llvm.org GIT mirror llvm / 0123b7d
Make tblgen a little smarter about constants smaller than i32. Currently, tblgen will complain if a sign-extended constant does not fit into a data type smaller than i32, e.g., i16. This causes a problem when certain hex constants are used, such as 0xff for byte masks or immediate xor values. tblgen will try the sign-extended value first and, if the sign extended value would overflow, it tries to see if the unsigned value will fit. Consequently, a software developer can now safely incant: (XORHIr16 R16C:$rA, 0xffff) which is somewhat clearer and more informative than incanting: (XORHIr16 R16C:$rA, (i16 -1)) even if the two are bitwise equivalent. Tblgen also outputs the 64-bit unsigned constant in the generated ISel code when getTargetConstant() is invoked. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47188 91177308-0d34-0410-b5e6-96231b3b80d8 Scott Michel 12 years ago
4 changed file(s) with 29 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
8484 return utostr(static_cast(X));
8585 }
8686
87 static inline std::string itohexstr(int64_t X) {
88 return utohexstr(static_cast(X));
89 }
90
8791 static inline std::string ftostr(double V) {
8892 char Buffer[200];
8993 sprintf(Buffer, "%20.6e", V);
38513851 case Expand: assert(0 && "Shouldn't need to expand other operators here!");
38523852 case Legal:
38533853 Tmp1 = LegalizeOp(Node->getOperand(0));
3854 if (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0)) ==
3855 TargetLowering::Custom) {
3856 Tmp2 = TLI.LowerOperation(Result, DAG);
3857 if (Tmp2.Val) {
3858 Tmp1 = Tmp2;
3859 }
3860 }
38543861 Result = DAG.UpdateNodeOperands(Result, Tmp1);
38553862 break;
38563863 case Promote:
701701 // Make sure that the value is representable for this type.
702702 if (Size < 32) {
703703 int Val = (II->getValue() << (32-Size)) >> (32-Size);
704 if (Val != II->getValue())
705 TP.error("Sign-extended integer value '" + itostr(II->getValue())+
706 "' is out of range for type '" +
707 getEnumName(getTypeNum(0)) + "'!");
704 if (Val != II->getValue()) {
705 // If sign-extended doesn't fit, does it fit as unsigned?
706 unsigned ValueMask = unsigned(MVT::getIntVTBitMask(VT));
707 unsigned UnsignedVal = unsigned(II->getValue());
708
709 if ((ValueMask & UnsignedVal) != UnsignedVal) {
710 TP.error("Integer value '" + itostr(II->getValue())+
711 "' is out of range for type '" +
712 getEnumName(getTypeNum(0)) + "'!");
713 }
714 }
708715 }
709716 }
710717 }
729729 const std::string &VarName = N->getName();
730730 std::string Val = VariableMap[VarName];
731731 bool ModifiedVal = false;
732 assert(!Val.empty() &&
733 "Variable referenced but not defined and not caught earlier!");
732 if (Val.empty()) {
733 cerr << "Variable '" << VarName << " referenced but not defined "
734 << "and not caught earlier!\n";
735 abort();
736 }
734737 if (Val[0] == 'T' && Val[1] == 'm' && Val[2] == 'p') {
735738 // Already selected this operand, just return the tmpval.
736739 NodeOps.push_back(Val);
857860 unsigned ResNo = TmpNo++;
858861 assert(N->getExtTypes().size() == 1 && "Multiple types not handled!");
859862 emitCode("SDOperand Tmp" + utostr(ResNo) +
860 " = CurDAG->getTargetConstant(" + itostr(II->getValue()) +
861 ", " + getEnumName(N->getTypeNum(0)) + ");");
863 " = CurDAG->getTargetConstant(0x" + itohexstr(II->getValue()) +
864 "ULL, " + getEnumName(N->getTypeNum(0)) + ");");
862865 NodeOps.push_back("Tmp" + utostr(ResNo));
863866 return NodeOps;
864867 }