Browse Source

* synchronized with trunk

git-svn-id: branches/wasm@47185 -
nickysn 4 years ago
parent
commit
1438e83939

+ 2 - 4
compiler/aoptobj.pas

@@ -2465,7 +2465,7 @@ Unit AoptObj;
 
     procedure TAOptObj.PeepHoleOptPass1;
       const
-        MaxPasses: array[1..4] of Cardinal = (1, 2, 8, 8);
+        MaxPasses: array[1..3] of Cardinal = (1, 2, 8);
       var
         p : tai;
         stoploop, FirstInstruction, JumpOptsAvailable: boolean;
@@ -2477,10 +2477,8 @@ Unit AoptObj;
         PassCount := 0;
 
         { Determine the maximum number of passes allowed based on the compiler switches }
-        if (cs_opt_level4 in current_settings.optimizerswitches) then
+        if (cs_opt_level3 in current_settings.optimizerswitches) then
           { it should never take more than 8 passes, but the limit is finite to protect against faulty optimisations }
-          MaxCount := MaxPasses[4]
-        else if (cs_opt_level3 in current_settings.optimizerswitches) then
           MaxCount := MaxPasses[3]
         else if (cs_opt_level2 in current_settings.optimizerswitches) then
           MaxCount := MaxPasses[2] { The original double run of Pass 1 }

+ 16 - 15
compiler/llvm/llvmtype.pas

@@ -186,10 +186,25 @@ implementation
 
 
     function TLLVMTypeInfo.record_def(def:tdef): tdef;
+      var
+        i: longint;
       begin
         result:=def;
         if def.stab_number<>0 then
           exit;
+        { the external symbol may never be called, in which case the types
+          of its parameters will never be process -> do it here }
+        if (def.typ=procdef) then
+          begin
+            { can't use this condition to determine whether or not we need
+              to generate the argument defs, because this information does
+              not get reset when multiple units are compiled during a
+              single compiler invocation }
+            tprocdef(def).init_paraloc_info(callerside);
+            for i:=0 to tprocdef(def).paras.count-1 do
+              record_def(llvmgetcgparadef(tparavarsym(tprocdef(def).paras[i]).paraloc[callerside],true,calleeside));
+            record_def(llvmgetcgparadef(tprocdef(def).funcretloc[callerside],true,calleeside));
+          end;
         def.stab_number:=1;
         { this is an internal llvm type }
         if def=llvm_metadatatype then
@@ -505,20 +520,6 @@ implementation
               sec:=sec_data;
             toplevellist.Concat(taillvmdecl.createdecl(sym,def,nil,sec,def.alignment));
             record_asmsym_def(sym,def,true);
-            { the external symbol may never be called, in which case the types
-              of its parameters will never be process -> do it here }
-            if (def.typ=procdef) then
-              begin
-                { can't use this condition to determine whether or not we need
-                  to generate the argument defs, because this information does
-                  not get reset when multiple units are compiled during a
-                  single compiler invocation }
-                if (tprocdef(def).has_paraloc_info=callnoside) then
-                  tprocdef(def).init_paraloc_info(callerside);
-                for i:=0 to tprocdef(def).paras.count-1 do
-                  record_def(llvmgetcgparadef(tparavarsym(tprocdef(def).paras[i]).paraloc[callerside],true,calleeside));
-                record_def(llvmgetcgparadef(tprocdef(def).funcretloc[callerside],true,calleeside));
-              end;
           end;
       end;
 
@@ -716,7 +717,7 @@ implementation
         defnumberlist:=TFPObjectList.create(false);
         deftowritelist:=TFPObjectList.create(false);
 
-        { write all global/static variables, part of flaggin all required tdefs  }
+        { write all global/static variables, part of flagging all required tdefs  }
         if assigned(current_module.globalsymtable) then
           write_symtable_syms(current_asmdata.asmlists[al_start],current_module.globalsymtable);
         if assigned(current_module.localsymtable) then

+ 10 - 2
compiler/nadd.pas

@@ -3569,12 +3569,16 @@ implementation
       var
         temp: tnode;
         leftoriginallysigned,
-        canbesignedconst, canbeunsignedconst: boolean;
+        canbesignedconst, canbeunsignedconst, swapped: boolean;
       begin
         result := false;
+        swapped := false;
         { make sure that if there is a constant, that it's on the right }
         if left.nodetype = ordconstn then
-          swapleftright;
+          begin
+            swapleftright;
+            swapped := true;
+          end;
         if is_32to64typeconv(left) then
           begin
             leftoriginallysigned:=is_signed(ttypeconvnode(left).left.resultdef);
@@ -3613,6 +3617,10 @@ implementation
                 result := true;
               end;
           end;
+        { pass_Typecheck caches left/right type and resultdef, so restore the
+          original order }
+        if not result and swapped then
+          swapleftright;
       end;
 
 

+ 51 - 0
compiler/x86/aoptx86.pas

@@ -5626,6 +5626,57 @@ unit aoptx86;
                 RemoveInstruction(hp1);
               end;
           end
+        else if reg_and_hp1_is_instr and
+          (taicpu(hp1).opcode = A_MOV) and
+          MatchOpType(taicpu(hp1),top_reg,top_reg) and
+          (((taicpu(p).opsize in [S_BW,S_BL,S_WL{$ifdef x86_64},S_BQ,S_WQ,S_LQ{$endif x86_64}]) and
+           (taicpu(hp1).opsize=S_B)) or
+           ((taicpu(p).opsize in [S_WL{$ifdef x86_64},S_WQ,S_LQ{$endif x86_64}]) and
+           (taicpu(hp1).opsize=S_W))
+{$ifdef x86_64}
+           or ((taicpu(p).opsize=S_LQ) and
+            (taicpu(hp1).opsize=S_L))
+{$endif x86_64}
+          ) and
+          SuperRegistersEqual(taicpu(p).oper[1]^.reg,taicpu(hp1).oper[0]^.reg) then
+          begin
+            { change
+              movx   %reg1,%reg2
+              mov    %reg2,%reg3
+              dealloc %reg2
+
+              into
+
+              mov   %reg1,%reg3
+
+              if the second mov accesses only the bits stored in reg1
+            }
+            TransferUsedRegs(TmpUsedRegs);
+            UpdateUsedRegs(TmpUsedRegs, tai(p.next));
+            if not(RegUsedAfterInstruction(taicpu(p).oper[1]^.reg,hp1,TmpUsedRegs)) then
+              begin
+                DebugMsg(SPeepholeOptimization + 'MovxMov2Mov',p);
+                if taicpu(p).oper[0]^.typ=top_reg then
+                  begin
+                    case taicpu(hp1).opsize of
+                      S_B:
+                        taicpu(hp1).loadreg(0,newreg(R_INTREGISTER,getsupreg(taicpu(p).oper[0]^.reg),R_SUBL));
+                      S_W:
+                        taicpu(hp1).loadreg(0,newreg(R_INTREGISTER,getsupreg(taicpu(p).oper[0]^.reg),R_SUBW));
+                      S_L:
+                        taicpu(hp1).loadreg(0,newreg(R_INTREGISTER,getsupreg(taicpu(p).oper[0]^.reg),R_SUBD));
+                      else
+                        Internalerror(2020102301);
+                    end;
+                    AllocRegBetween(taicpu(hp1).oper[0]^.reg,p,hp1,UsedRegs);
+                  end
+                else
+                  taicpu(hp1).loadref(0,taicpu(p).oper[0]^.ref^);
+                RemoveCurrentP(p);
+                result:=true;
+                exit;
+              end;
+          end
         else if reg_and_hp1_is_instr and
           (taicpu(p).oper[0]^.typ = top_reg) and
           (

+ 12 - 2
packages/openssl/src/openssl.pas

@@ -1467,6 +1467,7 @@ var
   procedure BN_free(a:PBIGNUM);
 
 function IsSSLloaded: Boolean;
+function InitSSLInterface(Const aSSLName, acryptoName : String) : Boolean; overload;
 function InitSSLInterface: Boolean; overload;
 function DestroySSLInterface: Boolean;
 
@@ -5613,13 +5614,15 @@ begin
 end;
 {$ENDIF}
 
-Function LoadLibraries : Boolean;
+Function LoadLibraries(Const aSSLName, aCryptoName : String) : Boolean;
 
 var
   Idx: Integer;
 
 begin
   Result:=False;
+  if (aSSLName<>'') and (aCryptoName<>'') then
+    Exit(TryLoadLibPair(aSSLName,aCryptoName));
 {$IF DEFINED(WINDOWS) OR DEFINED(OS2)}
   Assert(Low(SSL_DLL_Names) = Low(Crypto_DLL_Names));
   Assert(High(SSL_DLL_Names) = High(Crypto_DLL_Names));
@@ -5640,6 +5643,13 @@ begin
 end;
 
 function InitSSLInterface: Boolean;
+
+begin
+  Result:=InitSSLInterface('','');
+end;
+
+function InitSSLInterface(Const aSSLName, acryptoName : String) : Boolean;
+
 begin
   Result:=SSLLoaded;
   if Result then
@@ -5648,7 +5658,7 @@ begin
   try
     if SSLloaded then
       Exit;
-    Result:=LoadLibraries;
+    Result:=LoadLibraries(aSSLName,aCryptoName);
     if Not Result then
       begin
       UnloadLibraries;

+ 1 - 9
rtl/bsd/sysos.inc

@@ -32,15 +32,7 @@ function geterrnolocation: Plibcint; cdecl;external clib name '__errno';
 function geterrnolocation: Plibcint; cdecl;external clib name '__error';
 {$else}
 {$ifdef OpenBSD}
-
-var libcerrno : libcint; cvar;
-
-function geterrnolocation: Plibcint; cdecl;
-
-begin
- geterrnolocation:=@libcerrno;
-end;
-
+function geterrnolocation: Plibcint; cdecl;external clib name '__errno';
 {$else}
 {$endif}
 {$endif}

+ 2 - 2
rtl/win64/system.pp

@@ -83,8 +83,8 @@ asm
     stp fp,lr,[sp, #-16]!
 .seh_savefplr_x -16
 .seh_endprologue
-    blr x1                  { "arg" is passed in x0 }
-    nop                     { this nop is critical for exception handling }
+    blr x1                  // { "arg" is passed in x0 }
+    nop                     // { this nop is critical for exception handling }
     ldp	fp,lr,[sp], #16
 .seh_handler __FPC_default_handler,@except,@unwind
 end;

+ 1 - 0
tests/webtbs/tw37949.pp

@@ -1,3 +1,4 @@
+{ %norun }
 {$MODE ISO}
 program p(input, output);
 begin