diff --git a/clang/test/Pika/MIP/mip-stat-debug-info.c b/clang/test/Pika/MIP/mip-stat-debug-info.c --- a/clang/test/Pika/MIP/mip-stat-debug-info.c +++ b/clang/test/Pika/MIP/mip-stat-debug-info.c @@ -1,11 +1,28 @@ // REQUIRES: system-darwin && native && asserts // RUN: llvm-odrcov yaml2mip %p/Inputs/mip-stat-debug-info-x86.yaml -p %t.mip // RUN: %clang -isysroot %macos_sdk_root -g -target x86_64-apple-macosx -flto -c -o %t.o %s -// RUN: %clang -isysroot %macos_sdk_root -g -target x86_64-apple-macosx -Wl,-mllvm,-odrcov-use=%t.mip -Wl,-mllvm,-debug-only=mip-stat -o %t %t.o 2>/dev/stdout >/dev/null | FileCheck %s +// RUN: %clang -isysroot %macos_sdk_root -g -target x86_64-apple-macosx -Wl,-mllvm,-odrcov-use=%t.mip -Wl,-mllvm,-debug-only=mip-stat -o %t-ld64.out %t.o 2>%t/logs-ld64 >/dev/null +// RUN: FileCheck %s < %t/logs-ld64 +// RUN: llvm-objdump --section=__text -D %t-ld64.out | FileCheck --check-prefix OUTPUT-ORDER %s +// RUN: %clang -fuse-ld=lld.darwinnew -isysroot %macos_sdk_root -g -target x86_64-apple-macosx -Wl,-mllvm,-odrcov-use=%t.mip -Wl,-mllvm,-debug-only=mip-stat -o %t-lld.out %t.o 2>%t/logs-lld >/dev/null +// RUN: llvm-objdump --section=__text -D %t-lld.out | FileCheck --check-prefix OUTPUT-ORDER %s + +// # ld64 and lld should be running the same code for MIRProfile logic so the +// # output should be exactly the same. +// RUN: diff %t/logs-ld64 %t/logs-lld // RUN: llvm-odrcov yaml2mip %p/Inputs/mip-stat-debug-info-arm64.yaml -p %t-arm64.mip // RUN: %clang -isysroot %macos_sdk_root -g -target arm64-macosx -flto -c -o %t.o %s -// RUN: %clang -isysroot %macos_sdk_root -g -target arm64-macosx -Wl,-mllvm,-odrcov-use=%t-arm64.mip -Wl,-mllvm,-debug-only=mip-stat -o %t %t.o 2>/dev/stdout >/dev/null | FileCheck --check-prefix CHECK-ARM64 %s +// RUN: %clang -isysroot %macos_sdk_root -g -target arm64-macosx -Wl,-mllvm,-odrcov-use=%t-arm64.mip -Wl,-mllvm,-debug-only=mip-stat -o %t-arm64-ld64.out %t.o 2>%t/logs-arm64-ld64 >/dev/null +// RUN: FileCheck --check-prefix CHECK-ARM64 %s < %t/logs-arm64-ld64 +// RUN: llvm-objdump --section=__text -D %t-arm64-ld64.out | FileCheck --check-prefix OUTPUT-ORDER %s +// RUN: %clang -fuse-ld=lld.darwinnew -isysroot %macos_sdk_root -g -target arm64-macosx -Wl,-mllvm,-odrcov-use=%t-arm64.mip -Wl,-mllvm,-debug-only=mip-stat -o %t-arm64-lld.out %t.o 2>%t/logs-arm64-lld >/dev/null +// RUN: FileCheck --check-prefix CHECK-ARM64 %s < %t/logs-arm64-lld +// RUN: llvm-objdump --section=__text -D %t-arm64-lld.out | FileCheck --check-prefix OUTPUT-ORDER %s + +// # ld64 and lld should be running the same code for MIRProfile logic so the +// # output should be exactly the same. +// RUN: diff %t/logs-arm64-ld64 %t/logs-arm64-lld // CHECK: [OdrCov] Parsed profile [[MIP_PATH:.+\.mip]] // CHECK-NEXT: [MachineIRProfileStat] Start @@ -33,6 +50,12 @@ // CHECK-ARM64-NEXT: [MachineIRProfileStat] f3: 24 // CHECK-ARM64-NEXT: [MachineIRProfileStat] main: 56 +// OUTPUT-ORDER: Disassembly of section __TEXT,__text: +// OUTPUT-ORDER: <_f1>: +// OUTPUT-ORDER: <_f2>: +// OUTPUT-ORDER: <_f3>: +// OUTPUT-ORDER: <_f5>: + #include // Hot function diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -52,6 +52,7 @@ #include "llvm/Transforms/Utils/FunctionImportUtils.h" #include "llvm/Transforms/Utils/SplitModule.h" #ifdef __FACEBOOK__ +#include "pika/CodeGen/MIRProfileSummary.h" #include "pika/Transforms/IPO/IVarDirectAccess.h" #endif // __FACEBOOK__ @@ -977,10 +978,19 @@ return StatsFileOrErr.takeError(); std::unique_ptr StatsFile = std::move(StatsFileOrErr.get()); +#ifdef __FACEBOOK__ + MIRProfileSummary::parseProfile(); +#endif + Error Result = runRegularLTO(AddStream); if (!Result) Result = runThinLTO(AddStream, Cache, GUIDPreservedSymbols); +#ifdef __FACEBOOK__ + std::vector temp; + MIRProfileSummary::publishFinalOrderedSymbols(temp); +#endif + if (StatsFile) PrintStatisticsJSON(StatsFile->os());