diff options
| author | Yonghong Song <yhs@fb.com> | 2019-03-15 04:42:01 +0000 |
|---|---|---|
| committer | Yonghong Song <yhs@fb.com> | 2019-03-15 04:42:01 +0000 |
| commit | 5664d4c8cae925cb04994c6e7e46342aacc64bec (patch) | |
| tree | 5c0776a988665c3287105ad0c010593bf6b06749 /llvm/lib/Target | |
| parent | ef1e06df6ff153ba961608220a8467577c8ccd43 (diff) | |
| download | bcm5719-llvm-5664d4c8cae925cb04994c6e7e46342aacc64bec.tar.gz bcm5719-llvm-5664d4c8cae925cb04994c6e7e46342aacc64bec.zip | |
[BPF] do not generate unused local/global types
The kernel currently has a limit for # of types to be 64KB and
the size of string subsection to be 64KB. A simple bcc tool
runqlat.py generates:
. the size of ~33KB type section, roughly ~10K types
. the size of ~17KB string section
The majority type is from the types referenced by local
variables in the bpf program. For example, the kernel "task_struct"
itself recursively brings in ~900 other types.
This patch did the following optimization to avoid generating
unused types:
. do not generate types for local variables unless they are
function arguments.
. do not generate types for external globals.
If an external global is not used in the program, llvm
already removes it from IR, so global variable saving is
typical small. For runqlat.py, only one variable "llvm.used"
is the external global.
The types for locals and external globals can be added back
once there is a usage for them.
After the above optimization, the runqlat.py generates:
. the size of ~1.5KB type section, roughtly 500 types
. the size of ~0.7KB string section
Signed-off-by: Yonghong Song <yhs@fb.com>
llvm-svn: 356232
Diffstat (limited to 'llvm/lib/Target')
| -rw-r--r-- | llvm/lib/Target/BPF/BTFDebug.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/llvm/lib/Target/BPF/BTFDebug.cpp b/llvm/lib/Target/BPF/BTFDebug.cpp index 3f5531357a9..6e4ee039ca0 100644 --- a/llvm/lib/Target/BPF/BTFDebug.cpp +++ b/llvm/lib/Target/BPF/BTFDebug.cpp @@ -658,12 +658,12 @@ void BTFDebug::beginFunctionImpl(const MachineFunction *MF) { std::unordered_map<uint32_t, StringRef> FuncArgNames; for (const DINode *DN : SP->getRetainedNodes()) { if (const auto *DV = dyn_cast<DILocalVariable>(DN)) { - visitTypeEntry(DV->getType().resolve()); - // Collect function arguments for subprogram func type. uint32_t Arg = DV->getArg(); - if (Arg) + if (Arg) { + visitTypeEntry(DV->getType().resolve()); FuncArgNames[Arg] = DV->getName(); + } } } @@ -749,10 +749,15 @@ void BTFDebug::beginInstruction(const MachineInstr *MI) { void BTFDebug::endModule() { // Collect all types referenced by globals. const Module *M = MMI->getModule(); - for (const DICompileUnit *CUNode : M->debug_compile_units()) { - for (const auto *GVE : CUNode->getGlobalVariables()) { - DIGlobalVariable *GV = GVE->getVariable(); - visitTypeEntry(GV->getType().resolve()); + for (const GlobalVariable &Global : M->globals()) { + // Ignore external globals for now. + if (!Global.getInitializer()) + continue; + + SmallVector<DIGlobalVariableExpression *, 1> GVs; + Global.getDebugInfo(GVs); + for (auto *GVE : GVs) { + visitTypeEntry(GVE->getVariable()->getType().resolve()); } } |

