Files
ark_js_runtime/ecmascript/compiler/pass_manager.cpp
T
wanyanglan fd4c928922 Add information such as instruction immediate, method_id, string_id, etc.
The lowering slow path requires not only the vreg information of the
instruction, but also other information such as string id, method id, etc.

For each bytecode instruction, collect the various information stored in
the instruction, and use the information as the input of the gate, and
in the lowering stage, take out the required information from the gate.

issue:https://gitee.com/openharmony/ark_js_runtime/issues/I4WQR5

Signed-off-by: wanyanglan <wanyanglan1@huawei.com>
Change-Id: I42ef36554b0b88ce3e1cd0f593e8ce9e924b83e0
2022-03-15 11:02:40 +08:00

72 lines
2.6 KiB
C++

/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "pass_manager.h"
#include "ecmascript/ecma_handle_scope.h"
#include "ecmascript/js_tagged_value.h"
#include "ecmascript/jspandafile/js_pandafile_manager.h"
#include "ecmascript/jspandafile/panda_file_translator.h"
#include "ecmascript/ts_types/ts_loader.h"
#include "pass.h"
namespace panda::ecmascript::kungfu {
bool PassManager::Compile(std::string fileName)
{
BytecodeTranslationInfo translationInfo;
[[maybe_unused]] EcmaHandleScope handleScope(vm_->GetJSThread());
bool res = CollectInfoOfPandaFile(fileName, &translationInfo);
if (!res) {
std::cerr << "Cannot execute panda file '" << fileName << "' with entry '" << entry_ << "'" << std::endl;
return false;
}
for (size_t i = 0; i < translationInfo.methodPcInfos.size(); i++) {
BytecodeCircuitBuilder builder(vm_, translationInfo, i);
builder.BytecodeToCircuit();
PassData data(builder.GetCircuit());
PassRunner<PassData> pipeline(&data);
pipeline.RunPass<SlowPathLoweringPass>(&builder);
pipeline.RunPass<VerifierPass>();
pipeline.RunPass<SchedulingPass>();
pipeline.RunPass<LLVMIRGenPass>();
}
return true;
}
bool PassManager::CollectInfoOfPandaFile(const std::string &filename, BytecodeTranslationInfo *translateInfo)
{
if (translateInfo == nullptr) {
return false;
}
const JSPandaFile *jsPandaFile =
vm_->GetJSPandaFileManager()->LoadAotInfoFromPf(filename, &(translateInfo->methodPcInfos));
if (jsPandaFile == nullptr) {
return false;
}
translateInfo->jsPandaFile = jsPandaFile;
TSLoader *tsLoader = vm_->GetTSLoader();
tsLoader->DecodeTSTypes(*jsPandaFile->GetPandaFile());
PandaFileTranslator translator(vm_, jsPandaFile);
auto program = translator.GenerateProgram();
JSHandle<JSFunction> mainFunc(vm_->GetJSThread(), program->GetMainFunction());
JSHandle<JSTaggedValue> constPool(vm_->GetJSThread(), mainFunc->GetConstantPool());
translateInfo->constantPool = constPool;
return true;
}
}