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,21 @@ 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)"
70+ << Suffix;
71+ }
72+
5773void CallingConvEmitter::run (raw_ostream &O) {
5874 emitSourceFileHeader (" Calling Convention Implementation Fragment" , O);
5975
@@ -63,35 +79,20 @@ void CallingConvEmitter::run(raw_ostream &O) {
6379 // Emit prototypes for all of the non-custom CC's so that they can forward ref
6480 // each other.
6581 Records.getTimer ().startTimer (" Emit prototypes" );
66- O << " #ifndef GET_CC_REGISTER_LISTS\n\n " ;
82+ IfGuardEmitter IfGuard (O, " !defined( GET_CC_REGISTER_LISTS) " ) ;
6783 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- }
84+ if (!CC->getValueAsBit (" Custom" ))
85+ emitCCHeader (O, CC, " ;\n " );
8286 }
8387
8488 // Emit each non-custom calling convention description in full.
8589 Records.getTimer ().startTimer (" Emit full descriptions" );
8690 for (const Record *CC : CCs) {
87- if (!CC->getValueAsBit (" Custom" )) {
91+ if (!CC->getValueAsBit (" Custom" ))
8892 emitCallingConv (CC, O);
89- }
9093 }
9194
9295 emitArgRegisterLists (O);
93-
94- O << " \n #endif // CC_REGISTER_LIST\n " ;
9596}
9697
9798void CallingConvEmitter::emitCallingConv (const Record *CC, raw_ostream &O) {
@@ -105,18 +106,7 @@ void CallingConvEmitter::emitCallingConv(const Record *CC, raw_ostream &O) {
105106 AssignedRegsMap[CurrentAction] = {};
106107
107108 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 " ;
109+ emitCCHeader (O, CC, " {\n " );
120110 // Emit all of the actions, in order.
121111 for (unsigned I = 0 , E = CCActions->size (); I != E; ++I) {
122112 const Record *Action = CCActions->getElementAsRecord (I);
0 commit comments