KR20000003016A - Method for compiling of computer program - Google Patents

Method for compiling of computer program Download PDF

Info

Publication number
KR20000003016A
KR20000003016A KR1019980024083A KR19980024083A KR20000003016A KR 20000003016 A KR20000003016 A KR 20000003016A KR 1019980024083 A KR1019980024083 A KR 1019980024083A KR 19980024083 A KR19980024083 A KR 19980024083A KR 20000003016 A KR20000003016 A KR 20000003016A
Authority
KR
South Korea
Prior art keywords
instruction
branch
label
branch instruction
instructions
Prior art date
Application number
KR1019980024083A
Other languages
Korean (ko)
Inventor
김대환
Original Assignee
윤종용
삼성전자 주식회사
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 윤종용, 삼성전자 주식회사 filed Critical 윤종용
Priority to KR1019980024083A priority Critical patent/KR20000003016A/en
Publication of KR20000003016A publication Critical patent/KR20000003016A/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/30Arrangements for executing machine instructions, e.g. instruction decode
    • G06F9/30003Arrangements for executing specific machine instructions
    • G06F9/3005Arrangements for executing specific machine instructions to perform operations for flow control
    • G06F9/30058Conditional branch instructions

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

PURPOSE: Method for compiling of computer program is provided to remove branch instruction in converting source code of program to code be able performed by data processing system. CONSTITUTION: The method comprises the steps of: fetching instruction, determining the instruction is branch instruction, determining target label is located afterward of the branch instruction when the instruction is branch instruction, determining the instruction converts conditional flag or existence of target label which referred from outside between the branch instruction and the target label when the target label is located afterward of the branch instruction, converting at least first instruction, which exists between the branch instruction and the target label, to second instruction which includes opposite condition from condition of the branch instruction and deleting the branch instruction.

Description

컴퓨터 프로그램의 컴파일 방법(COMPILING METHOD FOR COMPUTER PROGRAM)COMPILING METHOD FOR COMPUTER PROGRAM

본 발명은 원시 언어로 된 프로그램을 다른 언어로 컴파일하는 방법에 관한 것으로, 좀 더 구체적으로는 원시 프로그램의 명령어의 실행 조건을 변경하여 컴파일하는 방법에 관한 것이다.The present invention relates to a method of compiling a program in a native language into another language, and more particularly, to a method of compiling by changing an execution condition of an instruction of a native program.

컴파일(Compilation)은 사람이 인식할 수 있는 언어로 작성된 프로그램의 소스 코드(source code)를 데이터 처리 시스템에서 수행 가능한 코드로 변환하는 과정이다. 컴파일은 프로그램의 각 문장을 하나 또는 하나 이상의 기계어(machine language) 문장으로 변환한다.Compilation is a process of converting source code of a program written in a language recognizable by a person into code that can be executed in a data processing system. Compilation converts each statement in a program into one or more machine language statements.

RISC(Reduced Instruction Set Computer)의 마이크로 프로세서(microprocessor)와 마이크로 컨트롤러(microcontroller)는 컴퓨터의 명령어의 형식을 간소화하여 제어 논리를 간단히 구현할 수 있게 하고, 빠른 동작을 위해 하드와이어된 제어를 사용한다. RISC 프로세서의 특징은 매 클락 사이클(clock cycle)마다 하나의 명령을 실행할 수 있다는 점이다. 이것은 파이프라인(pipeline)이라는 방법을 통해 둘 내지 세 명령어의 페치(fetch), 디코드, 실행 단계를 중첩시킴으로써 구현된다.Reduced instruction set computer (RISC) microprocessors and microcontrollers simplify the format of computer instructions, simplifying control logic, and using hardwired controls for faster operation. A feature of the RISC processor is that it can execute one instruction every clock cycle. This is accomplished by nesting two, three instructions to fetch, decode, and execute steps in a pipelined way.

RISC 프로세서에서 파이프라인 데이터 처리는 데이터의 흐름뿐만 아니라 명령어의 흐름에 대해서도 동작하는데, 명령어 파이프라인은 이전 명령어가 다른 세그먼트(segment)에서 실행되고 있는 동안에 메모리에 연속적으로 저장되어 있는 다음 명령어를 읽어온다. 즉 명령어의 페치와 실행 단계가 중첩되어 동시에 수행된다. 이러한 방법의 단점은 명령의 흐름에서 분기가 발생할 때 파이프라인이 모드 비워져야 하고, 따라서 분기 명령어 이후에 메모리에서 읽어온 명령어는 모두 무시되어야 하는 것이다. 이는 성능에 나쁜 영향을 끼친다.In a RISC processor, pipeline data processing operates not only on the data flow but also on the flow of instructions. The instruction pipeline reads the next instruction that is continuously stored in memory while the previous instruction is executing on another segment. . In other words, the instruction fetch and execution steps are overlapped and executed simultaneously. The disadvantage of this method is that when a branch occurs in the flow of instructions, the pipeline must be emptied and all instructions read from memory after the branch instruction must be ignored. This adversely affects performance.

이러한 문제점을 해결하기 위하여 하드웨어(hardware)적, 소프트웨어(software)적인 방법이 오랫동안 연구되어 왔다. 하드웨어적인 해결 방법의 하나는 명령어 집합의 모든 명령어를 조건부 실행이 가능하도록 만들고, 프로그래머가 모든 명령어에 직접 분기여부의 조건을 부가하도록 하는 것이다. 어드밴스드 리스크 머신즈(Advanced RISC Machines) 사에서 제조하는 마이크로프로세서는 이러한 기능을 하드웨어적으로 지원하여 분기 명령어(Branch instruction)를 없애도록 하였다. 그러나, 이러한 방법은 고급 언어(high-level language) 프로그래머가 직접 프로그래밍하기에는 많은 어려움이 따른다.In order to solve this problem, hardware and software methods have been studied for a long time. One hardware solution is to make all instructions in the instruction set conditional executable and allow the programmer to add a branching condition directly to all instructions. Microprocessors manufactured by Advanced RISC Machines support this feature in hardware, eliminating branch instructions. However, this method is difficult for high-level language programmers to program directly.

엠버디드(embedded) 시스템에서 프로그램은 롬(ROM)에 저장되는 것이 일반적이다. 롬의 사이즈는 곧 비용과 직결되므로 크기가 작은 목적 파일(object file)을 생성해야 할 필요가 있다. 상기 목적 파일은 컴파일러(compiler)에 의해 소스 코드가 기계어 코드로 변환된 것이다. 따라서, 목적 파일의 크기를 작게 줄일 수 있는 컴파일 방법이 필요하다.In an embedded system, the program is usually stored in a ROM. Since the size of the ROM is directly related to the cost, it is necessary to create a small object file. The object file is a source code converted into machine code by a compiler. Therefore, there is a need for a compilation method that can reduce the size of the object file.

따라서, 본 발명의 목적은 상술한 제반 문제점을 해결하기 위해 제안된 것으로, 프로그램의 소스 코드(source code)를 데이터 처리 시스템에서 수행 가능한 코드로 변환하는 과정에서 분기 명령어를 제거하고, 각 명령어를 조건부 실행 명령어로 변환하는 방법을 제공하는데 있다.Accordingly, an object of the present invention has been proposed to solve the above-mentioned problems, and removes the branch instruction in the process of converting the source code of the program into code that can be executed in the data processing system, and conditionally condition each instruction To provide a way to translate into executable instructions.

도 1은 본 발명의 바람직한 실시예에 따른 컴퓨터 프로그램을 컴파일하는 컴파일 프로그램의 동작 수순을 보여주는 플로우 차트이다.1 is a flow chart showing an operation procedure of a compiled program for compiling a computer program according to a preferred embodiment of the present invention.

상술한 바와 같은 본 발명의 목적을 달성하기 위한 본 발명의 특징에 의하면, 컴퓨터 프로그램의 컴파일 방법은: 명령어를 페치(fetch)하는 단계와; 상기 명령어가 분기(branch) 명령어인 지의 여부를 판별하는 단계와; 상기 명령어가 분기 명령어인 경우, 상기 분기 명령어의 타겟 레이블(target label)이 상기 분기 명령어 이후에 위치하는 지의 여부를 판별하는 단계와; 상기 타겟 레이블이 상기 분기 명령어 이후에 위치하는 경우, 상기 분기 명령어와 타겟 레이블 사이의 영역에 조건 플래그(conditional flag)를 변경하는 명령어 또는 상기 영역 밖에서 참조되는 타겟 레이블이 있는가를 판단하는 단계와; 상기 조건 플래그를 변경하는 명령어와 상기 영역 밖에서 참조되는 레이블이 없는 경우, 상기 분기 명령어와 상기 타겟 레이블 사이에 위치하는 적어도 하나의 제 1 명령어를 상기 분기 명령어의 분기 조건과 반대되는 조건을 포함하는 제 2 명령어로 변환한 후, 상기 분기 명령어를 삭제하는 단계를 포함한다.According to a feature of the present invention for achieving the object of the present invention as described above, a method of compiling a computer program comprises: fetching an instruction; Determining whether the instruction is a branch instruction; If the instruction is a branch instruction, determining whether a target label of the branch instruction is located after the branch instruction; If the target label is located after the branch instruction, determining whether there is an instruction for changing a conditional flag in the region between the branch instruction and the target label or a target label referenced outside the region; When there is no instruction to change the condition flag and a label referenced outside the region, the at least one first instruction positioned between the branch instruction and the target label includes a condition opposite to a branch condition of the branch instruction; After converting to two instructions, deleting the branch instruction.

바람직한 실시예에 있어서, 적어도 2 개의 분기 명령어들 다음에 위치하는 제 1 명령어는 상기 분기 명령어들의 분기 조건들과 반대되는 조건들을 앤드(AND) 연산한 결과를 포함하는 제 2 명령어로 변환된다.In a preferred embodiment, the first instruction located after the at least two branch instructions is converted to a second instruction that includes the result of ANDing conditions opposite to the branch conditions of the branch instructions.

(실시예)(Example)

이하 본 발명에 따른 실시예를 첨부된 도면 도 1을 참조하여 상세히 설명한다.Hereinafter, embodiments of the present invention will be described in detail with reference to the accompanying drawings.

본 발명의 신규한 컴퓨터 프로그램의 컴파일 방법은 분기 명령어와 타겟 레이블 사이에 위치하는 명령어들을 조건부 실행 명령어들로 변환한다. 원시 언어로 된 프로그램을 다른 언어로 컴파일시, 분기 명령어와 타겟 레이블 사이에 위치하는 명령어에 실행 조건을 부가함으로서 프로그램의 분기 명령어를 없앨 수 있다. 상기 분기 명령어와 타겟 레이블 사이에 위치하는 명령어들을 조건부 실행 명령어들로 변환할 수 있는 조건은, 상기 타겟 레이블이 분기 명령어 이후에 위치하여야 하며, 분기 명령어와 타겟 레이블 사이에 플레그 변경 명령어 또는 외부에서 참조되는 레이블이 없어야 한다. 분기 명령어와 타겟 레이블 사이에 위치하는 명령어들을 조건부 실행 명령어들로 변환함으로써 컴파일된 목적 코드의 크기가 줄어들어 메모리의 사이즈를 줄일 수 있다. 또한, 프로그램의 수행 속도가 향상된다.The novel computer program compilation method of the present invention converts instructions placed between the branch instruction and the target label into conditional execution instructions. When compiling a program in a native language into another language, you can eliminate the program's branch instructions by adding execution conditions to the instructions placed between the branch instruction and the target label. The condition for converting instructions placed between the branch instruction and the target label into conditional execution instructions may include the target label after the branch instruction, and a flag change instruction or an external reference between the branch instruction and the target label. There should be no label. By converting instructions placed between the branch instruction and the target label into conditional execution instructions, the size of the compiled object code can be reduced to reduce the size of the memory. In addition, the execution speed of the program is improved.

컴퓨터 프로그램의 컴파일 방법의 일 예로 ARM(Advanced RISC Machines) 사의 ARM 7 어셈블리 언어(assembly language)를 설명한다.As an example of how to compile a computer program, ARM 7 assembly language of ARM (Advanced RISC Machines) is described.

[프로그램 1][Program 1]

CMP R1, R2CMP R1, R2

BEQ Label_1BEQ Label_1

Instr_1_1Instr_1_1

Instr_1_2Instr_1_2

……… …

Instr_1_nInstr_1_n

B Label_2B Label_2

Label_1:Label_1:

Instr_2_1Instr_2_1

Instr_2_2Instr_2_2

……… …

Instr_2_nInstr_2_n

Label_2:Label_2:

……… …

상기 [프로그램 1]을 본 발명의 컴파일러에서 명령어를 변환한 결과가 다음과 같다.The result of converting the instruction of [Program 1] in the compiler of the present invention is as follows.

[결과 1][Result 1]

CMP R1, R2CMP R1, R2

Instr_1_1NEInstr_1_1NE

Instr_1_2NEInstr_1_2NE

……… …

Instr_1_nNEInstr_1_nNE

Instr_2_1EQInstr_2_1EQ

Instr_2_2EQInstr_2_2EQ

……… …

Instr_2_nEQInstr_2_nEQ

……… …

상기 [결과 1]에서 알 수 있듯이 분기 명령어 'BEQ Label_1' 및 'B Label_2'가 삭제된다. 분기 명령어와 타겟 레이블 사이의 명령어들에는 각각 분기 명령어의 반대 조건이 부가된다. 그러나, ARM 7과 같은 마이크로 프로세서에서는 명령어들에 조건이 부가된 조건부 실행 명령어가 되더라도 코드 사이즈는 일반 명령어와 동일하므로, 코드 사이즈가 증가하지 않는다. 그 결과, 전체 프로그램의 사이즈를 줄일 수 있다.As shown in [Result 1], the branch instructions 'BEQ Label_1' and 'B Label_2' are deleted. Instructions between the branch instruction and the target label are each added with the opposite condition of the branch instruction. However, in a microprocessor such as ARM 7, even if a conditional execution instruction is added to the instructions, the code size is the same as that of a general instruction, and thus the code size does not increase. As a result, the size of the entire program can be reduced.

상기 [프로그램 1] 및 [결과 1]을 보다 상세히 살펴보면, 'CMP R1, R2'에서 R1과 R2를 비교한 결과, 'BEQ Label_1'에 의해 상기 R1과 R2의 값이 동일한 경우(EQ) Label 1로 분기한다. 동일하지 않은 경우(NE)에는 다음 명령어를 수행한다. 따라서, BEQ Label_1 이후의 명령어들에는 'NE' 즉 not equal이라는 조건이 부가되었다. 이는 상기 분기 명령어의 분기 조건 'EQ(equal)'에 반대되는 조건이다. 레이블 'Label_1'이 실행될 조건은 R1과 R2의 값이 동일할 때이므로 'Label_1'에 속하는 명령어들에는 'EQ'가 부가되었다.Looking at [Program 1] and [Result 1] in more detail, when R1 and R2 are compared in 'CMP R1, R2', when the values of R1 and R2 are the same by 'BEQ Label_1' (EQ) Label 1 Branch to If it is not the same (NE), the following command is executed. Therefore, the commands after BEQ Label_1 have the condition 'NE', that is, not equal. This is a condition opposite to the branch condition 'EQ (equal)' of the branch instruction. The condition under which the label 'Label_1' is executed is when the values of R1 and R2 are the same, so 'EQ' is added to the commands belonging to 'Label_1'.

또 다른 예로 [프로그램 2]를 참조하여 설명한다.Another example will be described with reference to [Program 2].

[프로그램 2][Program 2]

L_00005:L_00005:

ADD R14, R3, R1, LSL #2ADD R14, R3, R1, LSL # 2

SUB R1, R1, #1SUB R1, R1, # 1

STR R12, [R14, #4]!STR R12, [R14, # 4]!

L_00006:L_00006:

CMP R1, #0CMP R1, # 0

BLT L_00007BLT L_00007

LDR R12, [R3, R1, LSL #2]LDR R12, [R3, R1, LSL # 2]

CMP R12, R4CMP R12, R4

BGT L_00005BGT L_00005

L_00007:L_00007:

……… …

[결과 2][Result 2]

L_00005:L_00005:

ADD R14, R3, R1, LSL #2ADD R14, R3, R1, LSL # 2

SUB R1, R1, #1SUB R1, R1, # 1

STR R12, [R14, #4]!STR R12, [R14, # 4]!

L_00006:L_00006:

CMP R1, #0CMP R1, # 0

LDRGE R12, [R3, R1, LSL #2]LDRGE R12, [R3, R1, LSL # 2]

CMPGE R12, R4CMPGE R12, R4

BGT L_00005BGT L_00005

L_00007:L_00007:

……… …

[프로그램 2]에서는 'CMP R1, #0'에서 R1과 0을 비교하고, 그 결과 R1이 0보다 작으면(LT) L_00007로 분기한다. 따라서 분기 명령어 'BLT L_00007'과 타겟 레이블 'L_00007' 사이의 명령어들은 R1이 0보다 크거나 같을 때(GE; Greater Than) 실행된다. [결과 2]에서와 같이 상기 분기 명령어와 타겟 레이블 사이의 명령어들에는 'GE'가 부가된다.[Program 2] compares R1 with 0 at 'CMP R1, # 0'. As a result, if R1 is less than 0 (LT), the process branches to L_00007. Therefore, instructions between the branch instruction 'BLT L_00007' and the target label 'L_00007' are executed when R1 is greater than or equal to 0 (GE; Greater Than). As shown in [Result 2], 'GE' is added to the instructions between the branch instruction and the target label.

다음 [프로그램 3]은 연속된 분기 명령어가 있는 경우를 보여주고 있다.[Program 3] below shows the case where there are consecutive branch instructions.

[프로그램 3][Program 3]

L_0001:L_0001:

CMP R3, R4CMP R3, R4

BEQ L_0002BEQ L_0002

BLT L_0003BLT L_0003

SUB R3, R3, R4SUB R3, R3, R4

B L_0001B L_0001

L_0002:L_0002:

SUB R4, R4, R3SUB R4, R4, R3

B L_0001B L_0001

L_0003:L_0003:

……… …

[결과 3][Result 3]

L_0001:L_0001:

CMP R3, R4CMP R3, R4

SUBGT R3, R3, R4SUBGT R3, R3, R4

SUBEQ R4, R4, R3SUBEQ R4, R4, R3

BGE L_0001BGE L_0001

L_0003:L_0003:

……… …

'EQ(equal)'와 'LT(less than)'의 반대되는 조건은 각각 'NE(not equal)'및 'GE(greater equal)'이고, 반대되는 조건들의 앤드(AND) 연산 결과는 'GT(greater than)'이다. 따라서 첫 번째 SUB 명령어에는 'GT'가 부가되었다. 레이블 'L_0002'를 수행하는 조건은 'BEQ L_0002'에서 R3과 R4가 같을 때이므로 두 번째 SUB 명령어에는 'EQ'가 부가된다.The opposite conditions of 'EQ (equal)' and 'LT (less than)' are 'NE (not equal)' and 'GE (greater equal)' respectively, and the result of AND operation of the opposite conditions is 'GT' (greater than) '. Therefore, 'GT' is added to the first SUB command. The condition to execute the label 'L_0002' is when R3 and R4 are the same in 'BEQ L_0002', so 'EQ' is added to the second SUB instruction.

다음 [프로그램 4] 및 [프로그램 5]는 분기 명령어 다음의 명령어를 조건부 실행 명령어로 변환할 수 없는 예를 보여주고 있다.[Program 4] and [Program 5] below show an example in which the instruction following the branch instruction cannot be converted to a conditional execution instruction.

먼저 [프로그램 4]는 분기 명령어와 타겟 레이블 사이에 조건 플래그들(conditional flags)을 변경시키는 명령어가 있는 경우이다.[Program 4] is a case where there is an instruction to change conditional flags between the branch instruction and the target label.

[프로그램 4][Program 4]

Label_1:Label_1:

CMP R1, R2CMP R1, R2

BEQ Label_2BEQ Label_2

ADD R3, R4ADD R3, R4

CMP R5, R6CMP R5, R6

SUB R7, R8SUB R7, R8

Label_2:Label_2:

……… …

[결과 4][Result 4]

Label_1:Label_1:

CMP R1, R2CMP R1, R2

ADDNE R3, R4ADDNE R3, R4

CMPNE R5, R6CMPNE R5, R6

SUBNE R7, R8SUBNE R7, R8

Label_2:Label_2:

……… …

상기 [프로그램 4]를 컴파일한 [결과 4]를 참조하면, 첫 번째 비교 명령어 'CMP R1, R2'의 결과에 따라 ADD 명령과, 두 번째 CMP 명령을 수행 여부가 결정된다. 만일 R1과 R2의 값이 달라(NE) 두 번째 CMP가 수행된다면 R5와 R6의 값에 따라 조건 플래그 값이 달라질 수 있다. [프로그램 4]에서 SUB 명령은 R1과 R2의 값이 다를 때 수행되도록 프로그램 되어 있는데, [결과 4]에서는 R5와 R6의 값이 다를 때 수행되도록 프로그램 되어 있다. 따라서 프로그래머 의도했던 결과와 다른 결과가 발생할 수도 있다.Referring to [Result 4] of compiling [Program 4], it is determined whether to execute the ADD instruction and the second CMP instruction according to the result of the first comparison instruction 'CMP R1 and R2'. If the values of R1 and R2 are different (NE), if the second CMP is performed, the condition flag value may vary according to the values of R5 and R6. In [Program 4], the SUB instruction is programmed to be executed when the values of R1 and R2 are different. In [Result 4], the SUB instruction is programmed to be executed when the values of R5 and R6 are different. As a result, results may differ from those intended by the programmer.

그러므로, 분기 명령어(BEQ Label_2)와 타겟 레이블(Label_2) 사이에 CMP와 같이 조건 플래그의 값을 변경시키는 명령어가 있는 경우, 상기 분기 명령어(BEQ Label_2)와 타겟 레이블(Label_2) 사이의 명령어들을 조건부 실행 명령어로 변경시키지 않는다.Therefore, when there is an instruction for changing the value of the condition flag, such as CMP, between the branch instruction BEQ Label_2 and the target label Label_2, conditionally executing the instructions between the branch instruction BEQ Label_2 and the target label Label_2. Do not change it with a command.

다음, [프로그램 5]는 분기 명령어 다음의 명령어를 조건부 실행 명령어로 변환할 수 없는 다른 예로, 분기 명령어와 타겟 레이블 사이에 외부에서 참조되는 레이블이 있는 경우이다.Next, [Program 5] is another example in which an instruction following a branch instruction cannot be converted to a conditional execution instruction, and there is an externally referenced label between the branch instruction and the target label.

[프로그램 5][Program 5]

Label_1:Label_1:

CMP R1, R2CMP R1, R2

BEQ Label_2BEQ Label_2

ADD R3, R4, R5ADD R3, R4, R5

Label_new:Label_new:

SUB R4, R5, R6SUB R4, R5, R6

Label_2:Label_2:

TEQ R10, R10TEQ R10, R10

BEQ Label_newBEQ Label_new

[결과 5][Result 5]

Label_1:Label_1:

CMP R1, R2CMP R1, R2

ADDNE R3, R4, R5ADDNE R3, R4, R5

Label_new:Label_new:

SUBNE R4, R5, R6SUBNE R4, R5, R6

Label_2:Label_2:

TEQ R10, R10TEQ R10, R10

BEQ Label_newBEQ Label_new

'TEQ' 명령어는 2 개의 오퍼랜드(operand)가 같은지를 비교하는 명령어이다. 레이블 'Label_2'에서 'TEQ R10, R10'의 결과는 참이므로 반드시 레이블 'Label_new'로 분기가 이루어진다. [프로그램 5]에서는 'BEQ Label_new'에 의해 분기되었을 때 'SUB' 명령어를 반드시 실행하도록 프로그램 되어 있다. 'SUB' 명령어가 조건부 실행 명령어 'SUBNE'로 변환된 결과, 'BEQ Label_new'에 의해 Label_new'로 분기되었을 때 'SUB' 명령어를 수행하지 않는다.The 'TEQ' instruction compares two operands for equality. Since the result of 'TEQ R10, R10' in the label 'Label_2' is true, a branch is made to the label 'Label_new'. Program 5 is programmed to execute the SUB command when branched by BEQ Label_new. As a result of converting the 'SUB' command to conditional execution command 'SUBNE', the 'SUB' command is not executed when branching to Label_new by 'BEQ Label_new'.

그러므로, 분기 명령어(BEQ Label_2)와 타겟 레이블(Label_2) 사이에 외부에서 참조되는 레이블(Label_new)이 있는 경우에는 상기 분기 명령어(BEQ Label_2)와 타겟 레이블(Label_2) 사이에 있는 명령어들을 조건부 실행 명령어로 변환하지 않는다.Therefore, when there is an externally referenced label (Label_new) between the branch instruction (BEQ Label_2) and the target label (Label_2), the instructions between the branch instruction (BEQ Label_2) and the target label (Label_2) are conditional execution instructions. Do not convert.

상술한 바와 같이 분기 명령어와 타겟 레이블 사이에 위치하는 명령어들을 조건부 실행 명령어로 변환하는 컴파일 프로그램의 동작 수순이 도 1에 도시되어 있다.As described above, an operation procedure of a compilation program for converting instructions positioned between a branch instruction and a target label into a conditional execution instruction is illustrated in FIG. 1.

단계 S10에서는, 명령어를 페치(fetch)한다. 다음 단계 S20에서는 프로그램의 마지막인 지 여부를 판별하여 마지막인 경우에는 컴파일을 종료하고, 마지막이 아닌 경우에는 단계 S30으로 진행한다.In step S10, the instruction is fetched. In the next step S20, it is determined whether or not the end of the program is completed. If it is the last time, the compilation is terminated.

단계 S30에서는, 페치한 명령어가 분기 명령어(branch instruction)인지의 여부를 판별한다. 분기 명령어가 아닌 경우에는 리턴하고, 분기 명령어인 경우에는 단계 S40으로 진행하여, 타겟 레이블(target label)이 상기 분기 명령어 이후에 위치하는 지의 여부를 판별한다. 상기 타겟 레이블이 상기 분기 명령어 이후에 위치하지 않는 경우에는 리턴하고, 분기 명령어 이후에 위치하는 경우에는 단계 S50으로 진행한다.In step S30, it is determined whether the fetched instruction is a branch instruction. If it is not a branch instruction, the method returns. If it is a branch instruction, the process proceeds to step S40 to determine whether a target label is located after the branch instruction. If the target label is not located after the branch instruction, the method returns. If the target label is located after the branch instruction, the process proceeds to step S50.

단계 S50에서는, 상기 분기 명령어와 타겟 레이블 사이의 영역에 조건 플래그(conditional flag)를 변경하는 명령어 또는 상기 영역 밖에서 참조되는 타겟 레이블이 있는가를 판단한다. 상기 조건 플래그를 변경하는 명령어와 상기 영역 밖에서 참조되는 레이블이 없는 경우에는 단계 S60으로 진행하고, 상기 조건 플래그를 변경하는 명령어와 상기 영역 밖에서 참조되는 레이블이 있는 경우에는 리턴한다.In step S50, it is determined whether there is an instruction for changing a conditional flag in the region between the branch instruction and the target label or a target label referenced outside the region. If there is no instruction to change the condition flag and a label referenced outside the region, the flow advances to step S60, and returns if there is a instruction to change the condition flag and a label referenced outside the region.

단계 S60에서는, 상기 분기 명령어와 상기 타겟 레이블 사이에 위치하는 모든 명령어를 상기 분기 명령어의 분기 조건과 반대되는 조건을 포함하는 조건부 실행 명령어(conditional execution instruction)로 변환한다. 상기 조건부 실행 명령어는 원래의 명령어에 조건을 부가한 것으로, 조건이 만족하는 경우에 명령을 수행하는 명령어이다. 만일 분기 명령어들이 연속적으로 두 개 이상 있다면, 상기 분기 명령어들 다음에 위치하는 명령어는 상기 분기 명령어들의 분기 조건들과 반대되는 조건들을 앤드(AND) 연산한 결과를 포함하는 제 2 명령어로 변환된다.In step S60, all instructions located between the branch instruction and the target label are converted into a conditional execution instruction including a condition opposite to the branch condition of the branch instruction. The conditional execution instruction adds a condition to the original instruction, and executes the instruction when the condition is satisfied. If there are two or more branch instructions in a row, the instruction placed after the branch instructions is converted to a second instruction including the result of ANDing conditions opposite to the branch conditions of the branch instructions.

본 발명의 또 다른 특징은, 분기 명령어가 페치되고 상기 분기 명령어가 지시하는 타겟 레이블을 찾는 범위 즉, 윈도우의 크기를 성능(performance)에 중점을 두느냐 또는 코드 사이즈에 중점을 두느냐에 따라 가변적으로 설정 가능하다. 즉, 윈도우의 크기를 크게 하면 코드 사이즈가 감소되는 효과가 크지만, 반면 윈도우 내의 모든 명령어들을 실행해야 하므로, 조건을 만족하지 않는 명령어들도 페치(fetch)하여 디코딩(decoding)하는 과정을 수행해야 한다. 실제로 수행하지 않을 명령어들에 대한 페치와 디코딩 과정은 성능을 저하시킬 수 있다. 따라서 프로그래머 또는 시스템이 요구하는 컴파일 성능과 코드 사이즈에 따라 명령어들을 조건부 분기 명령어로 변환하는 조건을 변경할 수 있다.Another feature of the present invention is the range in which a branch instruction is fetched and looking for a target label indicated by the branch instruction, that is, the size of the window is variably set depending on whether the performance is focused on performance or code size. It is possible. In other words, if the size of the window is increased, the code size is greatly reduced. On the other hand, since all instructions in the window must be executed, the process of fetching and decoding the instructions that do not satisfy the condition must be performed. do. Fetching and decoding the instructions that aren't actually executed can slow performance. Therefore, the condition for converting instructions into conditional branch instructions can be changed depending on the compilation performance and code size required by the programmer or the system.

이상과 같은 본 발명에 의하면, 원시 언어로 된 프로그램을 다른 언어로 컴파일시, 분기 명령어와 타겟 레이블 사이에 위치하는 명령어에 실행 조건을 부가함으로서 프로그램의 분기 명령어를 없앨 수 있다. 그 결과, 컴파일된 목적 코드의 크기가 줄어들어 메모리의 사이즈를 줄일 수 있다. 또한, 프로그램의 수행 속도가 향상된다.According to the present invention as described above, when compiling a program in a native language into another language, the branch instruction of the program can be eliminated by adding an execution condition to the instruction positioned between the branch instruction and the target label. As a result, the size of the compiled object code can be reduced, thereby reducing the size of the memory. In addition, the execution speed of the program is improved.

Claims (2)

컴퓨터 프로그램 명령어들을 컴파일러를 사용하여 컴파일하는 방법에 있어서:In order to compile computer program instructions using a compiler: 명령어가 분기(branch) 명령어인 지의 여부를 판별하는 단계와;Determining whether the instruction is a branch instruction; 상기 명령어가 분기 명령어인 경우, 상기 분기 명령어의 타겟 레이블(target label)이 상기 분기 명령어 이후에 위치하는 지의 여부를 판별하는 단계와;If the instruction is a branch instruction, determining whether a target label of the branch instruction is located after the branch instruction; 상기 타겟 레이블이 상기 분기 명령어 이후에 위치하는 경우, 상기 분기 명령어와 타겟 레이블 사이의 영역에 조건 플래그(conditional flag)를 변경하는 명령어 또는 상기 영역의 외부에서 참조되는 타겟 레이블이 있는가를 판단하는 단계와;If the target label is located after the branch instruction, determining whether there is an instruction for changing a conditional flag in the region between the branch instruction and the target label or a target label referenced outside of the region; 상기 조건 플래그를 변경하는 명령어와 상기 영역의 외부에서 참조되는 레이블이 없는 경우, 상기 분기 명령어와 상기 타겟 레이블 사이에 위치하는 적어도 하나의 제 1 명령어를 상기 분기 명령어의 분기 조건과 반대되는 조건을 포함하는 제 2 명령어로 변환한 후, 상기 분기 명령어를 삭제하는 단계를 포함하는 것을 특징으로 하는 컴퓨터 프로그램의 컴파일 방법.If there is no instruction to change the condition flag and a label referenced outside of the area, the at least one first instruction positioned between the branch instruction and the target label includes a condition opposite to the branch condition of the branch instruction. And converting the branch instruction to the second instruction. 제 1 항에 있어서,The method of claim 1, 적어도 2 개의 분기 명령어들 다음에 위치하는 제 1 명령어는 상기 분기 명령어들의 분기 조건들과 반대되는 조건들을 앤드(AND) 연산한 결과를 포함하는 제 2 명령어로 변환되는 것을 특징으로 하는 컴퓨터 프로그램의 컴파일 방법.A first instruction placed after at least two branch instructions is converted into a second instruction comprising a result of ANDing conditions opposite to the branch conditions of the branch instructions; Way.
KR1019980024083A 1998-06-25 1998-06-25 Method for compiling of computer program KR20000003016A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
KR1019980024083A KR20000003016A (en) 1998-06-25 1998-06-25 Method for compiling of computer program

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
KR1019980024083A KR20000003016A (en) 1998-06-25 1998-06-25 Method for compiling of computer program

Publications (1)

Publication Number Publication Date
KR20000003016A true KR20000003016A (en) 2000-01-15

Family

ID=19540748

Family Applications (1)

Application Number Title Priority Date Filing Date
KR1019980024083A KR20000003016A (en) 1998-06-25 1998-06-25 Method for compiling of computer program

Country Status (1)

Country Link
KR (1) KR20000003016A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR101048588B1 (en) * 2009-04-13 2011-07-12 한양대학교 산학협력단 Code control flow obfuscation apparatus and method

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR101048588B1 (en) * 2009-04-13 2011-07-12 한양대학교 산학협력단 Code control flow obfuscation apparatus and method

Similar Documents

Publication Publication Date Title
US11216258B2 (en) Direct function call substitution using preprocessor
US5452457A (en) Program construct and methods/systems for optimizing assembled code for execution
US5901308A (en) Software mechanism for reducing exceptions generated by speculatively scheduled instructions
US5193205A (en) Pipeline processor, with return address stack storing only pre-return processed address for judging validity and correction of unprocessed address
US5949995A (en) Programmable branch prediction system and method for inserting prediction operation which is independent of execution of program code
US5692169A (en) Method and system for deferring exceptions generated during speculative execution
JP3499252B2 (en) Compiling device and data processing device
US5778219A (en) Method and system for propagating exception status in data registers and for detecting exceptions from speculative operations with non-speculative operations
US4763255A (en) Method for generating short form instructions in an optimizing compiler
US6301705B1 (en) System and method for deferring exceptions generated during speculative execution
EP0833246B1 (en) A method of producing a computer program
US5802338A (en) Method of self-parallelizing and self-parallelizing multiprocessor using the method
US5446849A (en) Electronic computer which executes squash branching
US6615403B1 (en) Compare speculation in software-pipelined loops
EP0428560A4 (en) Machine process for translating programs in binary machine language into another binary machine language
EP0227117B1 (en) Program skip operation control system
US5978905A (en) Program translating apparatus and a processor which achieve high-speed execution of subroutine branch instructions
JPH0738158B2 (en) Code optimization method and compiler system
US7251594B2 (en) Execution time modification of instruction emulation parameters
JPH07120284B2 (en) Data processing device
KR20000003016A (en) Method for compiling of computer program
EP0180077B1 (en) A data processing machine for compiling computer programs
US7302555B2 (en) Zero overhead branching and looping in time stationary processors
Sun et al. Speculative vectorisation with selective replay
EP1168159A1 (en) Sub-pipelined and pipelined execution in a VLIW achitecture

Legal Events

Date Code Title Description
WITN Withdrawal due to no request for examination