llvm.org GIT mirror llvm / 9f219e8
Add !callees metadata This patch adds a new kind of metadata that indicates the possible callees of indirect calls. Differential Revision: https://reviews.llvm.org/D37354 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315944 91177308-0d34-0410-b5e6-96231b3b80d8 Matthew Simpson 1 year, 10 months ago
6 changed file(s) with 37 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
48774877 !0 = !{ i64 0, i64 256 }
48784878 !1 = !{ i64 -1, i64 -1 }
48794879
4880 '``callees``' Metadata
4881 ^^^^^^^^^^^^^^^^^^^^^^
4882
4883 ``callees`` metadata may be attached to indirect call sites. If ``callees``
4884 metadata is attached to a call site, and any callee is not among the set of
4885 functions provided by the metadata, the behavior is undefined. The intent of
4886 this metadata is to facilitate optimizations such as indirect-call promotion.
4887 For example, in the code below, the call instruction may only target the
4888 ``add`` or ``sub`` functions:
4889
4890 .. code-block:: llvm
4891
4892 %result = call i64 %binop(i64 %x, i64 %y), !callees !0
4893
4894 ...
4895 !0 = !{i64 (i64, i64)* @add, i64 (i64, i64)* @sub}
4896
48804897 '``unpredictable``' Metadata
48814898 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
48824899
9999 MD_section_prefix = 20, // "section_prefix"
100100 MD_absolute_symbol = 21, // "absolute_symbol"
101101 MD_associated = 22, // "associated"
102 MD_callees = 23, // "callees"
102103 };
103104
104105 /// Known operand bundle tag IDs, which always have the same value. All
8484 MDNode *createRange(Constant *Lo, Constant *Hi);
8585
8686 //===------------------------------------------------------------------===//
87 // Callees metadata.
88 //===------------------------------------------------------------------===//
89
90 /// \brief Return metadata indicating the possible callees of indirect
91 /// calls.
92 MDNode *createCallees(ArrayRef Callees);
93
94 //===------------------------------------------------------------------===//
8795 // AA metadata.
8896 //===------------------------------------------------------------------===//
8997
5858 {MD_section_prefix, "section_prefix"},
5959 {MD_absolute_symbol, "absolute_symbol"},
6060 {MD_associated, "associated"},
61 {MD_callees, "callees"},
6162 };
6263
6364 for (auto &MDKind : MDKinds) {
1313
1414 #include "llvm/IR/MDBuilder.h"
1515 #include "llvm/IR/Constants.h"
16 #include "llvm/IR/Function.h"
1617 #include "llvm/IR/Metadata.h"
1718 using namespace llvm;
1819
9293
9394 // Return the range [Lo, Hi).
9495 return MDNode::get(Context, {createConstant(Lo), createConstant(Hi)});
96 }
97
98 MDNode *MDBuilder::createCallees(ArrayRef Callees) {
99 SmallVector Ops;
100 for (Function *F : Callees)
101 Ops.push_back(createConstant(F));
102 return MDNode::get(Context, Ops);
95103 }
96104
97105 MDNode *MDBuilder::createAnonymousAARoot(StringRef Name, MDNode *Extra) {
99 ; RUN: llvm-lto -thinlto-action=import %t2.bc -thinlto-index=%t3.bc \
1010 ; RUN: -o /dev/null -stats \
1111 ; RUN: 2>&1 | FileCheck %s -check-prefix=LAZY
12 ; LAZY: 51 bitcode-reader - Number of Metadata records loaded
12 ; LAZY: 53 bitcode-reader - Number of Metadata records loaded
1313 ; LAZY: 2 bitcode-reader - Number of MDStrings loaded
1414
1515 ; RUN: llvm-lto -thinlto-action=import %t2.bc -thinlto-index=%t3.bc \
1616 ; RUN: -o /dev/null -disable-ondemand-mds-loading -stats \
1717 ; RUN: 2>&1 | FileCheck %s -check-prefix=NOTLAZY
18 ; NOTLAZY: 60 bitcode-reader - Number of Metadata records loaded
18 ; NOTLAZY: 62 bitcode-reader - Number of Metadata records loaded
1919 ; NOTLAZY: 7 bitcode-reader - Number of MDStrings loaded
2020
2121