Skip to content

Commit 67a284a

Browse files
[MemProf] Remove memprof attrs and metadata in non-LTO pipelines (#163853)
Follow up to PR163841 to use the new pass in the default non-LTO pipeline setup. This is needed so that we don't use the hints to convert allocation calls when we don't know whether we are linking with a library that supports those APIs.
1 parent 01db10a commit 67a284a

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

clang/test/CodeGen/distributed-thin-lto/supports-hot-cold-new.ll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646
; RUN: --implicit-check-not "!memprof" --implicit-check-not "!callsite" \
4747
; RUN: --implicit-check-not "memprof"="cold"
4848

49+
;; Ensure the attributes and metadata are stripped when running a non-LTO pipeline.
50+
; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -x ir %t.o -S -emit-llvm -o - | FileCheck %s \
51+
; RUN: --implicit-check-not "!memprof" --implicit-check-not "!callsite" \
52+
; RUN: --implicit-check-not "memprof"="cold"
53+
4954
source_filename = "thinlto-distributed-supports-hot-cold-new.ll"
5055
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
5156
target triple = "x86_64-unknown-linux-gnu"

llvm/lib/Passes/PassBuilderPipelines.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,6 +1658,16 @@ PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
16581658

16591659
ModulePassManager MPM;
16601660

1661+
// Currently this pipeline is only invoked in an LTO pre link pass or when we
1662+
// are not running LTO. If that changes the below checks may need updating.
1663+
assert(isLTOPreLink(Phase) || Phase == ThinOrFullLTOPhase::None);
1664+
1665+
// If we are invoking this in non-LTO mode, remove any MemProf related
1666+
// attributes and metadata, as we don't know whether we are linking with
1667+
// a library containing the necessary interfaces.
1668+
if (Phase == ThinOrFullLTOPhase::None)
1669+
MPM.addPass(MemProfRemoveInfo());
1670+
16611671
// Convert @llvm.global.annotations to !annotation metadata.
16621672
MPM.addPass(Annotation2MetadataPass());
16631673

llvm/test/LTO/X86/memprof-supports-hot-cold-new.ll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
; RUN: --implicit-check-not "!memprof" --implicit-check-not "!callsite" \
3535
; RUN: --implicit-check-not "memprof"="cold"
3636

37+
;; Ensure the attributes and metadata are stripped when running a non-LTO pipeline.
38+
; RUN: opt -O3 %t.o -S | FileCheck %s \
39+
; RUN: --implicit-check-not "!memprof" --implicit-check-not "!callsite" \
40+
; RUN: --implicit-check-not "memprof"="cold"
41+
3742
source_filename = "memprof-supports-hot-cold-new.ll"
3843
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
3944
target triple = "x86_64-unknown-linux-gnu"

0 commit comments

Comments
 (0)