mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-12-04 00:43:40 +00:00
!4061 Merge AOT code comment in multi-modules mode
Merge pull request !4061 from zhangyukun8/master
This commit is contained in:
commit
c672a8427b
@ -103,6 +103,7 @@ void Module::CollectFuncEntryInfo(std::map<uintptr_t, std::string> &addr2name, A
|
||||
auto engine = assembler_->GetEngine();
|
||||
std::vector<std::tuple<uint64_t, size_t, int>> funcInfo; // entry idx delta
|
||||
std::vector<kungfu::CalleeRegAndOffsetVec> calleeSaveRegisters; // entry idx delta
|
||||
// 1.Compile all functions and collect function infos
|
||||
llvmModule_->IteratefuncIndexMap([&](size_t idx, LLVMValueRef func) {
|
||||
uint64_t funcEntry = reinterpret_cast<uintptr_t>(LLVMGetPointerToGlobal(engine, func));
|
||||
uint64_t length = 0;
|
||||
@ -115,6 +116,7 @@ void Module::CollectFuncEntryInfo(std::map<uintptr_t, std::string> &addr2name, A
|
||||
kungfu::CalleeRegAndOffsetVec info = assembler_->GetCalleeReg2Offset(func, log);
|
||||
calleeSaveRegisters.emplace_back(info);
|
||||
});
|
||||
// 2.After all functions compiled, the module sections would be fixed
|
||||
uintptr_t textAddr = GetTextAddr();
|
||||
uint32_t textSize = GetTextSize();
|
||||
uint32_t rodataSize = GetRODataSize();
|
||||
@ -124,6 +126,7 @@ void Module::CollectFuncEntryInfo(std::map<uintptr_t, std::string> &addr2name, A
|
||||
const size_t funcCount = funcInfo.size();
|
||||
funcCount_ = funcCount;
|
||||
startIndex_ = aotInfo.GetEntrySize();
|
||||
// 3.Add function entries based on the module sections
|
||||
for (size_t i = 0; i < funcInfo.size(); i++) {
|
||||
uint64_t funcEntry;
|
||||
size_t idx;
|
||||
@ -193,9 +196,9 @@ void Module::RunAssembler(const CompilerLog &log)
|
||||
}
|
||||
|
||||
void Module::DisassemblerFunc(std::map<uintptr_t, std::string> &addr2name, uint64_t textOffset,
|
||||
const CompilerLog &log, const MethodLogList &logList)
|
||||
const CompilerLog &log, const MethodLogList &logList, std::ostringstream &codeStream)
|
||||
{
|
||||
assembler_->Disassemble(addr2name, textOffset, log, logList);
|
||||
assembler_->Disassemble(addr2name, textOffset, log, logList, codeStream);
|
||||
}
|
||||
|
||||
void Module::DestroyModule()
|
||||
@ -254,16 +257,21 @@ void StubFileGenerator::DisassembleAsmStubs(std::map<uintptr_t, std::string> &ad
|
||||
LLVMAssembler::Disassemble(&addr2name, tri, buf, size);
|
||||
}
|
||||
|
||||
uint64_t AOTFileGenerator::RollbackTextSize(Module *module)
|
||||
{
|
||||
return aotInfo_.GetCurTextSecOffset() - module->GetSectionSize(ElfSecName::TEXT);
|
||||
}
|
||||
|
||||
void AOTFileGenerator::CollectCodeInfo(Module *module, uint32_t moduleIdx)
|
||||
{
|
||||
std::map<uintptr_t, std::string> addr2name;
|
||||
module->CollectFuncEntryInfo(addr2name, aotInfo_, moduleIdx, GetLog());
|
||||
ModuleSectionDes des;
|
||||
uint64_t textOffset = aotInfo_.GetCurTextSecOffset() - module->GetSectionSize(ElfSecName::TEXT);
|
||||
uint64_t textOffset = RollbackTextSize(module);
|
||||
module->CollectAnModuleSectionDes(des, textOffset, pc2CallSiteInfoVec_, pc2DeoptVec_);
|
||||
aotInfo_.AddModuleDes(des);
|
||||
if (log_->OutputASM()) {
|
||||
module->DisassemblerFunc(addr2name, textOffset, *(log_), *(logList_));
|
||||
module->DisassemblerFunc(addr2name, textOffset, *(log_), *(logList_), codeStream_);
|
||||
}
|
||||
}
|
||||
|
||||
@ -363,6 +371,7 @@ void AOTFileGenerator::GenerateMergedStackmapSection()
|
||||
|
||||
void AOTFileGenerator::SaveAOTFile(const std::string &filename)
|
||||
{
|
||||
PrintMergedCodeComment();
|
||||
GenerateMergedStackmapSection();
|
||||
GenerateMethodToEntryIndexMap();
|
||||
aotInfo_.Save(filename, cfg_.GetTriple());
|
||||
|
@ -60,8 +60,8 @@ public:
|
||||
|
||||
void RunAssembler(const CompilerLog &log);
|
||||
|
||||
void DisassemblerFunc(std::map<uintptr_t, std::string> &addr2name, uint64_t textOffset,
|
||||
const CompilerLog &log, const MethodLogList &logList);
|
||||
void DisassemblerFunc(std::map<uintptr_t, std::string> &addr2name, uint64_t textOffset, const CompilerLog &log,
|
||||
const MethodLogList &logList, std::ostringstream &codeStream);
|
||||
|
||||
void DestroyModule();
|
||||
|
||||
@ -96,16 +96,27 @@ private:
|
||||
class FileGenerator {
|
||||
public:
|
||||
FileGenerator(const CompilerLog *log, const MethodLogList *logList) : log_(log), logList_(logList) {};
|
||||
virtual ~FileGenerator() = default;
|
||||
virtual ~FileGenerator()
|
||||
{
|
||||
codeStream_.clear();
|
||||
codeStream_.str("");
|
||||
}
|
||||
|
||||
const CompilerLog GetLog() const
|
||||
{
|
||||
return *log_;
|
||||
}
|
||||
|
||||
void PrintMergedCodeComment()
|
||||
{
|
||||
LOG_ECMA(INFO) << "\n" << codeStream_.str();
|
||||
}
|
||||
|
||||
protected:
|
||||
std::vector<Module> modulePackage_ {};
|
||||
const CompilerLog *log_ {nullptr};
|
||||
const MethodLogList *logList_ {nullptr};
|
||||
std::ostringstream codeStream_;
|
||||
|
||||
void RunLLVMAssembler()
|
||||
{
|
||||
@ -114,13 +125,6 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
void DisassembleEachFunc(std::map<uintptr_t, std::string> &addr2name)
|
||||
{
|
||||
for (auto m : modulePackage_) {
|
||||
m.DisassemblerFunc(addr2name, 0, *(log_), *(logList_));
|
||||
}
|
||||
}
|
||||
|
||||
void DestroyModule()
|
||||
{
|
||||
for (auto m : modulePackage_) {
|
||||
@ -176,6 +180,8 @@ private:
|
||||
|
||||
// collect aot component info
|
||||
void CollectCodeInfo(Module *module, uint32_t moduleIdx);
|
||||
|
||||
uint64_t RollbackTextSize(Module *module);
|
||||
};
|
||||
|
||||
enum class StubFileKind {
|
||||
@ -196,6 +202,14 @@ public:
|
||||
Module* AddModule(NativeAreaAllocator *allocator, const std::string &name, const std::string &triple,
|
||||
LOptions option, bool logDebug, StubFileKind k);
|
||||
|
||||
void DisassembleEachFunc(std::map<uintptr_t, std::string> &addr2name)
|
||||
{
|
||||
for (auto m : modulePackage_) {
|
||||
m.DisassemblerFunc(addr2name, 0, *(log_), *(logList_), codeStream_);
|
||||
}
|
||||
PrintMergedCodeComment();
|
||||
}
|
||||
|
||||
void DisassembleAsmStubs(std::map<uintptr_t, std::string> &addr2name);
|
||||
// save function funcs for aot files containing stubs
|
||||
void SaveStubFile(const std::string &filename);
|
||||
|
@ -446,7 +446,8 @@ static uint32_t GetInstrValue(size_t instrSize, uint8_t *instrAddr)
|
||||
}
|
||||
|
||||
void LLVMAssembler::PrintInstAndStep(uint64_t &instrOffset, uint8_t **instrAddr, uintptr_t &numBytes,
|
||||
size_t instSize, uint64_t textOffset, char *outString, bool logFlag)
|
||||
size_t instSize, uint64_t textOffset, char *outString,
|
||||
std::ostringstream &codeStream, bool logFlag)
|
||||
{
|
||||
if (instSize == 0) {
|
||||
instSize = 4; // 4: default instruction step size while instruction can't be resolved or be constant
|
||||
@ -454,8 +455,8 @@ void LLVMAssembler::PrintInstAndStep(uint64_t &instrOffset, uint8_t **instrAddr,
|
||||
if (logFlag) {
|
||||
uint64_t unitedInstOffset = instrOffset + textOffset;
|
||||
// 8: length of output content
|
||||
LOG_COMPILER(INFO) << std::setw(8) << std::setfill('0') << std::hex << unitedInstOffset << ":" << std::setw(8)
|
||||
<< GetInstrValue(instSize, *instrAddr) << " " << outString;
|
||||
codeStream << std::setw(8) << std::setfill('0') << std::hex << unitedInstOffset << ":" << std::setw(8)
|
||||
<< GetInstrValue(instSize, *instrAddr) << " " << outString << std::endl;
|
||||
}
|
||||
instrOffset += instSize;
|
||||
*instrAddr += instSize;
|
||||
@ -478,15 +479,18 @@ void LLVMAssembler::Disassemble(const std::map<uintptr_t, std::string> *addr2nam
|
||||
uint64_t instrOffset = 0;
|
||||
const size_t outStringSize = 256;
|
||||
char outString[outStringSize];
|
||||
std::ostringstream codeStream;
|
||||
while (numBytes > 0) {
|
||||
uint64_t addr = reinterpret_cast<uint64_t>(instrAddr) - bufAddr;
|
||||
if (addr2name != nullptr && addr2name->find(addr) != addr2name->end()) {
|
||||
std::string methodName = addr2name->at(addr);
|
||||
LOG_COMPILER(INFO) << "------------------- asm code [" << methodName << "] -------------------";
|
||||
codeStream << "------------------- asm code [" << methodName << "] -------------------"
|
||||
<< std::endl;
|
||||
}
|
||||
size_t instSize = LLVMDisasmInstruction(ctx, instrAddr, numBytes, instrOffset, outString, outStringSize);
|
||||
PrintInstAndStep(instrOffset, &instrAddr, numBytes, instSize, 0, outString);
|
||||
PrintInstAndStep(instrOffset, &instrAddr, numBytes, instSize, 0, outString, codeStream);
|
||||
}
|
||||
LOG_ECMA(INFO) << "\n" << codeStream.str();
|
||||
LLVMDisasmDispose(ctx);
|
||||
}
|
||||
|
||||
@ -529,7 +533,8 @@ uint64_t LLVMAssembler::GetTextSectionIndex() const
|
||||
}
|
||||
|
||||
void LLVMAssembler::Disassemble(const std::map<uintptr_t, std::string> &addr2name, uint64_t textOffset,
|
||||
const CompilerLog &log, const MethodLogList &logList) const
|
||||
const CompilerLog &log, const MethodLogList &logList,
|
||||
std::ostringstream &codeStream) const
|
||||
{
|
||||
const uint64_t textSecIndex = GetTextSectionIndex();
|
||||
LLVMDisasmContextRef disCtx = LLVMCreateDisasm(LLVMGetTarget(module_), nullptr, 0, nullptr, SymbolLookupCallback);
|
||||
@ -556,14 +561,15 @@ void LLVMAssembler::Disassemble(const std::map<uintptr_t, std::string> &addr2nam
|
||||
logFlag = false;
|
||||
}
|
||||
if (logFlag) {
|
||||
LOG_COMPILER(INFO) << "------------------- asm code [" << methodName << "] -------------------";
|
||||
codeStream << "------------------- asm code [" << methodName << "] -------------------"
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
size_t instSize = LLVMDisasmInstruction(disCtx, instrAddr, numBytes, instrOffset, outString, outStringSize);
|
||||
DecodeDebugInfo(instrOffset, textSecIndex, outString, outStringSize,
|
||||
dwarfCtx.get(), llvmModule_, methodName);
|
||||
PrintInstAndStep(instrOffset, &instrAddr, numBytes, instSize, textOffset, outString, logFlag);
|
||||
PrintInstAndStep(instrOffset, &instrAddr, numBytes, instSize, textOffset, outString, codeStream, logFlag);
|
||||
}
|
||||
}
|
||||
LLVMDisasmDispose(disCtx);
|
||||
|
@ -130,7 +130,7 @@ public:
|
||||
return engine_;
|
||||
}
|
||||
void Disassemble(const std::map<uintptr_t, std::string> &addr2name, uint64_t textOffset,
|
||||
const CompilerLog &log, const MethodLogList &logList) const;
|
||||
const CompilerLog &log, const MethodLogList &logList, std::ostringstream &codeStream) const;
|
||||
static void Disassemble(const std::map<uintptr_t, std::string> *addr2name,
|
||||
const std::string& triple, uint8_t *buf, size_t size);
|
||||
static int GetFpDeltaPrevFramSp(LLVMValueRef fn, const CompilerLog &log);
|
||||
@ -186,7 +186,8 @@ private:
|
||||
void BuildAndRunPasses();
|
||||
void Initialize(LOptions option);
|
||||
static void PrintInstAndStep(uint64_t &pc, uint8_t **byteSp, uintptr_t &numBytes, size_t instSize,
|
||||
uint64_t textOffset, char *outString, bool logFlag = true);
|
||||
uint64_t textOffset, char *outString, std::ostringstream &codeStream,
|
||||
bool logFlag = true);
|
||||
uint64_t GetTextSectionIndex() const;
|
||||
|
||||
LLVMMCJITCompilerOptions options_ {};
|
||||
|
Loading…
Reference in New Issue
Block a user