[cmake] Explicitly mark libraries defined in lib/ as "Component Libraries"
Summary:
Most libraries are defined in the lib/ directory but there are also a
few libraries defined in tools/ e.g. libLLVM, libLTO. I'm defining
"Component Libraries" as libraries defined in lib/ that may be included in
libLLVM.so. Explicitly marking the libraries in lib/ as component
libraries allows us to remove some fragile checks that attempt to
differentiate between lib/ libraries and tools/ libraires:
1. In tools/llvm-shlib, because
llvm_map_components_to_libnames(LIB_NAMES "all") returned a list of
all libraries defined in the whole project, there was custom code
needed to filter out libraries defined in tools/, none of which should
be included in libLLVM.so. This code assumed that any library
defined as static was from lib/ and everything else should be
excluded.
With this change, llvm_map_components_to_libnames(LIB_NAMES, "all")
only returns libraries that have been added to the LLVM_COMPONENT_LIBS
global cmake property, so this custom filtering logic can be removed.
Doing this also fixes the build with BUILD_SHARED_LIBS=ON
and LLVM_BUILD_LLVM_DYLIB=ON.
2. There was some code in llvm_add_library that assumed that
libraries defined in lib/ would not have LLVM_LINK_COMPONENTS or
ARG_LINK_COMPONENTS set. This is only true because libraries
defined lib lib/ use LLVMBuild.txt and don't set these values.
This code has been fixed now to check if the library has been
explicitly marked as a component library, which should now make it
easier to remove LLVMBuild at some point in the future.
I have tested this patch on Windows, MacOS and Linux with release builds
and the following combinations of CMake options:
- "" (No options)
- -DLLVM_BUILD_LLVM_DYLIB=ON
- -DLLVM_LINK_LLVM_DYLIB=ON
- -DBUILD_SHARED_LIBS=ON
- -DBUILD_SHARED_LIBS=ON -DLLVM_BUILD_LLVM_DYLIB=ON
- -DBUILD_SHARED_LIBS=ON -DLLVM_LINK_LLVM_DYLIB=ON
Reviewers: beanz, smeenai, compnerd, phosek
Reviewed By: beanz
Subscribers: wuzish, jholewinski, arsenm, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, nhaehnle, mgorny, mehdi_amini, sbc100, jgravelle-google, hiraditya, aheejin, fedor.sergeev, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, steven_wu, rogfer01, MartinMosbeck, brucehoult, the_o, dexonsmith, PkmX, jocewei, jsji, dang, Jim, lenary, s.egerton, pzheng, sameer.abuasal, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70179
2019-11-14 13:39:58 +08:00
|
|
|
add_llvm_component_library(LLVMMC
|
2014-06-19 02:17:25 +08:00
|
|
|
ConstantPools.cpp
|
2010-08-17 02:35:43 +08:00
|
|
|
ELFObjectWriter.cpp
|
2011-09-25 06:06:35 +08:00
|
|
|
MCAsmBackend.cpp
|
2009-08-23 06:07:08 +08:00
|
|
|
MCAsmInfo.cpp
|
|
|
|
MCAsmInfoCOFF.cpp
|
|
|
|
MCAsmInfoDarwin.cpp
|
2013-10-16 09:34:32 +08:00
|
|
|
MCAsmInfoELF.cpp
|
2017-02-22 09:23:18 +08:00
|
|
|
MCAsmInfoWasm.cpp
|
2019-07-10 03:21:01 +08:00
|
|
|
MCAsmInfoXCOFF.cpp
|
2018-03-06 22:07:01 +08:00
|
|
|
MCAsmMacro.cpp
|
2009-06-24 18:03:44 +08:00
|
|
|
MCAsmStreamer.cpp
|
2009-08-21 19:28:56 +08:00
|
|
|
MCAssembler.cpp
|
2009-08-27 10:08:37 +08:00
|
|
|
MCCodeEmitter.cpp
|
2016-01-29 08:49:42 +08:00
|
|
|
MCCodeView.cpp
|
2009-06-24 06:01:43 +08:00
|
|
|
MCContext.cpp
|
2011-09-25 06:06:35 +08:00
|
|
|
MCDwarf.cpp
|
2010-12-18 01:45:22 +08:00
|
|
|
MCELFObjectTargetWriter.cpp
|
2010-08-17 02:35:43 +08:00
|
|
|
MCELFStreamer.cpp
|
2009-08-31 16:06:59 +08:00
|
|
|
MCExpr.cpp
|
2015-12-29 17:06:16 +08:00
|
|
|
MCFragment.cpp
|
2009-08-27 15:57:12 +08:00
|
|
|
MCInst.cpp
|
2009-09-14 13:22:47 +08:00
|
|
|
MCInstPrinter.cpp
|
2011-08-09 03:09:02 +08:00
|
|
|
MCInstrAnalysis.cpp
|
2015-05-16 05:29:43 +08:00
|
|
|
MCInstrDesc.cpp
|
2020-03-30 03:09:07 +08:00
|
|
|
MCInstrInfo.cpp
|
2010-05-18 07:08:19 +08:00
|
|
|
MCLabel.cpp
|
2014-03-29 15:34:53 +08:00
|
|
|
MCLinkerOptimizationHint.cpp
|
2009-08-21 19:28:56 +08:00
|
|
|
MCMachOStreamer.cpp
|
2010-12-17 00:09:19 +08:00
|
|
|
MCMachObjectTargetWriter.cpp
|
2009-08-21 19:28:56 +08:00
|
|
|
MCNullStreamer.cpp
|
2011-07-20 14:35:24 +08:00
|
|
|
MCObjectFileInfo.cpp
|
2010-06-17 04:04:22 +08:00
|
|
|
MCObjectStreamer.cpp
|
2010-03-19 17:28:59 +08:00
|
|
|
MCObjectWriter.cpp
|
[CSSPGO] Pseudo probe encoding and emission.
This change implements pseudo probe encoding and emission for CSSPGO. Please see RFC here for more context: https://groups.google.com/g/llvm-dev/c/1p1rdYbL93s
Pseudo probes are in the form of intrinsic calls on IR/MIR but they do not turn into any machine instructions. Instead they are emitted into the binary as a piece of data in standalone sections. The probe-specific sections are not needed to be loaded into memory at execution time, thus they do not incur a runtime overhead.
**ELF object emission**
The binary data to emit are organized as two ELF sections, i.e, the `.pseudo_probe_desc` section and the `.pseudo_probe` section. The `.pseudo_probe_desc` section stores a function descriptor for each function and the `.pseudo_probe` section stores the actual probes, each fo which corresponds to an IR basic block or an IR function callsite. A function descriptor is stored as a module-level metadata during the compilation and is serialized into the object file during object emission.
Both the probe descriptors and pseudo probes can be emitted into a separate ELF section per function to leverage the linker for deduplication. A `.pseudo_probe` section shares the same COMDAT group with the function code so that when the function is dead, the probes are dead and disposed too. On the contrary, a `.pseudo_probe_desc` section has its own COMDAT group. This is because even if a function is dead, its probes may be inlined into other functions and its descriptor is still needed by the profile generation tool.
The format of `.pseudo_probe_desc` section looks like:
```
.section .pseudo_probe_desc,"",@progbits
.quad 6309742469962978389 // Func GUID
.quad 4294967295 // Func Hash
.byte 9 // Length of func name
.ascii "_Z5funcAi" // Func name
.quad 7102633082150537521
.quad 138828622701
.byte 12
.ascii "_Z8funcLeafi"
.quad 446061515086924981
.quad 4294967295
.byte 9
.ascii "_Z5funcBi"
.quad -2016976694713209516
.quad 72617220756
.byte 7
.ascii "_Z3fibi"
```
For each `.pseudoprobe` section, the encoded binary data consists of a single function record corresponding to an outlined function (i.e, a function with a code entry in the `.text` section). A function record has the following format :
```
FUNCTION BODY (one for each outlined function present in the text section)
GUID (uint64)
GUID of the function
NPROBES (ULEB128)
Number of probes originating from this function.
NUM_INLINED_FUNCTIONS (ULEB128)
Number of callees inlined into this function, aka number of
first-level inlinees
PROBE RECORDS
A list of NPROBES entries. Each entry contains:
INDEX (ULEB128)
TYPE (uint4)
0 - block probe, 1 - indirect call, 2 - direct call
ATTRIBUTE (uint3)
reserved
ADDRESS_TYPE (uint1)
0 - code address, 1 - address delta
CODE_ADDRESS (uint64 or ULEB128)
code address or address delta, depending on ADDRESS_TYPE
INLINED FUNCTION RECORDS
A list of NUM_INLINED_FUNCTIONS entries describing each of the inlined
callees. Each record contains:
INLINE SITE
GUID of the inlinee (uint64)
ID of the callsite probe (ULEB128)
FUNCTION BODY
A FUNCTION BODY entry describing the inlined function.
```
To support building a context-sensitive profile, probes from inlinees are grouped by their inline contexts. An inline context is logically a call path through which a callee function lands in a caller function. The probe emitter builds an inline tree based on the debug metadata for each outlined function in the form of a trie tree. A tree root is the outlined function. Each tree edge stands for a callsite where inlining happens. Pseudo probes originating from an inlinee function are stored in a tree node and the tree path starting from the root all the way down to the tree node is the inline context of the probes. The emission happens on the whole tree top-down recursively. Probes of a tree node will be emitted altogether with their direct parent edge. Since a pseudo probe corresponds to a real code address, for size savings, the address is encoded as a delta from the previous probe except for the first probe. Variant-sized integer encoding, aka LEB128, is used for address delta and probe index.
**Assembling**
Pseudo probes can be printed as assembly directives alternatively. This allows for good assembly code readability and also provides a view of how optimizations and pseudo probes affect each other, especially helpful for diff time assembly analysis.
A pseudo probe directive has the following operands in order: function GUID, probe index, probe type, probe attributes and inline context. The directive is generated by the compiler and can be parsed by the assembler to form an encoded `.pseudoprobe` section in the object file.
A example assembly looks like:
```
foo2: # @foo2
# %bb.0: # %bb0
pushq %rax
testl %edi, %edi
.pseudoprobe 837061429793323041 1 0 0
je .LBB1_1
# %bb.2: # %bb2
.pseudoprobe 837061429793323041 6 2 0
callq foo
.pseudoprobe 837061429793323041 3 0 0
.pseudoprobe 837061429793323041 4 0 0
popq %rax
retq
.LBB1_1: # %bb1
.pseudoprobe 837061429793323041 5 1 0
callq *%rsi
.pseudoprobe 837061429793323041 2 0 0
.pseudoprobe 837061429793323041 4 0 0
popq %rax
retq
# -- End function
.section .pseudo_probe_desc,"",@progbits
.quad 6699318081062747564
.quad 72617220756
.byte 3
.ascii "foo"
.quad 837061429793323041
.quad 281547593931412
.byte 4
.ascii "foo2"
```
With inlining turned on, the assembly may look different around %bb2 with an inlined probe:
```
# %bb.2: # %bb2
.pseudoprobe 837061429793323041 3 0
.pseudoprobe 6699318081062747564 1 0 @ 837061429793323041:6
.pseudoprobe 837061429793323041 4 0
popq %rax
retq
```
**Disassembling**
We have a disassembling tool (llvm-profgen) that can display disassembly alongside with pseudo probes. So far it only supports ELF executable file.
An example disassembly looks like:
```
00000000002011a0 <foo2>:
2011a0: 50 push rax
2011a1: 85 ff test edi,edi
[Probe]: FUNC: foo2 Index: 1 Type: Block
2011a3: 74 02 je 2011a7 <foo2+0x7>
[Probe]: FUNC: foo2 Index: 3 Type: Block
[Probe]: FUNC: foo2 Index: 4 Type: Block
[Probe]: FUNC: foo Index: 1 Type: Block Inlined: @ foo2:6
2011a5: 58 pop rax
2011a6: c3 ret
[Probe]: FUNC: foo2 Index: 2 Type: Block
2011a7: bf 01 00 00 00 mov edi,0x1
[Probe]: FUNC: foo2 Index: 5 Type: IndirectCall
2011ac: ff d6 call rsi
[Probe]: FUNC: foo2 Index: 4 Type: Block
2011ae: 58 pop rax
2011af: c3 ret
```
Reviewed By: wmi
Differential Revision: https://reviews.llvm.org/D91878
2020-12-09 07:37:32 +08:00
|
|
|
MCPseudoProbe.cpp
|
2012-07-28 00:25:20 +08:00
|
|
|
MCRegisterInfo.cpp
|
2015-07-11 06:13:43 +08:00
|
|
|
MCSchedule.cpp
|
2009-08-01 01:02:00 +08:00
|
|
|
MCSection.cpp
|
2010-05-08 01:29:48 +08:00
|
|
|
MCSectionCOFF.cpp
|
2009-08-13 13:07:35 +08:00
|
|
|
MCSectionELF.cpp
|
2009-08-11 02:15:01 +08:00
|
|
|
MCSectionMachO.cpp
|
2017-02-22 09:23:18 +08:00
|
|
|
MCSectionWasm.cpp
|
2019-07-10 03:21:01 +08:00
|
|
|
MCSectionXCOFF.cpp
|
2009-06-24 18:03:44 +08:00
|
|
|
MCStreamer.cpp
|
2011-07-02 04:45:01 +08:00
|
|
|
MCSubtargetInfo.cpp
|
2009-08-14 12:14:45 +08:00
|
|
|
MCSymbol.cpp
|
2015-06-03 04:38:46 +08:00
|
|
|
MCSymbolELF.cpp
|
2020-04-03 21:13:13 +08:00
|
|
|
MCSymbolXCOFF.cpp
|
2014-04-23 19:16:03 +08:00
|
|
|
MCTargetOptions.cpp
|
2020-03-04 07:47:43 +08:00
|
|
|
MCTargetOptionsCommandFlags.cpp
|
2009-08-14 12:14:45 +08:00
|
|
|
MCValue.cpp
|
2017-02-22 09:23:18 +08:00
|
|
|
MCWasmObjectTargetWriter.cpp
|
|
|
|
MCWasmStreamer.cpp
|
2011-05-22 11:01:05 +08:00
|
|
|
MCWin64EH.cpp
|
2017-06-22 04:58:17 +08:00
|
|
|
MCWinCOFFStreamer.cpp
|
2016-10-11 06:49:37 +08:00
|
|
|
MCWinEH.cpp
|
2019-07-10 03:21:01 +08:00
|
|
|
MCXCOFFObjectTargetWriter.cpp
|
|
|
|
MCXCOFFStreamer.cpp
|
2010-03-19 18:43:15 +08:00
|
|
|
MachObjectWriter.cpp
|
2014-07-03 10:01:39 +08:00
|
|
|
StringTableBuilder.cpp
|
2011-06-29 11:26:17 +08:00
|
|
|
SubtargetFeature.cpp
|
2017-02-22 09:23:18 +08:00
|
|
|
WasmObjectWriter.cpp
|
2011-09-25 06:06:35 +08:00
|
|
|
WinCOFFObjectWriter.cpp
|
2019-07-10 03:21:01 +08:00
|
|
|
XCOFFObjectWriter.cpp
|
2015-02-11 11:28:02 +08:00
|
|
|
|
|
|
|
ADDITIONAL_HEADER_DIRS
|
|
|
|
${LLVM_MAIN_INCLUDE_DIR}/llvm/MC
|
2020-10-10 00:41:21 +08:00
|
|
|
|
|
|
|
LINK_COMPONENTS
|
|
|
|
Support
|
|
|
|
BinaryFormat
|
|
|
|
DebugInfoCodeView
|
2009-06-24 06:01:43 +08:00
|
|
|
)
|
2011-02-19 06:06:14 +08:00
|
|
|
|
|
|
|
add_subdirectory(MCParser)
|
|
|
|
add_subdirectory(MCDisassembler)
|