!9834 输出aot code comment信息

Merge pull request !9834 from zhao1d/zld
This commit is contained in:
openharmony_ci 2024-11-22 06:40:33 +00:00 committed by Gitee
commit 61b4552be0
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
16 changed files with 154 additions and 8 deletions

View File

@ -74,6 +74,12 @@ ohos_shared_library("libcompiler_service") {
defines += [ "CODE_SIGN_ENABLE" ]
}
if (!ark_standalone_build && !(defined(is_arkui_x) && is_arkui_x) &&
is_ohos && is_standard_system) {
external_deps += [ "init:libbegetutil" ]
defines += [ "ENABLE_COMPILER_SERVICE_GET_PARAMETER" ]
}
install_enable = true
install_images = [ "system" ]

View File

@ -35,6 +35,7 @@ const std::string APP_SIGNATURE = "appIdentifier";
const std::string ABC_PATH = "ABC-Path";
const std::string TARGET_COMPILER_MODE = "target-compiler-mode";
const std::string COMPILER_PKG_INFO = "compiler-pkg-info";
const std::string COMPILER_ENABLE_AOT_CODE_COMMENT = "compiler-enable-aot-code-comment";
} // namespace ArgsIdx

View File

@ -35,6 +35,9 @@
#ifdef CODE_SIGN_ENABLE
#include "local_code_sign_kit.h"
#endif
#ifdef ENABLE_COMPILER_SERVICE_GET_PARAMETER
#include "base/startup/init/interfaces/innerkits/include/syspara/parameters.h"
#endif
#include "system_ability_definition.h"
namespace OHOS::ArkCompiler {
@ -96,6 +99,13 @@ int32_t AotCompilerImpl::PrepareArgs(const std::unordered_map<std::string, std::
hapArgs_.argVector.emplace_back(Symbols::PREFIX + argPair.first + Symbols::EQ + argPair.second);
}
}
#ifdef ENABLE_COMPILER_SERVICE_GET_PARAMETER
bool enableAotCodeComment = OHOS::system::GetBoolParameter("ark.aot.code_comment.enable", false);
if (enableAotCodeComment) {
hapArgs_.argVector.emplace_back(Symbols::PREFIX + ArgsIdx::COMPILER_ENABLE_AOT_CODE_COMMENT +
Symbols::EQ + "true");
}
#endif
hapArgs_.argVector.emplace_back(abcPath);
return ERR_OK;
}

View File

@ -222,7 +222,11 @@ int Main(const int argc, const char **argv)
compilerStats.SetIsLiteCg(isEnableLiteCG);
AOTFileGenerator generator(&log, &logList, &aotCompilationEnv, cOptions.triple_, isEnableLiteCG);
if (runtimeOptions.IsTargetCompilerMode() && runtimeOptions.IsEnableAotCodeComment()) {
if (!generator.CreateAOTCodeCommentFile(cOptions.outputFileName_ + AOTFileManager::FILE_EXTENSION_AN)) {
LOG_COMPILER(ERROR) << "Generate aot code comment file failed.";
}
}
passManager.CompileValidFiles(generator, ret, compilerStats);
if (compilerStats.GetCompilerMethodCount() == 0) {
return runtimeOptions.IsPartialCompilerMode() ? ERR_AN_EMPTY : ERR_OK;

View File

@ -92,6 +92,7 @@ struct CompilationOptions {
bool isEnableInductionVariableAnalysis_ {false};
bool isEnableVerifierPass_ {true};
bool isEnableBaselinePgo_ {false};
bool enableAotCodeComment_ {false};
std::map<std::string, std::vector<std::string>> optionSelectMethods_;
std::map<std::string, std::vector<std::string>> optionSkipMethods_;
};

View File

@ -166,8 +166,21 @@ public:
{
return codeInfo_;
}
void SetAotCodeCommentFile(const std::string &aotCodeCommentFile)
{
litecgCodeCommentFile_ = aotCodeCommentFile;
}
const std::string &GetAotCodeCommentFile() const
{
return litecgCodeCommentFile_;
}
protected:
CodeInfo codeInfo_;
private:
std::string litecgCodeCommentFile_ = "";
};
class CodeGeneratorImpl {

View File

@ -113,6 +113,7 @@ void LiteCGAssembler::Run(const CompilerLog &log, [[maybe_unused]] bool fastComp
liteCG.SetupLiteCGEmitMemoryManager(&codeInfo_, isJit ? AllocateCodeSectionOnDemand : AllocateCodeSection,
SaveFunc2Addr, SaveFunc2FPtoPrevSPDelta, SaveFunc2CalleeOffsetInfo,
SavePC2DeoptInfo, SavePC2CallSiteInfo);
liteCG.SetAotCodeCommentFile(GetAotCodeCommentFile());
#ifdef JIT_ENABLE_CODE_SIGN
isJit &= JitFort::IsResourceAvailable();
if (isJit) {

View File

@ -332,6 +332,16 @@ public:
ehExclusiveFile = ehExclusive;
}
void SetEmitAotCodeCommentFile(const std::string &aotCodeCommentFile)
{
aotCodeCommentFilePath = aotCodeCommentFile;
}
const std::string &GetEmitAotCodeCommentFile() const
{
return aotCodeCommentFilePath;
}
static std::unordered_set<std::string> &GetDumpPhases()
{
return dumpPhases;
@ -887,6 +897,7 @@ private:
std::string ehExclusiveFile;
/* we don't do exception handling in this list */
std::vector<std::string> ehExclusiveFunctionName;
std::string aotCodeCommentFilePath = "";
static std::string targetArch;
static std::unordered_set<std::string> dumpPhases;

View File

@ -22,6 +22,7 @@
#include <map>
#include <array>
#include <sstream>
#include <sys/stat.h>
#include "isa.h"
#include "asm_info.h"
#include "cg.h"

View File

@ -63,6 +63,7 @@ public:
#endif
void DumpCGIR();
void DoCG(bool isJit = false);
void SetAotCodeCommentFile(const std::string &aotCodeCommentFile);
private:
Module &module;

View File

@ -2796,9 +2796,12 @@ void Emitter::EmitHexUnsigned(uint64 num)
void Emitter::WriteDebugCommentToFile()
{
#ifdef ARK_LITECG_DEBUG
std::ofstream file(DEFAULT_PATH.c_str(), std::ios::app);
struct stat buffer;
std::string filePath = cg->GetCGOptions().GetEmitAotCodeCommentFile();
std::string outputFile = stat(filePath.c_str(), &buffer) == 0 ? filePath : DEFAULT_PATH;
std::ofstream file(outputFile.c_str(), std::ios::app);
if (!file.is_open()) {
std::cerr << DEFAULT_PATH << " Unable to open file for writing." << std::endl;
std::cerr << outputFile << " Unable to open file for writing." << std::endl;
return;
}

View File

@ -83,6 +83,11 @@ LiteCG &LiteCG::SetupLiteCGEmitMemoryManager(
return *this;
}
void LiteCG::SetAotCodeCommentFile(const std::string &aotCodeCommentFile)
{
cgOptions->SetEmitAotCodeCommentFile(aotCodeCommentFile);
}
void LiteCG::DoCG(bool isJit)
{
bool timePhases = cgOptions->IsEnableTimePhases();

View File

@ -320,8 +320,13 @@ uintptr_t Module::GetSectionAddr(ElfSecName sec) const
return assembler_->GetSectionAddr(sec);
}
void Module::RunAssembler(const CompilerLog &log, bool fastCompileMode, bool isJit)
void Module::RunAssembler(const CompilerLog &log, bool fastCompileMode, bool isJit, const std::string &filename)
{
if (!IsLLVM()) {
assembler_->SetAotCodeCommentFile(filename);
} else {
assembler_->SetAotCodeCommentFile("");
}
assembler_->Run(log, fastCompileMode, isJit);
}
@ -592,7 +597,7 @@ void AOTFileGenerator::CompileLatestModuleThenDestroy(bool isJit)
{
TimeScope timescope("LLVMIROpt", const_cast<CompilerLog *>(log_));
bool fastCompileMode = compilationEnv_->GetJSOptions().GetFastAOTCompileMode();
latestModule->RunAssembler(*(log_), fastCompileMode, isJit);
latestModule->RunAssembler(*(log_), fastCompileMode, isJit, GetAotCodeCommentFile());
}
{
TimeScope timescope("LLVMCodeGen", const_cast<CompilerLog *>(log_));
@ -804,4 +809,50 @@ bool AOTFileGenerator::SaveSnapshotFile()
SetSecurityLabel(aiPath.c_str());
return true;
}
bool AOTFileGenerator::CreateAOTCodeCommentFile(const std::string &filename)
{
if (!CreateDirIfNotExist(filename)) {
LOG_COMPILER(ERROR) << "Fail to access dir: " << filename;
return false;
}
std::string realPath;
if (!panda::ecmascript::RealPath(filename, realPath, false)) {
LOG_COMPILER(ERROR) << "Fail to get realPath: " << filename;
return false;
}
auto index = realPath.find_last_of('/');
if (index == std::string::npos) {
LOG_COMPILER(ERROR) << "Path: " << realPath << " is illegal";
return false;
}
std::string aotCodeCommentFile = realPath.substr(0, index) + "/aot_code_comment.txt";
SetAotCodeCommentFile(aotCodeCommentFile);
if (FileExist(aotCodeCommentFile.c_str())) {
if (Unlink(aotCodeCommentFile.c_str()) == -1) {
SetAotCodeCommentFile("");
LOG_COMPILER(ERROR) << "remove " << aotCodeCommentFile << " failed and errno is " << errno;
return false;
}
}
std::ofstream file(aotCodeCommentFile.c_str(), std::ofstream::app);
if (!file.is_open()) {
SetAotCodeCommentFile("");
LOG_COMPILER(ERROR) << "Failed to create " << aotCodeCommentFile;
return false;
}
file.close();
if (!panda::ecmascript::SetFileModeAsDefault(aotCodeCommentFile)) {
SetAotCodeCommentFile("");
Unlink(aotCodeCommentFile.c_str());
LOG_COMPILER(ERROR) << "Fail to set file mode: " << aotCodeCommentFile;
return false;
}
return true;
}
} // namespace panda::ecmascript::kungfu

View File

@ -83,7 +83,8 @@ public:
return std::make_tuple(addrBeforeText, sizeBeforeText, addrAfterText, sizeAfterText);
}
void RunAssembler(const CompilerLog &log, bool fastCompileMode, bool isJit = false);
void RunAssembler(const CompilerLog &log, bool fastCompileMode, bool isJit = false,
const std::string &filename = "");
void DisassemblerFunc(std::map<uintptr_t, std::string> &addr2name, uint64_t textOffset, const CompilerLog &log,
const MethodLogList &logList, std::ostringstream &codeStream);
@ -221,6 +222,19 @@ public:
bool GetMemoryCodeInfos(MachineCodeDesc &machineCodeDesc);
void JitCreateLitecgModule();
bool isAArch64() const;
bool CreateAOTCodeCommentFile(const std::string &filename);
const std::string &GetAotCodeCommentFile() const
{
return aotCodeCommentFile_;
}
void SetAotCodeCommentFile(const std::string &filename)
{
aotCodeCommentFile_ = filename;
}
private:
// collect aot component info
void CollectCodeInfo(Module *module, uint32_t moduleIdx);
@ -236,6 +250,7 @@ private:
std::map<uint32_t, uint32_t> methodToEntryIndexMap_ {};
const bool useLiteCG_;
CodeInfo::CodeSpaceOnDemand jitCodeSpace_ {};
std::string aotCodeCommentFile_ = "";
};
enum class StubFileKind {

View File

@ -196,7 +196,9 @@ const std::string PUBLIC_API HELP_OPTION_MSG =
"--async-load-abc-test: Enable asynchronous load abc test. Default: 'false'\n"
"--compiler-enable-concurrent: Enable concurrent compile(only support in ark_stub_compiler).\n"
" Default: 'true'\n"
"--compiler-opt-frame-state-elimination: Enable frame state elimination. Default: 'true'\n\n";
"--compiler-opt-frame-state-elimination: Enable frame state elimination. Default: 'true'\n"
"--compiler-enable-aot-code-comment Enable generate aot_code_comment.txt file during compilation.\n"
" Default : 'false'\n\n";
bool JSRuntimeOptions::ParseCommand(const int argc, const char **argv)
{
@ -336,6 +338,7 @@ bool JSRuntimeOptions::ParseCommand(const int argc, const char **argv)
{"compiler-enable-concurrent", required_argument, nullptr, OPTION_COMPILER_ENABLE_CONCURRENT},
{"compiler-opt-frame-state-elimination", required_argument, nullptr,
OPTION_COMPILER_OPT_FRAME_STATE_ELIMINATION},
{"compiler-enable-aot-code-comment", required_argument, nullptr, OPTION_COMPILER_ENABLE_AOT_CODE_COMMENT},
{nullptr, 0, nullptr, 0},
};
@ -1308,6 +1311,14 @@ bool JSRuntimeOptions::ParseCommand(const int argc, const char **argv)
return false;
}
break;
case OPTION_COMPILER_ENABLE_AOT_CODE_COMMENT:
ret = ParseBoolParam(&argBool);
if (ret) {
SetEnableAotCodeComment(argBool);
} else {
return false;
}
break;
default:
LOG_ECMA(ERROR) << "Invalid option\n";
return false;

View File

@ -216,6 +216,7 @@ enum CommandValues {
OPTION_OPEN_ARK_TOOLS,
OPTION_COMPILER_OPT_FRAME_STATE_ELIMINATION,
OPTION_COMPILER_ENABLE_PGO_SPACE,
OPTION_COMPILER_ENABLE_AOT_CODE_COMMENT,
};
static_assert(OPTION_SPLIT_ONE == 64); // add new option at the bottom, DO NOT modify this value
static_assert(OPTION_SPLIT_TWO == 128); // add new option at the bottom, DO NOT modify this value
@ -1965,6 +1966,16 @@ public:
return enablePgoSpace_;
}
void SetEnableAotCodeComment(bool value)
{
enableAotCodeComment_ = value;
}
bool IsEnableAotCodeComment() const
{
return enableAotCodeComment_;
}
public:
static constexpr int32_t MAX_APP_COMPILE_METHOD_SIZE = 4_KB;
@ -2126,6 +2137,7 @@ private:
bool enableTypedOpProfiler_ {false};
bool enableBranchProfiling_ {true};
bool enablePgoSpace_ {false};
bool enableAotCodeComment_ {false};
bool testAssert_ {false};
std::pair<uint32_t, uint32_t> compileMethodsRange_ {0, UINT32_MAX};
arg_list_t compileCodegenOption_ {{""}};