浏览代码

* ARM PC relative references optimization.

git-svn-id: trunk@5368 -
yury 18 年之前
父节点
当前提交
ba53db3b5d
共有 1 个文件被更改,包括 31 次插入3 次删除
  1. 31 3
      compiler/arm/aasmcpu.pas

+ 31 - 3
compiler/arm/aasmcpu.pas

@@ -627,9 +627,10 @@ implementation
         lastpos : longint;
         lastpos : longint;
         curop : longint;
         curop : longint;
         curtai : tai;
         curtai : tai;
-        curdatatai,hp : tai;
+        curdatatai,hp,hp2 : tai;
         curdata : TAsmList;
         curdata : TAsmList;
         l : tasmlabel;
         l : tasmlabel;
+        removeref : boolean;
       begin
       begin
         curdata:=TAsmList.create;
         curdata:=TAsmList.create;
         lastpos:=-1;
         lastpos:=-1;
@@ -652,11 +653,38 @@ implementation
                           { move only if we're at the first reference of a label }
                           { move only if we're at the first reference of a label }
                           (taicpu(curtai).oper[curop]^.ref^.offset=0) then
                           (taicpu(curtai).oper[curop]^.ref^.offset=0) then
                           begin
                           begin
-                            { if yes, insert till next symbol }
+                            { check if symbol already used. }
+                            { if yes, reuse the symbol }
+                            hp:=tai(curdatatai.next);
+                            removeref:=false;
+                            if assigned(hp) and (hp.typ=ait_const) then
+                              begin
+                                hp2:=tai(curdata.first);
+                                while assigned(hp2) do
+                                  begin
+                                    if (hp2.typ=ait_const) and (tai_const(hp2).sym=tai_const(hp).sym)
+                                      and (tai_const(hp2).value=tai_const(hp).value) and (tai(hp2.previous).typ=ait_label)
+                                    then
+                                      begin
+                                        with taicpu(curtai).oper[curop]^.ref^ do
+                                          begin
+                                            symboldata:=hp2.previous;
+                                            symbol:=tai_label(hp2.previous).labsym;
+                                          end;
+                                        removeref:=true;
+                                        break;
+                                      end;
+                                    hp2:=tai(hp2.next);
+                                  end;
+                              end;
+                            { move or remove symbol reference }
                             repeat
                             repeat
                               hp:=tai(curdatatai.next);
                               hp:=tai(curdatatai.next);
                               listtoinsert.remove(curdatatai);
                               listtoinsert.remove(curdatatai);
-                              curdata.concat(curdatatai);
+                              if removeref then
+                                curdatatai.free
+                              else
+                                curdata.concat(curdatatai);
                               curdatatai:=hp;
                               curdatatai:=hp;
                             until (curdatatai=nil) or (curdatatai.typ=ait_label);
                             until (curdatatai=nil) or (curdatatai.typ=ait_label);
                             if lastpos=-1 then
                             if lastpos=-1 then