!2981 update log for time snapshot and optimizer

Merge pull request !2981 from ChunyangWang/updatelog
This commit is contained in:
openharmony_ci 2022-11-18 09:35:16 +00:00 committed by Gitee
commit 84bedc0fbf
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
16 changed files with 210 additions and 99 deletions

View File

@ -150,7 +150,10 @@ void Circuit::GetAllGates(std::vector<GateRef>& gateList) const
for (size_t out = sizeof(Gate); out < circuitSize_;
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
out += Gate::GetGateSize(reinterpret_cast<const Out *>(LoadGatePtrConst(GateRef(out)))->GetIndex() + 1)) {
gateList.push_back(GetGateRef(reinterpret_cast<const Out *>(LoadGatePtrConst(GateRef(out)))->GetGateConst()));
auto gatePtr = reinterpret_cast<const Out *>(LoadGatePtrConst(GateRef(out)))->GetGateConst();
if (!gatePtr->GetOpCode().IsNop()) {
gateList.push_back(GetGateRef(gatePtr));
}
}
}

View File

@ -1548,7 +1548,8 @@ void Partition::MergeUses(std::map<uint32_t, std::vector<std::shared_ptr<Partiti
}
}
GlobalValueNumbering::GlobalValueNumbering(Circuit *circuit) : acc_(GateAccessor(circuit))
GlobalValueNumbering::GlobalValueNumbering(Circuit *circuit, bool enableLog)
: acc_(GateAccessor(circuit)), enableLog_(enableLog)
{
}
@ -1635,6 +1636,9 @@ void GlobalValueNumbering::TrySplit(std::queue<std::shared_ptr<Partition>> &work
void GlobalValueNumbering::EliminateRedundantGates(const std::vector<std::shared_ptr<Partition>> &partitions)
{
if (IsLogEnabled()) {
Print(partitions);
}
for (auto partition : partitions) {
std::map<uint32_t, std::vector<std::shared_ptr<PartitionNode>>> indexToUses;
partition->MergeUses(indexToUses);
@ -1671,4 +1675,27 @@ void GlobalValueNumbering::Run()
}
EliminateRedundantGates(partitions);
}
void GlobalValueNumbering::Print(const std::vector<std::shared_ptr<Partition>> &partitions)
{
for (auto partition : partitions) {
auto kingNode = partition->GetHead();
std::string log = "[global-value-numbering] replace [";
bool noGateReplaced = true;
for (auto node = kingNode->GetNext(); node != nullptr; node = node->GetNext()) {
if (noGateReplaced) {
noGateReplaced = false;
} else {
log += ", ";
}
log += std::to_string(acc_.GetId(node->GetGate()));
}
if (noGateReplaced) {
continue;
}
log += "] with " + acc_.GetOpCode(kingNode->GetGate()).Str() + " " +
std::to_string(acc_.GetId(kingNode->GetGate()));
LOG_COMPILER(INFO) << log;
}
}
} // namespace panda::ecmascript::kungfu

View File

@ -291,7 +291,7 @@ private:
class GlobalValueNumbering {
public:
GlobalValueNumbering(Circuit *circuit);
GlobalValueNumbering(Circuit *circuit, bool enableLog);
~GlobalValueNumbering() = default;
void GetPartitionNodes(std::vector<std::shared_ptr<PartitionNode>> &nodes);
void SplitByOpCode(const std::vector<std::shared_ptr<PartitionNode>> &nodes,
@ -301,8 +301,14 @@ public:
std::vector<std::shared_ptr<Partition>> &partitions);
void EliminateRedundantGates(const std::vector<std::shared_ptr<Partition>> &partitions);
void Run();
void Print(const std::vector<std::shared_ptr<Partition>> &partitions);
private:
bool IsLogEnabled() const
{
return enableLog_;
}
GateAccessor acc_;
bool enableLog_ {false};
};
} // namespace panda::ecmascript::kungfu

View File

@ -46,9 +46,9 @@ bool AotMethodLogList::IncludesMethod(const std::string &fileName, const std::st
if (fileMethods_.find(fileName) == fileMethods_.end()) {
return false;
}
std::vector mehtodVector = fileMethods_.at(fileName);
auto it = find(mehtodVector.begin(), mehtodVector.end(), methodName);
return (it != mehtodVector.end());
std::vector methodVector = fileMethods_.at(fileName);
auto it = find(methodVector.begin(), methodVector.end(), methodName);
return (it != methodVector.end());
}
std::vector<std::string> AotMethodLogList::spiltString(const std::string &str, const char ch)
@ -73,8 +73,8 @@ void AotMethodLogList::ParseFileMethodsName(const std::string &logMethods)
}
}
TimeScope::TimeScope(std::string name, std::string methodName, CompilerLog* log)
: ClockScope(), name_(std::move(name)), methodName_(std::move(methodName)), log_(log)
TimeScope::TimeScope(std::string name, std::string methodName, uint32_t methodOffset, CompilerLog* log)
: ClockScope(), name_(std::move(name)), methodName_(std::move(methodName)), methodOffset_(methodOffset), log_(log)
{
if (log_->GetEnableCompilerLogTime()) {
startTime_ = ClockScope().GetCurTime();
@ -85,11 +85,14 @@ TimeScope::~TimeScope()
{
if (log_->GetEnableCompilerLogTime()) {
timeUsed_ = ClockScope().GetCurTime() - startTime_;
LOG_COMPILER(INFO) << std::setw(PASS_LENS) << name_ << " " << std::setw(TIME_LENS) <<
GetShortName(methodName_) << " time used:" << timeUsed_ / MILLION_TIME << "ms";
if (log_->CertainMethod() && log_->GetEnableMethodLog()) {
LOG_COMPILER(INFO) << std::setw(PASS_LENS) << name_ << " " << std::setw(METHOD_LENS)
<< GetShortName(methodName_) << " offset:" << std::setw(OFFSET_LENS) << methodOffset_
<< " time used:" << std::setw(TIME_LENS) << timeUsed_ / MILLION_TIME << "ms";
}
std::string shortName = GetShortName(methodName_);
log_->AddPassTime(name_, timeUsed_);
log_->AddMethodTime(shortName, timeUsed_);
log_->AddMethodTime(shortName, methodOffset_, timeUsed_);
}
}
@ -119,8 +122,9 @@ void CompilerLog::PrintPassTime() const
}
for (auto [key, val] : PassTimeMap) {
LOG_COMPILER(INFO) << std::setw(PASS_LENS) << val << " Total cost time is "<< std::setw(TIME_LENS)
<< key / MILLION_TIME << "ms " << "percentage:" << std::fixed << std::setprecision(PERCENT_LENS)
<< key / allPassTimeforAllMethods * HUNDRED_TIME << "% ";
<< key / MILLION_TIME << "ms " << "percentage:"
<< std::fixed << std::setprecision(PERCENT_LENS)
<< key / allPassTimeforAllMethods * HUNDRED_TIME << "% ";
}
}
@ -128,8 +132,8 @@ void CompilerLog::PrintMethodTime() const
{
double methodTotalTime = 0;
auto myMap = timeMethodMap_;
std::multimap<double, std::string> MethodTimeMap;
std::map<std::string, double>::iterator it;
std::multimap<double, std::pair<uint32_t, std::string>> MethodTimeMap;
std::map<std::pair<uint32_t, std::string>, double>::iterator it;
for (it = myMap.begin(); it != myMap.end(); it++) {
MethodTimeMap.insert(make_pair(it->second, it->first));
}
@ -137,10 +141,12 @@ void CompilerLog::PrintMethodTime() const
methodTotalTime += key;
}
for (auto [key, val] : MethodTimeMap) {
LOG_COMPILER(INFO) << "method:" << std::setw(METHOD_LENS) << val << " all pass cost time is "
<< std::setw(TIME_LENS) << key / MILLION_TIME << "ms " << "percentage:" << std::fixed
<< std::setprecision(PERCENT_LENS) << key / methodTotalTime * HUNDRED_TIME << "% ";
LOG_COMPILER(INFO) << "method:" << std::setw(METHOD_LENS) << val.second
<< " offset:" << std::setw(OFFSET_LENS) << val.first << " all pass cost time is "
<< std::setw(TIME_LENS) << key / MILLION_TIME << "ms " << "percentage:" << std::fixed
<< std::setprecision(PERCENT_LENS) << key / methodTotalTime * HUNDRED_TIME << "% ";
}
LOG_COMPILER(INFO) << "total compile time is " << std::setw(TIME_LENS) << methodTotalTime / MILLION_TIME << "ms ";
}
void CompilerLog::PrintTime() const
@ -151,22 +157,15 @@ void CompilerLog::PrintTime() const
PrintMethodTime();
}
void CompilerLog::AddMethodTime(const std::string& name, double time)
void CompilerLog::AddMethodTime(const std::string& name, uint32_t id, double time)
{
if (timeMethodMap_.count(name) == 0) {
timeMethodMap_.insert(std::make_pair(name, time));
} else {
timeMethodMap_.insert(std::make_pair(name, time + timeMethodMap_.at(name)));
}
auto methodInfo = std::make_pair(id, name);
timeMethodMap_[methodInfo] += time;
}
void CompilerLog::AddPassTime(const std::string& name, double time)
{
if (timePassMap_.count(name) == 0) {
timePassMap_.insert(std::make_pair(name, time));
} else {
timePassMap_.insert(std::make_pair(name, time + timePassMap_.at(name)));
}
timePassMap_[name] += time;
}
// namespace panda::ecmascript::kungfu
}

View File

@ -83,17 +83,33 @@ public:
compilerLogTime_ = compilerLogTime;
}
bool GetEnableMethodLog() const
{
return enableMethodLog_;
}
void SetEnableMethodLog(bool enableMethodLog)
{
enableMethodLog_ = enableMethodLog;
}
bool EnableMethodCIRLog() const
{
return GetEnableMethodLog() && OutputCIR();
}
void PrintPassTime() const;
void PrintMethodTime() const;
void PrintTime() const;
void AddMethodTime(const std::string& name, double time);
void AddMethodTime(const std::string& name, uint32_t id, double time);
void AddPassTime(const std::string& name, double time);
private:
static constexpr int PASS_LENS = 25;
static constexpr int METHOD_LENS = 18;
static constexpr int PASS_LENS = 32;
static constexpr int METHOD_LENS = 16;
static constexpr int OFFSET_LENS = 8;
static constexpr int PERCENT_LENS = 4;
static constexpr int TIME_LENS = 12;
static constexpr int TIME_LENS = 8;
static constexpr int MILLION_TIME = 1000;
static constexpr int HUNDRED_TIME = 100;
@ -106,8 +122,9 @@ private:
bool outputType_ {false};
bool enableBCTrace_ {false};
bool compilerLogTime_ {true};
bool enableMethodLog_ {false};
std::map<std::string, double> timePassMap_ {};
std::map<std::string, double> timeMethodMap_ {};
std::map<std::pair<uint32_t, std::string>, double> timeMethodMap_ {};
};
class MethodLogList {
@ -140,18 +157,21 @@ private:
class TimeScope : public ClockScope {
public:
TimeScope(std::string name, std::string methodName, CompilerLog* log);
TimeScope(std::string name, std::string methodName, uint32_t methodOffset, CompilerLog* log);
~TimeScope();
private:
static constexpr int PASS_LENS = 25;
static constexpr int TIME_LENS = 12;
static constexpr int PASS_LENS = 32;
static constexpr int METHOD_LENS = 16;
static constexpr int OFFSET_LENS = 8;
static constexpr int TIME_LENS = 8;
static constexpr int MILLION_TIME = 1000;
std::string name_ {""};
double startTime_ {0};
double timeUsed_ {0};
std::string methodName_ {""};
uint32_t methodOffset_ {0};
CompilerLog *log_ {nullptr};
const std::string GetShortName(const std::string& methodName);

View File

@ -86,8 +86,6 @@ public:
uint64_t length = 0;
std::string funcName(LLVMGetValueName2(func, reinterpret_cast<size_t *>(&length)));
ASSERT(length != 0);
LOG_COMPILER(INFO) << " ";
LOG_COMPILER(INFO) << "CollectCodeInfo for AOT func: " << funcName.c_str() << " methodID:" << idx;
addr2name[funcEntry] = funcName;
int delta = assembler_->GetFpDeltaPrevFramSp(func, log);
ASSERT(delta >= 0 && (delta % sizeof(uintptr_t) == 0));

View File

@ -44,6 +44,10 @@ void GuardEliminating::ProcessTwoConditions(GateRef gate, std::set<GateRef> &con
return;
}
if (conditionSet.count(left) > 0 && conditionSet.count(right) > 0) {
if (IsLogEnabled()) {
LOG_COMPILER(INFO) << "[guard-eliminating] delete guard " << acc_.GetId(guard) << " for "
<< acc_.GetOpCode(gate).Str() << " " << acc_.GetId(gate);
}
acc_.DeleteGuardAndFrameState(gate);
} else if (conditionSet.count(left) > 0) {
acc_.ReplaceValueIn(guard, right, 0);
@ -63,6 +67,10 @@ void GuardEliminating::ProcessOneCondition(GateRef gate, std::set<GateRef> &cond
ASSERT(acc_.GetOpCode(guard) == OpCode::GUARD);
auto condition = acc_.GetValueIn(guard, 0);
if (conditionSet.count(condition) > 0) {
if (IsLogEnabled()) {
LOG_COMPILER(INFO) << "[guard-eliminating] delete guard " << acc_.GetId(guard) << " for "
<< acc_.GetOpCode(gate).Str() << " " << acc_.GetId(gate);
}
acc_.DeleteGuardAndFrameState(gate);
} else {
conditionSet.insert(condition);
@ -102,6 +110,10 @@ void GuardEliminating::RemoveOneTrusted(GateRef gate)
ASSERT(acc_.GetOpCode(guard) == OpCode::GUARD);
auto condition = acc_.GetValueIn(guard);
if (condition == builder_.Boolean(true)) {
if (IsLogEnabled()) {
LOG_COMPILER(INFO) << "[guard-eliminating] delete guard " << acc_.GetId(guard) << " for "
<< acc_.GetOpCode(gate).Str() << " " << acc_.GetId(gate);
}
acc_.DeleteGuardAndFrameState(gate);
}
}
@ -114,6 +126,10 @@ void GuardEliminating::RemoveTwoTrusted(GateRef gate)
auto left = acc_.GetValueIn(condition, 0);
auto right = acc_.GetValueIn(condition, 1);
if (left == builder_.Boolean(true) && right == builder_.Boolean(true)) {
if (IsLogEnabled()) {
LOG_COMPILER(INFO) << "[guard-eliminating] delete guard " << acc_.GetId(guard) << " for "
<< acc_.GetOpCode(gate).Str() << " " << acc_.GetId(gate);
}
acc_.DeleteGuardAndFrameState(gate);
} else if (left == builder_.Boolean(true)) {
acc_.ReplaceValueIn(guard, right, 0);
@ -170,7 +186,11 @@ void GuardEliminating::RemoveTrustedTypeCheck(const std::vector<GateRef>& guarde
void GuardEliminating::Run()
{
// eliminate duplicate typecheck
GlobalValueNumbering(circuit_).Run();
if (IsLogEnabled()) {
LOG_COMPILER(INFO) << "";
}
GlobalValueNumbering(circuit_, IsLogEnabled()).Run();
// calculate dominator tree
std::vector<GateRef> bbGatesList;

View File

@ -270,7 +270,6 @@ kungfu::CalleeRegAndOffsetVec LLVMAssembler::GetCalleeReg2Offset(LLVMValueRef fn
auto value = std::stoi(std::string(Attr.getValueAsString()));
info.push_back(std::make_pair(RegNum, value));
(void)log;
LOG_COMPILER(INFO) << " RegNum:" << RegNum << " value:" << value << std::endl;
}
}
}

View File

@ -35,8 +35,8 @@ namespace panda::ecmascript::kungfu {
struct CompilationInfo;
class PassData {
public:
explicit PassData(Circuit *circuit, CompilerLog *log, bool enableMethodLog, std::string name)
: circuit_(circuit), log_(log), enableMethodLog_(enableMethodLog), name_(name)
explicit PassData(Circuit *circuit, CompilerLog *log, std::string methodName, uint32_t methodOffset = 0)
: circuit_(circuit), log_(log), methodName_(methodName), methodOffset_(methodOffset)
{
}
@ -61,22 +61,22 @@ public:
return log_;
}
bool GetEnableMethodLog() const
{
return enableMethodLog_;
}
const std::string& GetMethodName() const
{
return name_;
return methodName_;
}
uint32_t GetMethodOffset() const
{
return methodOffset_;
}
private:
Circuit *circuit_ {nullptr};
ControlFlowGraph cfg_;
CompilerLog *log_ {nullptr};
bool enableMethodLog_ {false};
std::string name_;
std::string methodName_;
uint32_t methodOffset_;
};
template<typename T1>
@ -99,9 +99,9 @@ class TypeInferPass {
public:
bool Run(PassData* data, BytecodeCircuitBuilder *builder, CompilationInfo *info, size_t methodId, bool hasTypes)
{
TimeScope timescope("TypeInferPass", data->GetMethodName(), data->GetLog());
TimeScope timescope("TypeInferPass", data->GetMethodName(), data->GetMethodOffset(), data->GetLog());
if (hasTypes) {
bool enableLog = data->GetEnableMethodLog() && data->GetLog()->OutputType();
bool enableLog = data->GetLog()->GetEnableMethodLog() && data->GetLog()->OutputType();
TypeInfer typeInfer(builder, data->GetCircuit(), info, methodId, enableLog, data->GetMethodName());
typeInfer.TraverseCircuit();
}
@ -113,8 +113,8 @@ class TSTypeLoweringPass {
public:
bool Run(PassData *data, CompilationInfo *info)
{
TimeScope timescope("TSTypeLoweringPass", data->GetMethodName(), data->GetLog());
bool enableLog = data->GetEnableMethodLog() && data->GetLog()->OutputCIR();
TimeScope timescope("TSTypeLoweringPass", data->GetMethodName(), data->GetMethodOffset(), data->GetLog());
bool enableLog = data->GetLog()->EnableMethodCIRLog();
TSTypeLowering lowering(data->GetCircuit(), info, enableLog,
data->GetMethodName());
lowering.RunTSTypeLowering();
@ -126,8 +126,8 @@ class TypeLoweringPass {
public:
bool Run(PassData *data, CompilationConfig *cmpCfg, TSManager *tsManager)
{
TimeScope timescope("TypeLoweringPass", data->GetMethodName(), data->GetLog());
bool enableLog = data->GetEnableMethodLog() && data->GetLog()->OutputCIR();
TimeScope timescope("TypeLoweringPass", data->GetMethodName(), data->GetMethodOffset(), data->GetLog());
bool enableLog = data->GetLog()->EnableMethodCIRLog();
TypeLowering lowering(data->GetCircuit(), cmpCfg, tsManager, enableLog, data->GetMethodName());
lowering.RunTypeLowering();
return true;
@ -138,8 +138,8 @@ class TSInlineLoweringPass {
public:
bool Run(PassData *data, CompilationInfo *info)
{
TimeScope timescope("TSInlineLoweringPass", data->GetMethodName(), data->GetLog());
bool enableLog = data->GetEnableMethodLog() && data->GetLog()->OutputCIR();
TimeScope timescope("TSInlineLoweringPass", data->GetMethodName(), data->GetMethodOffset(), data->GetLog());
bool enableLog = data->GetLog()->EnableMethodCIRLog();
TSInlineLowering inlining(data->GetCircuit(), info, enableLog, data->GetMethodName());
inlining.RunTSInlineLowering();
return true;
@ -150,9 +150,10 @@ class SlowPathLoweringPass {
public:
bool Run(PassData* data, CompilationConfig *cmpCfg, TSManager *tsManager, const MethodLiteral *methodLiteral)
{
TimeScope timescope("SlowPathLoweringPass", data->GetMethodName(), data->GetLog());
bool enableLog = data->GetEnableMethodLog() && data->GetLog()->OutputCIR();
SlowPathLowering lowering(data->GetCircuit(), cmpCfg, tsManager, methodLiteral, enableLog, data->GetMethodName());
TimeScope timescope("SlowPathLoweringPass", data->GetMethodName(), data->GetMethodOffset(), data->GetLog());
bool enableLog = data->GetLog()->EnableMethodCIRLog();
SlowPathLowering lowering(data->GetCircuit(), cmpCfg, tsManager, methodLiteral,
enableLog, data->GetMethodName());
lowering.CallRuntimeLowering();
return true;
}
@ -162,8 +163,8 @@ class VerifierPass {
public:
bool Run(PassData* data)
{
TimeScope timescope("VerifierPass", data->GetMethodName(), data->GetLog());
bool enableLog = data->GetEnableMethodLog() && data->GetLog()->OutputCIR();
TimeScope timescope("VerifierPass", data->GetMethodName(), data->GetMethodOffset(), data->GetLog());
bool enableLog = data->GetLog()->EnableMethodCIRLog();
bool isQualified = Verifier::Run(data->GetCircuit(), data->GetMethodName(), enableLog);
if (!isQualified) {
LOG_FULL(FATAL) << "VerifierPass fail";
@ -177,8 +178,8 @@ class GuardEliminatingPass {
public:
bool Run(PassData* data, CompilationConfig *cmpCfg)
{
TimeScope timescope("GuardEliminatingPass", data->GetMethodName(), data->GetLog());
bool enableLog = data->GetEnableMethodLog() && data->GetLog()->OutputCIR();
TimeScope timescope("GuardEliminatingPass", data->GetMethodName(), data->GetMethodOffset(), data->GetLog());
bool enableLog = data->GetLog()->EnableMethodCIRLog();
GuardEliminating(data->GetCircuit(), cmpCfg, enableLog, data->GetMethodName()).Run();
return true;
}
@ -188,8 +189,8 @@ class SchedulingPass {
public:
bool Run(PassData* data)
{
TimeScope timescope("SchedulingPass", data->GetMethodName(), data->GetLog());
bool enableLog = data->GetEnableMethodLog() && data->GetLog()->OutputCIR();
TimeScope timescope("SchedulingPass", data->GetMethodName(), data->GetMethodOffset(), data->GetLog());
bool enableLog = data->GetLog()->EnableMethodCIRLog();
data->SetScheduleResult(Scheduler::Run(data->GetCircuit(), data->GetMethodName(), enableLog));
return true;
}
@ -205,8 +206,8 @@ public:
bool Run(PassData *data, LLVMModule *module, const MethodLiteral *methodLiteral,
const JSPandaFile *jsPandaFile)
{
TimeScope timescope("LLVMIRGenPass", data->GetMethodName(), data->GetLog());
bool enableLog = data->GetEnableMethodLog() && data->GetLog()->OutputCIR();
TimeScope timescope("LLVMIRGenPass", data->GetMethodName(), data->GetMethodOffset(), data->GetLog());
bool enableLog = data->GetLog()->EnableMethodCIRLog();
CreateCodeGen(module, enableLog);
CodeGenerator codegen(llvmImpl_, data->GetMethodName());
codegen.Run(data->GetCircuit(), data->GetScheduleResult(), module->GetCompilationConfig(),
@ -221,8 +222,9 @@ class AsyncFunctionLoweringPass {
public:
bool Run(PassData* data, BytecodeCircuitBuilder *builder, CompilationConfig *cmpCfg)
{
TimeScope timescope("AsyncFunctionLoweringPass", data->GetMethodName(), data->GetLog());
bool enableLog = data->GetEnableMethodLog() && data->GetLog()->OutputCIR();
TimeScope timescope("AsyncFunctionLoweringPass", data->GetMethodName(),
data->GetMethodOffset(), data->GetLog());
bool enableLog = data->GetLog()->EnableMethodCIRLog();
AsyncFunctionLowering lowering(builder, data->GetCircuit(), cmpCfg, enableLog, data->GetMethodName());
if (lowering.IsAsyncRelated()) {
lowering.ProcessAll();
@ -235,8 +237,8 @@ class GuardLoweringPass {
public:
bool Run(PassData* data, CompilationConfig *cmpCfg)
{
TimeScope timescope("GuardLoweringPass", data->GetMethodName(), data->GetLog());
bool enableLog = data->GetEnableMethodLog() && data->GetLog()->OutputCIR();
TimeScope timescope("GuardLoweringPass", data->GetMethodName(), data->GetMethodOffset(), data->GetLog());
bool enableLog = data->GetLog()->EnableMethodCIRLog();
GuardLowering(cmpCfg, data->GetCircuit(), data->GetMethodName(), enableLog).Run();
return true;
}

View File

@ -63,11 +63,11 @@ bool PassManager::Compile(const std::string &fileName, AOTFileGenerator &generat
auto tsManager = info.tsManager;
auto method = jsPandaFile->FindMethodLiteral(methodOffset);
const std::string methodName(MethodLiteral::GetMethodName(jsPandaFile, method->GetMethodId()));
uint32_t methodId = method->GetMethodId().GetOffset();
if (log_->CertainMethod()) {
enableMethodLog = logList_->IncludesMethod(fileName, methodName);
}
log_->SetEnableMethodLog(enableMethodLog);
std::string fullName = methodName + "@" + fileName;
if (enableMethodLog) {
@ -80,17 +80,17 @@ bool PassManager::Compile(const std::string &fileName, AOTFileGenerator &generat
info.bytecodes, hasTyps, enableMethodLog && log_->OutputCIR(),
EnableTypeLowering(), fullName, recordName);
{
TimeScope timeScope("BytecodeToCircuit", methodName, log_);
TimeScope timeScope("BytecodeToCircuit", methodName, methodOffset, log_);
builder.BytecodeToCircuit();
}
if (tsManager->IsSkippedMethod(methodId)) {
if (tsManager->IsSkippedMethod(methodOffset)) {
++skippedMethodNum;
LOG_COMPILER(INFO) << " method " << methodName << " has been skipped";
return;
}
PassData data(&circuit, log_, enableMethodLog, fullName);
PassData data(&circuit, log_, fullName, methodOffset);
PassRunner<PassData> pipeline(&data);
if (EnableTypeInfer()) {
pipeline.RunPass<TypeInferPass>(&builder, &info, methodInfoId, hasTyps);
@ -108,7 +108,9 @@ bool PassManager::Compile(const std::string &fileName, AOTFileGenerator &generat
pipeline.RunPass<LLVMIRGenPass>(aotModule, method, jsPandaFile);
});
LOG_COMPILER(INFO) << skippedMethodNum << " large methods in " << fileName << " have been skipped";
log_->PrintTime();
if (log_->GetEnableCompilerLogTime()) {
log_->PrintTime();
}
generator.AddModule(aotModule, aotModuleAssembler);
return true;
}

View File

@ -33,8 +33,8 @@
namespace panda::ecmascript::kungfu {
class StubPassData : public PassData {
public:
explicit StubPassData(Stub *stub, LLVMModule *module, CompilerLog *log, bool enableMethodLog)
: PassData(nullptr, log, enableMethodLog, "stubs"), module_(module), stub_(stub) {}
explicit StubPassData(Stub *stub, LLVMModule *module, CompilerLog *log)
: PassData(nullptr, log, "stubs"), module_(module), stub_(stub) {}
~StubPassData() = default;
const CompilationConfig *GetCompilationConfig() const
@ -82,7 +82,7 @@ public:
bool Run(StubPassData *data, size_t index)
{
bool enableLog = data->GetEnableMethodLog() && data->GetLog()->OutputCIR();
bool enableLog = data->GetLog()->GetEnableMethodLog() && data->GetLog()->OutputCIR();
auto stubModule = data->GetStubModule();
CreateCodeGen(stubModule, enableLog);
CodeGenerator codegen(llvmImpl_, "stubs");
@ -113,7 +113,7 @@ void StubCompiler::RunPipeline(LLVMModule *module) const
enableMethodLog = logList->IncludesMethod(stub.GetMethodName());
}
StubPassData data(&stub, module, log, enableMethodLog);
StubPassData data(&stub, module, log);
PassRunner<StubPassData> pipeline(&data);
pipeline.RunPass<StubBuildCircuitPass>();
pipeline.RunPass<VerifierPass>();

View File

@ -350,7 +350,7 @@ HWTEST_F_L0(CircuitOptimizerTests, TestSmallSizeGlobalValueNumbering) {
0,
{constantA, argB},
GateType::NJSValue());
ecmascript::kungfu::GlobalValueNumbering(&circuit).Run();
ecmascript::kungfu::GlobalValueNumbering(&circuit, false).Run();
EXPECT_FALSE(acc.GetOpCode(add3).IsNop());
EXPECT_FALSE(acc.GetOpCode(argA).IsNop());
EXPECT_FALSE(acc.GetOpCode(argB).IsNop());
@ -413,7 +413,7 @@ HWTEST_F_L0(CircuitOptimizerTests, TestMultiLevelGlobalValueNumbering) {
subToSub[sub] = pairToSub[np];
subToSubs[subToSub[sub]].emplace_back(sub);
}
ecmascript::kungfu::GlobalValueNumbering(&circuit).Run();
ecmascript::kungfu::GlobalValueNumbering(&circuit, false).Run();
std::map<GateRef, GateRef> gateToKing;
for (const auto &p : addToAdds) {
uint32_t cnt = 0;
@ -512,7 +512,7 @@ HWTEST_F_L0(CircuitOptimizerTests, TestSmallWorldGlobalValueNumbering) {
addToAdd[add] = pairToAdd[np];
addToAdds[addToAdd[add]].emplace_back(add);
}
ecmascript::kungfu::GlobalValueNumbering(&circuit).Run();
ecmascript::kungfu::GlobalValueNumbering(&circuit, false).Run();
std::map<GateRef, GateRef> gateToKing;
for (const auto &p : addToAdds) {
uint32_t cnt = 0;

View File

@ -164,11 +164,11 @@ void TSInlineLowering::InlineCall(MethodInfo &methodInfo, MethodPcInfo &methodPC
info_->bytecodes, true, IsLogEnabled(),
hasTyps, fullName, recordName);
{
TimeScope timeScope("BytecodeToCircuit", methodName, log);
TimeScope timeScope("BytecodeToCircuit", methodName, method->GetMethodId().GetOffset(), log);
builder.BytecodeToCircuit();
}
PassData data(circuit_, log, IsLogEnabled(), fullName);
PassData data(circuit_, log, fullName, method->GetMethodId().GetOffset());
PassRunner<PassData> pipeline(&data);
pipeline.RunPass<TypeInferPass>(&builder, info_, methodInfo.methodInfoIndex, hasTyps);
pipeline.RunPass<AsyncFunctionLoweringPass>(&builder, cmpCfg);

View File

@ -33,6 +33,7 @@ bool JSRuntimeOptions::ParseCommand(const int argc, const char **argv)
{"builtins-dts", required_argument, nullptr, OPTION_BUILTINS_DTS},
{"compiler-log", required_argument, nullptr, OPTION_COMPILER_LOG_OPT},
{"compiler-log-methods", required_argument, nullptr, OPTION_COMPILER_LOG_METHODS},
{"compiler-log-snapshot", required_argument, nullptr, OPTION_COMPILER_LOG_SNAPSHOT},
{"compiler-log-time", required_argument, nullptr, OPTION_COMPILER_LOG_TIME},
{"enable-ark-tools", required_argument, nullptr, OPTION_ENABLE_ARK_TOOLS},
{"enable-bytecode-trace", required_argument, nullptr, OPTION_ENABLE_BC_TRACE},
@ -150,6 +151,14 @@ bool JSRuntimeOptions::ParseCommand(const int argc, const char **argv)
case OPTION_COMPILER_LOG_OPT:
SetCompilerLogOption(optarg);
break;
case OPTION_COMPILER_LOG_SNAPSHOT:
ret = ParseBoolParam(&argBool);
if (ret) {
SetCompilerLogSnapshot(argBool);
} else {
return false;
}
break;
case OPTION_COMPILER_LOG_TIME:
ret = ParseBoolParam(&argBool);
if (ret) {

View File

@ -79,6 +79,7 @@ const std::string HELP_OPTION_MSG =
" Default: \"none\"\n"
"--compiler-log-methods: specific method list for compiler log output, only used when compiler-log."
"Default: \"none\"\n"
"--compiler-log-snapshot: Enable to print snapshot information. Default: false\n"
"--compiler-log-time: Enable to print pass compiler time. Default: false\n"
"--enable-ark-tools: Enable ark tools to debug. Default: false\n"
"--enable-bytecode-trace: enable tracing bytecode for aot runtime. Default: false\n"
@ -163,6 +164,7 @@ enum CommandValues {
OPTION_ENABLE_RUNTIME_STAT,
OPTION_ASSERT_TYPES,
OPTION_PRINT_ANY_TYPES,
OPTION_COMPILER_LOG_SNAPSHOT,
OPTION_COMPILER_LOG_TIME,
OPTION_IS_WORKER,
OPTION_BUILTINS_DTS,
@ -505,6 +507,21 @@ public:
GetCompilerLogOption().find("all") == std::string::npos;
}
void SetCompilerLogSnapshot(bool value)
{
compilerLogSnapshot_ = value;
}
bool IsEnableCompilerLogSnapshot() const
{
return compilerLogSnapshot_;
}
bool WasSetCompilerLogSnapshot() const
{
return WasOptionSet(OPTION_COMPILER_LOG_SNAPSHOT);
}
void SetCompilerLogTime(bool value)
{
compilerLogTime_ = value;
@ -917,6 +934,7 @@ private:
bool startupTime_ {false};
std::string compilerLogOpt_ {"none"};
std::string compilerLogMethods_ {"none"};
bool compilerLogSnapshot_ {false};
bool compilerLogTime_ {false};
bool enableRuntimeStat_ {false};
bool assertTypes_ {false};

View File

@ -750,8 +750,10 @@ void TSManager::AddHClassToSnapshotConstantPool()
uint32_t constantPoolSize = cp->GetCacheLength();
const auto &hclassCache = snapshotRecordInfo_.GetHClassCache();
uint32_t hclassCacheSize = snapshotRecordInfo_.GetHClassCacheSize();
LOG_COMPILER(INFO) << "snapshot: constantPoolSize: " << constantPoolSize;
LOG_COMPILER(INFO) << "snapshot: hclassCacheSize: " << hclassCacheSize;
if (vm_->GetJSOptions().IsEnableCompilerLogSnapshot()) {
LOG_COMPILER(INFO) << "[aot-snapshot] constantPoolSize: " << constantPoolSize;
LOG_COMPILER(INFO) << "[aot-snapshot] hclassCacheSize: " << hclassCacheSize;
}
JSHandle<ConstantPool> newConstantPool = factory_->NewConstantPool(constantPoolSize + hclassCacheSize);
for (uint32_t i = 0; i < constantPoolSize; ++i) {
newConstantPool->SetObjectToCache(thread_, i, cp->GetObjectFromCache(i));
@ -859,9 +861,11 @@ void TSManager::ResolveSnapshotConstantPool(const std::map<uint32_t, uint32_t> &
for (auto item: recordMethodIndex) {
JSTaggedValue val = snapshotConstantPool->GetObjectFromCache(item);
uint32_t methodID = static_cast<uint32_t>(val.GetInt());
LOG_COMPILER(INFO) << "snapshot: resolve function method ID: " << methodID;
uint32_t entryIndex = methodToEntryIndexMap.at(methodID);
uint32_t methodOffset = static_cast<uint32_t>(val.GetInt());
if (vm_->GetJSOptions().IsEnableCompilerLogSnapshot()) {
LOG_COMPILER(INFO) << "[aot-snapshot] store AOT entry index of method (offset: " << methodOffset << ") ";
}
uint32_t entryIndex = methodToEntryIndexMap.at(methodOffset);
snapshotConstantPool->SetObjectToCache(thread_, item, JSTaggedValue(entryIndex));
}
@ -870,13 +874,17 @@ void TSManager::ResolveSnapshotConstantPool(const std::map<uint32_t, uint32_t> &
AOTLiteralInfo *aotLiteralInfo = AOTLiteralInfo::Cast(val.GetTaggedObject());
uint32_t aotLiteralInfoLen = aotLiteralInfo->GetLength();
for (uint32_t i = 0; i < aotLiteralInfoLen; ++i) {
JSTaggedValue methodIDVal = aotLiteralInfo->Get(i);
if (methodIDVal.GetInt() != -1) {
uint32_t methodID = static_cast<uint32_t>(methodIDVal.GetInt());
LOG_COMPILER(INFO) << "snapshot: resolve function method ID: " << methodID;
uint32_t entryIndex = methodToEntryIndexMap.at(methodID);
aotLiteralInfo->Set(thread_, i, JSTaggedValue(entryIndex));
JSTaggedValue methodOffsetVal = aotLiteralInfo->Get(i);
if (methodOffsetVal.GetInt() == -1) {
continue;
}
uint32_t methodOffset = static_cast<uint32_t>(methodOffsetVal.GetInt());
if (vm_->GetJSOptions().IsEnableCompilerLogSnapshot()) {
LOG_COMPILER(INFO) << "[aot-snapshot] store AOT entry index of method (offset: "
<< methodOffset << ") ";
}
uint32_t entryIndex = methodToEntryIndexMap.at(methodOffset);
aotLiteralInfo->Set(thread_, i, JSTaggedValue(entryIndex));
}
}
}