Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit54fbd47

Browse files
authored
Improve linker performance by avoiding IndexOf (#90721)
* Improve linker performance by avoiding IndexOf* Fix typos
1 parent5c92887 commit54fbd47

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

‎src/tools/illink/src/linker/Linker.Steps/UnreachableBlocksOptimizer.cs‎

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,39 @@ static bool IsMethodSupported (MethodDefinition method)
9292
returntrue;
9393
}
9494

95-
staticboolHasJumpIntoTargetRange(Collection<Instruction>instructions,intfirstInstr,intlastInstr,Func<Instruction,int>?mapping=null)
95+
staticboolHasJumpIntoTargetRange(Collection<Instruction>instructions,intfirstInstr,intlastInstr,Func<Instruction,int?>?mapping=null)
9696
{
9797
foreach(varinstrininstructions){
9898
switch(instr.OpCode.FlowControl){
9999
caseFlowControl.Branch:
100100
caseFlowControl.Cond_Branch:
101101
if(instr.OperandisInstructiontarget){
102-
intindex=mapping==null?instructions.IndexOf(target):mapping(target);
103-
if(index>=firstInstr&&index<=lastInstr)
104-
returntrue;
102+
if(mapping!=null&&mapping(target)isintindex){
103+
if(index>=firstInstr&&index<=lastInstr){
104+
returntrue;
105+
}
106+
}
107+
else{
108+
for(inti=firstInstr;i<=lastInstr;i++){
109+
if(instructions[i]==target){
110+
returntrue;
111+
}
112+
}
113+
}
105114
}else{
106115
foreach(varrtargetin(Instruction[])instr.Operand){
107-
intindex=mapping==null?instructions.IndexOf(rtarget):mapping(rtarget);
108-
if(index>=firstInstr&&index<=lastInstr)
109-
returntrue;
116+
if(mapping!=null&&mapping(rtarget)isintindex){
117+
if(index>=firstInstr&&index<=lastInstr){
118+
returntrue;
119+
}
120+
}
121+
else{
122+
for(inti=firstInstr;i<=lastInstr;i++){
123+
if(instructions[i]==rtarget){
124+
returntrue;
125+
}
126+
}
127+
}
110128
}
111129
}
112130

@@ -1175,6 +1193,15 @@ int GetInstructionIndex (Instruction instruction)
11751193
returnidx;
11761194
}
11771195

1196+
int?TryGetInstructionIndex(Instructioninstruction)
1197+
{
1198+
Debug.Assert(mapping!=null);
1199+
if(mapping.TryGetValue(instruction,outintidx))
1200+
returnidx;
1201+
1202+
returnnull;
1203+
}
1204+
11781205
boolGetOperandsConstantValues(intindex,outobject?left,outobject?right)
11791206
{
11801207
Debug.Assert(FoldedInstructions!=null);
@@ -1213,7 +1240,7 @@ static bool IsPairedStlocLdloc (Instruction first, Instruction second)
12131240
boolIsJumpTargetRange(intfirstInstr,intlastInstr)
12141241
{
12151242
Debug.Assert(FoldedInstructions!=null);
1216-
returnHasJumpIntoTargetRange(FoldedInstructions,firstInstr,lastInstr,GetInstructionIndex);
1243+
returnHasJumpIntoTargetRange(FoldedInstructions,firstInstr,lastInstr,TryGetInstructionIndex);
12171244
}
12181245
}
12191246

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp