Skip to content

Commit d9ec86e

Browse files
committed
Address review comments and minor cleanup.
* Added support for emitting ref metadata on functions. * Added testing for ref metadata on functions. * Fixed up lang ref description. * Renamed tests to match metadatas nameing.
1 parent ecf915e commit d9ec86e

File tree

7 files changed

+61
-15
lines changed

7 files changed

+61
-15
lines changed

llvm/docs/LangRef.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8673,21 +8673,21 @@ denoting if the type contains a pointer.
86738673
'``ref``' Metadata
86748674
^^^^^^^^^^^^^^^^^^
86758675

8676-
The ``ref`` metadata may be attached to a global variable definition with a
8677-
single argument that references a global object. The metadata is lowered to a
8678-
.ref directive which will emit a relocation introducing an explicit dependence
8679-
to the referenced symbol. This is typically used when there is some implicit
8680-
dependence between the symbols that is otherwise opaque to the linker. One such
8681-
example is metadata which is accessed by a runtime with associated
8682-
``__start_<section_name>`` and ``__stop_<section_name>`` symbols.
8676+
The ``ref`` metadata may be attached to a function or global variable
8677+
definition with a single argument that references a global object.
8678+
This is typically used when there is some implicit dependence between the
8679+
symbols that is otherwise opaque to the linker. One such example is metadata
8680+
which is accessed by a runtime with associated ``__start_<section_name>`` and
8681+
``__stop_<section_name>`` symbols.
8682+
8683+
It does not have any effect on non-XCOFF targets.
86838684

86848685
This metadata lowers to the .ref assembly directive which will add a relocation
86858686
representing an implicit reference from the section the global belongs to, to
8686-
the associated symbol. This link will keep the associated symbol alive if the
8687-
section is not garbage collected. More than one associated node can be attached
8688-
to the same global variable.
8687+
the associated symbol. This link will keep the referenced symbol alive if the
8688+
section is not garbage collected. More than one ref node can be attached
8689+
to the same function or global variable.
86898690

8690-
It does not have any effect on non-XCOFF targets.
86918691

86928692
Example:
86938693

llvm/lib/IR/Verifier.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,8 +777,6 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
777777
Check(MD->getNumOperands() == 1, "ref metadata must have one operand",
778778
&GV, MD);
779779
const Metadata *Op = MD->getOperand(0).get();
780-
Check(Op, "ref metadata must have a global value", GO, MD);
781-
782780
const auto *VM = dyn_cast_or_null<ValueAsMetadata>(Op);
783781
Check(VM, "ref metadata must be ValueAsMetadata", GO, MD);
784782
if (VM) {

llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2899,10 +2899,16 @@ void PPCAIXAsmPrinter::emitFunctionEntryLabel() {
28992899
if (!TM.getFunctionSections() || MF->getFunction().hasSection())
29002900
PPCAsmPrinter::emitFunctionEntryLabel();
29012901

2902+
const Function *F = &MF->getFunction();
2903+
29022904
// Emit aliasing label for function entry point label.
2903-
for (const GlobalAlias *Alias : GOAliasMap[&MF->getFunction()])
2905+
for (const GlobalAlias *Alias : GOAliasMap[F])
29042906
OutStreamer->emitLabel(
29052907
getObjFileLowering().getFunctionEntryPointSymbol(Alias, TM));
2908+
2909+
if (F->hasMetadata(LLVMContext::MD_ref)) {
2910+
emitRefMetadata(F);
2911+
}
29062912
}
29072913

29082914
void PPCAIXAsmPrinter::emitPGORefs(Module &M) {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
; RUN: llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff < %s | \
2+
; RUN: FileCheck %s -check-prefixes=NOFSECTS,CHECK
3+
4+
; RUN: llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff --function-sections < %s | \
5+
; RUN: FileCheck %s -check-prefixes=FSECTS,CHECK
6+
7+
@a = global i32 1
8+
@b = global i32 2
9+
@c = global i32 3
10+
11+
define i32 @foo() !ref !0 {
12+
ret i32 0
13+
}
14+
15+
define i32 @bar() !ref !1 !ref !2 {
16+
ret i32 0
17+
}
18+
19+
!0 = !{ptr @a}
20+
!1 = !{ptr @b}
21+
!2 = !{ptr @c}
22+
23+
; NOFSECTS: .foo:
24+
; FSECTS: .csect .foo[PR]
25+
; CHECK: .ref a[RW]
26+
27+
; NOFSECTS: .bar:
28+
; FSECTS: .csect .bar[PR]
29+
; CHECK: .ref b[RW]
30+
; CHECK: .ref c[RW]
31+

llvm/test/Verifier/ref-func.ll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
; RUN: llvm-as < %s -o /dev/null 2>&1
2+
3+
@a = global i32 1
4+
@b = global i32 2
5+
@c = global i32 3, !ref !0
6+
7+
define i32 @foo() !ref !1 {
8+
ret i32 0
9+
}
10+
11+
!0 = !{ptr @a}
12+
!1 = !{ptr @b}

llvm/test/Verifier/ref.ll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,3 @@
2525
; CHECK: ref metadata must have one operand
2626
; CHECK: ptr @d
2727
; CHECK: !3 = !{ptr @c, ptr @a}
28-

0 commit comments

Comments
 (0)