mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-10-07 08:03:29 +00:00
!911 Adaptation for aot framework helloworld test.
Merge pull request !911 from luochuhao/aotCompiler
This commit is contained in:
commit
111a44610f
@ -23,7 +23,7 @@ void AotFileManager::CollectAOTCodeInfoOfStubs()
|
||||
auto engine = assembler_.GetEngine();
|
||||
std::map<uintptr_t, std::string> addr2name;
|
||||
auto callSigns = llvmModule_->GetCSigns();
|
||||
for (size_t i = 0; i < llvmModule_->GetFuncsSize(); i++) {
|
||||
for (size_t i = 0; i < llvmModule_->GetFuncCount(); i++) {
|
||||
auto cs = callSigns[i];
|
||||
LLVMValueRef func = llvmModule_->GetFunction(i);
|
||||
ASSERT(func != nullptr);
|
||||
@ -47,14 +47,15 @@ void AotFileManager::CollectAOTCodeInfo()
|
||||
{
|
||||
auto codeBuff = reinterpret_cast<uint64_t>(assembler_.GetCodeBuffer());
|
||||
auto engine = assembler_.GetEngine();
|
||||
auto moduleInllvm = llvmModule_->GetModule();
|
||||
for (auto func = LLVMGetFirstFunction(moduleInllvm); func; func = LLVMGetNextFunction(func)) {
|
||||
for (size_t i = 0; i < llvmModule_->GetFuncCount(); i++) {
|
||||
LLVMValueRef func = llvmModule_->GetFunction(i);
|
||||
uint64_t funcEntry = reinterpret_cast<uint64_t>(LLVMGetPointerToGlobal(engine, func));
|
||||
uint64_t length = 0;
|
||||
std::string tmp(LLVMGetValueName2(func, &length));
|
||||
if (length == 0) {
|
||||
continue;
|
||||
}
|
||||
std::cout << "CollectAOTCodeInfo " << tmp.c_str() << std::endl;
|
||||
aotInfo_.SetAOTFuncOffset(tmp, funcEntry - codeBuff);
|
||||
}
|
||||
aotInfo_.SetHostCodeSectionAddr(codeBuff);
|
||||
|
@ -22,8 +22,8 @@
|
||||
namespace panda::ecmascript::kungfu {
|
||||
class AotFileManager {
|
||||
public:
|
||||
AotFileManager(LLVMModule *llvmModule, bool isFpElim = false) : llvmModule_(llvmModule),
|
||||
assembler_(llvmModule->GetModule(), isFpElim) {};
|
||||
AotFileManager(LLVMModule *llvmModule, bool genFp = true) : llvmModule_(llvmModule),
|
||||
assembler_(llvmModule->GetModule(), genFp) {};
|
||||
~AotFileManager() = default;
|
||||
// save function funcs for aot files containing stubs
|
||||
void SaveStubFile(const std::string &filename);
|
||||
|
@ -2000,7 +2000,13 @@ void BytecodeCircuitBuilder::BuildCircuit(BytecodeGraph &byteCodeGraph)
|
||||
const size_t actualNumArgs = GetActualNumArgs(numArgs);
|
||||
std::vector<GateRef> argGates(actualNumArgs);
|
||||
|
||||
for (size_t argIdx = 0; argIdx < CommonArgIdx::NUM_OF_ARGS; argIdx++) {
|
||||
auto glueGate = circuit_.NewGate(OpCode(OpCode::ARG), MachineType::I64, 0,
|
||||
{Circuit::GetCircuitRoot(OpCode(OpCode::ARG_LIST))},
|
||||
GateType::C_VALUE);
|
||||
argGates.at(0) = glueGate;
|
||||
commonArgs_.at(0) = glueGate;
|
||||
|
||||
for (size_t argIdx = 1; argIdx < CommonArgIdx::NUM_OF_ARGS; argIdx++) {
|
||||
auto argGate = circuit_.NewGate(OpCode(OpCode::ARG), MachineType::I64, argIdx,
|
||||
{Circuit::GetCircuitRoot(OpCode(OpCode::ARG_LIST))},
|
||||
GateType::TAGGED_VALUE);
|
||||
@ -2011,7 +2017,7 @@ void BytecodeCircuitBuilder::BuildCircuit(BytecodeGraph &byteCodeGraph)
|
||||
for (size_t argIdx = CommonArgIdx::NUM_OF_ARGS; argIdx < actualNumArgs; argIdx++) {
|
||||
argGates.at(argIdx) = circuit_.NewGate(OpCode(OpCode::ARG), MachineType::I64, argIdx,
|
||||
{Circuit::GetCircuitRoot(OpCode(OpCode::ARG_LIST))},
|
||||
GateType::JS_ANY);
|
||||
GateType::TAGGED_VALUE);
|
||||
}
|
||||
// get number of expanded state predicates of each block
|
||||
// one block-level try catch edge may correspond to multiple bytecode-level edges
|
||||
|
@ -173,9 +173,9 @@ void LLVMAssembler::BuildAndRunPasses()
|
||||
COMPILER_LOG(DEBUG) << "BuildAndRunPasses + ";
|
||||
}
|
||||
|
||||
LLVMAssembler::LLVMAssembler(LLVMModuleRef module, bool isFpElim) : module_(module)
|
||||
LLVMAssembler::LLVMAssembler(LLVMModuleRef module, bool genFp) : module_(module)
|
||||
{
|
||||
Initialize(isFpElim);
|
||||
Initialize(genFp);
|
||||
}
|
||||
|
||||
LLVMAssembler::~LLVMAssembler()
|
||||
@ -216,7 +216,7 @@ void LLVMAssembler::Run()
|
||||
LLVMPrintModuleToFile(module_, optName.c_str(), &error);
|
||||
}
|
||||
|
||||
void LLVMAssembler::Initialize(bool isFpElim)
|
||||
void LLVMAssembler::Initialize(bool genFp)
|
||||
{
|
||||
std::string triple(LLVMGetTarget(module_));
|
||||
if (triple.compare("x86_64-unknown-linux-gnu") == 0) {
|
||||
@ -248,7 +248,7 @@ void LLVMAssembler::Initialize(bool isFpElim)
|
||||
LLVMInitializeMCJITCompilerOptions(&options_, sizeof(options_));
|
||||
options_.OptLevel = 3; // opt level 3
|
||||
// NOTE: Just ensure that this field still exists for PIC option
|
||||
options_.NoFramePointerElim = isFpElim ? false : true;
|
||||
options_.NoFramePointerElim = genFp;
|
||||
options_.CodeModel = LLVMCodeModelSmall;
|
||||
}
|
||||
|
||||
|
@ -103,6 +103,7 @@ struct CodeInfo {
|
||||
dataSectionList_.push_back(std::vector<uint8_t>());
|
||||
dataSectionList_.back().resize(size);
|
||||
dataSectionNames_.push_back(sectionName);
|
||||
std::cout << "AllocaDataSection " << sectionName << std::endl;
|
||||
addr = static_cast<uint8_t *>(dataSectionList_.back().data());
|
||||
if (!strcmp(sectionName, ".llvm_stackmaps")) {
|
||||
LOG_ECMA(INFO) << "llvm_stackmaps : " << addr << " size:" << size;
|
||||
@ -165,7 +166,7 @@ private:
|
||||
|
||||
class LLVMAssembler {
|
||||
public:
|
||||
LLVMAssembler(LLVMModuleRef module, bool isFpElim = false);
|
||||
LLVMAssembler(LLVMModuleRef module, bool genFp = true);
|
||||
virtual ~LLVMAssembler();
|
||||
void Run();
|
||||
const LLVMExecutionEngineRef &GetEngine()
|
||||
@ -202,7 +203,7 @@ private:
|
||||
void UseRoundTripSectionMemoryManager();
|
||||
bool BuildMCJITEngine();
|
||||
void BuildAndRunPasses();
|
||||
void Initialize(bool isFpElim);
|
||||
void Initialize(bool genFp);
|
||||
|
||||
LLVMMCJITCompilerOptions options_ {};
|
||||
LLVMModuleRef module_;
|
||||
|
@ -1923,21 +1923,24 @@ LLVMTypeRef LLVMModule::ConvertLLVMTypeFromVariableType(VariableType type)
|
||||
|
||||
LLVMValueRef LLVMModule::AddFunc(const panda::ecmascript::JSMethod *method)
|
||||
{
|
||||
VariableType retType(MachineType::I64, GateType::C_VALUE); // possibly get it for circuit
|
||||
VariableType retType(MachineType::I64, GateType::TAGGED_VALUE); // possibly get it for circuit
|
||||
LLVMTypeRef returnType = ConvertLLVMTypeFromVariableType(retType);
|
||||
std::vector<LLVMTypeRef> paramTys;
|
||||
auto paramCount = method->GetNumArgs() + CommonArgIdx::NUM_OF_ARGS;
|
||||
for (uint32_t i = 0; i < CommonArgIdx::NUM_OF_ARGS; i++) {
|
||||
VariableType paramsType(MachineType::I64, GateType::TAGGED_POINTER);
|
||||
VariableType glueParamType(MachineType::I64, GateType::C_VALUE);
|
||||
paramTys.push_back(ConvertLLVMTypeFromVariableType(glueParamType));
|
||||
for (uint32_t i = 1; i < CommonArgIdx::NUM_OF_ARGS; i++) {
|
||||
VariableType paramsType(MachineType::I64, GateType::TAGGED_VALUE);
|
||||
paramTys.push_back(ConvertLLVMTypeFromVariableType(paramsType));
|
||||
}
|
||||
for (uint32_t j = CommonArgIdx::NUM_OF_ARGS; j < paramCount; j++) {
|
||||
VariableType paramsType(MachineType::I64, GateType::C_VALUE);
|
||||
VariableType paramsType(MachineType::I64, GateType::TAGGED_VALUE);
|
||||
paramTys.push_back(ConvertLLVMTypeFromVariableType(paramsType));
|
||||
}
|
||||
auto funcType = LLVMFunctionType(returnType, paramTys.data(), paramCount, false); // not variable args
|
||||
CString name = method->ParseFunctionName();
|
||||
auto function = LLVMAddFunction(module_, name.c_str(), funcType);
|
||||
functions_.emplace_back(function);
|
||||
return function;
|
||||
}
|
||||
} // namespace panda::ecmascript::kungfu
|
||||
|
@ -138,7 +138,7 @@ public:
|
||||
return callSigns_;
|
||||
}
|
||||
|
||||
size_t GetFuncsSize() const
|
||||
size_t GetFuncCount() const
|
||||
{
|
||||
return functions_.size();
|
||||
}
|
||||
|
@ -232,7 +232,8 @@ GateRef SlowPathLowering::GetValueFromConstStringTable(GateRef glue, GateRef gat
|
||||
{
|
||||
GateRef id = builder_.Int64(RTSTUB_ID(LoadValueFromConstantStringTable));
|
||||
auto idGate = acc_.GetValueIn(gate, inIndex);
|
||||
return builder_.RuntimeCall(glue, id, Circuit::GetCircuitRoot(OpCode(OpCode::DEPEND_ENTRY)), {idGate});
|
||||
GateRef dependGate = acc_.GetDep(gate);
|
||||
return builder_.RuntimeCall(glue, id, dependGate, {idGate});
|
||||
}
|
||||
|
||||
void SlowPathLowering::Lower(GateRef gate, EcmaOpcode op)
|
||||
@ -553,6 +554,7 @@ void SlowPathLowering::LowerTryLdGlobalByName(GateRef gate, GateRef glue)
|
||||
{
|
||||
GateRef prop = GetValueFromConstStringTable(glue, gate, 0);
|
||||
GateRef id = builder_.Int64(RTSTUB_ID(TryLdGlobalByName));
|
||||
acc_.SetDep(gate, prop);
|
||||
ASSERT(acc_.GetNumValueIn(gate) == 1);
|
||||
GateRef newGate = builder_.RuntimeCall(glue, id, Circuit::GetCircuitRoot(OpCode(OpCode::DEPEND_ENTRY)), {prop});
|
||||
LowerHirToCall(gate, newGate);
|
||||
@ -562,6 +564,7 @@ void SlowPathLowering::LowerStGlobalVar(GateRef gate, GateRef glue)
|
||||
{
|
||||
GateRef prop = GetValueFromConstStringTable(glue, gate, 0);
|
||||
GateRef id = builder_.Int64(RTSTUB_ID(StGlobalVar));
|
||||
acc_.SetDep(gate, prop);
|
||||
ASSERT(acc_.GetNumValueIn(gate) == 2); // 2: number of value inputs
|
||||
GateRef newGate = builder_.RuntimeCall(glue, id, Circuit::GetCircuitRoot(OpCode(OpCode::DEPEND_ENTRY)),
|
||||
{prop, acc_.GetValueIn(gate, 0)});
|
||||
|
@ -136,7 +136,7 @@ bool StubCompiler::BuildStubModuleAndSave(const std::string &triple, const std::
|
||||
LLVMModule bcHandlerStubModule("bc_stub", triple);
|
||||
bcHandlerStubModule.SetUpForBytecodeHandlerStubs();
|
||||
RunPipeline(bcHandlerStubModule);
|
||||
AotFileManager manager(&bcHandlerStubModule, true);
|
||||
AotFileManager manager(&bcHandlerStubModule, false);
|
||||
manager.SaveStubFile(bcHandlerStubFile);
|
||||
std::cerr << "finish" << std::endl;
|
||||
res++;
|
||||
|
@ -114,6 +114,7 @@ bool AotCodeInfo::Deserialize(EcmaVM *vm, const std::string &filename)
|
||||
uint64_t curFuncOffset = 0;
|
||||
for (uint32_t i = 0; i < funcNum; i++) {
|
||||
moduleFile.read(reinterpret_cast<char *>(&curfuncNameSize), sizeof(uint32_t));
|
||||
curFuncName.resize(curfuncNameSize);
|
||||
moduleFile.read(reinterpret_cast<char *>(curFuncName.data()), curfuncNameSize);
|
||||
moduleFile.read(reinterpret_cast<char *>(&curFuncOffset), sizeof(uint64_t));
|
||||
aotFuncEntryOffsets_.insert(make_pair(curFuncName, curFuncOffset));
|
||||
|
@ -757,7 +757,7 @@ DEF_RUNTIME_STUBS(Shl2Dyn)
|
||||
RUNTIME_STUBS_HEADER(Shl2Dyn);
|
||||
CONVERT_ARG_TAGGED_CHECKED(left, 0);
|
||||
CONVERT_ARG_TAGGED_CHECKED(right, 1);
|
||||
|
||||
|
||||
auto res = SlowRuntimeStub::Shl2Dyn(thread, left, right);
|
||||
return JSTaggedValue(res).GetRawData();
|
||||
}
|
||||
@ -767,7 +767,7 @@ DEF_RUNTIME_STUBS(Shr2Dyn)
|
||||
RUNTIME_STUBS_HEADER(Shr2Dyn);
|
||||
CONVERT_ARG_TAGGED_CHECKED(left, 0);
|
||||
CONVERT_ARG_TAGGED_CHECKED(right, 1);
|
||||
|
||||
|
||||
auto res = SlowRuntimeStub::Shr2Dyn(thread, left, right);
|
||||
return JSTaggedValue(res).GetRawData();
|
||||
}
|
||||
@ -777,7 +777,7 @@ DEF_RUNTIME_STUBS(Ashr2Dyn)
|
||||
RUNTIME_STUBS_HEADER(Ashr2Dyn);
|
||||
CONVERT_ARG_TAGGED_CHECKED(left, 0);
|
||||
CONVERT_ARG_TAGGED_CHECKED(right, 1);
|
||||
|
||||
|
||||
auto res = SlowRuntimeStub::Ashr2Dyn(thread, left, right);
|
||||
return JSTaggedValue(res).GetRawData();
|
||||
}
|
||||
@ -787,7 +787,7 @@ DEF_RUNTIME_STUBS(And2Dyn)
|
||||
RUNTIME_STUBS_HEADER(And2Dyn);
|
||||
CONVERT_ARG_TAGGED_CHECKED(left, 0);
|
||||
CONVERT_ARG_TAGGED_CHECKED(right, 1);
|
||||
|
||||
|
||||
auto res = SlowRuntimeStub::And2Dyn(thread, left, right);
|
||||
return JSTaggedValue(res).GetRawData();
|
||||
}
|
||||
@ -807,7 +807,7 @@ DEF_RUNTIME_STUBS(Or2Dyn)
|
||||
RUNTIME_STUBS_HEADER(Or2Dyn);
|
||||
CONVERT_ARG_TAGGED_CHECKED(left, 0);
|
||||
CONVERT_ARG_TAGGED_CHECKED(right, 1);
|
||||
|
||||
|
||||
auto res = SlowRuntimeStub::Or2Dyn(thread, left, right);
|
||||
return JSTaggedValue(res).GetRawData();
|
||||
}
|
||||
@ -1260,9 +1260,9 @@ DEF_RUNTIME_STUBS(GetLexicalEnv)
|
||||
DEF_RUNTIME_STUBS(LoadValueFromConstantStringTable)
|
||||
{
|
||||
RUNTIME_STUBS_HEADER(LoadValueFromConstantStringTable);
|
||||
CONVERT_ARG_TAGGED_CHECKED(id, 0);
|
||||
CONVERT_ARG_TAGGED_TYPE_CHECKED(id, 0);
|
||||
auto tsLoader = thread->GetEcmaVM()->GetTSLoader();
|
||||
return tsLoader->GetStringById(id.GetInt()).GetTaggedValue().GetRawData();
|
||||
return tsLoader->GetStringById(id).GetTaggedValue().GetRawData();
|
||||
}
|
||||
|
||||
DEF_RUNTIME_STUBS(CallArg0Dyn)
|
||||
|
@ -110,7 +110,7 @@ JSFunctionEntry:
|
||||
|
||||
movq %rdi, %rax // move glue to rax
|
||||
call *%r9 // then call jsFunction
|
||||
leaq (,%r14,8), %rcx // todo:: fixed for 3 extra arguments
|
||||
leaq (,%r14,8), %rcx // NOTE: fixed for 3 extra arguments
|
||||
addq %rcx, %rsp
|
||||
|
||||
testb $1, %r14b // stack 16bytes align check
|
||||
@ -263,7 +263,7 @@ OptimizedCallRuntime:
|
||||
movq %rsp, %rbp // set frame pointer
|
||||
movq %rbp, ASM_GLUE_CURRENT_FRAME_OFFSET(%rax) // save to thread->currentFrame_
|
||||
pushq $LEAVE_FRAME_TYPE
|
||||
|
||||
|
||||
// callee save
|
||||
pushq %r10
|
||||
pushq %rdx
|
||||
@ -293,7 +293,7 @@ AsmIntCallRuntime:
|
||||
pushq $0
|
||||
movq %rsp, ASM_GLUE_LEAVE_FRAME_OFFSET(%rax) // save to thread->leaveFrame_
|
||||
pushq $ASM_LEAVE_FRAME_TYPE
|
||||
|
||||
|
||||
// callee save
|
||||
pushq %r10
|
||||
pushq %rdx
|
||||
|
Loading…
Reference in New Issue
Block a user