From 58d43607862096aeb32d72173911c9df244a30f1 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Sat, 19 Jan 2019 08:50:56 +0000 Subject: Update the file headers across all of the LLVM projects in the monorepo to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@351636 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/profile/InstrProfilingFile.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lib/profile/InstrProfilingFile.c') diff --git a/lib/profile/InstrProfilingFile.c b/lib/profile/InstrProfilingFile.c index c4cf3ccd7..99b138b2d 100644 --- a/lib/profile/InstrProfilingFile.c +++ b/lib/profile/InstrProfilingFile.c @@ -1,9 +1,8 @@ /*===- InstrProfilingFile.c - Write instrumentation to a file -------------===*\ |* -|* The LLVM Compiler Infrastructure -|* -|* This file is distributed under the University of Illinois Open Source -|* License. See LICENSE.TXT for details. +|* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +|* See https://llvm.org/LICENSE.txt for license information. +|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |* \*===----------------------------------------------------------------------===*/ -- cgit v1.2.1 From da91a27b9d940dde91a8a3090d2f26ed17d8295e Mon Sep 17 00:00:00 2001 From: Manman Ren Date: Mon, 4 Mar 2019 22:28:38 +0000 Subject: Order File Instrumentation: dump the data in compiler-rt The profile data will be dumped in a file default_xxx.profraw.order. Differential Revision: https://reviews.llvm.org/D57530 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@355343 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/profile/InstrProfilingFile.c | 86 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) (limited to 'lib/profile/InstrProfilingFile.c') diff --git a/lib/profile/InstrProfilingFile.c b/lib/profile/InstrProfilingFile.c index 99b138b2d..8c32bde9d 100644 --- a/lib/profile/InstrProfilingFile.c +++ b/lib/profile/InstrProfilingFile.c @@ -111,6 +111,15 @@ static uint32_t fileWriter(ProfDataWriter *This, ProfDataIOVec *IOVecs, return 0; } +/* TODO: make buffer size controllable by an internal option, and compiler can pass the size + to runtime via a variable. */ +static uint32_t orderFileWriter(FILE *File, const uint32_t *DataStart) { + if (fwrite(DataStart, sizeof(uint32_t), INSTR_ORDER_FILE_BUFFER_SIZE, File) != + INSTR_ORDER_FILE_BUFFER_SIZE) + return 1; + return 0; +} + static void initFileWriter(ProfDataWriter *This, FILE *File) { This->Write = fileWriter; This->WriterCtx = File; @@ -260,6 +269,27 @@ static int writeFile(const char *OutputName) { return RetVal; } +/* Write order data to file \c OutputName. */ +static int writeOrderFile(const char *OutputName) { + int RetVal; + FILE *OutputFile; + + OutputFile = fopen(OutputName, "w"); + + if (!OutputFile) { + PROF_WARN("can't open file with mode ab: %s\n", OutputName); + return -1; + } + + FreeHook = &free; + setupIOBuffer(); + const uint32_t *DataBegin = __llvm_profile_begin_orderfile(); + RetVal = orderFileWriter(OutputFile, DataBegin); + + fclose(OutputFile); + return RetVal; +} + static void truncateCurrentFile(void) { const char *Filename; char *FilenameBuf; @@ -648,6 +678,62 @@ int __llvm_profile_dump(void) { return rc; } +/* Order file data will be saved in a file with suffx .order. */ +static const char *OrderFileSuffix = ".order"; + +COMPILER_RT_VISIBILITY +int __llvm_orderfile_write_file(void) { + int rc, Length, LengthBeforeAppend, SuffixLength; + const char *Filename; + char *FilenameBuf; + int PDeathSig = 0; + + SuffixLength = strlen(OrderFileSuffix); + Length = getCurFilenameLength() + SuffixLength; + FilenameBuf = (char *)COMPILER_RT_ALLOCA(Length + 1); + Filename = getCurFilename(FilenameBuf, 1); + + /* Check the filename. */ + if (!Filename) { + PROF_ERR("Failed to write file : %s\n", "Filename not set"); + return -1; + } + + /* Append order file suffix */ + LengthBeforeAppend = strlen(Filename); + memcpy(FilenameBuf + LengthBeforeAppend, OrderFileSuffix, SuffixLength); + FilenameBuf[LengthBeforeAppend + SuffixLength] = '\0'; + + /* Check if there is llvm/runtime version mismatch. */ + if (GET_VERSION(__llvm_profile_get_version()) != INSTR_PROF_RAW_VERSION) { + PROF_ERR("Runtime and instrumentation version mismatch : " + "expected %d, but get %d\n", + INSTR_PROF_RAW_VERSION, + (int)GET_VERSION(__llvm_profile_get_version())); + return -1; + } + + // Temporarily suspend getting SIGKILL when the parent exits. + PDeathSig = lprofSuspendSigKill(); + + /* Write order data to the file. */ + rc = writeOrderFile(Filename); + if (rc) + PROF_ERR("Failed to write file \"%s\": %s\n", Filename, strerror(errno)); + + // Restore SIGKILL. + if (PDeathSig == 1) + lprofRestoreSigKill(); + + return rc; +} + +COMPILER_RT_VISIBILITY +int __llvm_orderfile_dump(void) { + int rc = __llvm_orderfile_write_file(); + return rc; +} + static void writeFileWithoutReturn(void) { __llvm_profile_write_file(); } COMPILER_RT_VISIBILITY -- cgit v1.2.1 From f4bdc161222c5769fb0e2a5b6e9fb24962d1e08f Mon Sep 17 00:00:00 2001 From: Manman Ren Date: Tue, 5 Mar 2019 01:21:40 +0000 Subject: Revert compiler-rt diffs for order file instrumentation to get bot green! This caused issues on Linux/Windows and other platforms. r355343 355350 355350 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@355363 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/profile/InstrProfilingFile.c | 86 ---------------------------------------- 1 file changed, 86 deletions(-) (limited to 'lib/profile/InstrProfilingFile.c') diff --git a/lib/profile/InstrProfilingFile.c b/lib/profile/InstrProfilingFile.c index 8c32bde9d..99b138b2d 100644 --- a/lib/profile/InstrProfilingFile.c +++ b/lib/profile/InstrProfilingFile.c @@ -111,15 +111,6 @@ static uint32_t fileWriter(ProfDataWriter *This, ProfDataIOVec *IOVecs, return 0; } -/* TODO: make buffer size controllable by an internal option, and compiler can pass the size - to runtime via a variable. */ -static uint32_t orderFileWriter(FILE *File, const uint32_t *DataStart) { - if (fwrite(DataStart, sizeof(uint32_t), INSTR_ORDER_FILE_BUFFER_SIZE, File) != - INSTR_ORDER_FILE_BUFFER_SIZE) - return 1; - return 0; -} - static void initFileWriter(ProfDataWriter *This, FILE *File) { This->Write = fileWriter; This->WriterCtx = File; @@ -269,27 +260,6 @@ static int writeFile(const char *OutputName) { return RetVal; } -/* Write order data to file \c OutputName. */ -static int writeOrderFile(const char *OutputName) { - int RetVal; - FILE *OutputFile; - - OutputFile = fopen(OutputName, "w"); - - if (!OutputFile) { - PROF_WARN("can't open file with mode ab: %s\n", OutputName); - return -1; - } - - FreeHook = &free; - setupIOBuffer(); - const uint32_t *DataBegin = __llvm_profile_begin_orderfile(); - RetVal = orderFileWriter(OutputFile, DataBegin); - - fclose(OutputFile); - return RetVal; -} - static void truncateCurrentFile(void) { const char *Filename; char *FilenameBuf; @@ -678,62 +648,6 @@ int __llvm_profile_dump(void) { return rc; } -/* Order file data will be saved in a file with suffx .order. */ -static const char *OrderFileSuffix = ".order"; - -COMPILER_RT_VISIBILITY -int __llvm_orderfile_write_file(void) { - int rc, Length, LengthBeforeAppend, SuffixLength; - const char *Filename; - char *FilenameBuf; - int PDeathSig = 0; - - SuffixLength = strlen(OrderFileSuffix); - Length = getCurFilenameLength() + SuffixLength; - FilenameBuf = (char *)COMPILER_RT_ALLOCA(Length + 1); - Filename = getCurFilename(FilenameBuf, 1); - - /* Check the filename. */ - if (!Filename) { - PROF_ERR("Failed to write file : %s\n", "Filename not set"); - return -1; - } - - /* Append order file suffix */ - LengthBeforeAppend = strlen(Filename); - memcpy(FilenameBuf + LengthBeforeAppend, OrderFileSuffix, SuffixLength); - FilenameBuf[LengthBeforeAppend + SuffixLength] = '\0'; - - /* Check if there is llvm/runtime version mismatch. */ - if (GET_VERSION(__llvm_profile_get_version()) != INSTR_PROF_RAW_VERSION) { - PROF_ERR("Runtime and instrumentation version mismatch : " - "expected %d, but get %d\n", - INSTR_PROF_RAW_VERSION, - (int)GET_VERSION(__llvm_profile_get_version())); - return -1; - } - - // Temporarily suspend getting SIGKILL when the parent exits. - PDeathSig = lprofSuspendSigKill(); - - /* Write order data to the file. */ - rc = writeOrderFile(Filename); - if (rc) - PROF_ERR("Failed to write file \"%s\": %s\n", Filename, strerror(errno)); - - // Restore SIGKILL. - if (PDeathSig == 1) - lprofRestoreSigKill(); - - return rc; -} - -COMPILER_RT_VISIBILITY -int __llvm_orderfile_dump(void) { - int rc = __llvm_orderfile_write_file(); - return rc; -} - static void writeFileWithoutReturn(void) { __llvm_profile_write_file(); } COMPILER_RT_VISIBILITY -- cgit v1.2.1 From 3137e93cfd656fb907f6b357bb73c91f901e493a Mon Sep 17 00:00:00 2001 From: Manman Ren Date: Fri, 8 Mar 2019 15:30:56 +0000 Subject: Reland compiler-rt support for order file instrumentation. r355343 was landed and was reverted in r355363 due to build breakage. This patch adds Linux/Windows support on top of r355343. In this patch, Darwin should be working with testing case. Linux should be working, I will enable the testing case in a follwup diff. Windows/Other should be building. Correct implementation for Other platforms will be added. Thanks David for reviewing the original diff, helping me with issues on Linux, and giving suggestions for adding support for Other platforms. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@355701 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/profile/InstrProfilingFile.c | 86 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) (limited to 'lib/profile/InstrProfilingFile.c') diff --git a/lib/profile/InstrProfilingFile.c b/lib/profile/InstrProfilingFile.c index 99b138b2d..8c32bde9d 100644 --- a/lib/profile/InstrProfilingFile.c +++ b/lib/profile/InstrProfilingFile.c @@ -111,6 +111,15 @@ static uint32_t fileWriter(ProfDataWriter *This, ProfDataIOVec *IOVecs, return 0; } +/* TODO: make buffer size controllable by an internal option, and compiler can pass the size + to runtime via a variable. */ +static uint32_t orderFileWriter(FILE *File, const uint32_t *DataStart) { + if (fwrite(DataStart, sizeof(uint32_t), INSTR_ORDER_FILE_BUFFER_SIZE, File) != + INSTR_ORDER_FILE_BUFFER_SIZE) + return 1; + return 0; +} + static void initFileWriter(ProfDataWriter *This, FILE *File) { This->Write = fileWriter; This->WriterCtx = File; @@ -260,6 +269,27 @@ static int writeFile(const char *OutputName) { return RetVal; } +/* Write order data to file \c OutputName. */ +static int writeOrderFile(const char *OutputName) { + int RetVal; + FILE *OutputFile; + + OutputFile = fopen(OutputName, "w"); + + if (!OutputFile) { + PROF_WARN("can't open file with mode ab: %s\n", OutputName); + return -1; + } + + FreeHook = &free; + setupIOBuffer(); + const uint32_t *DataBegin = __llvm_profile_begin_orderfile(); + RetVal = orderFileWriter(OutputFile, DataBegin); + + fclose(OutputFile); + return RetVal; +} + static void truncateCurrentFile(void) { const char *Filename; char *FilenameBuf; @@ -648,6 +678,62 @@ int __llvm_profile_dump(void) { return rc; } +/* Order file data will be saved in a file with suffx .order. */ +static const char *OrderFileSuffix = ".order"; + +COMPILER_RT_VISIBILITY +int __llvm_orderfile_write_file(void) { + int rc, Length, LengthBeforeAppend, SuffixLength; + const char *Filename; + char *FilenameBuf; + int PDeathSig = 0; + + SuffixLength = strlen(OrderFileSuffix); + Length = getCurFilenameLength() + SuffixLength; + FilenameBuf = (char *)COMPILER_RT_ALLOCA(Length + 1); + Filename = getCurFilename(FilenameBuf, 1); + + /* Check the filename. */ + if (!Filename) { + PROF_ERR("Failed to write file : %s\n", "Filename not set"); + return -1; + } + + /* Append order file suffix */ + LengthBeforeAppend = strlen(Filename); + memcpy(FilenameBuf + LengthBeforeAppend, OrderFileSuffix, SuffixLength); + FilenameBuf[LengthBeforeAppend + SuffixLength] = '\0'; + + /* Check if there is llvm/runtime version mismatch. */ + if (GET_VERSION(__llvm_profile_get_version()) != INSTR_PROF_RAW_VERSION) { + PROF_ERR("Runtime and instrumentation version mismatch : " + "expected %d, but get %d\n", + INSTR_PROF_RAW_VERSION, + (int)GET_VERSION(__llvm_profile_get_version())); + return -1; + } + + // Temporarily suspend getting SIGKILL when the parent exits. + PDeathSig = lprofSuspendSigKill(); + + /* Write order data to the file. */ + rc = writeOrderFile(Filename); + if (rc) + PROF_ERR("Failed to write file \"%s\": %s\n", Filename, strerror(errno)); + + // Restore SIGKILL. + if (PDeathSig == 1) + lprofRestoreSigKill(); + + return rc; +} + +COMPILER_RT_VISIBILITY +int __llvm_orderfile_dump(void) { + int rc = __llvm_orderfile_write_file(); + return rc; +} + static void writeFileWithoutReturn(void) { __llvm_profile_write_file(); } COMPILER_RT_VISIBILITY -- cgit v1.2.1