1515#include " Common/CodeGenTarget.h"
1616#include " llvm/Support/FormatVariadic.h"
1717#include " llvm/Support/InterleavedRange.h"
18+ #include " llvm/TableGen/CodeGenHelpers.h"
1819#include " llvm/TableGen/Error.h"
1920#include " llvm/TableGen/Record.h"
2021#include " llvm/TableGen/TGTimer.h"
@@ -54,6 +55,20 @@ class CallingConvEmitter {
5455};
5556} // End anonymous namespace
5657
58+ static void emitCCHeader (raw_ostream &O, const Record *CC, StringRef Suffix) {
59+ unsigned Pad = CC->getName ().size ();
60+ if (CC->getValueAsBit (" Entry" )) {
61+ O << " bool llvm::" ;
62+ Pad += 12 ;
63+ } else {
64+ O << " static bool " ;
65+ Pad += 13 ;
66+ }
67+ O << CC->getName () << " (unsigned ValNo, MVT ValVT,\n "
68+ << indent (Pad) << " MVT LocVT, CCValAssign::LocInfo LocInfo,\n "
69+ << indent (Pad) << " ISD::ArgFlagsTy ArgFlags, Type *OrigTy, CCState &State)" << Suffix;
70+ }
71+
5772void CallingConvEmitter::run (raw_ostream &O) {
5873 emitSourceFileHeader (" Calling Convention Implementation Fragment" , O);
5974
@@ -63,35 +78,20 @@ void CallingConvEmitter::run(raw_ostream &O) {
6378 // Emit prototypes for all of the non-custom CC's so that they can forward ref
6479 // each other.
6580 Records.getTimer ().startTimer (" Emit prototypes" );
66- O << " #ifndef GET_CC_REGISTER_LISTS\n\n " ;
81+ IfGuardEmitter IfGuard (O, " !defined( GET_CC_REGISTER_LISTS) " ) ;
6782 for (const Record *CC : CCs) {
68- if (!CC->getValueAsBit (" Custom" )) {
69- unsigned Pad = CC->getName ().size ();
70- if (CC->getValueAsBit (" Entry" )) {
71- O << " bool llvm::" ;
72- Pad += 12 ;
73- } else {
74- O << " static bool " ;
75- Pad += 13 ;
76- }
77- O << CC->getName () << " (unsigned ValNo, MVT ValVT,\n "
78- << std::string (Pad, ' ' ) << " MVT LocVT, CCValAssign::LocInfo LocInfo,\n "
79- << std::string (Pad, ' ' )
80- << " ISD::ArgFlagsTy ArgFlags, Type *OrigTy, CCState &State);\n " ;
81- }
83+ if (!CC->getValueAsBit (" Custom" ))
84+ emitCCHeader (O, CC, " ;\n " );
8285 }
8386
8487 // Emit each non-custom calling convention description in full.
8588 Records.getTimer ().startTimer (" Emit full descriptions" );
8689 for (const Record *CC : CCs) {
87- if (!CC->getValueAsBit (" Custom" )) {
90+ if (!CC->getValueAsBit (" Custom" ))
8891 emitCallingConv (CC, O);
89- }
9092 }
9193
9294 emitArgRegisterLists (O);
93-
94- O << " \n #endif // CC_REGISTER_LIST\n " ;
9595}
9696
9797void CallingConvEmitter::emitCallingConv (const Record *CC, raw_ostream &O) {
@@ -105,18 +105,7 @@ void CallingConvEmitter::emitCallingConv(const Record *CC, raw_ostream &O) {
105105 AssignedRegsMap[CurrentAction] = {};
106106
107107 O << " \n\n " ;
108- unsigned Pad = CurrentAction.size ();
109- if (CC->getValueAsBit (" Entry" )) {
110- O << " bool llvm::" ;
111- Pad += 12 ;
112- } else {
113- O << " static bool " ;
114- Pad += 13 ;
115- }
116- O << CurrentAction << " (unsigned ValNo, MVT ValVT,\n "
117- << std::string (Pad, ' ' ) << " MVT LocVT, CCValAssign::LocInfo LocInfo,\n "
118- << std::string (Pad, ' ' ) << " ISD::ArgFlagsTy ArgFlags, Type *OrigTy, "
119- << " CCState &State) {\n " ;
108+ emitCCHeader (O, CC, " {\n " );
120109 // Emit all of the actions, in order.
121110 for (unsigned I = 0 , E = CCActions->size (); I != E; ++I) {
122111 const Record *Action = CCActions->getElementAsRecord (I);
0 commit comments