Skip to content

Commit bcd5787

Browse files
committed
simplify copts, add extra tests
Created using spr 1.3.8-beta.1
1 parent a161378 commit bcd5787

File tree

3 files changed

+57
-12
lines changed

3 files changed

+57
-12
lines changed

llvm/lib/Transforms/Instrumentation/AllocToken.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,24 @@ cl::opt<std::string> ClFuncPrefix("alloc-token-prefix",
6767
cl::desc("The allocation function prefix"),
6868
cl::Hidden, cl::init("__alloc_token_"));
6969

70-
cl::opt<std::optional<uint64_t>, false, cl::parser<uint64_t>>
70+
cl::opt<uint64_t>
7171
ClMaxTokens("alloc-token-max",
7272
cl::desc("Maximum number of tokens (0 = target SIZE_MAX)"),
73-
cl::Hidden, cl::init(std::nullopt));
73+
cl::Hidden, cl::init(0));
7474

75-
cl::opt<std::optional<bool>, false, cl::parser<bool>>
75+
cl::opt<bool>
7676
ClFastABI("alloc-token-fast-abi",
7777
cl::desc("The token ID is encoded in the function name"),
78-
cl::Hidden, cl::init(std::nullopt));
78+
cl::Hidden, cl::init(false));
7979

8080
// Instrument libcalls only by default - compatible allocators only need to take
8181
// care of providing standard allocation functions. With extended coverage, also
8282
// instrument non-libcall allocation function calls with !alloc_token
8383
// metadata.
84-
cl::opt<std::optional<bool>, false, cl::parser<bool>>
84+
cl::opt<bool>
8585
ClExtended("alloc-token-extended",
8686
cl::desc("Extend coverage to custom allocation functions"),
87-
cl::Hidden, cl::init(std::nullopt));
87+
cl::Hidden, cl::init(false));
8888

8989
// C++ defines ::operator new (and variants) as replaceable (vs. standard
9090
// library versions), which are nobuiltin, and are therefore not covered by
@@ -252,12 +252,12 @@ static AllocTokenOptions resolveOptions(AllocTokenOptions Opts,
252252
Opts.Extended |= Val->isOne();
253253

254254
// Allow overriding options from command line options.
255-
if (ClMaxTokens.has_value())
256-
Opts.MaxTokens = *ClMaxTokens;
257-
if (ClFastABI.has_value())
258-
Opts.FastABI = *ClFastABI;
259-
if (ClExtended.has_value())
260-
Opts.Extended = *ClExtended;
255+
if (ClMaxTokens.getNumOccurrences())
256+
Opts.MaxTokens = ClMaxTokens;
257+
if (ClFastABI.getNumOccurrences())
258+
Opts.FastABI = ClFastABI;
259+
if (ClExtended.getNumOccurrences())
260+
Opts.Extended = ClExtended;
261261

262262
return Opts;
263263
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; Manually add instcombine to ensure the hot/cold transformation happens before
2+
; the LTO pipeline. The default LTO pipeline includes MemProfRemoveInfo which
3+
; strips the memprof attributes unless the summary index indicates support.
4+
; RUN: opt < %s -passes='function(instcombine),thinlto<O2>' -optimize-hot-cold-new -S | FileCheck %s
5+
; RUN: opt < %s -passes='function(instcombine),lto<O2>' -optimize-hot-cold-new -S | FileCheck %s
6+
; RUN: opt < %s -passes='function(instcombine),alloc-token' -optimize-hot-cold-new -S | FileCheck %s
7+
8+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
9+
10+
declare ptr @_Znwm(i64)
11+
12+
define ptr @new_hot() sanitize_alloc_token {
13+
; CHECK-LABEL: @new_hot(
14+
; CHECK: call {{.*}} @__alloc_token__Znwm12__hot_cold_t(i64 10, i8 -2, i64 2689373973731826898){{.*}} !alloc_token
15+
%ret = call ptr @_Znwm(i64 10) #0, !alloc_token !0
16+
ret ptr %ret
17+
}
18+
19+
attributes #0 = { builtin allocsize(0) "memprof"="hot" }
20+
!0 = !{!"int", i1 false}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
; RUN: opt -module-summary -o %t.thin.bc %s
2+
; RUN: llvm-lto2 run %t.thin.bc -o %t.thin.out \
3+
; RUN: -r=%t.thin.bc,main,plx \
4+
; RUN: -r=%t.thin.bc,_Znwm, \
5+
; RUN: -r=%t.thin.bc,sink,pl \
6+
; RUN: -supports-hot-cold-new -optimize-hot-cold-new
7+
; RUN: llvm-objdump -d -r %t.thin.out.1 | FileCheck %s
8+
9+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
10+
target triple = "x86_64-unknown-linux-gnu"
11+
12+
declare ptr @_Znwm(i64)
13+
14+
@sink = global ptr null
15+
16+
; CHECK-LABEL: <main>:
17+
; CHECK: callq
18+
; CHECK-NEXT: R_X86_64_PLT32 __alloc_token__Znwm12__hot_cold_t
19+
define void @main() sanitize_alloc_token {
20+
%call = call ptr @_Znwm(i64 8) #0
21+
store volatile ptr %call, ptr @sink
22+
ret void
23+
}
24+
25+
attributes #0 = { builtin allocsize(0) "memprof"="hot" }

0 commit comments

Comments
 (0)