From 06b23fb1aaaf76387e9821817c4e2725f5ae2d46 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Sat, 28 Dec 2024 17:14:18 +0300 Subject: [PATCH] Don't count instructions that ge going to be eliminated by MEM2SSA pass --- ir_load_llvm.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ir_load_llvm.c b/ir_load_llvm.c index 3dcc3be0..b2201e3c 100644 --- a/ir_load_llvm.c +++ b/ir_load_llvm.c @@ -1179,6 +1179,26 @@ static int llvm2ir_inline_cost(LLVMValueRef func) for (bb = LLVMGetFirstBasicBlock(func); bb; bb = LLVMGetNextBasicBlock(bb)) { for (insn = LLVMGetFirstInstruction(bb); insn; insn = LLVMGetNextInstruction(insn)) { + LLVMOpcode opcode = LLVMGetInstructionOpcode(insn); + + /* Skip SSA related instuctions */ + if (opcode == LLVMPHI + || opcode == LLVMAlloca + || (opcode == LLVMStore && LLVMGetInstructionOpcode(LLVMGetOperand(insn, 1)) == LLVMAlloca) + || (opcode == LLVMLoad && LLVMGetInstructionOpcode(LLVMGetOperand(insn, 0)) == LLVMAlloca)) { + continue; + } else if (opcode == LLVMCall) { + LLVMValueRef f = LLVMGetCalledValue(insn); + if (LLVMGetValueKind(f) == LLVMFunctionValueKind) { + size_t name_len; + const char *name; + + name = LLVMGetValueName2(f, &name_len); + if (STR_START(name, name_len, "llvm.lifetime.")) { + continue; + } + } + } count++; } }