Skip to content

Commit 29901dd

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:195ba4572129befa25ca56439515d7cb91587c56 into amd-gfx:44b8a8572373
Local branch amd-gfx 44b8a85 Merged main:702198fc9ac5dba392f9d9ba7c56467996343c0a into amd-gfx:ddd6f4a278f2 Remote branch main 195ba45 [MCAsmParser] .macro/.rept/.irp/.irpc: remove excess \n after expansion
2 parents 44b8a85 + 195ba45 commit 29901dd

File tree

9 files changed

+151
-60
lines changed

9 files changed

+151
-60
lines changed

compiler-rt/lib/ctx_profile/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,12 @@ append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ EXTRA_FLAGS)
1818
if(COMPILER_RT_INCLUDE_TESTS)
1919
add_subdirectory(tests)
2020
endif()
21+
22+
add_compiler_rt_runtime(clang_rt.ctx_profile
23+
STATIC
24+
ARCHS ${CTX_PROFILE_SUPPORTED_ARCH}
25+
OBJECT_LIBS RTSanitizerCommon RTSanitizerCommonLibc
26+
CFLAGS ${EXTRA_FLAGS}
27+
SOURCES ${CTX_PROFILE_SOURCES}
28+
ADDITIONAL_HEADERS ${CTX_PROFILE_HEADERS}
29+
PARENT_TARGET ctx_profile)
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// Simple integration test for contextual instrumentation
2+
//
3+
// Copy the header defining ContextNode.
4+
// RUN: mkdir -p %t_include
5+
// RUN: cp %llvm_src/include/llvm/ProfileData/CtxInstrContextNode.h %t_include/
6+
//
7+
// Compile with ctx instrumentation "on". We treat "theRoot" as callgraph root.
8+
// RUN: %clangxx %s -lclang_rt.ctx_profile -I%t_include -O2 -o %t.bin -mllvm -profile-context-root=theRoot
9+
//
10+
// Run the binary, and observe the profile fetch handler's output.
11+
// RUN: %t.bin | FileCheck %s
12+
13+
#include "CtxInstrContextNode.h"
14+
#include <cstdio>
15+
#include <iostream>
16+
17+
using namespace llvm::ctx_profile;
18+
extern "C" bool __llvm_ctx_profile_fetch(void *Data,
19+
bool (*Writer)(void *,
20+
const ContextNode &));
21+
22+
// avoid name mangling
23+
extern "C" {
24+
__attribute__((noinline)) void someFunction(int I) {
25+
if (I % 2)
26+
printf("check odd\n");
27+
else
28+
printf("check even\n");
29+
}
30+
31+
// block inlining because the pre-inliner otherwise will inline this - it's
32+
// too small.
33+
__attribute__((noinline)) void theRoot() {
34+
printf("check 1\n");
35+
someFunction(1);
36+
#pragma nounroll
37+
for (auto I = 0; I < 2; ++I) {
38+
someFunction(I);
39+
}
40+
}
41+
}
42+
43+
// Make sure the program actually ran correctly.
44+
// CHECK: check 1
45+
// CHECK-NEXT: check odd
46+
// CHECK-NEXT: check even
47+
// CHECK-NEXT: check odd
48+
49+
void printProfile(const ContextNode &Node, const std::string &Indent,
50+
const std::string &Increment) {
51+
std::cout << Indent << "Guid: " << Node.guid() << std::endl;
52+
std::cout << Indent << "Entries: " << Node.entrycount() << std::endl;
53+
std::cout << Indent << Node.counters_size() << " counters and "
54+
<< Node.callsites_size() << " callsites" << std::endl;
55+
std::cout << Indent << "Counter values: ";
56+
for (uint32_t I = 0U; I < Node.counters_size(); ++I)
57+
std::cout << Node.counters()[I] << " ";
58+
std::cout << std::endl;
59+
for (uint32_t I = 0U; I < Node.callsites_size(); ++I)
60+
for (const auto *N = Node.subContexts()[I]; N; N = N->next()) {
61+
std::cout << Indent << "At Index " << I << ":" << std::endl;
62+
printProfile(*N, Indent + Increment, Increment);
63+
}
64+
}
65+
66+
// 8657661246551306189 is theRoot. We expect 2 callsites and 2 counters - one
67+
// for the entry basic block and one for the loop.
68+
// 6759619411192316602 is someFunction. We expect all context instances to show
69+
// the same nr of counters and callsites, but the counters will be different.
70+
// The first context is for the first callsite with theRoot as parent, and the
71+
// second counter in someFunction will be 0 (we pass an odd nr, and the other
72+
// path gets instrumented).
73+
// The second context is in the loop. We expect 2 entries and each of the
74+
// branches would be taken once, so the second counter is 1.
75+
// CHECK-NEXT: Guid: 8657661246551306189
76+
// CHECK-NEXT: Entries: 1
77+
// CHECK-NEXT: 2 counters and 3 callsites
78+
// CHECK-NEXT: Counter values: 1 2
79+
// CHECK-NEXT: At Index 1:
80+
// CHECK-NEXT: Guid: 6759619411192316602
81+
// CHECK-NEXT: Entries: 1
82+
// CHECK-NEXT: 2 counters and 2 callsites
83+
// CHECK-NEXT: Counter values: 1 0
84+
// CHECK-NEXT: At Index 2:
85+
// CHECK-NEXT: Guid: 6759619411192316602
86+
// CHECK-NEXT: Entries: 2
87+
// CHECK-NEXT: 2 counters and 2 callsites
88+
// CHECK-NEXT: Counter values: 2 1
89+
90+
bool profileWriter() {
91+
return __llvm_ctx_profile_fetch(
92+
nullptr, +[](void *, const ContextNode &Node) {
93+
printProfile(Node, "", " ");
94+
return true;
95+
});
96+
}
97+
98+
int main(int argc, char **argv) {
99+
theRoot();
100+
// This would be implemented in a specific RPC handler, but here we just call
101+
// it directly.
102+
return !profileWriter();
103+
}

compiler-rt/test/ctx_profile/lit.cfg.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ def get_required_attr(config, attr_name):
2929
config.test_source_root = os.path.dirname(__file__)
3030
# Default test suffixes.
3131
config.suffixes = [".c", ".cpp", ".test"]
32+
33+
config.substitutions.append(
34+
("%clangxx ", " ".join([config.clang] + config.cxx_mode_flags) + " -ldl -lpthread ")
35+
)

etime-function.mlir

Lines changed: 0 additions & 25 deletions
This file was deleted.

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* Indicate that this is LLVM compiled from the amd-gfx branch. */
1818
#define LLVM_HAVE_BRANCH_AMD_GFX
19-
#define LLVM_MAIN_REVISION 499090
19+
#define LLVM_MAIN_REVISION 499094
2020

2121
/* Define if LLVM_ENABLE_DUMP is enabled */
2222
#cmakedefine LLVM_ENABLE_DUMP

llvm/lib/MC/MCParser/AsmParser.cpp

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2920,6 +2920,10 @@ void AsmParser::handleMacroExit() {
29202920
// Jump to the EndOfStatement we should return to, and consume it.
29212921
jumpToLoc(ActiveMacros.back()->ExitLoc, ActiveMacros.back()->ExitBuffer);
29222922
Lex();
2923+
// If .endm/.endr is followed by \n instead of a comment, consume it so that
2924+
// we don't print an excess \n.
2925+
if (getTok().is(AsmToken::EndOfStatement))
2926+
Lex();
29232927

29242928
// Pop the instantiation entry.
29252929
delete ActiveMacros.back();
@@ -5624,27 +5628,22 @@ MCAsmMacro *AsmParser::parseMacroLikeBody(SMLoc DirectiveLoc) {
56245628
return nullptr;
56255629
}
56265630

5627-
if (Lexer.is(AsmToken::Identifier) &&
5628-
(getTok().getIdentifier() == ".rep" ||
5629-
getTok().getIdentifier() == ".rept" ||
5630-
getTok().getIdentifier() == ".irp" ||
5631-
getTok().getIdentifier() == ".irpc")) {
5632-
++NestLevel;
5633-
}
5634-
5635-
// Otherwise, check whether we have reached the .endr.
5636-
if (Lexer.is(AsmToken::Identifier) && getTok().getIdentifier() == ".endr") {
5637-
if (NestLevel == 0) {
5638-
EndToken = getTok();
5639-
Lex();
5640-
if (Lexer.isNot(AsmToken::EndOfStatement)) {
5641-
printError(getTok().getLoc(),
5642-
"unexpected token in '.endr' directive");
5631+
if (Lexer.is(AsmToken::Identifier)) {
5632+
StringRef Ident = getTok().getIdentifier();
5633+
if (Ident == ".rep" || Ident == ".rept" || Ident == ".irp" ||
5634+
Ident == ".irpc") {
5635+
++NestLevel;
5636+
} else if (Ident == ".endr") {
5637+
if (NestLevel == 0) {
5638+
EndToken = getTok();
5639+
Lex();
5640+
if (Lexer.is(AsmToken::EndOfStatement))
5641+
break;
5642+
printError(getTok().getLoc(), "expected newline");
56435643
return nullptr;
56445644
}
5645-
break;
5645+
--NestLevel;
56465646
}
5647-
--NestLevel;
56485647
}
56495648

56505649
// Otherwise, scan till the end of the statement.

llvm/test/MC/AsmParser/macro-arg.s

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ escape 3
1717

1818
# CHECK: .long -1
1919
# CHECK-NEXT: .long -1
20-
# CHECK-EMPTY:
2120
double
22-
# CHECK: .long -1
2321
# CHECK-NEXT: .long -1
24-
# CHECK-EMPTY:
22+
# CHECK-NEXT: .long -1
2523
double ,
26-
# CHECK: .long 1
24+
# CHECK-NEXT: .long 1
2725
# CHECK-NEXT: .long -1
2826
double 1
2927
# CHECK: .long 2

llvm/test/MC/AsmParser/macro-irp.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
.irp reg,%eax,%ebx
44
pushl \reg
55
.endr
6+
pushl %ecx
67

78
// CHECK: pushl %eax
89
// CHECK: pushl %ebx
10+
// CHECK-NEXT: pushl %ecx
911

1012
.irp reg,%eax,%ebx
1113
.irp imm,4,3,5

llvm/test/MC/AsmParser/macro-rept.s

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
// RUN: llvm-mc -triple x86_64-unknown-unknown %s | FileCheck %s
1+
# RUN: llvm-mc -triple x86_64 %s | FileCheck %s
22

33
.rept 2
44
.long 1
55
.endr
66
# 3 "a.s"
7-
/// Test line marker after .endr \n.
7+
## Test line marker after .endr \n.
88

99
.rept 3
1010
.rept 2
1111
.long 0
1212
.endr
13-
.endr
14-
15-
// CHECK: .long 1
16-
// CHECK: .long 1
13+
.endr # comment after .endr
14+
.long 42
1715

18-
// CHECK: .long 0
19-
// CHECK: .long 0
20-
// CHECK: .long 0
16+
# CHECK: .long 1
17+
# CHECK-NEXT: .long 1
2118

22-
// CHECK: .long 0
23-
// CHECK: .long 0
24-
// CHECK: .long 0
19+
# CHECK: .long 0
20+
# CHECK-NEXT: .long 0
21+
# CHECK-NEXT: .long 0
22+
# CHECK-NEXT: .long 0
23+
# CHECK-NEXT: .long 0
24+
# CHECK-NEXT: .long 0
25+
# CHECK-NEXT: .long 42

0 commit comments

Comments
 (0)