Skip to content

Commit

Permalink
BPF: rename BTF_KIND_TAG to BTF_KIND_DECL_TAG
Browse files Browse the repository at this point in the history
Per discussion in https://reviews.llvm.org/D111199,
the existing btf_tag attribute will be renamed to
btf_decl_tag. This patch updated BTF backend to
use btf_decl_tag attribute name and also
renamed BTF_KIND_TAG to BTF_KIND_DECL_TAG.

Differential Revision: https://reviews.llvm.org/D111592
  • Loading branch information
yonghong-song committed Oct 12, 2021
1 parent f7de696 commit 1321e47
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 30 deletions.
2 changes: 1 addition & 1 deletion llvm/lib/Target/BPF/BTF.def
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ HANDLE_BTF_KIND(13, FUNC_PROTO)
HANDLE_BTF_KIND(14, VAR)
HANDLE_BTF_KIND(15, DATASEC)
HANDLE_BTF_KIND(16, FLOAT)
HANDLE_BTF_KIND(17, TAG)
HANDLE_BTF_KIND(17, DECL_TAG)

#undef HANDLE_BTF_KIND
4 changes: 2 additions & 2 deletions llvm/lib/Target/BPF/BTF.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ struct CommonType {
/// Bits 24-27: kind (e.g. int, ptr, array...etc)
/// Bits 28-30: unused
/// Bit 31: kind_flag, currently used by
/// struct, union, fwd and tag
/// struct, union, fwd and decl_tag
uint32_t Info;

/// "Size" is used by INT, ENUM, STRUCT and UNION.
/// "Size" tells the size of the type it is describing.
///
/// "Type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT,
/// FUNC, FUNC_PROTO, VAR and TAG.
/// FUNC, FUNC_PROTO, VAR and DECL_TAG.
/// "Type" is a type_id referring to another type.
union {
uint32_t Size;
Expand Down
15 changes: 8 additions & 7 deletions llvm/lib/Target/BPF/BTFDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,23 +386,24 @@ void BTFTypeFloat::completeType(BTFDebug &BDebug) {
BTFType.NameOff = BDebug.addString(Name);
}

BTFTypeTag::BTFTypeTag(uint32_t BaseTypeId, int ComponentIdx, StringRef Tag)
BTFTypeDeclTag::BTFTypeDeclTag(uint32_t BaseTypeId, int ComponentIdx,
StringRef Tag)
: Tag(Tag) {
Kind = BTF::BTF_KIND_TAG;
Kind = BTF::BTF_KIND_DECL_TAG;
BTFType.Info = Kind << 24;
BTFType.Type = BaseTypeId;
Info = ComponentIdx;
}

void BTFTypeTag::completeType(BTFDebug &BDebug) {
void BTFTypeDeclTag::completeType(BTFDebug &BDebug) {
if (IsCompleted)
return;
IsCompleted = true;

BTFType.NameOff = BDebug.addString(Tag);
}

void BTFTypeTag::emitType(MCStreamer &OS) {
void BTFTypeDeclTag::emitType(MCStreamer &OS) {
BTFTypeBase::emitType(OS);
OS.emitInt32(Info);
}
Expand Down Expand Up @@ -504,12 +505,12 @@ void BTFDebug::processAnnotations(DINodeArray Annotations, uint32_t BaseTypeId,
for (const Metadata *Annotation : Annotations->operands()) {
const MDNode *MD = cast<MDNode>(Annotation);
const MDString *Name = cast<MDString>(MD->getOperand(0));
if (!Name->getString().equals("btf_tag"))
if (!Name->getString().equals("btf_decl_tag"))
continue;

const MDString *Value = cast<MDString>(MD->getOperand(1));
auto TypeEntry = std::make_unique<BTFTypeTag>(BaseTypeId, ComponentIdx,
Value->getString());
auto TypeEntry = std::make_unique<BTFTypeDeclTag>(BaseTypeId, ComponentIdx,
Value->getString());
addType(std::move(TypeEntry));
}
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/BPF/BTFDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,12 @@ class BTFTypeFloat : public BTFTypeBase {
};

/// Handle tags.
class BTFTypeTag : public BTFTypeBase {
class BTFTypeDeclTag : public BTFTypeBase {
uint32_t Info;
StringRef Tag;

public:
BTFTypeTag(uint32_t BaseTypeId, int ComponentId, StringRef Tag);
BTFTypeDeclTag(uint32_t BaseTypeId, int ComponentId, StringRef Tag);
uint32_t getSize() override { return BTFTypeBase::getSize() + 4; }
void completeType(BTFDebug &BDebug) override;
void emitType(MCStreamer &OS) override;
Expand Down
20 changes: 10 additions & 10 deletions llvm/test/CodeGen/BPF/BTF/tag-1.ll
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
; RUN: llc -march=bpfeb -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s

; Source code:
; #define __tag1 __attribute__((btf_tag("tag1")))
; #define __tag2 __attribute__((btf_tag("tag2")))
; #define __tag1 __attribute__((btf_decl_tag("tag1")))
; #define __tag2 __attribute__((btf_decl_tag("tag2")))
; struct t1 {
; int a1;
; int a2 __tag1 __tag2;
Expand Down Expand Up @@ -32,8 +32,8 @@
!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!10 = !DIDerivedType(tag: DW_TAG_member, name: "a2", scope: !6, file: !3, line: 5, baseType: !9, size: 32, offset: 32, annotations: !11)
!11 = !{!12, !13}
!12 = !{!"btf_tag", !"tag1"}
!13 = !{!"btf_tag", !"tag2"}
!12 = !{!"btf_decl_tag", !"tag1"}
!13 = !{!"btf_decl_tag", !"tag2"}
!14 = !{i32 7, !"Dwarf Version", i32 4}
!15 = !{i32 2, !"Debug Info Version", i32 3}
!16 = !{i32 1, !"wchar_size", i32 4}
Expand All @@ -49,35 +49,35 @@
; CHECK-NEXT: .long 7
; CHECK-NEXT: .long 4
; CHECK-NEXT: .long 32 # 0x20
; CHECK-NEXT: .long 10 # BTF_KIND_TAG(id = 2)
; CHECK-NEXT: .long 10 # BTF_KIND_DECL_TAG(id = 2)
; CHECK-NEXT: .long 285212672 # 0x11000000
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 4294967295
; CHECK-NEXT: .long 15 # BTF_KIND_TAG(id = 3)
; CHECK-NEXT: .long 15 # BTF_KIND_DECL_TAG(id = 3)
; CHECK-NEXT: .long 285212672 # 0x11000000
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 4294967295
; CHECK-NEXT: .long 20 # BTF_KIND_INT(id = 4)
; CHECK-NEXT: .long 16777216 # 0x1000000
; CHECK-NEXT: .long 4
; CHECK-NEXT: .long 16777248 # 0x1000020
; CHECK-NEXT: .long 10 # BTF_KIND_TAG(id = 5)
; CHECK-NEXT: .long 10 # BTF_KIND_DECL_TAG(id = 5)
; CHECK-NEXT: .long 285212672 # 0x11000000
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 15 # BTF_KIND_TAG(id = 6)
; CHECK-NEXT: .long 15 # BTF_KIND_DECL_TAG(id = 6)
; CHECK-NEXT: .long 285212672 # 0x11000000
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 24 # BTF_KIND_VAR(id = 7)
; CHECK-NEXT: .long 234881024 # 0xe000000
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 10 # BTF_KIND_TAG(id = 8)
; CHECK-NEXT: .long 10 # BTF_KIND_DECL_TAG(id = 8)
; CHECK-NEXT: .long 285212672 # 0x11000000
; CHECK-NEXT: .long 7
; CHECK-NEXT: .long 4294967295
; CHECK-NEXT: .long 15 # BTF_KIND_TAG(id = 9)
; CHECK-NEXT: .long 15 # BTF_KIND_DECL_TAG(id = 9)
; CHECK-NEXT: .long 285212672 # 0x11000000
; CHECK-NEXT: .long 7
; CHECK-NEXT: .long 4294967295
Expand Down
16 changes: 8 additions & 8 deletions llvm/test/CodeGen/BPF/BTF/tag-2.ll
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
; RUN: llc -march=bpfeb -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s

; Source code:
; #define __tag1 __attribute__((btf_tag("tag1")))
; #define __tag2 __attribute__((btf_tag("tag2")))
; #define __tag1 __attribute__((btf_decl_tag("tag1")))
; #define __tag2 __attribute__((btf_decl_tag("tag2")))
; extern int bar(int a1, int a2) __tag1 __tag2;
; int __tag1 foo(int arg1, int *arg2 __tag1) {
; ; return arg1 + *arg2 + bar(arg1, arg1 + 1);
Expand Down Expand Up @@ -55,7 +55,7 @@ attributes #3 = { nounwind }
!14 = !DILocalVariable(name: "arg1", arg: 1, scope: !8, file: !1, line: 4, type: !11)
!15 = !DILocalVariable(name: "arg2", arg: 2, scope: !8, file: !1, line: 4, type: !12, annotations: !16)
!16 = !{!17}
!17 = !{!"btf_tag", !"tag1"}
!17 = !{!"btf_decl_tag", !"tag1"}
!18 = !DILocation(line: 0, scope: !8)
!19 = !DILocation(line: 5, column: 17, scope: !8)
!20 = !{!21, !21, i64 0}
Expand All @@ -71,7 +71,7 @@ attributes #3 = { nounwind }
!30 = !DISubroutineType(types: !31)
!31 = !{!11, !11, !11}
!32 = !{!17, !33}
!33 = !{!"btf_tag", !"tag2"}
!33 = !{!"btf_decl_tag", !"tag2"}

; CHECK: .long 1 # BTF_KIND_INT(id = 1)
; CHECK-NEXT: .long 16777216 # 0x1000000
Expand All @@ -90,11 +90,11 @@ attributes #3 = { nounwind }
; CHECK-NEXT: .long 15 # BTF_KIND_FUNC(id = 4)
; CHECK-NEXT: .long 201326593 # 0xc000001
; CHECK-NEXT: .long 3
; CHECK-NEXT: .long 19 # BTF_KIND_TAG(id = 5)
; CHECK-NEXT: .long 19 # BTF_KIND_DECL_TAG(id = 5)
; CHECK-NEXT: .long 285212672 # 0x11000000
; CHECK-NEXT: .long 4
; CHECK-NEXT: .long 1
; CHECK-NEXT: .long 19 # BTF_KIND_TAG(id = 6)
; CHECK-NEXT: .long 19 # BTF_KIND_DECL_TAG(id = 6)
; CHECK-NEXT: .long 285212672 # 0x11000000
; CHECK-NEXT: .long 4
; CHECK-NEXT: .long 4294967295
Expand All @@ -108,11 +108,11 @@ attributes #3 = { nounwind }
; CHECK-NEXT: .long 72 # BTF_KIND_FUNC(id = 8)
; CHECK-NEXT: .long 201326594 # 0xc000002
; CHECK-NEXT: .long 7
; CHECK-NEXT: .long 19 # BTF_KIND_TAG(id = 9)
; CHECK-NEXT: .long 19 # BTF_KIND_DECL_TAG(id = 9)
; CHECK-NEXT: .long 285212672 # 0x11000000
; CHECK-NEXT: .long 8
; CHECK-NEXT: .long 4294967295
; CHECK-NEXT: .long 76 # BTF_KIND_TAG(id = 10)
; CHECK-NEXT: .long 76 # BTF_KIND_DECL_TAG(id = 10)
; CHECK-NEXT: .long 285212672 # 0x11000000
; CHECK-NEXT: .long 8
; CHECK-NEXT: .long 4294967295
Expand Down

0 comments on commit 1321e47

Please sign in to comment.