llvm.org GIT mirror llvm / 61131ab
Remove exception handling usage from tblgen. Most places can use PrintFatalError as the unwinding mechanism was not used for anything other than printing the error. The single exception was CodeGenDAGPatterns.cpp, where intermediate errors during type resolution were ignored to simplify incremental platform development. This use is replaced by an error flag in TreePattern and bailout earlier in various places if it is set. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166712 91177308-0d34-0410-b5e6-96231b3b80d8 Joerg Sonnenberger 7 years ago
32 changed file(s) with 483 addition(s) and 447 deletion(s). Raw diff Collapse all Expand all
1818
1919 namespace llvm {
2020
21 class TGError {
22 SmallVector Locs;
23 std::string Message;
24 public:
25 TGError(ArrayRef locs, const std::string &message)
26 : Locs(locs.begin(), locs.end()), Message(message) {}
27
28 ArrayRef getLoc() const { return Locs; }
29 const std::string &getMessage() const { return Message; }
30 };
31
3221 void PrintWarning(ArrayRef WarningLoc, const Twine &Msg);
3322 void PrintWarning(const char *Loc, const Twine &Msg);
3423 void PrintWarning(const Twine &Msg);
35 void PrintWarning(const TGError &Warning);
3624
3725 void PrintError(ArrayRef ErrorLoc, const Twine &Msg);
3826 void PrintError(const char *Loc, const Twine &Msg);
3927 void PrintError(const Twine &Msg);
40 void PrintError(const TGError &Error);
4128
4229 LLVM_ATTRIBUTE_NORETURN void PrintFatalError(const std::string &Msg);
4330 LLVM_ATTRIBUTE_NORETURN void PrintFatalError(ArrayRef ErrorLoc,
None set(LLVM_REQUIRES_EH 1)
1
2 add_llvm_library(LLVMTableGen
31 Error.cpp
42 Main.cpp
4444 errs() << "warning:" << Msg << "\n";
4545 }
4646
47 void PrintWarning(const TGError &Warning) {
48 PrintWarning(Warning.getLoc(), Warning.getMessage());
49 }
50
5147 void PrintError(ArrayRef ErrorLoc, const Twine &Msg) {
5248 PrintMessage(ErrorLoc, SourceMgr::DK_Error, Msg);
5349 }
5854
5955 void PrintError(const Twine &Msg) {
6056 errs() << "error:" << Msg << "\n";
61 }
62
63 void PrintError(const TGError &Error) {
64 PrintError(Error.getLoc(), Error.getMessage());
6557 }
6658
6759 void PrintFatalError(const std::string &Msg) {
7979 int TableGenMain(char *argv0, TableGenMainFn *MainFn) {
8080 RecordKeeper Records;
8181
82 try {
83 // Parse the input file.
84 OwningPtr File;
85 if (error_code ec =
86 MemoryBuffer::getFileOrSTDIN(InputFilename.c_str(), File)) {
87 errs() << "Could not open input file '" << InputFilename << "': "
88 << ec.message() <<"\n";
89 return 1;
90 }
91 MemoryBuffer *F = File.take();
82 // Parse the input file.
83 OwningPtr File;
84 if (error_code ec =
85 MemoryBuffer::getFileOrSTDIN(InputFilename.c_str(), File)) {
86 errs() << "Could not open input file '" << InputFilename << "': "
87 << ec.message() <<"\n";
88 return 1;
89 }
90 MemoryBuffer *F = File.take();
9291
93 // Tell SrcMgr about this buffer, which is what TGParser will pick up.
94 SrcMgr.AddNewSourceBuffer(F, SMLoc());
92 // Tell SrcMgr about this buffer, which is what TGParser will pick up.
93 SrcMgr.AddNewSourceBuffer(F, SMLoc());
9594
96 // Record the location of the include directory so that the lexer can find
97 // it later.
98 SrcMgr.setIncludeDirs(IncludeDirs);
95 // Record the location of the include directory so that the lexer can find
96 // it later.
97 SrcMgr.setIncludeDirs(IncludeDirs);
9998
100 TGParser Parser(SrcMgr, Records);
99 TGParser Parser(SrcMgr, Records);
101100
102 if (Parser.ParseFile())
103 return 1;
101 if (Parser.ParseFile())
102 return 1;
104103
105 std::string Error;
106 tool_output_file Out(OutputFilename.c_str(), Error);
107 if (!Error.empty()) {
108 errs() << argv0 << ": error opening " << OutputFilename
109 << ":" << Error << "\n";
110 return 1;
111 }
112 if (!DependFilename.empty())
113 if (int Ret = createDependencyFile(Parser, argv0))
114 return Ret;
104 std::string Error;
105 tool_output_file Out(OutputFilename.c_str(), Error);
106 if (!Error.empty()) {
107 errs() << argv0 << ": error opening " << OutputFilename
108 << ":" << Error << "\n";
109 return 1;
110 }
111 if (!DependFilename.empty()) {
112 if (int Ret = createDependencyFile(Parser, argv0))
113 return Ret;
114 }
115115
116 if (MainFn(Out.os(), Records))
117 return 1;
116 if (MainFn(Out.os(), Records))
117 return 1;
118118
119 // Declare success.
120 Out.keep();
121 return 0;
122
123 } catch (const TGError &Error) {
124 PrintError(Error);
125 } catch (const std::string &Error) {
126 PrintError(Error);
127 } catch (const char *Error) {
128 PrintError(Error);
129 } catch (...) {
130 errs() << argv0 << ": Unknown unexpected exception occurred.\n";
131 }
119 // Declare success.
120 Out.keep();
121 return 0;
132122
133123 return 1;
134124 }
1010 LIBRARYNAME = LLVMTableGen
1111 BUILD_ARCHIVE = 1
1212
13 REQUIRES_EH = 1
14
1513 include $(LEVEL)/Makefile.common
615615 Record *ListInit::getElementAsRecord(unsigned i) const {
616616 assert(i < Values.size() && "List element index out of range!");
617617 DefInit *DI = dyn_cast(Values[i]);
618 if (DI == 0) throw "Expected record in list!";
618 if (DI == 0)
619 PrintFatalError("Expected record in list!");
619620 return DI->getDef();
620621 }
621622
724725 if (CurRec) {
725726 if (const RecordVal *RV = CurRec->getValue(Name)) {
726727 if (RV->getType() != getType())
727 throw "type mismatch in cast";
728 PrintFatalError("type mismatch in cast");
728729 return VarInit::get(Name, RV->getType());
729730 }
730731
736737 assert(RV && "Template arg doesn't exist??");
737738
738739 if (RV->getType() != getType())
739 throw "type mismatch in cast";
740 PrintFatalError("type mismatch in cast");
740741
741742 return VarInit::get(TemplateArgName, RV->getType());
742743 }
750751 assert(RV && "Template arg doesn't exist??");
751752
752753 if (RV->getType() != getType())
753 throw "type mismatch in cast";
754 PrintFatalError("type mismatch in cast");
754755
755756 return VarInit::get(MCName, RV->getType());
756757 }
759760 if (Record *D = (CurRec->getRecords()).getDef(Name))
760761 return DefInit::get(D);
761762
762 throw TGError(CurRec->getLoc(), "Undefined reference:'" + Name + "'\n");
763 PrintFatalError(CurRec->getLoc(),
764 "Undefined reference:'" + Name + "'\n");
763765 }
764766 }
765767 break;
859861 DefInit *LOp = dyn_cast(LHSs->getOperator());
860862 DefInit *ROp = dyn_cast(RHSs->getOperator());
861863 if (LOp == 0 || ROp == 0 || LOp->getDef() != ROp->getDef())
862 throw "Concated Dag operators do not match!";
864 PrintFatalError("Concated Dag operators do not match!");
863865 std::vector Args;
864866 std::vector ArgNames;
865867 for (unsigned i = 0, e = LHSs->getNumArgs(); i != e; ++i) {
10261028 OpInit *RHSo = dyn_cast(RHS);
10271029
10281030 if (!RHSo) {
1029 throw TGError(CurRec->getLoc(), "!foreach requires an operator\n");
1031 PrintFatalError(CurRec->getLoc(), "!foreach requires an operator\n");
10301032 }
10311033
10321034 TypedInit *LHSt = dyn_cast(LHS);
10331035
1034 if (!LHSt) {
1035 throw TGError(CurRec->getLoc(), "!foreach requires typed variable\n");
1036 }
1036 if (!LHSt)
1037 PrintFatalError(CurRec->getLoc(), "!foreach requires typed variable\n");
10371038
10381039 if ((MHSd && isa(Type)) || (MHSl && isa(Type))) {
10391040 if (MHSd) {
16311632 assert(TypedName && "Record name is not typed!");
16321633 RecTy *Type = TypedName->getType();
16331634 if (!isa(Type))
1634 throw TGError(getLoc(), "Record name is not a string!");
1635 PrintFatalError(getLoc(), "Record name is not a string!");
16351636 }
16361637
16371638 DefInit *Record::getDefInit() {
16821683 continue;
16831684 if (Init *V = Values[i].getValue())
16841685 if (Values[i].setValue(V->resolveReferences(*this, RV)))
1685 throw TGError(getLoc(), "Invalid value is found when setting '"
1686 PrintFatalError(getLoc(), "Invalid value is found when setting '"
16861687 + Values[i].getNameInitAsString()
16871688 + "' after resolving references"
16881689 + (RV ? " against '" + RV->getNameInitAsString()
17371738 }
17381739
17391740 /// getValueInit - Return the initializer for a value with the specified name,
1740 /// or throw an exception if the field does not exist.
1741 /// or abort if the field does not exist.
17411742 ///
17421743 Init *Record::getValueInit(StringRef FieldName) const {
17431744 const RecordVal *R = getValue(FieldName);
17441745 if (R == 0 || R->getValue() == 0)
1745 throw "Record `" + getName() + "' does not have a field named `" +
1746 FieldName.str() + "'!\n";
1746 PrintFatalError(getLoc(), "Record `" + getName() +
1747 "' does not have a field named `" + FieldName.str() + "'!\n");
17471748 return R->getValue();
17481749 }
17491750
17501751
17511752 /// getValueAsString - This method looks up the specified field and returns its
1752 /// value as a string, throwing an exception if the field does not exist or if
1753 /// value as a string, aborts if the field does not exist or if
17531754 /// the value is not a string.
17541755 ///
17551756 std::string Record::getValueAsString(StringRef FieldName) const {
17561757 const RecordVal *R = getValue(FieldName);
17571758 if (R == 0 || R->getValue() == 0)
1758 throw "Record `" + getName() + "' does not have a field named `" +
1759 FieldName.str() + "'!\n";
1759 PrintFatalError(getLoc(), "Record `" + getName() +
1760 "' does not have a field named `" + FieldName.str() + "'!\n");
17601761
17611762 if (StringInit *SI = dyn_cast(R->getValue()))
17621763 return SI->getValue();
1763 throw "Record `" + getName() + "', field `" + FieldName.str() +
1764 "' does not have a string initializer!";
1764 PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
1765 FieldName.str() + "' does not have a string initializer!");
17651766 }
17661767
17671768 /// getValueAsBitsInit - This method looks up the specified field and returns
1768 /// its value as a BitsInit, throwing an exception if the field does not exist
1769 /// or if the value is not the right type.
1769 /// its value as a BitsInit, aborts if the field does not exist or if
1770 /// the value is not the right type.
17701771 ///
17711772 BitsInit *Record::getValueAsBitsInit(StringRef FieldName) const {
17721773 const RecordVal *R = getValue(FieldName);
17731774 if (R == 0 || R->getValue() == 0)
1774 throw "Record `" + getName() + "' does not have a field named `" +
1775 FieldName.str() + "'!\n";
1775 PrintFatalError(getLoc(), "Record `" + getName() +
1776 "' does not have a field named `" + FieldName.str() + "'!\n");
17761777
17771778 if (BitsInit *BI = dyn_cast(R->getValue()))
17781779 return BI;
1779 throw "Record `" + getName() + "', field `" + FieldName.str() +
1780 "' does not have a BitsInit initializer!";
1780 PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
1781 FieldName.str() + "' does not have a BitsInit initializer!");
17811782 }
17821783
17831784 /// getValueAsListInit - This method looks up the specified field and returns
1784 /// its value as a ListInit, throwing an exception if the field does not exist
1785 /// or if the value is not the right type.
1785 /// its value as a ListInit, aborting if the field does not exist or if
1786 /// the value is not the right type.
17861787 ///
17871788 ListInit *Record::getValueAsListInit(StringRef FieldName) const {
17881789 const RecordVal *R = getValue(FieldName);
17891790 if (R == 0 || R->getValue() == 0)
1790 throw "Record `" + getName() + "' does not have a field named `" +
1791 FieldName.str() + "'!\n";
1791 PrintFatalError(getLoc(), "Record `" + getName() +
1792 "' does not have a field named `" + FieldName.str() + "'!\n");
17921793
17931794 if (ListInit *LI = dyn_cast(R->getValue()))
17941795 return LI;
1795 throw "Record `" + getName() + "', field `" + FieldName.str() +
1796 "' does not have a list initializer!";
1796 PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
1797 FieldName.str() + "' does not have a list initializer!");
17971798 }
17981799
17991800 /// getValueAsListOfDefs - This method looks up the specified field and returns
1800 /// its value as a vector of records, throwing an exception if the field does
1801 /// not exist or if the value is not the right type.
1801 /// its value as a vector of records, aborting if the field does not exist
1802 /// or if the value is not the right type.
18021803 ///
18031804 std::vector
18041805 Record::getValueAsListOfDefs(StringRef FieldName) const {
18081809 if (DefInit *DI = dyn_cast(List->getElement(i))) {
18091810 Defs.push_back(DI->getDef());
18101811 } else {
1811 throw "Record `" + getName() + "', field `" + FieldName.str() +
1812 "' list is not entirely DefInit!";
1812 PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
1813 FieldName.str() + "' list is not entirely DefInit!");
18131814 }
18141815 }
18151816 return Defs;
18161817 }
18171818
18181819 /// getValueAsInt - This method looks up the specified field and returns its
1819 /// value as an int64_t, throwing an exception if the field does not exist or if
1820 /// the value is not the right type.
1820 /// value as an int64_t, aborting if the field does not exist or if the value
1821 /// is not the right type.
18211822 ///
18221823 int64_t Record::getValueAsInt(StringRef FieldName) const {
18231824 const RecordVal *R = getValue(FieldName);
18241825 if (R == 0 || R->getValue() == 0)
1825 throw "Record `" + getName() + "' does not have a field named `" +
1826 FieldName.str() + "'!\n";
1826 PrintFatalError(getLoc(), "Record `" + getName() +
1827 "' does not have a field named `" + FieldName.str() + "'!\n");
18271828
18281829 if (IntInit *II = dyn_cast(R->getValue()))
18291830 return II->getValue();
1830 throw "Record `" + getName() + "', field `" + FieldName.str() +
1831 "' does not have an int initializer!";
1831 PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
1832 FieldName.str() + "' does not have an int initializer!");
18321833 }
18331834
18341835 /// getValueAsListOfInts - This method looks up the specified field and returns
1835 /// its value as a vector of integers, throwing an exception if the field does
1836 /// not exist or if the value is not the right type.
1836 /// its value as a vector of integers, aborting if the field does not exist or
1837 /// if the value is not the right type.
18371838 ///
18381839 std::vector
18391840 Record::getValueAsListOfInts(StringRef FieldName) const {
18431844 if (IntInit *II = dyn_cast(List->getElement(i))) {
18441845 Ints.push_back(II->getValue());
18451846 } else {
1846 throw "Record `" + getName() + "', field `" + FieldName.str() +
1847 "' does not have a list of ints initializer!";
1847 PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
1848 FieldName.str() + "' does not have a list of ints initializer!");
18481849 }
18491850 }
18501851 return Ints;
18511852 }
18521853
18531854 /// getValueAsListOfStrings - This method looks up the specified field and
1854 /// returns its value as a vector of strings, throwing an exception if the
1855 /// field does not exist or if the value is not the right type.
1855 /// returns its value as a vector of strings, aborting if the field does not
1856 /// exist or if the value is not the right type.
18561857 ///
18571858 std::vector
18581859 Record::getValueAsListOfStrings(StringRef FieldName) const {
18621863 if (StringInit *II = dyn_cast(List->getElement(i))) {
18631864 Strings.push_back(II->getValue());
18641865 } else {
1865 throw "Record `" + getName() + "', field `" + FieldName.str() +
1866 "' does not have a list of strings initializer!";
1866 PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
1867 FieldName.str() + "' does not have a list of strings initializer!");
18671868 }
18681869 }
18691870 return Strings;
18701871 }
18711872
18721873 /// getValueAsDef - This method looks up the specified field and returns its
1873 /// value as a Record, throwing an exception if the field does not exist or if
1874 /// the value is not the right type.
1874 /// value as a Record, aborting if the field does not exist or if the value
1875 /// is not the right type.
18751876 ///
18761877 Record *Record::getValueAsDef(StringRef FieldName) const {
18771878 const RecordVal *R = getValue(FieldName);
18781879 if (R == 0 || R->getValue() == 0)
1879 throw "Record `" + getName() + "' does not have a field named `" +
1880 FieldName.str() + "'!\n";
1880 PrintFatalError(getLoc(), "Record `" + getName() +
1881 "' does not have a field named `" + FieldName.str() + "'!\n");
18811882
18821883 if (DefInit *DI = dyn_cast(R->getValue()))
18831884 return DI->getDef();
1884 throw "Record `" + getName() + "', field `" + FieldName.str() +
1885 "' does not have a def initializer!";
1885 PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
1886 FieldName.str() + "' does not have a def initializer!");
18861887 }
18871888
18881889 /// getValueAsBit - This method looks up the specified field and returns its
1889 /// value as a bit, throwing an exception if the field does not exist or if
1890 /// the value is not the right type.
1890 /// value as a bit, aborting if the field does not exist or if the value is
1891 /// not the right type.
18911892 ///
18921893 bool Record::getValueAsBit(StringRef FieldName) const {
18931894 const RecordVal *R = getValue(FieldName);
18941895 if (R == 0 || R->getValue() == 0)
1895 throw "Record `" + getName() + "' does not have a field named `" +
1896 FieldName.str() + "'!\n";
1896 PrintFatalError(getLoc(), "Record `" + getName() +
1897 "' does not have a field named `" + FieldName.str() + "'!\n");
18971898
18981899 if (BitInit *BI = dyn_cast(R->getValue()))
18991900 return BI->getValue();
1900 throw "Record `" + getName() + "', field `" + FieldName.str() +
1901 "' does not have a bit initializer!";
1901 PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
1902 FieldName.str() + "' does not have a bit initializer!");
19021903 }
19031904
19041905 bool Record::getValueAsBitOrUnset(StringRef FieldName, bool &Unset) const {
19051906 const RecordVal *R = getValue(FieldName);
19061907 if (R == 0 || R->getValue() == 0)
1907 throw "Record `" + getName() + "' does not have a field named `" +
1908 FieldName.str() + "'!\n";
1908 PrintFatalError(getLoc(), "Record `" + getName() +
1909 "' does not have a field named `" + FieldName.str() + "'!\n");
19091910
19101911 if (R->getValue() == UnsetInit::get()) {
19111912 Unset = true;
19141915 Unset = false;
19151916 if (BitInit *BI = dyn_cast(R->getValue()))
19161917 return BI->getValue();
1917 throw "Record `" + getName() + "', field `" + FieldName.str() +
1918 "' does not have a bit initializer!";
1918 PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
1919 FieldName.str() + "' does not have a bit initializer!");
19191920 }
19201921
19211922 /// getValueAsDag - This method looks up the specified field and returns its
1922 /// value as an Dag, throwing an exception if the field does not exist or if
1923 /// the value is not the right type.
1923 /// value as an Dag, aborting if the field does not exist or if the value is
1924 /// not the right type.
19241925 ///
19251926 DagInit *Record::getValueAsDag(StringRef FieldName) const {
19261927 const RecordVal *R = getValue(FieldName);
19271928 if (R == 0 || R->getValue() == 0)
1928 throw "Record `" + getName() + "' does not have a field named `" +
1929 FieldName.str() + "'!\n";
1929 PrintFatalError(getLoc(), "Record `" + getName() +
1930 "' does not have a field named `" + FieldName.str() + "'!\n");
19301931
19311932 if (DagInit *DI = dyn_cast(R->getValue()))
19321933 return DI;
1933 throw "Record `" + getName() + "', field `" + FieldName.str() +
1934 "' does not have a dag initializer!";
1934 PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
1935 FieldName.str() + "' does not have a dag initializer!");
19351936 }
19361937
19371938
19741975 RecordKeeper::getAllDerivedDefinitions(const std::string &ClassName) const {
19751976 Record *Class = getClass(ClassName);
19761977 if (!Class)
1977 throw "ERROR: Couldn't find the `" + ClassName + "' class!\n";
1978 PrintFatalError("ERROR: Couldn't find the `" + ClassName + "' class!\n");
19781979
19791980 std::vector Defs;
19801981 for (std::map::const_iterator I = getDefs().begin(),
688688 // Split via the '='.
689689 std::pair Ops = S.split('=');
690690 if (Ops.second == "")
691 throw TGError(Loc, "missing '=' in two-operand alias constraint");
691 PrintFatalError(Loc, "missing '=' in two-operand alias constraint");
692692 // Trim whitespace and the leading '$' on the operand names.
693693 size_t start = Ops.first.find_first_of('$');
694694 if (start == std::string::npos)
695 throw TGError(Loc, "expected '$' prefix on asm operand name");
695 PrintFatalError(Loc, "expected '$' prefix on asm operand name");
696696 Ops.first = Ops.first.slice(start + 1, std::string::npos);
697697 size_t end = Ops.first.find_last_of(" \t");
698698 Ops.first = Ops.first.slice(0, end);
699699 // Now the second operand.
700700 start = Ops.second.find_first_of('$');
701701 if (start == std::string::npos)
702 throw TGError(Loc, "expected '$' prefix on asm operand name");
702 PrintFatalError(Loc, "expected '$' prefix on asm operand name");
703703 Ops.second = Ops.second.slice(start + 1, std::string::npos);
704704 end = Ops.second.find_last_of(" \t");
705705 Ops.first = Ops.first.slice(0, end);
715715 int SrcAsmOperand = findAsmOperandNamed(Ops.first);
716716 int DstAsmOperand = findAsmOperandNamed(Ops.second);
717717 if (SrcAsmOperand == -1)
718 throw TGError(TheDef->getLoc(),
718 PrintFatalError(TheDef->getLoc(),
719719 "unknown source two-operand alias operand '" +
720720 Ops.first.str() + "'.");
721721 if (DstAsmOperand == -1)
722 throw TGError(TheDef->getLoc(),
722 PrintFatalError(TheDef->getLoc(),
723723 "unknown destination two-operand alias operand '" +
724724 Ops.second.str() + "'.");
725725
851851 // The first token of the instruction is the mnemonic, which must be a
852852 // simple string, not a $foo variable or a singleton register.
853853 if (AsmOperands.empty())
854 throw TGError(TheDef->getLoc(),
854 PrintFatalError(TheDef->getLoc(),
855855 "Instruction '" + TheDef->getName() + "' has no tokens");
856856 Mnemonic = AsmOperands[0].Token;
857857 if (Mnemonic.empty())
858 throw TGError(TheDef->getLoc(),
858 PrintFatalError(TheDef->getLoc(),
859859 "Missing instruction mnemonic");
860860 // FIXME : Check and raise an error if it is a register.
861861 if (Mnemonic[0] == '$')
862 throw TGError(TheDef->getLoc(),
862 PrintFatalError(TheDef->getLoc(),
863863 "Invalid instruction mnemonic '" + Mnemonic.str() + "'!");
864864
865865 // Remove the first operand, it is tracked in the mnemonic field.
869869 bool MatchableInfo::validate(StringRef CommentDelimiter, bool Hack) const {
870870 // Reject matchables with no .s string.
871871 if (AsmString.empty())
872 throw TGError(TheDef->getLoc(), "instruction with empty asm string");
872 PrintFatalError(TheDef->getLoc(), "instruction with empty asm string");
873873
874874 // Reject any matchables with a newline in them, they should be marked
875875 // isCodeGenOnly if they are pseudo instructions.
876876 if (AsmString.find('\n') != std::string::npos)
877 throw TGError(TheDef->getLoc(),
877 PrintFatalError(TheDef->getLoc(),
878878 "multiline instruction is not valid for the asmparser, "
879879 "mark it isCodeGenOnly");
880880
882882 // has one line.
883883 if (!CommentDelimiter.empty() &&
884884 StringRef(AsmString).find(CommentDelimiter) != StringRef::npos)
885 throw TGError(TheDef->getLoc(),
885 PrintFatalError(TheDef->getLoc(),
886886 "asmstring for instruction has comment character in it, "
887887 "mark it isCodeGenOnly");
888888
896896 for (unsigned i = 0, e = AsmOperands.size(); i != e; ++i) {
897897 StringRef Tok = AsmOperands[i].Token;
898898 if (Tok[0] == '$' && Tok.find(':') != StringRef::npos)
899 throw TGError(TheDef->getLoc(),
899 PrintFatalError(TheDef->getLoc(),
900900 "matchable with operand modifier '" + Tok.str() +
901901 "' not supported by asm matcher. Mark isCodeGenOnly!");
902902
904904 // We reject aliases and ignore instructions for now.
905905 if (Tok[0] == '$' && !OperandNames.insert(Tok).second) {
906906 if (!Hack)
907 throw TGError(TheDef->getLoc(),
907 PrintFatalError(TheDef->getLoc(),
908908 "ERROR: matchable with tied operand '" + Tok.str() +
909909 "' can never be matched!");
910910 // FIXME: Should reject these. The ARM backend hits this with $lane in a
10031003 // use it, else just fall back to the underlying register class.
10041004 const RecordVal *R = Rec->getValue("ParserMatchClass");
10051005 if (R == 0 || R->getValue() == 0)
1006 throw "Record `" + Rec->getName() +
1007 "' does not have a ParserMatchClass!\n";
1006 PrintFatalError("Record `" + Rec->getName() +
1007 "' does not have a ParserMatchClass!\n");
10081008
10091009 if (DefInit *DI= dyn_cast(R->getValue())) {
10101010 Record *MatchClass = DI->getDef();
10151015 // No custom match class. Just use the register class.
10161016 Record *ClassRec = Rec->getValueAsDef("RegClass");
10171017 if (!ClassRec)
1018 throw TGError(Rec->getLoc(), "RegisterOperand `" + Rec->getName() +
1018 PrintFatalError(Rec->getLoc(), "RegisterOperand `" + Rec->getName() +
10191019 "' has no associated register class!\n");
10201020 if (ClassInfo *CI = RegisterClassClasses[ClassRec])
10211021 return CI;
1022 throw TGError(Rec->getLoc(), "register class has no class info!");
1022 PrintFatalError(Rec->getLoc(), "register class has no class info!");
10231023 }
10241024
10251025
10261026 if (Rec->isSubClassOf("RegisterClass")) {
10271027 if (ClassInfo *CI = RegisterClassClasses[Rec])
10281028 return CI;
1029 throw TGError(Rec->getLoc(), "register class has no class info!");
1029 PrintFatalError(Rec->getLoc(), "register class has no class info!");
10301030 }
10311031
10321032 if (!Rec->isSubClassOf("Operand"))
1033 throw TGError(Rec->getLoc(), "Operand `" + Rec->getName() +
1033 PrintFatalError(Rec->getLoc(), "Operand `" + Rec->getName() +
10341034 "' does not derive from class Operand!\n");
10351035 Record *MatchClass = Rec->getValueAsDef("ParserMatchClass");
10361036 if (ClassInfo *CI = AsmOperandClasses[MatchClass])
10371037 return CI;
10381038
1039 throw TGError(Rec->getLoc(), "operand has no match class!");
1039 PrintFatalError(Rec->getLoc(), "operand has no match class!");
10401040 }
10411041
10421042 void AsmMatcherInfo::
12861286 continue;
12871287
12881288 if (Pred->getName().empty())
1289 throw TGError(Pred->getLoc(), "Predicate has no name!");
1289 PrintFatalError(Pred->getLoc(), "Predicate has no name!");
12901290
12911291 unsigned FeatureNo = SubtargetFeatures.size();
12921292 SubtargetFeatures[Pred] = new SubtargetFeatureInfo(Pred, FeatureNo);
14671467 ClassInfo *FromClass = getTokenClass(Rec->getValueAsString("FromToken"));
14681468 ClassInfo *ToClass = getTokenClass(Rec->getValueAsString("ToToken"));
14691469 if (FromClass == ToClass)
1470 throw TGError(Rec->getLoc(),
1470 PrintFatalError(Rec->getLoc(),
14711471 "error: Destination value identical to source value.");
14721472 FromClass->SuperClasses.push_back(ToClass);
14731473 }
14891489 // Map this token to an operand.
14901490 unsigned Idx;
14911491 if (!Operands.hasOperandNamed(OperandName, Idx))
1492 throw TGError(II->TheDef->getLoc(), "error: unable to find operand: '" +
1492 PrintFatalError(II->TheDef->getLoc(), "error: unable to find operand: '" +
14931493 OperandName.str() + "'");
14941494
14951495 // If the instruction operand has multiple suboperands, but the parser
15601560 return;
15611561 }
15621562
1563 throw TGError(II->TheDef->getLoc(), "error: unable to find operand: '" +
1563 PrintFatalError(II->TheDef->getLoc(), "error: unable to find operand: '" +
15641564 OperandName.str() + "'");
15651565 }
15661566
15821582 // Find out what operand from the asmparser this MCInst operand comes from.
15831583 int SrcOperand = findAsmOperandNamed(OpInfo.Name);
15841584 if (OpInfo.Name.empty() || SrcOperand == -1)
1585 throw TGError(TheDef->getLoc(), "Instruction '" +
1585 PrintFatalError(TheDef->getLoc(), "Instruction '" +
15861586 TheDef->getName() + "' has operand '" + OpInfo.Name +
15871587 "' that doesn't appear in asm string!");
15881588
16341634 StringRef Name = CGA.ResultOperands[AliasOpNo].getName();
16351635 int SrcOperand = findAsmOperand(Name, SubIdx);
16361636 if (SrcOperand == -1)
1637 throw TGError(TheDef->getLoc(), "Instruction '" +
1637 PrintFatalError(TheDef->getLoc(), "Instruction '" +
16381638 TheDef->getName() + "' has operand '" + OpName +
16391639 "' that doesn't appear in asm string!");
16401640 unsigned NumOperands = (SubIdx == -1 ? OpInfo->MINumOperands : 1);
22692269 SubtargetFeatureInfo *F = Info.getSubtargetFeature(ReqFeatures[i]);
22702270
22712271 if (F == 0)
2272 throw TGError(R->getLoc(), "Predicate '" + ReqFeatures[i]->getName() +
2272 PrintFatalError(R->getLoc(), "Predicate '" + ReqFeatures[i]->getName() +
22732273 "' is not marked as an AssemblerPredicate!");
22742274
22752275 if (NumFeatures)
23322332 // We can't have two aliases from the same mnemonic with no predicate.
23332333 PrintError(ToVec[AliasWithNoPredicate]->getLoc(),
23342334 "two MnemonicAliases with the same 'from' mnemonic!");
2335 throw TGError(R->getLoc(), "this is the other MnemonicAlias.");
2335 PrintFatalError(R->getLoc(), "this is the other MnemonicAlias.");
23362336 }
23372337
23382338 AliasWithNoPredicate = i;
23392339 continue;
23402340 }
23412341 if (R->getValueAsString("ToMnemonic") == I->first)
2342 throw TGError(R->getLoc(), "MnemonicAlias to the same string");
2342 PrintFatalError(R->getLoc(), "MnemonicAlias to the same string");
23432343
23442344 if (!MatchCode.empty())
23452345 MatchCode += "else ";
565565 std::vector AltNames =
566566 Reg.TheDef->getValueAsListOfStrings("AltNames");
567567 if (AltNames.size() <= Idx)
568 throw TGError(Reg.TheDef->getLoc(),
569 (Twine("Register definition missing alt name for '") +
570 AltName + "'.").str());
568 PrintFatalError(Reg.TheDef->getLoc(),
569 (Twine("Register definition missing alt name for '") +
570 AltName + "'.").str());
571571 AsmName = AltNames[Idx];
572572 }
573573 }
1313 #include "AsmWriterInst.h"
1414 #include "CodeGenTarget.h"
1515 #include "llvm/ADT/StringExtras.h"
16 #include "llvm/TableGen/Error.h"
1617 #include "llvm/TableGen/Record.h"
1718
1819 using namespace llvm;
122123 != std::string::npos) {
123124 AddLiteralString(std::string(1, AsmString[DollarPos+1]));
124125 } else {
125 throw "Non-supported escaped character found in instruction '" +
126 CGI.TheDef->getName() + "'!";
126 PrintFatalError("Non-supported escaped character found in instruction '" +
127 CGI.TheDef->getName() + "'!");
127128 }
128129 LastEmitted = DollarPos+2;
129130 continue;
161162 // brace.
162163 if (hasCurlyBraces) {
163164 if (VarEnd >= AsmString.size())
164 throw "Reached end of string before terminating curly brace in '"
165 + CGI.TheDef->getName() + "'";
165 PrintFatalError("Reached end of string before terminating curly brace in '"
166 + CGI.TheDef->getName() + "'");
166167
167168 // Look for a modifier string.
168169 if (AsmString[VarEnd] == ':') {
169170 ++VarEnd;
170171 if (VarEnd >= AsmString.size())
171 throw "Reached end of string before terminating curly brace in '"
172 + CGI.TheDef->getName() + "'";
172 PrintFatalError("Reached end of string before terminating curly brace in '"
173 + CGI.TheDef->getName() + "'");
173174
174175 unsigned ModifierStart = VarEnd;
175176 while (VarEnd < AsmString.size() && isIdentChar(AsmString[VarEnd]))
177178 Modifier = std::string(AsmString.begin()+ModifierStart,
178179 AsmString.begin()+VarEnd);
179180 if (Modifier.empty())
180 throw "Bad operand modifier name in '"+ CGI.TheDef->getName() + "'";
181 PrintFatalError("Bad operand modifier name in '"+ CGI.TheDef->getName() + "'");
181182 }
182183
183184 if (AsmString[VarEnd] != '}')
184 throw "Variable name beginning with '{' did not end with '}' in '"
185 + CGI.TheDef->getName() + "'";
185 PrintFatalError("Variable name beginning with '{' did not end with '}' in '"
186 + CGI.TheDef->getName() + "'");
186187 ++VarEnd;
187188 }
188189 if (VarName.empty() && Modifier.empty())
189 throw "Stray '$' in '" + CGI.TheDef->getName() +
190 "' asm string, maybe you want $$?";
190 PrintFatalError("Stray '$' in '" + CGI.TheDef->getName() +
191 "' asm string, maybe you want $$?");
191192
192193 if (VarName.empty()) {
193194 // Just a modifier, pass this into PrintSpecial.
None set(LLVM_REQUIRES_EH 1)
1 set(LLVM_LINK_COMPONENTS Support)
21
32 add_tablegen(llvm-tblgen LLVM
1212 //===----------------------------------------------------------------------===//
1313
1414 #include "CodeGenTarget.h"
15 #include "llvm/TableGen/Error.h"
1516 #include "llvm/TableGen/Record.h"
1617 #include "llvm/TableGen/TableGenBackend.h"
1718 #include
9293 O << Action->getValueAsString("Predicate");
9394 } else {
9495 Action->dump();
95 throw "Unknown CCPredicateAction!";
96 PrintFatalError("Unknown CCPredicateAction!");
9697 }
9798
9899 O << ") {\n";
130131 ListInit *ShadowRegList = Action->getValueAsListInit("ShadowRegList");
131132 if (ShadowRegList->getSize() >0 &&
132133 ShadowRegList->getSize() != RegList->getSize())
133 throw "Invalid length of list of shadowed registers";
134 PrintFatalError("Invalid length of list of shadowed registers");
134135
135136 if (RegList->getSize() == 1) {
136137 O << IndentStr << "if (unsigned Reg = State.AllocateReg(";
220221 O << IndentStr << IndentStr << "return false;\n";
221222 } else {
222223 Action->dump();
223 throw "Unknown CCAction!";
224 PrintFatalError("Unknown CCAction!");
224225 }
225226 }
226227 }
7878 const std::vector &LegalTypes =
7979 TP.getDAGPatterns().getTargetInfo().getLegalValueTypes();
8080
81 if (TP.hasError())
82 return false;
83
8184 for (unsigned i = 0, e = LegalTypes.size(); i != e; ++i)
8285 if (Pred == 0 || Pred(LegalTypes[i]))
8386 TypeVec.push_back(LegalTypes[i]);
8487
8588 // If we have nothing that matches the predicate, bail out.
86 if (TypeVec.empty())
89 if (TypeVec.empty()) {
8790 TP.error("Type inference contradiction found, no " +
8891 std::string(PredicateName) + " types found");
92 return false;
93 }
8994 // No need to sort with one element.
9095 if (TypeVec.size() == 1) return true;
9196
145150
146151 /// MergeInTypeInfo - This merges in type information from the specified
147152 /// argument. If 'this' changes, it returns true. If the two types are
148 /// contradictory (e.g. merge f32 into i32) then this throws an exception.
153 /// contradictory (e.g. merge f32 into i32) then this flags an error.
149154 bool EEVT::TypeSet::MergeInTypeInfo(const EEVT::TypeSet &InVT, TreePattern &TP){
150 if (InVT.isCompletelyUnknown() || *this == InVT)
155 if (InVT.isCompletelyUnknown() || *this == InVT || TP.hasError())
151156 return false;
152157
153158 if (isCompletelyUnknown()) {
223228 // FIXME: Really want an SMLoc here!
224229 TP.error("Type inference contradiction found, merging '" +
225230 InVT.getName() + "' into '" + InputSet.getName() + "'");
226 return true; // unreachable
231 return false;
227232 }
228233
229234 /// EnforceInteger - Remove all non-integer types from this set.
230235 bool EEVT::TypeSet::EnforceInteger(TreePattern &TP) {
236 if (TP.hasError())
237 return false;
231238 // If we know nothing, then get the full set.
232239 if (TypeVec.empty())
233240 return FillWithPossibleTypes(TP, isInteger, "integer");
241248 if (!isInteger(TypeVec[i]))
242249 TypeVec.erase(TypeVec.begin()+i--);
243250
244 if (TypeVec.empty())
251 if (TypeVec.empty()) {
245252 TP.error("Type inference contradiction found, '" +
246253 InputSet.getName() + "' needs to be integer");
254 return false;
255 }
247256 return true;
248257 }
249258
250259 /// EnforceFloatingPoint - Remove all integer types from this set.
251260 bool EEVT::TypeSet::EnforceFloatingPoint(TreePattern &TP) {
261 if (TP.hasError())
262 return false;
252263 // If we know nothing, then get the full set.
253264 if (TypeVec.empty())
254265 return FillWithPossibleTypes(TP, isFloatingPoint, "floating point");
263274 if (!isFloatingPoint(TypeVec[i]))
264275 TypeVec.erase(TypeVec.begin()+i--);
265276
266 if (TypeVec.empty())
277 if (TypeVec.empty()) {
267278 TP.error("Type inference contradiction found, '" +
268279 InputSet.getName() + "' needs to be floating point");
280 return false;
281 }
269282 return true;
270283 }
271284
272285 /// EnforceScalar - Remove all vector types from this.
273286 bool EEVT::TypeSet::EnforceScalar(TreePattern &TP) {
287 if (TP.hasError())
288 return false;
289
274290 // If we know nothing, then get the full set.
275291 if (TypeVec.empty())
276292 return FillWithPossibleTypes(TP, isScalar, "scalar");
285301 if (!isScalar(TypeVec[i]))
286302 TypeVec.erase(TypeVec.begin()+i--);
287303
288 if (TypeVec.empty())
304 if (TypeVec.empty()) {
289305 TP.error("Type inference contradiction found, '" +
290306 InputSet.getName() + "' needs to be scalar");
307 return false;
308 }
291309 return true;
292310 }
293311
294312 /// EnforceVector - Remove all vector types from this.
295313 bool EEVT::TypeSet::EnforceVector(TreePattern &TP) {
314 if (TP.hasError())
315 return false;
316
296317 // If we know nothing, then get the full set.
297318 if (TypeVec.empty())
298319 return FillWithPossibleTypes(TP, isVector, "vector");
307328 MadeChange = true;
308329 }
309330
310 if (TypeVec.empty())
331 if (TypeVec.empty()) {
311332 TP.error("Type inference contradiction found, '" +
312333 InputSet.getName() + "' needs to be a vector");
334 return false;
335 }
313336 return MadeChange;
314337 }
315338
318341 /// EnforceSmallerThan - 'this' must be a smaller VT than Other. Update
319342 /// this an other based on this information.
320343 bool EEVT::TypeSet::EnforceSmallerThan(EEVT::TypeSet &Other, TreePattern &TP) {
344 if (TP.hasError())
345 return false;
346
321347 // Both operands must be integer or FP, but we don't care which.
322348 bool MadeChange = false;
323349
364390 if (hasVectorTypes() && Other.hasVectorTypes()) {
365391 if (Type.getSizeInBits() >= OtherType.getSizeInBits())
366392 if (Type.getVectorElementType().getSizeInBits()
367 >= OtherType.getVectorElementType().getSizeInBits())
393 >= OtherType.getVectorElementType().getSizeInBits()) {
368394 TP.error("Type inference contradiction found, '" +
369395 getName() + "' element type not smaller than '" +
370396 Other.getName() +"'!");
397 return false;
398 }
371399 }
372400 else
373401 // For scalar types, the bitsize of this type must be larger
374402 // than that of the other.
375 if (Type.getSizeInBits() >= OtherType.getSizeInBits())
403 if (Type.getSizeInBits() >= OtherType.getSizeInBits()) {
376404 TP.error("Type inference contradiction found, '" +
377405 getName() + "' is not smaller than '" +
378406 Other.getName() +"'!");
379
407 return false;
408 }
380409 }
381410
382411
436465 // If this is the only type in the large set, the constraint can never be
437466 // satisfied.
438467 if ((Other.hasIntegerTypes() && OtherIntSize == 0)
439 || (Other.hasFloatingPointTypes() && OtherFPSize == 0))
468 || (Other.hasFloatingPointTypes() && OtherFPSize == 0)) {
440469 TP.error("Type inference contradiction found, '" +
441470 Other.getName() + "' has nothing larger than '" + getName() +"'!");
471 return false;
472 }
442473
443474 // Okay, find the largest type in the Other set and remove it from the
444475 // current set.
492523 // If this is the only type in the small set, the constraint can never be
493524 // satisfied.
494525 if ((hasIntegerTypes() && IntSize == 0)
495 || (hasFloatingPointTypes() && FPSize == 0))
526 || (hasFloatingPointTypes() && FPSize == 0)) {
496527 TP.error("Type inference contradiction found, '" +
497528 getName() + "' has nothing smaller than '" + Other.getName()+"'!");
529 return false;
530 }
498531
499532 return MadeChange;
500533 }
503536 /// whose element is specified by VTOperand.
504537 bool EEVT::TypeSet::EnforceVectorEltTypeIs(EEVT::TypeSet &VTOperand,
505538 TreePattern &TP) {
539 if (TP.hasError())
540 return false;
541
506542 // "This" must be a vector and "VTOperand" must be a scalar.
507543 bool MadeChange = false;
508544 MadeChange |= EnforceVector(TP);
534570 }
535571 }
536572
537 if (TypeVec.empty()) // FIXME: Really want an SMLoc here!
573 if (TypeVec.empty()) { // FIXME: Really want an SMLoc here!
538574 TP.error("Type inference contradiction found, forcing '" +
539575 InputSet.getName() + "' to have a vector element");
576 return false;
577 }
540578 return MadeChange;
541579 }
542580
768806 ConstraintType = SDTCisVT;
769807 x.SDTCisVT_Info.VT = getValueType(R->getValueAsDef("VT"));
770808 if (x.SDTCisVT_Info.VT == MVT::isVoid)
771 throw TGError(R->getLoc(), "Cannot use 'Void' as type to SDTCisVT");
809 PrintFatalError(R->getLoc(), "Cannot use 'Void' as type to SDTCisVT");
772810
773811 } else if (R->isSubClassOf("SDTCisPtrTy")) {
774812 ConstraintType = SDTCisPtrTy;
828866
829867 /// ApplyTypeConstraint - Given a node in a pattern, apply this type
830868 /// constraint to the nodes operands. This returns true if it makes a
831 /// change, false otherwise. If a type contradiction is found, throw an
832 /// exception.
869 /// change, false otherwise. If a type contradiction is found, flag an error.
833870 bool SDTypeConstraint::ApplyTypeConstraint(TreePatternNode *N,
834871 const SDNodeInfo &NodeInfo,
835872 TreePattern &TP) const {
873 if (TP.hasError())
874 return false;
875
836876 unsigned ResNo = 0; // The result number being referenced.
837877 TreePatternNode *NodeToApply = getOperandNum(OperandNo, N, NodeInfo, ResNo);
838878
865905 if (!NodeToApply->isLeaf() ||
866906 !isa(NodeToApply->getLeafValue()) ||
867907 !static_cast(NodeToApply->getLeafValue())->getDef()
868 ->isSubClassOf("ValueType"))
908 ->isSubClassOf("ValueType")) {
869909 TP.error(N->getOperator()->getName() + " expects a VT operand!");
910 return false;
911 }
870912 MVT::SimpleValueType VT =
871913 getValueType(static_cast(NodeToApply->getLeafValue())->getDef());
872914
11751217 /// fragments, inline them into place, giving us a pattern without any
11761218 /// PatFrag references.
11771219 TreePatternNode *TreePatternNode::InlinePatternFragments(TreePattern &TP) {
1178 if (isLeaf()) return this; // nothing to do.
1220 if (TP.hasError())
1221 return false;
1222
1223 if (isLeaf())
1224 return this; // nothing to do.
11791225 Record *Op = getOperator();
11801226
11811227 if (!Op->isSubClassOf("PatFrag")) {
11981244 TreePattern *Frag = TP.getDAGPatterns().getPatternFragment(Op);
11991245
12001246 // Verify that we are passing the right number of operands.
1201 if (Frag->getNumArgs() != Children.size())
1247 if (Frag->getNumArgs() != Children.size()) {
12021248 TP.error("'" + Op->getName() + "' fragment requires " +
12031249 utostr(Frag->getNumArgs()) + " operands!");
1250 return false;
1251 }
12041252
12051253 TreePatternNode *FragTree = Frag->getOnlyTree()->clone();
12061254
13741422
13751423 /// ApplyTypeConstraints - Apply all of the type constraints relevant to
13761424 /// this node and its children in the tree. This returns true if it makes a
1377 /// change, false otherwise. If a type contradiction is found, throw an
1378 /// exception.
1425 /// change, false otherwise. If a type contradiction is found, flag an error.
13791426 bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
1427 if (TP.hasError())
1428 return false;
1429
13801430 CodeGenDAGPatterns &CDP = TP.getDAGPatterns();
13811431 if (isLeaf()) {
13821432 if (DefInit *DI = dyn_cast(getLeafValue())) {
14131463
14141464 TP.error("Integer value '" + itostr(II->getValue()) +
14151465 "' is out of range for type '" + getEnumName(getType(0)) + "'!");
1416 return MadeChange;
1466 return false;
14171467 }
14181468 return false;
14191469 }
14761526 for (unsigned i = 0, e = NumRetVTs; i != e; ++i)
14771527 MadeChange |= UpdateNodeType(i, Int->IS.RetVTs[i], TP);
14781528
1479 if (getNumChildren() != NumParamVTs + 1)
1529 if (getNumChildren() != NumParamVTs + 1) {
14801530 TP.error("Intrinsic '" + Int->Name + "' expects " +
14811531 utostr(NumParamVTs) + " operands, not " +
14821532 utostr(getNumChildren() - 1) + " operands!");
1533 return false;
1534 }
14831535
14841536 // Apply type info to the intrinsic ID.
14851537 MadeChange |= getChild(0)->UpdateNodeType(0, MVT::iPTR, TP);
14991551
15001552 // Check that the number of operands is sane. Negative operands -> varargs.
15011553 if (NI.getNumOperands() >= 0 &&
1502 getNumChildren() != (unsigned)NI.getNumOperands())
1554 getNumChildren() != (unsigned)NI.getNumOperands()) {
15031555 TP.error(getOperator()->getName() + " node requires exactly " +
15041556 itostr(NI.getNumOperands()) + " operands!");
1557 return false;
1558 }
15051559
15061560 bool MadeChange = NI.ApplyTypeConstraints(this, TP);
15071561 for (unsigned i = 0, e = getNumChildren(); i != e; ++i)
15751629 continue;
15761630
15771631 // Verify that we didn't run out of provided operands.
1578 if (ChildNo >= getNumChildren())
1632 if (ChildNo >= getNumChildren()) {
15791633 TP.error("Instruction '" + getOperator()->getName() +
15801634 "' expects more operands than were provided.");
1635 return false;
1636 }
15811637
15821638 MVT::SimpleValueType VT;
15831639 TreePatternNode *Child = getChild(ChildNo++);
16051661 MadeChange |= Child->ApplyTypeConstraints(TP, NotRegisters);
16061662 }
16071663
1608 if (ChildNo != getNumChildren())
1664 if (ChildNo != getNumChildren()) {
16091665 TP.error("Instruction '" + getOperator()->getName() +
16101666 "' was provided too many operands!");
1667 return false;
1668 }
16111669
16121670 return MadeChange;
16131671 }
16151673 assert(getOperator()->isSubClassOf("SDNodeXForm") && "Unknown node type!");
16161674
16171675 // Node transforms always take one operand.
1618 if (getNumChildren() != 1)
1676 if (getNumChildren() != 1) {
16191677 TP.error("Node transform '" + getOperator()->getName() +
16201678 "' requires one operand!");
1679 return false;
1680 }
16211681
16221682 bool MadeChange = getChild(0)->ApplyTypeConstraints(TP, NotRegisters);
16231683
16911751 //
16921752
16931753 TreePattern::TreePattern(Record *TheRec, ListInit *RawPat, bool isInput,
1694 CodeGenDAGPatterns &cdp) : TheRecord(TheRec), CDP(cdp){
1695 isInputPattern = isInput;
1754 CodeGenDAGPatterns &cdp) : TheRecord(TheRec), CDP(cdp),
1755 isInputPattern(isInput), HasError(false) {
16961756 for (unsigned i = 0, e = RawPat->getSize(); i != e; ++i)
16971757 Trees.push_back(ParseTreePattern(RawPat->getElement(i), ""));
16981758 }
16991759
17001760 TreePattern::TreePattern(Record *TheRec, DagInit *Pat, bool isInput,
1701 CodeGenDAGPatterns &cdp) : TheRecord(TheRec), CDP(cdp){
1702 isInputPattern = isInput;
1761 CodeGenDAGPatterns &cdp) : TheRecord(TheRec), CDP(cdp),
1762 isInputPattern(isInput), HasError(false) {
17031763 Trees.push_back(ParseTreePattern(Pat, ""));
17041764 }
17051765
17061766 TreePattern::TreePattern(Record *TheRec, TreePatternNode *Pat, bool isInput,
1707 CodeGenDAGPatterns &cdp) : TheRecord(TheRec), CDP(cdp){
1708 isInputPattern = isInput;
1767 CodeGenDAGPatterns &cdp) : TheRecord(TheRec), CDP(cdp),
1768 isInputPattern(isInput), HasError(false) {
17091769 Trees.push_back(Pat);
17101770 }
17111771
1712 void TreePattern::error(const std::string &Msg) const {
1772 void TreePattern::error(const std::string &Msg) {
1773 if (HasError)
1774 return;
17131775 dump();
1714 throw TGError(TheRecord->getLoc(), "In " + TheRecord->getName() + ": " + Msg);
1776 PrintError(TheRecord->getLoc(), "In " + TheRecord->getName() + ": " + Msg);
1777 HasError = true;
17151778 }
17161779
17171780 void TreePattern::ComputeNamedNodes() {
19001963
19011964 /// InferAllTypes - Infer/propagate as many types throughout the expression
19021965 /// patterns as possible. Return true if all types are inferred, false
1903 /// otherwise. Throw an exception if a type contradiction is found.
1966 /// otherwise. Flags an error if a type contradiction is found.
19041967 bool TreePattern::
19051968 InferAllTypes(const StringMap > *InNamedTypes) {
19061969 if (NamedNodes.empty())
21512214
21522215 // Infer as many types as possible. Don't worry about it if we don't infer
21532216 // all of them, some may depend on the inputs of the pattern.
2154 try {
2155 ThePat->InferAllTypes();
2156 } catch (...) {
2157 // If this pattern fragment is not supported by this target (no types can
2158 // satisfy its constraints), just ignore it. If the bogus pattern is
2159 // actually used by instructions, the type consistency error will be
2160 // reported there.
2161 }
2217 ThePat->InferAllTypes();
2218 ThePat->resetError();
21622219
21632220 // If debugging, print out the pattern fragment result.
21642221 DEBUG(ThePat->dump());
21982255 /* Resolve all types */;
21992256
22002257 if (TPN->ContainsUnresolvedType()) {
2201 throw "Value #" + utostr(i) + " of OperandWithDefaultOps '" +
2202 DefaultOps[i]->getName() +"' doesn't have a concrete type!";
2258 PrintFatalError("Value #" + utostr(i) + " of OperandWithDefaultOps '" +
2259 DefaultOps[i]->getName() +"' doesn't have a concrete type!");
22032260 }
22042261 DefaultOpInfo.DefaultOps.push_back(TPN);
22052262 }
27452802 Instructions.begin(),
27462803 E = Instructions.end(); II != E; ++II) {
27472804 DAGInstruction &TheInst = II->second;
2748 const TreePattern *I = TheInst.getPattern();
2805 TreePattern *I = TheInst.getPattern();
27492806 if (I == 0) continue; // No pattern.
27502807
27512808 // FIXME: Assume only the first tree is the pattern. The others are clobber
27762833
27772834 static void FindNames(const TreePatternNode *P,
27782835 std::map &Names,
2779 const TreePattern *PatternTop) {
2836 TreePattern *PatternTop) {
27802837 if (!P->getName().empty()) {
27812838 NameRecord &Rec = Names[P->getName()];
27822839 // If this is the first instance of the name, remember the node.
27932850 }
27942851 }
27952852
2796 void CodeGenDAGPatterns::AddPatternToMatch(const TreePattern *Pattern,
2853 void CodeGenDAGPatterns::AddPatternToMatch(TreePattern *Pattern,
27972854 const PatternToMatch &PTM) {
27982855 // Do some sanity checking on the pattern we're about to match.
27992856 std::string Reason;
28942951 }
28952952
28962953 if (Errors)
2897 throw "pattern conflicts";
2954 PrintFatalError("pattern conflicts");
28982955
28992956 // Revisit instructions with undefined flags and no pattern.
29002957 if (Target.guessInstructionProperties()) {
29913048 }
29923049 }
29933050 if (Errors)
2994 throw "Errors in DAG patterns";
3051 PrintFatalError("Errors in DAG patterns");
29953052 }
29963053
29973054 /// Given a pattern result with an unresolved type, see if we can find one
104104
105105 /// MergeInTypeInfo - This merges in type information from the specified
106106 /// argument. If 'this' changes, it returns true. If the two types are
107 /// contradictory (e.g. merge f32 into i32) then this throws an exception.
107 /// contradictory (e.g. merge f32 into i32) then this flags an error.
108108 bool MergeInTypeInfo(const EEVT::TypeSet &InVT, TreePattern &TP);
109109
110110 bool MergeInTypeInfo(MVT::SimpleValueType InVT, TreePattern &TP) {
186186
187187 /// ApplyTypeConstraint - Given a node in a pattern, apply this type
188188 /// constraint to the nodes operands. This returns true if it makes a
189 /// change, false otherwise. If a type contradiction is found, throw an
190 /// exception.
189 /// change, false otherwise. If a type contradiction is found, an error
190 /// is flagged.
191191 bool ApplyTypeConstraint(TreePatternNode *N, const SDNodeInfo &NodeInfo,
192192 TreePattern &TP) const;
193193 };
231231 /// ApplyTypeConstraints - Given a node in a pattern, apply the type
232232 /// constraints for this node to the operands of the node. This returns
233233 /// true if it makes a change, false otherwise. If a type contradiction is
234 /// found, throw an exception.
234 /// found, an error is flagged.
235235 bool ApplyTypeConstraints(TreePatternNode *N, TreePattern &TP) const {
236236 bool MadeChange = false;
237237 for (unsigned i = 0, e = TypeConstraints.size(); i != e; ++i)
445445
446446 /// ApplyTypeConstraints - Apply all of the type constraints relevant to
447447 /// this node and its children in the tree. This returns true if it makes a
448 /// change, false otherwise. If a type contradiction is found, throw an
449 /// exception.
448 /// change, false otherwise. If a type contradiction is found, flag an error.
450449 bool ApplyTypeConstraints(TreePattern &TP, bool NotRegisters);
451450
452451 /// UpdateNodeType - Set the node type of N to VT if VT contains
453 /// information. If N already contains a conflicting type, then throw an
454 /// exception. This returns true if any information was updated.
452 /// information. If N already contains a conflicting type, then flag an
453 /// error. This returns true if any information was updated.
455454 ///
456455 bool UpdateNodeType(unsigned ResNo, const EEVT::TypeSet &InTy,
457456 TreePattern &TP) {
513512 /// isInputPattern - True if this is an input pattern, something to match.
514513 /// False if this is an output pattern, something to emit.
515514 bool isInputPattern;
515
516 /// hasError - True if the currently processed nodes have unresolvable types
517 /// or other non-fatal errors
518 bool HasError;
516519 public:
517520
518521 /// TreePattern constructor - Parse the specified DagInits into the
564567
565568 /// InferAllTypes - Infer/propagate as many types throughout the expression
566569 /// patterns as possible. Return true if all types are inferred, false
567 /// otherwise. Throw an exception if a type contradiction is found.
570 /// otherwise. Bail out if a type contradiction is found.
568571 bool InferAllTypes(const StringMap >
569572 *NamedTypes=0);
570573
571 /// error - Throw an exception, prefixing it with information about this
572 /// pattern.
573 void error(const std::string &Msg) const;
574 /// error - If this is the first error in the current resolution step,
575 /// print it and set the error flag. Otherwise, continue silently.
576 void error(const std::string &Msg);
577 bool hasError() const {
578 return HasError;
579 }
580 void resetError() {
581 HasError = false;
582 }
574583
575584 void print(raw_ostream &OS) const;
576585 void dump() const;
601610 : Pattern(TP), Results(results), Operands(operands),
602611 ImpResults(impresults), ResultPattern(0) {}
603612
604 const TreePattern *getPattern() const { return Pattern; }
613 TreePattern *getPattern() const { return Pattern; }
605614 unsigned getNumResults() const { return Results.size(); }
606615 unsigned getNumOperands() const { return Operands.size(); }
607616 unsigned getNumImpResults() const { return ImpResults.size(); }
793802 void GenerateVariants();
794803 void VerifyInstructionFlags();
795804
796 void AddPatternToMatch(const TreePattern *Pattern, const PatternToMatch &PTM);
805 void AddPatternToMatch(TreePattern *Pattern, const PatternToMatch &PTM);
797806 void FindPatternInputsAndOutputs(TreePattern *I, TreePatternNode *Pat,
798807 std::map
799808 TreePatternNode*> &InstInputs,
3333
3434 if (DefInit *Init = dyn_cast(OutDI->getOperator())) {
3535 if (Init->getDef()->getName() != "outs")
36 throw R->getName() + ": invalid def name for output list: use 'outs'";
36 PrintFatalError(R->getName() + ": invalid def name for output list: use 'outs'");
3737 } else
38 throw R->getName() + ": invalid output list: use 'outs'";
38 PrintFatalError(R->getName() + ": invalid output list: use 'outs'");
3939
4040 NumDefs = OutDI->getNumArgs();
4141
4242 DagInit *InDI = R->getValueAsDag("InOperandList");
4343 if (DefInit *Init = dyn_cast(InDI->getOperator())) {
4444 if (Init->getDef()->getName() != "ins")
45 throw R->getName() + ": invalid def name for input list: use 'ins'";
45 PrintFatalError(R->getName() + ": invalid def name for input list: use 'ins'");
4646 } else
47 throw R->getName() + ": invalid input list: use 'ins'";
47 PrintFatalError(R->getName() + ": invalid input list: use 'ins'");
4848
4949 unsigned MIOperandNo = 0;
5050 std::set OperandNames;
6161
6262 DefInit *Arg = dyn_cast(ArgInit);
6363 if (!Arg)
64 throw "Illegal operand for the '" + R->getName() + "' instruction!";
64 PrintFatalError("Illegal operand for the '" + R->getName() + "' instruction!");
6565
6666 Record *Rec = Arg->getDef();
6767 std::string PrintMethod = "printOperand";
8181 // Verify that MIOpInfo has an 'ops' root value.
8282 if (!isa(MIOpInfo->getOperator()) ||
8383 cast(MIOpInfo->getOperator())->getDef()->getName() != "ops")
84 throw "Bad value for MIOperandInfo in operand '" + Rec->getName() +
85 "'\n";
84 PrintFatalError("Bad value for MIOperandInfo in operand '" + Rec->getName() +
85 "'\n");
8686
8787 // If we have MIOpInfo, then we have #operands equal to number of entries
8888 // in MIOperandInfo.
100100 OperandType = "OPERAND_REGISTER";
101101 } else if (!Rec->isSubClassOf("PointerLikeRegClass") &&
102102 !Rec->isSubClassOf("unknown_class"))
103 throw "Unknown operand class '" + Rec->getName() +
104 "' in '" + R->getName() + "' instruction!";
103 PrintFatalError("Unknown operand class '" + Rec->getName() +
104 "' in '" + R->getName() + "' instruction!");
105105
106106 // Check that the operand has a name and that it's unique.
107107 if (ArgName.empty())
108 throw "In instruction '" + R->getName() + "', operand #" + utostr(i) +
109 " has no name!";
108 PrintFatalError("In instruction '" + R->getName() + "', operand #" + utostr(i) +
109 " has no name!");
110110 if (!OperandNames.insert(ArgName).second)
111 throw "In instruction '" + R->getName() + "', operand #" + utostr(i) +
112 " has the same name as a previous operand!";
111 PrintFatalError("In instruction '" + R->getName() + "', operand #" + utostr(i) +
112 " has the same name as a previous operand!");
113113
114114 OperandList.push_back(OperandInfo(Rec, ArgName, PrintMethod, EncoderMethod,
115115 OperandType, MIOperandNo, NumOps,
127127
128128 /// getOperandNamed - Return the index of the operand with the specified
129129 /// non-empty name. If the instruction does not have an operand with the
130 /// specified name, throw an exception.
130 /// specified name, abort.
131131 ///
132132 unsigned CGIOperandList::getOperandNamed(StringRef Name) const {
133133 unsigned OpIdx;
134134 if (hasOperandNamed(Name, OpIdx)) return OpIdx;
135 throw "'" + TheDef->getName() + "' does not have an operand named '$" +
136 Name.str() + "'!";
135 PrintFatalError("'" + TheDef->getName() + "' does not have an operand named '$" +
136 Name.str() + "'!");
137137 }
138138
139139 /// hasOperandNamed - Query whether the instruction has an operand of the
152152 std::pair
153153 CGIOperandList::ParseOperandName(const std::string &Op, bool AllowWholeOp) {
154154 if (Op.empty() || Op[0] != '$')
155 throw TheDef->getName() + ": Illegal operand name: '" + Op + "'";
155 PrintFatalError(TheDef->getName() + ": Illegal operand name: '" + Op + "'");
156156
157157 std::string OpName = Op.substr(1);
158158 std::string SubOpName;
162162 if (DotIdx != std::string::npos) {
163163 SubOpName = OpName.substr(DotIdx+1);
164164 if (SubOpName.empty())
165 throw TheDef->getName() + ": illegal empty suboperand name in '" +Op +"'";
165 PrintFatalError(TheDef->getName() + ": illegal empty suboperand name in '" +Op +"'");
166166 OpName = OpName.substr(0, DotIdx);
167167 }
168168
172172 // If one was needed, throw.
173173 if (OperandList[OpIdx].MINumOperands > 1 && !AllowWholeOp &&
174174 SubOpName.empty())
175 throw TheDef->getName() + ": Illegal to refer to"
176 " whole operand part of complex operand '" + Op + "'";
175 PrintFatalError(TheDef->getName() + ": Illegal to refer to"
176 " whole operand part of complex operand '" + Op + "'");
177177
178178 // Otherwise, return the operand.
179179 return std::make_pair(OpIdx, 0U);
182182 // Find the suboperand number involved.
183183 DagInit *MIOpInfo = OperandList[OpIdx].MIOperandInfo;
184184 if (MIOpInfo == 0)
185 throw TheDef->getName() + ": unknown suboperand name in '" + Op + "'";
185 PrintFatalError(TheDef->getName() + ": unknown suboperand name in '" + Op + "'");
186186
187187 // Find the operand with the right name.
188188 for (unsigned i = 0, e = MIOpInfo->getNumArgs(); i != e; ++i)
190190 return std::make_pair(OpIdx, i);
191191
192192 // Otherwise, didn't find it!
193 throw TheDef->getName() + ": unknown suboperand name in '" + Op + "'";
193 PrintFatalError(TheDef->getName() + ": unknown suboperand name in '" + Op + "'");
194194 }
195195
196196 static void ParseConstraint(const std::string &CStr, CGIOperandList &Ops) {
202202 std::string Name = CStr.substr(wpos+1);
203203 wpos = Name.find_first_not_of(" \t");
204204 if (wpos == std::string::npos)
205 throw "Illegal format for @earlyclobber constraint: '" + CStr + "'";
205 PrintFatalError("Illegal format for @earlyclobber constraint: '" + CStr + "'");
206206 Name = Name.substr(wpos);
207207 std::pair Op = Ops.ParseOperandName(Name, false);
208208
209209 // Build the string for the operand
210210 if (!Ops[Op.first].Constraints[Op.second].isNone())
211 throw "Operand '" + Name + "' cannot have multiple constraints!";
211 PrintFatalError("Operand '" + Name + "' cannot have multiple constraints!");
212212 Ops[Op.first].Constraints[Op.second] =
213213 CGIOperandList::ConstraintInfo::getEarlyClobber();
214214 return;
223223 // TIED_TO: $src1 = $dst
224224 wpos = Name.find_first_of(" \t");
225225 if (wpos == std::string::npos)
226 throw "Illegal format for tied-to constraint: '" + CStr + "'";
226 PrintFatalError("Illegal format for tied-to constraint: '" + CStr + "'");
227227 std::string DestOpName = Name.substr(0, wpos);
228228 std::pair DestOp = Ops.ParseOperandName(DestOpName, false);
229229
230230 Name = CStr.substr(pos+1);
231231 wpos = Name.find_first_not_of(" \t");
232232 if (wpos == std::string::npos)
233 throw "Illegal format for tied-to constraint: '" + CStr + "'";
233 PrintFatalError("Illegal format for tied-to constraint: '" + CStr + "'");
234234
235235 std::string SrcOpName = Name.substr(wpos);
236236 std::pair SrcOp = Ops.ParseOperandName(SrcOpName, false);
242242 unsigned FlatOpNo = Ops.getFlattenedOperandNumber(SrcOp);
243243
244244 if (!Ops[DestOp.first].Constraints[DestOp.second].isNone())
245 throw "Operand '" + DestOpName + "' cannot have multiple constraints!";
245 PrintFatalError("Operand '" + DestOpName +
246 "' cannot have multiple constraints!");
246247 Ops[DestOp.first].Constraints[DestOp.second] =
247248 CGIOperandList::ConstraintInfo::getTied(FlatOpNo);
248249 }
327328 ImplicitUses = R->getValueAsListOfDefs("Uses");
328329
329330 if (neverHasSideEffects + hasSideEffects > 1)
330 throw R->getName() + ": multiple conflicting side-effect flags set!";
331 PrintFatalError(R->getName() + ": multiple conflicting side-effect flags set!");
331332
332333 // Parse Constraints.
333334 ParseConstraints(R->getValueAsString("Constraints"), Operands);
421422 // If the operand is a record, it must have a name, and the record type
422423 // must match up with the instruction's argument type.
423424 if (Result->getArgName(AliasOpNo).empty())
424 throw TGError(Loc, "result argument #" + utostr(AliasOpNo) +
425 PrintFatalError(Loc, "result argument #" + utostr(AliasOpNo) +
425426 " must have a name!");
426427 ResOp = ResultOperand(Result->getArgName(AliasOpNo), ADI->getDef());
427428 return true;
456457
457458 if (!T.getRegisterClass(InstOpRec)
458459 .contains(T.getRegBank().getReg(ADI->getDef())))
459 throw TGError(Loc, "fixed register " + ADI->getDef()->getName() +
460 " is not a member of the " + InstOpRec->getName() +
461 " register class!");
460 PrintFatalError(Loc, "fixed register " + ADI->getDef()->getName() +
461 " is not a member of the " + InstOpRec->getName() +
462 " register class!");
462463
463464 if (!Result->getArgName(AliasOpNo).empty())
464 throw TGError(Loc, "result fixed register argument must "
465 "not have a name!");
465 PrintFatalError(Loc, "result fixed register argument must "
466 "not have a name!");
466467
467468 ResOp = ResultOperand(ADI->getDef());
468469 return true;
490491 return false;
491492 // Integer arguments can't have names.
492493 if (!Result->getArgName(AliasOpNo).empty())
493 throw TGError(Loc, "result argument #" + utostr(AliasOpNo) +
494 " must not have a name!");
494 PrintFatalError(Loc, "result argument #" + utostr(AliasOpNo) +
495 " must not have a name!");
495496 ResOp = ResultOperand(II->getValue());
496497 return true;
497498 }
519520 // Verify that the root of the result is an instruction.
520521 DefInit *DI = dyn_cast(Result->getOperator());
521522 if (DI == 0 || !DI->getDef()->isSubClassOf("Instruction"))
522 throw TGError(R->getLoc(), "result of inst alias should be an instruction");
523 PrintFatalError(R->getLoc(),
524 "result of inst alias should be an instruction");
523525
524526 ResultInst = &T.getInstruction(DI->getDef());
525527
535537 // same type.
536538 Record *&Entry = NameClass[Result->getArgName(i)];
537539 if (Entry && Entry != ADI->getDef())
538 throw TGError(R->getLoc(), "result value $" + Result->getArgName(i) +
539 " is both " + Entry->getName() + " and " +
540 ADI->getDef()->getName() + "!");
540 PrintFatalError(R->getLoc(), "result value $" + Result->getArgName(i) +
541 " is both " + Entry->getName() + " and " +
542 ADI->getDef()->getName() + "!");
541543 Entry = ADI->getDef();
542544 }
543545
553555 continue;
554556
555557 if (AliasOpNo >= Result->getNumArgs())
556 throw TGError(R->getLoc(), "not enough arguments for instruction!");
558 PrintFatalError(R->getLoc(), "not enough arguments for instruction!");
557559
558560 Record *InstOpRec = ResultInst->Operands[i].Rec;
559561 unsigned NumSubOps = ResultInst->Operands[i].MINumOperands;
594596 DagInit *MIOI = ResultInst->Operands[i].MIOperandInfo;
595597 for (unsigned SubOp = 0; SubOp != NumSubOps; ++SubOp) {
596598 if (AliasOpNo >= Result->getNumArgs())
597 throw TGError(R->getLoc(), "not enough arguments for instruction!");
599 PrintFatalError(R->getLoc(), "not enough arguments for instruction!");
598600 Record *SubRec = cast(MIOI->getArg(SubOp))->getDef();
599601 if (tryAliasOpMatch(Result, AliasOpNo, SubRec, false,
600602 R->getLoc(), T, ResOp)) {
602604 ResultInstOperandIndex.push_back(std::make_pair(i, SubOp));
603605 ++AliasOpNo;
604606 } else {
605 throw TGError(R->getLoc(), "result argument #" + utostr(AliasOpNo) +
607 PrintFatalError(R->getLoc(), "result argument #" + utostr(AliasOpNo) +
606608 " does not match instruction operand class " +
607609 (SubOp == 0 ? InstOpRec->getName() :SubRec->getName()));
608610 }
609611 }
610612 continue;
611613 }
612 throw TGError(R->getLoc(), "result argument #" + utostr(AliasOpNo) +
613 " does not match instruction operand class " +
614 InstOpRec->getName());
614 PrintFatalError(R->getLoc(), "result argument #" + utostr(AliasOpNo) +
615 " does not match instruction operand class " +
616 InstOpRec->getName());
615617 }
616618
617619 if (AliasOpNo != Result->getNumArgs())
618 throw TGError(R->getLoc(), "too many operands for instruction!");
619 }
620 PrintFatalError(R->getLoc(), "too many operands for instruction!");
621 }
151151
152152 /// getOperandNamed - Return the index of the operand with the specified
153153 /// non-empty name. If the instruction does not have an operand with the
154 /// specified name, throw an exception.
154 /// specified name, abort.
155155 unsigned getOperandNamed(StringRef Name) const;
156156
157157 /// hasOperandNamed - Query whether the instruction has an operand of the
161161
162162 /// ParseOperandName - Parse an operand name like "$foo" or "$foo.bar",
163163 /// where $foo is a whole operand and $foo.bar refers to a suboperand.
164 /// This throws an exception if the name is invalid. If AllowWholeOp is
165 /// true, references to operands with suboperands are allowed, otherwise
166 /// not.
164 /// This aborts if the name is invalid. If AllowWholeOp is true, references
165 /// to operands with suboperands are allowed, otherwise not.
167166 std::pair ParseOperandName(const std::string &Op,
168167 bool AllowWholeOp = true);
169168
7777
7878 #include "CodeGenTarget.h"
7979 #include "llvm/Support/Format.h"
80 #include "llvm/TableGen/Error.h"
8081 using namespace llvm;
8182 typedef std::map > InstrRelMapTy;
8283
127128
128129 // Each instruction map must specify at least one column for it to be valid.
129130 if (ColValList->getSize() == 0)
130 throw "InstrMapping record `" + MapRec->getName() + "' has empty " +
131 "`ValueCols' field!";
131 PrintFatalError(MapRec->getLoc(), "InstrMapping record `" +
132 MapRec->getName() + "' has empty " + "`ValueCols' field!");
132133
133134 for (unsigned i = 0, e = ColValList->getSize(); i < e; i++) {
134135 ListInit *ColI = dyn_cast(ColValList->getElement(i));
135136
136137 // Make sure that all the sub-lists in 'ValueCols' have same number of
137138 // elements as the fields in 'ColFields'.
138 if (ColI->getSize() == ColFields->getSize())
139 ValueCols.push_back(ColI);
140 else {
141 throw "Record `" + MapRec->getName() + "', field `" + "ValueCols" +
142 "' entries don't match with the entries in 'ColFields'!";
143 }
139 if (ColI->getSize() != ColFields->getSize())
140 PrintFatalError(MapRec->getLoc(), "Record `" + MapRec->getName() +
141 "', field `ValueCols' entries don't match with " +
142 " the entries in 'ColFields'!");
143 ValueCols.push_back(ColI);
144144 }
145145 }
146146
343343 if (MatchFound) {
344344 if (MatchInstr) // Already had a match
345345 // Error if multiple matches are found for a column.
346 throw "Multiple matches found for `" + KeyInstr->getName() +
347 "', for the relation `" + InstrMapDesc.getName();
348 else
349 MatchInstr = CurInstr;
346 PrintFatalError("Multiple matches found for `" + KeyInstr->getName() +
347 "', for the relation `" + InstrMapDesc.getName());
348 MatchInstr = CurInstr;
350349 }
351350 }
352351 return MatchInstr;
515514 for (unsigned j = 0; j < ListSize; j++) {
516515 ListInit *ListJ = dyn_cast(List->getElement(j));
517516
518 if (ListJ->getSize() != ColFields->getSize()) {
519 throw "Record `" + CurMap->getName() + "', field `" + "ValueCols" +
520 "' entries don't match with the entries in 'ColFields' !";
521 }
517 if (ListJ->getSize() != ColFields->getSize())
518 PrintFatalError("Record `" + CurMap->getName() + "', field "
519 "`ValueCols' entries don't match with the entries in 'ColFields' !");
522520 ValueCols.push_back(ListJ);
523521 }
524522
5353 std::vector Comps = TheDef->getValueAsListOfDefs("ComposedOf");
5454 if (!Comps.empty()) {
5555 if (Comps.size() != 2)
56 throw TGError(TheDef->getLoc(), "ComposedOf must have exactly two entries");
56 PrintFatalError(TheDef->getLoc(),
57 "ComposedOf must have exactly two entries");
5758 CodeGenSubRegIndex *A = RegBank.getSubRegIdx(Comps[0]);
5859 CodeGenSubRegIndex *B = RegBank.getSubRegIdx(Comps[1]);
5960 CodeGenSubRegIndex *X = A->addComposite(B, this);
6061 if (X)
61 throw TGError(TheDef->getLoc(), "Ambiguous ComposedOf entries");
62 PrintFatalError(TheDef->getLoc(), "Ambiguous ComposedOf entries");
6263 }
6364
6465 std::vector Parts =
6566 TheDef->getValueAsListOfDefs("CoveringSubRegIndices");
6667 if (!Parts.empty()) {
6768 if (Parts.size() < 2)
68 throw TGError(TheDef->getLoc(),
69 PrintFatalError(TheDef->getLoc(),
6970 "CoveredBySubRegs must have two or more entries");
7071 SmallVector IdxParts;
7172 for (unsigned i = 0, e = Parts.size(); i != e; ++i)
111112 std::vector SRs = TheDef->getValueAsListOfDefs("SubRegs");
112113
113114 if (SRIs.size() != SRs.size())
114 throw TGError(TheDef->getLoc(),
115 "SubRegs and SubRegIndices must have the same size");
115 PrintFatalError(TheDef->getLoc(),
116 "SubRegs and SubRegIndices must have the same size");
116117
117118 for (unsigned i = 0, e = SRIs.size(); i != e; ++i) {
118119 ExplicitSubRegIndices.push_back(RegBank.getSubRegIdx(SRIs[i]));
223224 CodeGenRegister *SR = ExplicitSubRegs[i];
224225 CodeGenSubRegIndex *Idx = ExplicitSubRegIndices[i];
225226 if (!SubRegs.insert(std::make_pair(Idx, SR)).second)
226 throw TGError(TheDef->getLoc(), "SubRegIndex " + Idx->getName() +
227 " appears twice in Register " + getName());
227 PrintFatalError(TheDef->getLoc(), "SubRegIndex " + Idx->getName() +
228 " appears twice in Register " + getName());
228229 // Map explicit sub-registers first, so the names take precedence.
229230 // The inherited sub-registers are mapped below.
230231 SubReg2Idx.insert(std::make_pair(SR, Idx));
307308 ArrayRef Loc;
308309 if (TheDef)
309310 Loc = TheDef->getLoc();
310 throw TGError(Loc, "Register " + getName() +
311 " has itself as a sub-register");
311 PrintFatalError(Loc, "Register " + getName() +
312 " has itself as a sub-register");
312313 }
313314 // Ensure that every sub-register has a unique name.
314315 DenseMap::iterator Ins =
319320 ArrayRef Loc;
320321 if (TheDef)
321322 Loc = TheDef->getLoc();
322 throw TGError(Loc, "Sub-register can't have two names: " +
323 PrintFatalError(Loc, "Sub-register can't have two names: " +
323324 SI->second->getName() + " available as " +
324325 SI->first->getName() + " and " + Ins->second->getName());
325326 }
466467 SE = NewSubReg->SubRegs.end(); SI != SE; ++SI) {
467468 CodeGenSubRegIndex *SubIdx = getSubRegIndex(SI->second);
468469 if (!SubIdx)
469 throw TGError(TheDef->getLoc(), "No SubRegIndex for " +
470 SI->second->getName() + " in " + getName());
470 PrintFatalError(TheDef->getLoc(), "No SubRegIndex for " +
471 SI->second->getName() + " in " + getName());
471472 NewIdx->addComposite(SI->first, SubIdx);
472473 }
473474 }
591592 unsigned Dim = Indices.size();
592593 ListInit *SubRegs = Def->getValueAsListInit("SubRegs");
593594 if (Dim != SubRegs->getSize())
594 throw TGError(Def->getLoc(), "SubRegIndices and SubRegs size mismatch");
595 PrintFatalError(Def->getLoc(), "SubRegIndices and SubRegs size mismatch");
595596 if (Dim < 2)
596 throw TGError(Def->getLoc(), "Tuples must have at least 2 sub-registers");
597 PrintFatalError(Def->getLoc(),
598 "Tuples must have at least 2 sub-registers");
597599
598600 // Evaluate the sub-register lists to be zipped.
599601 unsigned Length = ~0u;
705707 for (unsigned i = 0, e = TypeList.size(); i != e; ++i) {
706708 Record *Type = TypeList[i];
707709 if (!Type->isSubClassOf("ValueType"))
708 throw "RegTypes list member '" + Type->getName() +
709 "' does not derive from the ValueType class!";
710 PrintFatalError("RegTypes list member '" + Type->getName() +
711 "' does not derive from the ValueType class!");
710712 VTs.push_back(getValueType(Type));
711713 }
712714 assert(!VTs.empty() && "RegisterClass must contain at least one ValueType!");
734736 CodeGenRegister *Reg = RegBank.getReg(Order.back());
735737 Order.pop_back();
736738 if (!contains(Reg))
737 throw TGError(R->getLoc(), " AltOrder register " + Reg->getName() +
739 PrintFatalError(R->getLoc(), " AltOrder register " + Reg->getName() +
738740 " is not a class member");
739741 }
740742 }
10201022 // Read in register class definitions.
10211023 std::vector RCs = Records.getAllDerivedDefinitions("RegisterClass");
10221024 if (RCs.empty())
1023 throw std::string("No 'RegisterClass' subclasses defined!");
1025 PrintFatalError(std::string("No 'RegisterClass' subclasses defined!"));
10241026
10251027 // Allocate user-defined register classes.
10261028 RegClasses.reserve(RCs.size());
10971099 if (CodeGenRegisterClass *RC = Def2RC[Def])
10981100 return RC;
10991101
1100 throw TGError(Def->getLoc(), "Not a known RegisterClass!");
1102 PrintFatalError(Def->getLoc(), "Not a known RegisterClass!");
11011103 }
11021104
11031105 CodeGenSubRegIndex*
6262 AI = Expr->arg_begin(), AE = Expr->arg_end(); AI != AE; ++AI) {
6363 StringInit *SI = dyn_cast(*AI);
6464 if (!SI)
65 throw TGError(Loc, "instregex requires pattern string: "
65 PrintFatalError(Loc, "instregex requires pattern string: "
6666 + Expr->getAsString());
6767 std::string pat = SI->getValue();
6868 // Implement a python-style prefix match.
267267 Record *AliasDef = (*AI)->getValueAsDef("AliasRW");
268268 if (MatchDef->isSubClassOf("SchedWrite")) {
269269 if (!AliasDef->isSubClassOf("SchedWrite"))
270 throw TGError((*AI)->getLoc(), "SchedWrite Alias must be SchedWrite");
270 PrintFatalError((*AI)->getLoc(), "SchedWrite Alias must be SchedWrite");
271271 scanSchedRW(AliasDef, SWDefs, RWSet);
272272 }
273273 else {
274274 assert(MatchDef->isSubClassOf("SchedRead") && "Unknown SchedReadWrite");
275275 if (!AliasDef->isSubClassOf("SchedRead"))
276 throw TGError((*AI)->getLoc(), "SchedRead Alias must be SchedRead");
276 PrintFatalError((*AI)->getLoc(), "SchedRead Alias must be SchedRead");
277277 scanSchedRW(AliasDef, SRDefs, RWSet);
278278 }
279279 }
304304 Record *MatchDef = (*AI)->getValueAsDef("MatchRW");
305305 CodeGenSchedRW &RW = getSchedRW(MatchDef);
306306 if (RW.IsAlias)
307 throw TGError((*AI)->getLoc(), "Cannot Alias an Alias");
307 PrintFatalError((*AI)->getLoc(), "Cannot Alias an Alias");
308308 RW.Aliases.push_back(*AI);
309309 }
310310 DEBUG(
436436 continue;
437437 }
438438 if (AliasDef)
439 throw TGError(AliasRW.TheDef->getLoc(), "Multiple aliases "
440 "defined for processor " + ProcModel.ModelName +
441 " Ensure only one SchedAlias exists per RW.");
439 PrintFatalError(AliasRW.TheDef->getLoc(), "Multiple aliases "
440 "defined for processor " + ProcModel.ModelName +
441 " Ensure only one SchedAlias exists per RW.");
442442 AliasDef = AliasRW.TheDef;
443443 }
444444 if (AliasDef) {
705705 // Sort Instrs into sets.
706706 const RecVec *InstDefs = Sets.expand(InstRWDef);
707707 if (InstDefs->empty())
708 throw TGError(InstRWDef->getLoc(), "No matching instruction opcodes");
708 PrintFatalError(InstRWDef->getLoc(), "No matching instruction opcodes");
709709
710710 for (RecIter I = InstDefs->begin(), E = InstDefs->end(); I != E; ++I) {
711711 unsigned SCIdx = 0;
765765 for (RecIter RI = SchedClasses[OldSCIdx].InstRWs.begin(),
766766 RE = SchedClasses[OldSCIdx].InstRWs.end(); RI != RE; ++RI) {
767767 if ((*RI)->getValueAsDef("SchedModel") == RWModelDef) {
768 throw TGError(InstRWDef->getLoc(), "Overlapping InstRW def " +
768 PrintFatalError(InstRWDef->getLoc(), "Overlapping InstRW def " +
769769 (*II)->getName() + " also matches " +
770770 (*RI)->getValue("Instrs")->getValue()->getAsString());
771771 }
824824 std::sort(ItinRWDefs.begin(), ItinRWDefs.end(), LessRecord());
825825 for (RecIter II = ItinRWDefs.begin(), IE = ItinRWDefs.end(); II != IE; ++II) {
826826 if (!(*II)->getValueInit("SchedModel")->isComplete())
827 throw TGError((*II)->getLoc(), "SchedModel is undefined");
827 PrintFatalError((*II)->getLoc(), "SchedModel is undefined");
828828 Record *ModelDef = (*II)->getValueAsDef("SchedModel");
829829 ProcModelMapTy::const_iterator I = ProcModelMap.find(ModelDef);
830830 if (I == ProcModelMap.end()) {
831 throw TGError((*II)->getLoc(), "Undefined SchedMachineModel "
831 PrintFatalError((*II)->getLoc(), "Undefined SchedMachineModel "
832832 + ModelDef->getName());
833833 }
834834 ProcModels[I->second].ItinRWDefs.push_back(*II);
866866 if (!std::count(Matched.begin(), Matched.end(), ItinClassDef))
867867 continue;
868868 if (HasMatch)
869 throw TGError((*II)->getLoc(), "Duplicate itinerary class "
869 PrintFatalError((*II)->getLoc(), "Duplicate itinerary class "
870870 + ItinClassDef->getName()
871871 + " in ItinResources for " + PM.ModelName);
872872 HasMatch = true;
10941094 if (Cnt > 1) {
10951095 const CodeGenProcModel &PM =
10961096 *(SchedModels.procModelBegin() + Variant.ProcIdx);
1097 throw TGError(Variant.VarOrSeqDef->getLoc(),
1098 "Multiple variants defined for processor " + PM.ModelName +
1099 " Ensure only one SchedAlias exists per RW.");
1097 PrintFatalError(Variant.VarOrSeqDef->getLoc(),
1098 "Multiple variants defined for processor " +
1099 PM.ModelName +
1100 " Ensure only one SchedAlias exists per RW.");
11001101 }
11011102 }
11021103 if (Variant.VarOrSeqDef->isSubClassOf("SchedVar")) {
12141215 std::vector IntersectingVariants;
12151216 getIntersectingVariants(SchedRW, TransIdx, IntersectingVariants);
12161217 if (IntersectingVariants.empty())
1217 throw TGError(SchedRW.TheDef->getLoc(), "No variant of this type has a "
1218 "matching predicate on any processor ");
1218 PrintFatalError(SchedRW.TheDef->getLoc(),
1219 "No variant of this type has "
1220 "a matching predicate on any processor");
12191221 // Now expand each variant on top of its copy of the transition.
12201222 for (std::vector::const_iterator
12211223 IVI = IntersectingVariants.begin(),
14391441 if (!std::count(Matched.begin(), Matched.end(), ItinClassDef))
14401442 continue;
14411443 if (HasMatch)
1442 throw TGError((*II)->getLoc(), "Duplicate itinerary class "
1443 + ItinClassDef->getName()
1444 + " in ItinResources for " + PM.ModelName);
1444 PrintFatalError((*II)->getLoc(), "Duplicate itinerary class "
1445 + ItinClassDef->getName()
1446 + " in ItinResources for " + PM.ModelName);
14451447 HasMatch = true;
14461448 IdxVec Writes, Reads;
14471449 findRWs((*II)->getValueAsListOfDefs("OperandReadWrites"), Writes, Reads);
15181520 if ((*RI)->getValueAsDef("Kind") == ProcResKind
15191521 && (*RI)->getValueAsDef("SchedModel") == PM.ModelDef) {
15201522 if (ProcUnitDef) {
1521 throw TGError((*RI)->getLoc(),
1522 "Multiple ProcessorResourceUnits associated with "
1523 + ProcResKind->getName());
1523 PrintFatalError((*RI)->getLoc(),
1524 "Multiple ProcessorResourceUnits associated with "
1525 + ProcResKind->getName());
15241526 }
15251527 ProcUnitDef = *RI;
15261528 }
15271529 }
15281530 if (!ProcUnitDef) {
1529 throw TGError(ProcResKind->getLoc(),
1530 "No ProcessorResources associated with "
1531 + ProcResKind->getName());
1531 PrintFatalError(ProcResKind->getLoc(),
1532 "No ProcessorResources associated with "
1533 + ProcResKind->getName());
15321534 }
15331535 return ProcUnitDef;
15341536 }
15851587 RecIter PRPos = std::find(ProcResourceDefs.begin(), ProcResourceDefs.end(),
15861588 PRDef);
15871589 if (PRPos == ProcResourceDefs.end())
1588 throw TGError(PRDef->getLoc(), "ProcResource def is not included in "
1589 "the ProcResources list for " + ModelName);
1590 PrintFatalError(PRDef->getLoc(), "ProcResource def is not included in "
1591 "the ProcResources list for " + ModelName);
15901592 // Idx=0 is reserved for invalid.
15911593 return 1 + PRPos - ProcResourceDefs.begin();
15921594 }
99 // This class wraps target description classes used by the various code
1010 // generation TableGen backends. This makes it easier to access the data and
1111 // provides a single place that needs to check it for validity. All of these
12 // classes throw exceptions on error conditions.
12 // classes abort on error conditions.
1313 //
1414 //===----------------------------------------------------------------------===//
1515
1616 #include "CodeGenTarget.h"
1717 #include "CodeGenIntrinsics.h"
1818 #include "CodeGenSchedule.h"
19 #include "llvm/TableGen/Error.h"
1920 #include "llvm/TableGen/Record.h"
2021 #include "llvm/ADT/StringExtras.h"
2122 #include "llvm/ADT/STLExtras.h"
123124 : Records(records), RegBank(0), SchedModels(0) {
124125 std::vector Targets = Records.getAllDerivedDefinitions("Target");
125126 if (Targets.size() == 0)
126 throw std::string("ERROR: No 'Target' subclasses defined!");
127 PrintFatalError("ERROR: No 'Target' subclasses defined!");
127128 if (Targets.size() != 1)
128 throw std::string("ERROR: Multiple subclasses of Target defined!");
129 PrintFatalError("ERROR: Multiple subclasses of Target defined!");
129130 TargetRec = Targets[0];
130131 }
131132
159160 Record *CodeGenTarget::getAsmParser() const {
160161 std::vector LI = TargetRec->getValueAsListOfDefs("AssemblyParsers");
161162 if (AsmParserNum >= LI.size())
162 throw "Target does not have an AsmParser #" + utostr(AsmParserNum) + "!";
163 PrintFatalError("Target does not have an AsmParser #" + utostr(AsmParserNum) + "!");
163164 return LI[AsmParserNum];
164165 }
165166
170171 std::vector LI =
171172 TargetRec->getValueAsListOfDefs("AssemblyParserVariants");
172173 if (i >= LI.size())
173 throw "Target does not have an AsmParserVariant #" + utostr(i) + "!";
174 PrintFatalError("Target does not have an AsmParserVariant #" + utostr(i) + "!");
174175 return LI[i];
175176 }
176177
188189 Record *CodeGenTarget::getAsmWriter() const {
189190 std::vector LI = TargetRec->getValueAsListOfDefs("AssemblyWriters");
190191 if (AsmWriterNum >= LI.size())
191 throw "Target does not have an AsmWriter #" + utostr(AsmWriterNum) + "!";
192 PrintFatalError("Target does not have an AsmWriter #" + utostr(AsmWriterNum) + "!");
192193 return LI[AsmWriterNum];
193194 }
194195
255256 void CodeGenTarget::ReadInstructions() const {
256257 std::vector Insts = Records.getAllDerivedDefinitions("Instruction");
257258 if (Insts.size() <= 2)
258 throw std::string("No 'Instruction' subclasses defined!");
259 PrintFatalError("No 'Instruction' subclasses defined!");
259260
260261 // Parse the instructions defined in the .td file.
261262 for (unsigned i = 0, e = Insts.size(); i != e; ++i)
271272 DenseMap::const_iterator
272273 I = Insts.find(Rec);
273274 if (Rec == 0 || I == Insts.end())
274 throw std::string("Could not find '") + Name + "' instruction!";
275 PrintFatalError(std::string("Could not find '") + Name + "' instruction!");
275276 return I->second;
276277 }
277278
418419
419420 if (DefName.size() <= 4 ||
420421 std::string(DefName.begin(), DefName.begin() + 4) != "int_")
421 throw "Intrinsic '" + DefName + "' does not start with 'int_'!";
422 PrintFatalError("Intrinsic '" + DefName + "' does not start with 'int_'!");
422423
423424 EnumName = std::string(DefName.begin()+4, DefName.end());
424425
438439 // Verify it starts with "llvm.".
439440 if (Name.size() <= 5 ||
440441 std::string(Name.begin(), Name.begin() + 5) != "llvm.")
441 throw "Intrinsic '" + DefName + "'s name does not start with 'llvm.'!";
442 PrintFatalError("Intrinsic '" + DefName + "'s name does not start with 'llvm.'!");
442443 }
443444
444445 // If TargetPrefix is specified, make sure that Name starts with
447448 if (Name.size() < 6+TargetPrefix.size() ||
448449 std::string(Name.begin() + 5, Name.begin() + 6 + TargetPrefix.size())
449450 != (TargetPrefix + "."))
450 throw "Intrinsic '" + DefName + "' does not start with 'llvm." +
451 TargetPrefix + ".'!";
451 PrintFatalError("Intrinsic '" + DefName + "' does not start with 'llvm." +
452 TargetPrefix + ".'!");
452453 }
453454
454455 // Parse the list of return types.
480481
481482 // Reject invalid types.
482483 if (VT == MVT::isVoid)
483 throw "Intrinsic '" + DefName + " has void in result type list!";
484 PrintFatalError("Intrinsic '" + DefName + " has void in result type list!");
484485
485486 IS.RetVTs.push_back(VT);
486487 IS.RetTypeDefs.push_back(TyEl);
514515
515516 // Reject invalid types.
516517 if (VT == MVT::isVoid && i != e-1 /*void at end means varargs*/)
517 throw "Intrinsic '" + DefName + " has void in result type list!";
518 PrintFatalError("Intrinsic '" + DefName + " has void in result type list!");
518519
519520 IS.ParamVTs.push_back(VT);
520521 IS.ParamTypeDefs.push_back(TyEl);
88 //
99 // This file defines wrappers for the Target class and related global
1010 // functionality. This makes it easier to access the data and provides a single
11 // place that needs to check it for validity. All of these classes throw
12 // exceptions on error conditions.
11 // place that needs to check it for validity. All of these classes abort
12 // on error conditions.
1313 //
1414 //===----------------------------------------------------------------------===//
1515
99 #include "DAGISelMatcher.h"
1010 #include "CodeGenDAGPatterns.h"
1111 #include "CodeGenRegisters.h"
12 #include "llvm/TableGen/Error.h"
1213 #include "llvm/TableGen/Record.h"
1314 #include "llvm/ADT/DenseMap.h"
1415 #include "llvm/ADT/SmallVector.h"
171172 // diagnostics, which we know are impossible at this point.
172173 TreePattern &TP = *CGP.pf_begin()->second;
173174
174 try {
175 bool MadeChange = true;
176 while (MadeChange)
177 MadeChange = PatWithNoTypes->ApplyTypeConstraints(TP,
178 true/*Ignore reg constraints*/);
179 } catch (...) {
180 errs() << "Type constraint application shouldn't fail!";
181 abort();
182 }
175 bool MadeChange = true;
176 while (MadeChange)
177 MadeChange = PatWithNoTypes->ApplyTypeConstraints(TP,
178 true/*Ignore reg constraints*/);
183179 }
184180
185181
875871 if (OpRec->isSubClassOf("SDNodeXForm"))
876872 return EmitResultSDNodeXFormAsOperand(N, ResultOps);
877873 errs() << "Unknown result node to emit code for: " << *N << '\n';
878 throw std::string("Unknown node in result pattern!");
874 PrintFatalError("Unknown node in result pattern!");
879875 }
880876
881877 void MatcherGen::EmitResultCode() {
116116 for (unsigned i = 0, e = numberedInstructions.size(); i != e; ++i)
117117 RecognizableInstr::processInstr(Tables, *numberedInstructions[i], i);
118118
119 // FIXME: As long as we are using exceptions, might as well drop this to the
120 // actual conflict site.
121119 if (Tables.hasConflicts())
122 throw TGError(Target.getTargetRecord()->getLoc(),
123 "Primary decode conflict");
120 PrintFatalError(Target.getTargetRecord()->getLoc(),
121 "Primary decode conflict");
124122
125123 Tables.emit(OS);
126124 return;
1818 #include "llvm/Support/ErrorHandling.h"
1919 #include "llvm/Support/Format.h"
2020 #include "llvm/Support/raw_ostream.h"
21 #include "llvm/TableGen/Error.h"
2122 #include "llvm/TableGen/Record.h"
2223 #include "llvm/TableGen/TableGenBackend.h"
2324 #include
776777 errs() << "Operand type: " << rec.getName() << '\n';
777778 errs() << "Operand name: " << operandInfo.Name << '\n';
778779 errs() << "Instruction name: " << inst.TheDef->getName() << '\n';
779 throw("Unhandled type in EDEmitter");
780 PrintFatalError("Unhandled type in EDEmitter");
780781 }
781782 }
782783 }
548548 };
549549
550550 if (SimplePatterns[Operands][OpcodeName][VT][RetVT].count(PredicateCheck))
551 throw TGError(Pattern.getSrcRecord()->getLoc(),
551 PrintFatalError(Pattern.getSrcRecord()->getLoc(),
552552 "Duplicate record in FastISel table!");
553553
554554 SimplePatterns[Operands][OpcodeName][VT][RetVT][PredicateCheck] = Memo;
1414 #define DEBUG_TYPE "decoder-emitter"
1515
1616 #include "CodeGenTarget.h"
17 #include "llvm/TableGen/Error.h"
1718 #include "llvm/TableGen/Record.h"
1819 #include "llvm/ADT/APInt.h"
1920 #include "llvm/ADT/SmallString.h"
740741
741742 switch (*I) {
742743 default:
743 throw "invalid decode table opcode";
744 PrintFatalError("invalid decode table opcode");
744745 case MCD::OPC_ExtractField: {
745746 ++I;
746747 unsigned Start = *I++;
1818 #include "TableGenBackends.h"
1919 #include "SequenceToOffsetTable.h"
2020 #include "llvm/ADT/StringExtras.h"
21 #include "llvm/TableGen/Error.h"
2122 #include "llvm/TableGen/Record.h"
2223 #include "llvm/TableGen/TableGenBackend.h"
2324 #include
342343
343344 // Emit all of the target-specific flags...
344345 BitsInit *TSF = Inst.TheDef->getValueAsBitsInit("TSFlags");
345 if (!TSF) throw "no TSFlags?";
346 if (!TSF)
347 PrintFatalError("no TSFlags?");
346348 uint64_t Value = 0;
347349 for (unsigned i = 0, e = TSF->getNumBits(); i != e; ++i) {
348350 if (BitInit *Bit = dyn_cast(TSF->getBit(i)))
349351 Value |= uint64_t(Bit->getValue()) << i;
350352 else
351 throw "Invalid TSFlags bit in " + Inst.TheDef->getName();
353 PrintFatalError("Invalid TSFlags bit in " + Inst.TheDef->getName());
352354 }
353355 OS << ", 0x";
354356 OS.write_hex(Value);
1414 #include "CodeGenTarget.h"
1515 #include "SequenceToOffsetTable.h"
1616 #include "llvm/ADT/StringExtras.h"
17 #include "llvm/TableGen/Error.h"
1718 #include "llvm/TableGen/Record.h"
1819 #include "llvm/TableGen/StringMatcher.h"
1920 #include "llvm/TableGen/TableGenBackend.h"
248249 if (EVT(VT).isInteger()) {
249250 unsigned BitWidth = EVT(VT).getSizeInBits();
250251 switch (BitWidth) {
251 default: throw "unhandled integer type width in intrinsic!";
252 default: PrintFatalError("unhandled integer type width in intrinsic!");
252253 case 1: return Sig.push_back(IIT_I1);
253254 case 8: return Sig.push_back(IIT_I8);
254255 case 16: return Sig.push_back(IIT_I16);
258259 }
259260
260261 switch (VT) {
261 default: throw "unhandled MVT in intrinsic!";
262 default: PrintFatalError("unhandled MVT in intrinsic!");
262263 case MVT::f32: return Sig.push_back(IIT_F32);
263264 case MVT::f64: return Sig.push_back(IIT_F64);
264265 case MVT::Metadata: return Sig.push_back(IIT_METADATA);
327328 if (EVT(VT).isVector()) {
328329 EVT VVT = VT;
329330 switch (VVT.getVectorNumElements()) {
330 default: throw "unhandled vector type width in intrinsic!";
331 default: PrintFatalError("unhandled vector type width in intrinsic!");
331332 case 2: Sig.push_back(IIT_V2); break;
332333 case 4: Sig.push_back(IIT_V4); break;
333334 case 8: Sig.push_back(IIT_V8); break;
691692
692693 if (!BIM.insert(std::make_pair(Ints[i].GCCBuiltinName,
693694 Ints[i].EnumName)).second)
694 throw "Intrinsic '" + Ints[i].TheDef->getName() +
695 "': duplicate GCC builtin name!";
695 PrintFatalError("Intrinsic '" + Ints[i].TheDef->getName() +
696 "': duplicate GCC builtin name!");
696697 }
697698 }
698699
99 LEVEL = ../..
1010 TOOLNAME = llvm-tblgen
1111 USEDLIBS = LLVMTableGen.a LLVMSupport.a
12 REQUIRES_EH := 1
1312
1413 # This tool has no plugins, optimize startup time.
1514 TOOL_NO_EXPORTS = 1
8989 // FIXME: We probably shouldn't ever get a non-zero BaseIdx here.
9090 assert(BaseIdx == 0 && "Named subargument in pseudo expansion?!");
9191 if (DI->getDef() != Insn.Operands[BaseIdx + i].Rec)
92 throw TGError(Rec->getLoc(),
92 PrintFatalError(Rec->getLoc(),
9393 "Pseudo operand type '" + DI->getDef()->getName() +
9494 "' does not match expansion operand type '" +
9595 Insn.Operands[BaseIdx + i].Rec->getName() + "'");
128128
129129 DefInit *OpDef = dyn_cast(Dag->getOperator());
130130 if (!OpDef)
131 throw TGError(Rec->getLoc(), Rec->getName() +
131 PrintFatalError(Rec->getLoc(), Rec->getName() +
132132 " has unexpected operator type!");
133133 Record *Operator = OpDef->getDef();
134134 if (!Operator->isSubClassOf("Instruction"))
135 throw TGError(Rec->getLoc(), "Pseudo result '" + Operator->getName() +
136 "' is not an instruction!");
135 PrintFatalError(Rec->getLoc(), "Pseudo result '" + Operator->getName() +
136 "' is not an instruction!");
137137
138138 CodeGenInstruction Insn(Operator);
139139
140140 if (Insn.isCodeGenOnly || Insn.isPseudo)
141 throw TGError(Rec->getLoc(), "Pseudo result '" + Operator->getName() +
142 "' cannot be another pseudo instruction!");
141 PrintFatalError(Rec->getLoc(), "Pseudo result '" + Operator->getName() +
142 "' cannot be another pseudo instruction!");
143143
144144 if (Insn.Operands.size() != Dag->getNumArgs())
145 throw TGError(Rec->getLoc(), "Pseudo result '" + Operator->getName() +
146 "' operand count mismatch");
145 PrintFatalError(Rec->getLoc(), "Pseudo result '" + Operator->getName() +
146 "' operand count mismatch");
147147
148148 unsigned NumMIOperands = 0;
149149 for (unsigned i = 0, e = Insn.Operands.size(); i != e; ++i)
178178 StringMap::iterator SourceOp =
179179 SourceOperands.find(Dag->getArgName(i));
180180 if (SourceOp == SourceOperands.end())
181 throw TGError(Rec->getLoc(),
182 "Pseudo output operand '" + Dag->getArgName(i) +
183 "' has no matching source operand.");
181 PrintFatalError(Rec->getLoc(),
182 "Pseudo output operand '" + Dag->getArgName(i) +
183 "' has no matching source operand.");
184184 // Map the source operand to the destination operand index for each
185185 // MachineInstr operand.
186186 for (unsigned I = 0, E = Insn.Operands[i].MINumOperands; I != E; ++I)
10911091 else if (RegisterClasses.size() < UINT16_MAX)
10921092 OS << " static const uint16_t Table[";
10931093 else
1094 throw "Too many register classes.";
1094 PrintFatalError("Too many register classes.");
10951095 OS << RegisterClasses.size() << "][" << SubRegIndices.size() << "] = {\n";
10961096 for (unsigned rci = 0, rce = RegisterClasses.size(); rci != rce; ++rci) {
10971097 const CodeGenRegisterClass &RC = *RegisterClasses[rci];
3535 struct SubOp : public SetTheory::Operator {
3636 void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts, ArrayRef Loc) {
3737 if (Expr->arg_size() < 2)
38 throw TGError(Loc, "Set difference needs at least two arguments: " +
38 PrintFatalError(Loc, "Set difference needs at least two arguments: " +
3939 Expr->getAsString());
4040 RecSet Add, Sub;
4141 ST.evaluate(*Expr->arg_begin(), Add, Loc);
5050 struct AndOp : public SetTheory::Operator {
5151 void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts, ArrayRef Loc) {
5252 if (Expr->arg_size() != 2)
53 throw TGError(Loc, "Set intersection requires two arguments: " +
53 PrintFatalError(Loc, "Set intersection requires two arguments: " +
5454 Expr->getAsString());
5555 RecSet S1, S2;
5656 ST.evaluate(Expr->arg_begin()[0], S1, Loc);
6969
7070 void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts, ArrayRef Loc) {
7171 if (Expr->arg_size() != 2)
72 throw TGError(Loc, "Operator requires (Op Set, Int) arguments: " +
72 PrintFatalError(Loc, "Operator requires (Op Set, Int) arguments: " +
7373 Expr->getAsString());
7474 RecSet Set;
7575 ST.evaluate(Expr->arg_begin()[0], Set, Loc);
7676 IntInit *II = dyn_cast(Expr->arg_begin()[1]);
7777 if (!II)
78 throw TGError(Loc, "Second argument must be an integer: " +
78 PrintFatalError(Loc, "Second argument must be an integer: " +
7979 Expr->getAsString());
8080 apply2(ST, Expr, Set, II->getValue(), Elts, Loc);
8181 }
8787 RecSet &Set, int64_t N,
8888 RecSet &Elts, ArrayRef Loc) {
8989 if (N < 0)
90 throw TGError(Loc, "Positive shift required: " +
90 PrintFatalError(Loc, "Positive shift required: " +
9191 Expr->getAsString());
9292 if (unsigned(N) < Set.size())
9393 Elts.insert(Set.begin() + N, Set.end());
100100 RecSet &Set, int64_t N,
101101 RecSet &Elts, ArrayRef Loc) {
102102 if (N < 0)
103 throw TGError(Loc, "Positive length required: " +
103 PrintFatalError(Loc, "Positive length required: " +
104104 Expr->getAsString());
105105 if (unsigned(N) > Set.size())
106106 N = Set.size();
137137 RecSet &Set, int64_t N,
138138 RecSet &Elts, ArrayRef Loc) {
139139 if (N <= 0)
140 throw TGError(Loc, "Positive stride required: " +
140 PrintFatalError(Loc, "Positive stride required: " +
141141 Expr->getAsString());
142142 for (unsigned I = 0; I < Set.size(); I += N)
143143 Elts.insert(Set[I]);
167167 void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts, ArrayRef Loc) {
168168 int Step = 1;
169169 if (Expr->arg_size() > 4)
170 throw TGError(Loc, "Bad args to (sequence \"Format\", From, To): " +
170 PrintFatalError(Loc, "Bad args to (sequence \"Format\", From, To): " +
171171 Expr->getAsString());
172172 else if (Expr->arg_size() == 4) {
173173 if (IntInit *II = dyn_cast(Expr->arg_begin()[3])) {
174174 Step = II->getValue();
175175 } else
176 throw TGError(Loc, "Stride must be an integer: " + Expr->getAsString());
176 PrintFatalError(Loc, "Stride must be an integer: " +
177 Expr->getAsString());
177178 }
178179
179180 std::string Format;
180181 if (StringInit *SI = dyn_cast(Expr->arg_begin()[0]))
181182 Format = SI->getValue();
182183 else
183 throw TGError(Loc, "Format must be a string: " + Expr->getAsString());
184 PrintFatalError(Loc, "Format must be a string: " + Expr->getAsString());
184185
185186 int64_t From, To;
186187 if (IntInit *II = dyn_cast(Expr->arg_begin()[1]))
187188 From = II->getValue();
188189 else
189 throw TGError(Loc, "From must be an integer: " + Expr->getAsString());
190 PrintFatalError(Loc, "From must be an integer: " + Expr->getAsString());
190191 if (From < 0 || From >= (1 << 30))
191 throw TGError(Loc, "From out of range");
192 PrintFatalError(Loc, "From out of range");
192193
193194 if (IntInit *II = dyn_cast(Expr->arg_begin()[2]))
194195 To = II->getValue();
195196 else
196 throw TGError(Loc, "From must be an integer: " + Expr->getAsString());
197 PrintFatalError(Loc, "From must be an integer: " + Expr->getAsString());
197198 if (To < 0 || To >= (1 << 30))
198 throw TGError(Loc, "To out of range");
199 PrintFatalError(Loc, "To out of range");
199200
200201 RecordKeeper &Records =
201202 cast(Expr->getOperator())->getDef()->getRecords();
211212 OS << format(Format.c_str(), unsigned(From));
212213 Record *Rec = Records.getDef(OS.str());
213214 if (!Rec)
214 throw TGError(Loc, "No def named '" + Name + "': " +
215 PrintFatalError(Loc, "No def named '" + Name + "': " +
215216 Expr->getAsString());
216217 // Try to reevaluate Rec in case it is a set.
217218 if (const RecVec *Result = ST.expand(Rec))
281282 // Anything else must be a DAG.
282283 DagInit *DagExpr = dyn_cast(Expr);
283284 if (!DagExpr)
284 throw TGError(Loc, "Invalid set element: " + Expr->getAsString());
285 PrintFatalError(Loc, "Invalid set element: " + Expr->getAsString());
285286 DefInit *OpInit = dyn_cast(DagExpr->getOperator());
286287 if (!OpInit)
287 throw TGError(Loc, "Bad set expression: " + Expr->getAsString());
288 PrintFatalError(Loc, "Bad set expression: " + Expr->getAsString());
288289 Operator *Op = Operators.lookup(OpInit->getDef()->getName());
289290 if (!Op)
290 throw TGError(Loc, "Unknown set operator: " + Expr->getAsString());
291 PrintFatalError(Loc, "Unknown set operator: " + Expr->getAsString());
291292 Op->apply(*this, DagExpr, Elts, Loc);
292293 }
293294
674674 continue;
675675 }
676676 if (AliasDef)
677 throw TGError(AliasRW.TheDef->getLoc(), "Multiple aliases "
677 PrintFatalError(AliasRW.TheDef->getLoc(), "Multiple aliases "
678678 "defined for processor " + ProcModel.ModelName +
679679 " Ensure only one SchedAlias exists per RW.");
680680 AliasDef = AliasRW.TheDef;
691691 if (AliasDef == (*WRI)->getValueAsDef("WriteType")
692692 || SchedWrite.TheDef == (*WRI)->getValueAsDef("WriteType")) {
693693 if (ResDef) {
694 throw TGError((*WRI)->getLoc(), "Resources are defined for both "
694 PrintFatalError((*WRI)->getLoc(), "Resources are defined for both "
695695 "SchedWrite and its alias on processor " +
696696 ProcModel.ModelName);
697697 }
701701 // TODO: If ProcModel has a base model (previous generation processor),
702702 // then call FindWriteResources recursively with that model here.
703703 if (!ResDef) {
704 throw TGError(ProcModel.ModelDef->getLoc(),
704 PrintFatalError(ProcModel.ModelDef->getLoc(),
705705 std::string("Processor does not define resources for ")
706706 + SchedWrite.TheDef->getName());
707707 }
728728 continue;
729729 }
730730 if (AliasDef)
731 throw TGError(AliasRW.TheDef->getLoc(), "Multiple aliases "
731 PrintFatalError(AliasRW.TheDef->getLoc(), "Multiple aliases "
732732 "defined for processor " + ProcModel.ModelName +
733733 " Ensure only one SchedAlias exists per RW.");
734734 AliasDef = AliasRW.TheDef;
745745 if (AliasDef == (*RAI)->getValueAsDef("ReadType")
746746 || SchedRead.TheDef == (*RAI)->getValueAsDef("ReadType")) {
747747 if (ResDef) {
748 throw TGError((*RAI)->getLoc(), "Resources are defined for both "
748 PrintFatalError((*RAI)->getLoc(), "Resources are defined for both "
749749 "SchedRead and its alias on processor " +
750750 ProcModel.ModelName);
751751 }
755755 // TODO: If ProcModel has a base model (previous generation processor),
756756 // then call FindReadAdvance recursively with that model here.
757757 if (!ResDef && SchedRead.TheDef->getName() != "ReadDefault") {
758 throw TGError(ProcModel.ModelDef->getLoc(),
758 PrintFatalError(ProcModel.ModelDef->getLoc(),
759759 std::string("Processor does not define resources for ")
760760 + SchedRead.TheDef->getName());
761761 }
10971097 if (PI->hasInstrSchedModel())
10981098 EmitProcessorResources(*PI, OS);
10991099 else if(!PI->ProcResourceDefs.empty())
1100 throw TGError(PI->ModelDef->getLoc(), "SchedMachineModel defines "
1100 PrintFatalError(PI->ModelDef->getLoc(), "SchedMachineModel defines "
11011101 "ProcResources without defining WriteRes SchedWriteRes");
11021102
11031103 // Begin processor itinerary properties