diff --git a/llvm/utils/TableGen/CallingConvEmitter.cpp b/llvm/utils/TableGen/CallingConvEmitter.cpp index e0d933723ad66..2b20b854a9b1a 100644 --- a/llvm/utils/TableGen/CallingConvEmitter.cpp +++ b/llvm/utils/TableGen/CallingConvEmitter.cpp @@ -15,6 +15,7 @@ #include "Common/CodeGenTarget.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/InterleavedRange.h" +#include "llvm/TableGen/CodeGenHelpers.h" #include "llvm/TableGen/Error.h" #include "llvm/TableGen/Record.h" #include "llvm/TableGen/TGTimer.h" @@ -54,6 +55,21 @@ class CallingConvEmitter { }; } // End anonymous namespace +static void emitCCHeader(raw_ostream &O, const Record *CC, StringRef Suffix) { + unsigned Pad = CC->getName().size(); + if (CC->getValueAsBit("Entry")) { + O << "bool llvm::"; + Pad += 12; + } else { + O << "static bool "; + Pad += 13; + } + O << CC->getName() << "(unsigned ValNo, MVT ValVT,\n" + << indent(Pad) << "MVT LocVT, CCValAssign::LocInfo LocInfo,\n" + << indent(Pad) << "ISD::ArgFlagsTy ArgFlags, Type *OrigTy, CCState &State)" + << Suffix; +} + void CallingConvEmitter::run(raw_ostream &O) { emitSourceFileHeader("Calling Convention Implementation Fragment", O); @@ -63,35 +79,20 @@ void CallingConvEmitter::run(raw_ostream &O) { // Emit prototypes for all of the non-custom CC's so that they can forward ref // each other. Records.getTimer().startTimer("Emit prototypes"); - O << "#ifndef GET_CC_REGISTER_LISTS\n\n"; + IfGuardEmitter IfGuard(O, "!defined(GET_CC_REGISTER_LISTS)"); for (const Record *CC : CCs) { - if (!CC->getValueAsBit("Custom")) { - unsigned Pad = CC->getName().size(); - if (CC->getValueAsBit("Entry")) { - O << "bool llvm::"; - Pad += 12; - } else { - O << "static bool "; - Pad += 13; - } - O << CC->getName() << "(unsigned ValNo, MVT ValVT,\n" - << std::string(Pad, ' ') << "MVT LocVT, CCValAssign::LocInfo LocInfo,\n" - << std::string(Pad, ' ') - << "ISD::ArgFlagsTy ArgFlags, Type *OrigTy, CCState &State);\n"; - } + if (!CC->getValueAsBit("Custom")) + emitCCHeader(O, CC, ";\n"); } // Emit each non-custom calling convention description in full. Records.getTimer().startTimer("Emit full descriptions"); for (const Record *CC : CCs) { - if (!CC->getValueAsBit("Custom")) { + if (!CC->getValueAsBit("Custom")) emitCallingConv(CC, O); - } } emitArgRegisterLists(O); - - O << "\n#endif // CC_REGISTER_LIST\n"; } void CallingConvEmitter::emitCallingConv(const Record *CC, raw_ostream &O) { @@ -105,18 +106,7 @@ void CallingConvEmitter::emitCallingConv(const Record *CC, raw_ostream &O) { AssignedRegsMap[CurrentAction] = {}; O << "\n\n"; - unsigned Pad = CurrentAction.size(); - if (CC->getValueAsBit("Entry")) { - O << "bool llvm::"; - Pad += 12; - } else { - O << "static bool "; - Pad += 13; - } - O << CurrentAction << "(unsigned ValNo, MVT ValVT,\n" - << std::string(Pad, ' ') << "MVT LocVT, CCValAssign::LocInfo LocInfo,\n" - << std::string(Pad, ' ') << "ISD::ArgFlagsTy ArgFlags, Type *OrigTy, " - << "CCState &State) {\n"; + emitCCHeader(O, CC, " {\n"); // Emit all of the actions, in order. for (unsigned I = 0, E = CCActions->size(); I != E; ++I) { const Record *Action = CCActions->getElementAsRecord(I);