Skip to content
This repository has been archived by the owner on Jan 19, 2025. It is now read-only.

Durandin Vladimir. Lab 3. Option 2. #105

Merged
merged 12 commits into from
May 13, 2024

Conversation

Sturmannn
Copy link

Implemented Pass, which

Counts the number of machine instructions executed during the execution of a function (excluding program counter increments).

You suggested

To make it easier to select a register to store the counter in a global variable, you can define and initialize it in a function.

But the simple instruction ic = 0 does not allow access to the register, due to the fact that this instruction does not work with registers, but only with memory.
This can be solved by initializing it with a more complex object, but I decided to create my own virtual register for the counter. This allows you to avoid adding initialization of the is variable inside the function.

Example:

// test.cpp
void empty_func() {}
; test.ll
; Function Attrs: mustprogress noinline nounwind optnone uwtable
define dso_local void @_Z10empty_funcv() #0 {
entry:
  ret void
}
# test_input.mir
  bb.0.entry:
    frame-setup PUSH64r killed $rbp, implicit-def $rsp, implicit $rsp
    frame-setup CFI_INSTRUCTION def_cfa_offset 16
    frame-setup CFI_INSTRUCTION offset $rbp, -16
    $rbp = frame-setup MOV64rr $rsp
    frame-setup CFI_INSTRUCTION def_cfa_register $rbp
    $rbp = frame-destroy POP64r implicit-def $rsp, implicit $rsp
    frame-destroy CFI_INSTRUCTION def_cfa $rsp, 8
    RET64
# test_output.mir
  bb.0.entry:
    MOV64mr %0, &ic
    frame-setup PUSH64r killed $rbp, implicit-def $rsp, implicit $rsp
    frame-setup CFI_INSTRUCTION def_cfa_offset 16
    frame-setup CFI_INSTRUCTION offset $rbp, -16
    $rbp = frame-setup MOV64rr $rsp
    frame-setup CFI_INSTRUCTION def_cfa_register $rbp
    $rbp = frame-destroy POP64r implicit-def $rsp, implicit $rsp
    frame-destroy CFI_INSTRUCTION def_cfa $rsp, 8
    %0:gr64 = ADD64ri8 %0, 8, implicit-def $eflags
    RET64

@Sturmannn Sturmannn requested a review from m-ly4 May 2, 2024 21:52
@Sturmannn Sturmannn requested a review from m-ly4 May 12, 2024 21:08
@m-ly4 m-ly4 merged commit f7e10e3 into NN-complr-tech:course-spring-2024 May 13, 2024
5 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants