From 38f9900aa5241dd8fcb70dce3543a294d0d3e870 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Sat, 19 Jan 2019 00:33:02 +0000 Subject: [X86] Deduplicate static calling convention helpers for code size, NFC Summary: Right now we include ${TGT}GenCallingConv.inc once per each instruction selection method implemented by ${TGT}: - ${TGT}ISelLowering.cpp - ${TGT}CallLowering.cpp - ${TGT}FastISel.cpp Instead, add a mechanism to tablegen for marking a particular convention as "External", which causes tablegen to emit into the ::llvm namespace, instead of as a static helper. This allows us to provide a header to forward declare it, so we can simply call the function from all the places it is referenced. Typically the calling convention analyzer is called indirectly, so it doesn't benefit from inlining. This saves a bit of final binary size, but mostly just saves object file size: before after diff artifact 12852K 12492K -360K X86ISelLowering.cpp.obj 4640K 4280K -360K X86FastISel.cpp.obj 1704K 2092K +388K X86CallingConv.cpp.obj 52448K 52336K -112K llc.exe I didn't collect before numbers for X86CallLowering.cpp.obj, which is for GlobalISel, but we should save 360K there as well. This patch applies the strategy to the X86 backend, but there is no reason it couldn't be applied to the other backends that implement multiple ISel strategies, like AArch64. Reviewers: craig.topper, hfinkel, efriedma Subscribers: javed.absar, kristof.beyls, hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D56883 llvm-svn: 351616 --- llvm/utils/TableGen/CallingConvEmitter.cpp | 34 ++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'llvm/utils/TableGen/CallingConvEmitter.cpp') diff --git a/llvm/utils/TableGen/CallingConvEmitter.cpp b/llvm/utils/TableGen/CallingConvEmitter.cpp index d452031f885..41cea62f271 100644 --- a/llvm/utils/TableGen/CallingConvEmitter.cpp +++ b/llvm/utils/TableGen/CallingConvEmitter.cpp @@ -41,11 +41,17 @@ void CallingConvEmitter::run(raw_ostream &O) { // each other. for (Record *CC : CCs) { if (!CC->getValueAsBit("Custom")) { - O << "static bool " << CC->getName() - << "(unsigned ValNo, MVT ValVT,\n" - << std::string(CC->getName().size() + 13, ' ') - << "MVT LocVT, CCValAssign::LocInfo LocInfo,\n" - << std::string(CC->getName().size() + 13, ' ') + 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, CCState &State);\n"; } } @@ -62,12 +68,18 @@ void CallingConvEmitter::EmitCallingConv(Record *CC, raw_ostream &O) { ListInit *CCActions = CC->getValueAsListInit("Actions"); Counter = 0; - O << "\n\nstatic bool " << CC->getName() - << "(unsigned ValNo, MVT ValVT,\n" - << std::string(CC->getName().size()+13, ' ') - << "MVT LocVT, CCValAssign::LocInfo LocInfo,\n" - << std::string(CC->getName().size()+13, ' ') - << "ISD::ArgFlagsTy ArgFlags, CCState &State) {\n"; + O << "\n\n"; + 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, CCState &State) {\n"; // Emit all of the actions, in order. for (unsigned i = 0, e = CCActions->size(); i != e; ++i) { O << "\n"; -- cgit v1.2.3