forked from dotnet/llilc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLLILCEnv.ps1
1127 lines (944 loc) · 32.1 KB
/
LLILCEnv.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -------------------------------------------------------------------------
#
# This script provides LLILC development environment and test harness.
#
# -------------------------------------------------------------------------
<#
.SYNOPSIS
Setup LLILC development environment and provide test harness.
.DESCRIPTION
This script set up the LLILC environment with the assumptions below:
1. The following software are installed:
Visual Studio 12.0, Git, CMake, Python, GnuWin32, and DiffMerge
The script will check if the desired executable is already on path.
If not, it will stop going further.
2. LLVM and LLILC local repositories are created. The location of
LLVM source has to be specified with envrironment variable LLVMSOURCE.
LLILC repo can be placed in the default location under LLVMSOURCE\tools,
it will be automatically picked up. The LLILC repo can be placed out of
the LLVM source tree also. In this case, environment variable LLILCSOURCE
has to be used to specify that location.
A default location will be used for LLVM build directory. You can override
the location by specifying environmental variable LLVMBUILD. If LLILC
source is at default location in tree, LLILC will be built as part of LLVM
solution automatically. If LLILC is placed out of tree, a default LLILC
build directory will be used. You can override the location by specifying
environmental variable LLILCBUILD.
This script completes the environment setup and reports the status.
Typical steps to use this envrironment and test harness:
A. In first launch, BuildAll, it will build LLVM and LLILC.
In daily use, replace BuildAll with just Build, which only builds LLILC.
B. The second step is to do BuildTest. It will build the regression
tests in downloaded CoreCLR test assets.
C. The third step is to do RunTest. It will run the CoreCLR regression
tests, reports results, and create LLVM IR diff against baseline.
D. The fourth step is to do CheckDiff. If there were any diff,
you can use CheckDiff to bring the diffs into DiffMerge to examine
in details.
This script provides some daily routines beside the above four
common tasks:
llilc, CopyJIT, ReBaseAll, ApplyFilter, CheckEnv
Under the hood, LLILC uses CoreCLR's test assets and a CoreCLR
Runtime paired with LLILC JIT for testing. The two parts will
be downloaded and put in a default location. You can override
the location by specifying environment variable LLILCTESTRESULT.
As of now, only release version of CoreCLR Runtime is available.
Debug version of CoreCLR Runtime support will be added when it
is available.
.PARAMETER Arch
Target Architecture
.PARAMETER Build
Debug or Release Build
.EXAMPLE
LLILCEnv.ps1
LLILCEnv.ps1 -Arch x64 -Build Debug
#>
[CmdletBinding()]
Param(
[string]$Arch="x64",
[string]$Build="Debug",
[switch]$NoTestUpdate
)
# -------------------------------------------------------------------------
#
# Validate preconditions: software installations and environment variables
#
# -------------------------------------------------------------------------
function ValidatePreConditions
{
# Validate Visual Studio
$VSExists = Test-Path Env:\VS120COMNTOOLS
if (!$VSExists) {
throw "!!! Visual Studio 12.0 not installed."
}
# Validate Git
IsOnPath -executable "git.exe" -software "Git"
# Validate CMake
IsOnPath -executable "cmake.exe" -software "CMake"
# Validate Python
IsOnPath -executable "python.exe" -software "Python"
# Validate GnuWin32
# IsOnPath -executable "grep.exe" -software "GnuWin32"
# Validate LLVM
$LLVMSourceExists = Test-Path Env:\LLVMSOURCE
if (!$LLVMSourceExists) {
throw "!!! LLVM Source not specified."
}
else {
$LLVMSourceExists = Test-Path $Env:LLVMSOURCE
if (!$LLVMSourceExists) {
throw "!!! LLVM Source not available in specified location."
}
}
# Validate LLILC
$LLILCSourceExists = Test-Path Env:\LLILCSOURCE
if (!$LLILCSourceExists) {
Write-Warning "LLILC source directory is not specified."
$DefaultLLILCSource = DefaultLLILCSource
$LLILCSourceExists = Test-Path $DefaultLLILCSource
if (!$LLILCSourceExists) {
throw "!!! Default LLILC source not available."
}
else {
Write-Warning "Default LLILC source directory: $DefaultLLILCSource"
}
}
else {
$LLILCSourceExists = Test-Path $Env:LLILCSOURCE
if (!$LLILCSourceExists) {
throw "!!! LLILC source not available in specified location."
}
}
# Validate LLVMBuild
$LLVMBuildExists = Test-Path Env:\LLVMBUILD
if (!$LLVMBuildExists) {
Write-Warning "LLVM build directory is not specified."
$DefaultLLVMBuild = DefaultLLVMBuild
Write-Warning "Default LLVM build directory: $DefaultLLVMBuild"
}
# Validate LLILCBuild
$OutOfTree = Test-Path Env:\LLILCSOURCE
if ($OutOfTree) {
$LLILCBuildExists = Test-Path Env:\LLILCBUILD
if (!$LLILCBuildExists) {
Write-Warning "LLILC build directory is not specified."
$DefaultLLILCBuild = DefaultLLILCBuild
Write-Warning "Default LLILC build directory: $DefaultLLILCBuild"
}
}
# Validate CoreCLR
$CORECLRSOURCEExists = Test-Path Env:\CORECLRSOURCE
if (!$CORECLRSOURCEExists) {
Write-Warning "CORECLRSOURCE not specificed. Specify CORECLRSOURCE in the environment."
throw "CORECLRSOURCE not specified"
}
}
# -------------------------------------------------------------------------
#
# A list of resource location functions
#
# -------------------------------------------------------------------------
# set CoreCLRSource variable from the environment.
$Global:CoreCLRSource = $ENV:CORECLRSOURCE
$Global:CoreCLRRuntime = "$CoreCLRSource\bin\Product\Windows_NT.$Arch.$Build"
$Global:CoreCLRTest = "$CoreCLRSource\bin\tests\Windows_NT.$Arch.$Build"
function Global:DefaultLLILCSource
{
return "$Env:LLVMSOURCE\tools\llilc"
}
function Global:LLILCSource
{
$LLILCSourceExists = Test-Path Env:\LLILCSOURCE
if (!$LLILCSourceExists) {
$DefaultLLILCSource = DefaultLLILCSource
return "$DefaultLLILCSource"
}
else {
return "$Env:LLILCSOURCE"
}
}
function Global:LLILCTest
{
$LLILCSource = LLILCSource
return "$LLILCSource\test"
}
function Global:LLILCJit([string]$Build="Debug")
{
$OutOfTree = Test-Path Env:\LLILCSOURCE
if ($OutOfTree) {
$LLILCBuild = LLILCBuild
$LLILCJit = "$LLILCBuild\bin\$Build\LLILCJit.dll"
}
else {
$LLVMBuild = LLVMBuild
$LLILCJit = "$LLVMBUILD\bin\$Build\LLILCJit.dll"
}
return $LLILCJit
}
function Global:DefaultLLILCTestResult
{
return "$Env:TEMP\LLILCTestResult"
}
function Global:LLILCTestResult
{
$LLILCTestResultExists = Test-Path Env:\LLILCTESTRESULT
if (!$LLILCTestResultExists) {
$DefaultLLILCTestResult = DefaultLLILCTestResult
return "$DefaultLLILCTestResult"
}
else {
return $Env:LLILCTESTRESULT
}
}
function Global:DefaultLLILCBuild
{
return "$Env:TEMP\LLILCBuild"
}
function Global:LLILCBuild
{
$LLILCBuildExists = Test-Path Env:\LLILCBUILD
if (!$LLILCBuildExists) {
$DefaultLLILCBuild = DefaultLLILCBuild
return "$DefaultLLILCBuild"
}
else {
return $Env:LLILCBUILD
}
}
function Global:CoreCLRRuntime
{
return "$CoreCLRSource"
}
function Global:CoreCLRTestAssets
{
return "$CoreCLRSource"
}
function Global:CoreCLRTestTargetBinaries([string]$Arch="x64", [string]$Build="Debug")
{
return "$CoreCLRSource\bin\tests\Windows_NT.$Arch.$Build"
}
function Global:DefaultLLVMBuild
{
return "$Env:TEMP\LLVMBuild"
}
function Global:LLVMBuild
{
$LLVMBuildExists = Test-Path Env:\LLVMBUILD
if (!$LLVMBuildExists) {
$DefaultLLVMBuild = DefaultLLVMBuild
return "$DefaultLLVMBuild"
}
else {
return $Env:LLVMBUILD
}
}
# -------------------------------------------------------------------------
#
# Get the CoreCLR Version
#
# -------------------------------------------------------------------------
function Global:CoreCLRVersion
{
$LLILCSource = LLILCSOURCE
(Get-Content $LLILCSource\utils\packages.config) | ForEach-Object {
if ($_ -match 'package id="(.*?)" version="(.*?)"') {
$Result = $matches[1] + "." + $matches[2]
return $Result
}
}
}
# -------------------------------------------------------------------------
#
# Get the build of downloaded CoreCLR package
#
# -------------------------------------------------------------------------
#function Global:CoreCLRBuild
#{
# $CoreCLRVersion = CoreCLRVersion
# if ($CoreCLRVersion -match "Debug") {
# $CoreCLRBuild = "Debug"
# }
# else {
# $CoreCLRBuild = "Release"
# }
# return $CoreCLRBuild
#}
# -------------------------------------------------------------------------
#
# Set Visual Studio Command line environment variables.
#
# -------------------------------------------------------------------------
function SetVCVars
{
# This is complicated two things:
# 1. When powershell invokes a cmd or bat file, any environment variables
# changes made by that file are lost when the file finishes executing.
# So one must resort to trickery to capture the environment variables.
# 2. by the fact that the path to the batch
# file that set these has blanks in it.
#
# To work around the limitations of cmd we create a temporary batch file and
# execute it to capture the new environment variables.
# Create the temp file in the user's temp directory and
# use the current pid to avoid comflict with other instances
# that might be running.
$TempBat = Join-Path $Env:TEMP "getvc$pid.bat"
#echo "TempBat = $TempBat"
$File = "$Env:VS120COMNTOOLS\VsDevCmd.bat"
#echo "VC batch file = $File"
("call ""$File""", "echo ENV_VARS_START", "set") | Out-File -Encoding ascii $TempBat
$CmdOut = cmd /q /c $TempBat
# If batch file fails we need to propagate the error.
if ($LASTEXITCODE -gt 0) {
$CmdOut
exit $LASTEXITCODE
}
Remove-Item $TempBat | Out-Null
## Erase our current set of environment variables
Remove-Item -path env:* | Out-Null
## Go through the environment variables returned by cmd.exe.
## For each of them, set the variable in our local environment.
$FoundStartFlag = $false
foreach ($Line in $CmdOut) {
if ($Line -eq "ENV_VARS_START") {
Write-Output ""
$FoundStartFlag = $true
continue
}
if ($FoundStartFlag -and ($Line -match "^(.*?)=(.*)$")) {
$N = $matches[1]
if ($N -eq "prompt") {
# Ignore: Setting the prompt environment variable has no
# connection to the PowerShell prompt
} elseif ($N -eq "title") {
$host.ui.rawui.windowtitle = $matches[2]
Set-Item -Path "env:$N" -Value $matches[2]
} else {
Set-Item -Path "env:$N" -Value $matches[2]
}
}
elseif (!$FoundStartFlag) {
# Output prior to our special flag is stuff generated by
# setenv.cmd. Just pass it on to whomever is watching.
Write-Output $Line
}
}
}
# -------------------------------------------------------------------------
#
# Check if executable is already on the Path
#
# -------------------------------------------------------------------------
function Global:IsOnPath([string]$executable, [string]$software)
{
if (-Not (Get-Command $executable -ErrorAction SilentlyContinue)) {
throw "!!! $executable not on path. Check the installation of $software."
}
}
# -------------------------------------------------------------------------
#
# Do the rest of environment setup after validation
#
# -------------------------------------------------------------------------
function CompleteEnvInit
{
SetVCVars
CreateLLILCBuildDirectory
#CreateLLILCTestResultDirectory
CreateLLVMBuildDirectory
#NuGetCLR
}
# -------------------------------------------------------------------------
#
# Download nuget.exe
#
# -------------------------------------------------------------------------
function Global:DownloadNuGet
{
$CoreCLRRuntime = CoreCLRRuntime
$NuGetExists = Test-Path $CoreCLRRuntime\NuGet.exe
if (!$NuGetExists) {
pushd .
cd $CoreCLRRuntime
Invoke-WebRequest http://nuget.org/NuGet.exe -OutFile NuGet.exe
$NuGetExists = Test-Path $CoreCLRRuntime\Nuget.exe
if (!$NuGetExists) {
throw "!!! NuGet failed to successfully download."
}
popd
}
}
# -------------------------------------------------------------------------
#
# Clear NuGet Cache
#
# -------------------------------------------------------------------------
function Global:ClearNuGetCache
{
$NuGetCacheExists = Test-Path $Env:LOCALAPPDATA\NuGet\Cache
if ($NuGetCacheExists) {
Remove-Item $Env:LOCALAPPDATA\NuGet\Cache\*
}
}
# -------------------------------------------------------------------------
#
# Perform a CoreCLR package Nuget.
#
# -------------------------------------------------------------------------
function Global:NuGetCLR
{
$CoreCLRRuntime = CoreCLRRuntime
$CoreCLRRuntimeExists = Test-Path $CoreCLRRuntime
$LLILCSource = LLILCSource
if (!$CoreCLRRuntimeExists) {
New-Item $CoreCLRRuntime -ItemType directory | Out-Null
}
else {
Write-OutPut("CoreCLR Runtime already downloaded.")
return
}
Write-OutPut("Downloading NuGet.exe...")
DownloadNuGet
Write-OutPut("Clear NuGet Cache...")
ClearNuGetCache
copy $LLILCSource\utils\NuGet.config $CoreCLRRuntime
copy $LLILCSource\utils\packages.config $CoreCLRRuntime
pushd .
cd $CoreCLRRUNTIME
Write-OutPut("Performing a CoreCLR package NuGet...")
& .\NuGet.exe install
popd
}
# -------------------------------------------------------------------------
#
# Get CLR Test Assets by cloning CoreCLR repo.
#
# -------------------------------------------------------------------------
function Global:GetCLRTestAssets
{
throw "Use pre enlisted CoreCLR Drop"
}
# -------------------------------------------------------------------------
#
# Check the status of development environment.
#
# -------------------------------------------------------------------------
function Global:CheckEnv
{
$OutOfTree = Test-Path Env:\LLILCSOURCE
$LLVMBuild = LLVMBuild
if ($OutofTree) {
$LLILCBuild = LLILCBuild
}
$LLILCSource = LLILCSource
$LLILCTest = LLILCTest
$LLILCTestResult = LLILCTestResult
$CoreCLRTestAssets = CoreCLRTestAssets
$CoreCLRRuntime = CoreCLRRuntime
#$CoreCLRVersion = CoreCLRVersion
Write-Output("************************************ LLILC Work Environment **************************************")
Write-Output("LLVM Source : $Env:LLVMSOURCE")
Write-Output("LLVM Build : $LLVMBuild")
Write-Output("LLILC Source : $LLILCSource")
if ($OutOfTree) {
Write-Output("LLILC Build : $LLILCBuild")
}
Write-Output("LLILC Test : $LLILCTest")
Write-Output("LLILC Test Result : $LLILCTestResult")
Write-Output("CoreCLR Test Assets : $CoreCLRTestAssets")
Write-Output("CoreCLR Runtime : $CoreCLRRuntime")
#Write-Output("CoreCLR Version : $CoreCLRVersion")
Write-Output("**************************************************************************************************")
}
# -------------------------------------------------------------------------
#
# Create LLILC Test Result Directory. It will hold CoreCLR test assets,
# CoreCLR package, and Diff results.
#
# -------------------------------------------------------------------------
function CreateLLILCTestResultDirectory
{
$LLILCTestResult = LLILCTestResult
$LLILCTestResultExist = Test-Path $LLILCTestResult
if (!$LLILCTestResultExist) {
New-Item $LLILCTestResult -itemtype Directory | Out-Null
}
}
# -------------------------------------------------------------------------
#
# Create LLVM build directory
#
# -------------------------------------------------------------------------
function CreateLLVMBuildDirectory
{
$LLVMBuild = LLVMBuild
$LLVMBuildExists = Test-Path $LLVMBuild
if (!$LLVMBuildExists) {
New-Item $LLVMBuild -itemtype Directory | Out-Null
}
}
# -------------------------------------------------------------------------
#
# Create LLILC build directory
#
# -------------------------------------------------------------------------
function CreateLLILCBuildDirectory
{
$OutOfTree = Test-Path Env:\LLILCSOURCE
if ($OutOfTree) {
$LLILCBuild = LLILCBuild
$LLILCBuildExists = Test-Path $LLILCBuild
if (!$LLILCBuildExists) {
New-Item $LLILCBuild -itemtype Directory | Out-Null
}
}
}
# -------------------------------------------------------------------------
#
# Setup LLILC development environment.
#
# -------------------------------------------------------------------------
function LLILCEnvInit
{
ValidatePreConditions
CompleteEnvInit
CheckEnv
Write-Output("Use llilc for a list of commands. Use CheckEnv for a list of work environment.")
# start with LLILC Source Directory
$LLILCSource = LLILCSource
cd $LLILCSource
}
# -------------------------------------------------------------------------
#
# Copy in LLILC JIT dll into CoreCLR runtime
#
# -------------------------------------------------------------------------
function Global:CopyJIT([string]$Build="Debug")
{
$CoreCLRBinaries = $CoreCLRRuntime
#$CoreCLRVersion = CoreCLRVersion
$LLILCJit = LLILCJit($Build)
$JitName = "LLILCJit.dll"
$WorkLLILCJitExists = Test-Path $CoreCLRBinaries\$JitName
if ($WorkLLILCJitExists) {
Remove-Item $CoreCLRBinaries\$JitName | Out-Null
}
pushd $CoreCLRBinaries
Write-Output ("Copying LLILC JIT $LLILCJit $JitName")
copy $LLILCJit $JitName
Write-Output ("LLILC JIT Copied")
popd
}
# -------------------------------------------------------------------------
#
# CMake Configuration based on architecture
#
# -------------------------------------------------------------------------
function Global:CMakeConfig([string]$Arch="x64")
{
if ($Arch -eq "x64") {
$CMakeConfig = "Visual Studio 12 2013 Win64"
}
else {
$CMakeConfig = "Visual Studio 12"
}
return $CMakeConfig
}
# -------------------------------------------------------------------------
#
# Configure LLVM Solution
#
# -------------------------------------------------------------------------
function Global:ConfigureLLVM([string]$Arch="x64", [string]$Build="Debug")
{
$LLVMBuild = LLVMBuild
pushd .
cd $LLVMBuild
$CMakeConfig = CMakeConfig -Arch $Arch
cmake -G $CMakeConfig $Env:LLVMSOURCE -DLLVM_TARGETS_TO_BUILD:STRING=X86 -DCMAKE_BUILD_TYPE:STRING=$Build
popd
}
# -------------------------------------------------------------------------
#
# Configure LLILC solution if LLILC is out of LLVM source tree
#
# -------------------------------------------------------------------------
function Global:ConfigureLLILC([string]$Arch="x64", [string]$Build="Debug")
{
$OutOfTree = Test-Path Env:\LLILCSOURCE
if (!$OutOfTree) {
return
}
$LLVMBuild = LLVMBuild
$LLILCBuild = LLILCBuild
pushd .
cd $LLILCBuild
$CMakeConfig = CMakeConfig -Arch $Arch
cmake -G $CMakeConfig $Env:LLILCSOURCE -DWITH_LLVM:STRING=$LLVMBuild -DCMAKE_BUILD_TYPE:STRING=$Build
popd
}
# -------------------------------------------------------------------------
#
# Build LLVM, including LLILC if it is in default location in LLVM source.
#
# -------------------------------------------------------------------------
function Global:BuildLLVM([string]$Arch="x64", [string]$Build="Debug", [bool]$Parallel=$True)
{
$LLVMBuild = LLVMBuild
$TempBat = Join-Path $Env:TEMP "buildllvm.bat"
$File = "$Env:VS120COMNTOOLS\..\..\VC\vcvarsall.bat"
if ($Parallel) {
$MSwitch = " /m "
}
else {
$MSwitch = ""
}
("call ""$File"" x86", "msbuild $LLVMBuild\LLVM.sln /p:Configuration=$Build /p:Platfrom=$Arch /t:ALL_BUILD $MSwitch") | Out-File -Encoding ascii $TempBat
Write-Output ("Building LLVM...")
cmd /c $TempBat
Remove-Item -force $TempBat | Out-Null
$OutOfTree = Test-Path Env:\LLILCSOURCE
if (!$OutOfTree) {
CopyJIT -Build $Build
}
}
# -------------------------------------------------------------------------
#
# Build LLILC JIT
#
# -------------------------------------------------------------------------
function Global:Build([string]$Build="Debug")
{
$OutOfTree = Test-Path Env:\LLILCSOURCE
$TempBat = Join-Path $Env:TEMP "buildllilc.bat"
$File = "$Env:VS120COMNTOOLS\..\..\VC\vcvarsall.bat"
if ($OutOfTree) {
$LLILCBuild = LLILCBuild
$WhatToBuild = "$LLILCBuild\LLILC.sln"
}
else {
$LLVMBuild = LLVMBuild
$WhatToBuild = "/Project llilcjit $LLVMBuild\LLVM.sln"
}
("call ""$File"" x86", "devenv /Build $Build $WhatToBuild") | Out-File -Encoding ascii $TempBat
cmd /c $TempBat
Remove-Item -force $TempBat | Out-Null
CopyJIT -Build $Build
}
# -------------------------------------------------------------------------
#
# Configure and Build LLVM including LLILC JIT
#
# -------------------------------------------------------------------------
function Global:BuildAll([string]$Arch="x64", [string]$Build="Debug", [bool]$Parallel=$True)
{
ConfigureLLVM -Arch $Arch -Build $Build
BuildLLVM -Arch $Arch -Build $Build -Parallel $Parallel
$OutOfTree = Test-Path Env:\LLILCSOURCE
if ($OutOfTree) {
ConfigureLLILC -Arch $Arch -Build $Build
Build -Build $Build
}
}
# -------------------------------------------------------------------------
#
# Apply Filter to suppress allowable LLVM IR difference in pipeline
#
# -------------------------------------------------------------------------
function Global:ApplyFilterAll{
param(
[Parameter(
Position=0,
Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)
]
[Alias('FullName')]
[String[]]$FilePath
)
process {
foreach($path in $FilePath)
{
ApplyFilter $path
}
}
}
# -------------------------------------------------------------------------
#
# Filter to suppress allowable LLVM IR difference
# Using python script applyfilter.py for filtering
#
# -------------------------------------------------------------------------
function Global:ApplyFilter([string]$File)
{
$LLILCTest = LLILCTest
& $LLILCTest\applyfilter.py $File "$File.tmp"
Remove-Item -force $File | Out-Null
Rename-Item "$File.tmp" $File | Out-Null
}
# -------------------------------------------------------------------------
#
# Build CoreCLR regression tests
#
# -------------------------------------------------------------------------
function Global:BuildTest([string]$Arch="x64", [string]$Build="Debug")
{
pushd $CoreCLRSource\tests
.\buildtest $Arch $Build clean
popd
}
# -------------------------------------------------------------------------
#
# Return the number of failures of RunTest
# Return -1 if the log file does not exist
#
# -------------------------------------------------------------------------
function Global:CheckFailure([string]$Arch="x64", [string]$Build="Release")
{
$CoreCLRTestAssets = CoreCLRTestAssets
$RunResult = "$CoreCLRTestAssets\bin\Logs\TestRunResults_Windows_NT__"
$RunResult = $RunResult + "$Arch"
$RunResult = $RunResult + "__$Build.log"
$RunResultsExists = Test-Path $RunResult
if (!$RunResultsExists) {
return -1
}
else {
Get-Content $RunResult | Where-Object { $_.Contains("Failed: ") } | ForEach-Object { $_ -match "Failed: (\d+)," } | Out-Null
return $matches[1]
}
}
# -------------------------------------------------------------------------
#
# Run LLILC enabled CoreCLR regression tests
#
# -------------------------------------------------------------------------
function Global:RunTest
{
Param(
[string]$Arch="x64",
[string]$Build="Debug",
[string]$Jit="",
[string]$Result="",
[string]$Dump="NoDump"
)
#$CoreCLRTestAssets = CoreCLRTestAssets
#$CoreCLRRuntime = CoreCLRRuntime
#$CoreCLRVersion = CoreCLRVersion
$LLILCTest = LLILCTest
$LLILCTestResult = LLILCTestResult
$CoreCLRTestTargetBinaries = CoreCLRTestTargetBinaries -Arch $Arch -Build $Build
# Workaround exception handling issue
chcp 65001 | Out-Null
# Reserve the old jit and copy in the specified jit.
if ($Jit -ne "") {
#$CoreCLRRuntime = CoreCLRRuntime
#$CoreCLRVersion = CoreCLRVersion
Rename-Item $CoreCLRRuntime\LLILCJit.dll $CoreCLRRuntime\\LLILCJit.dll.backupcopy
Copy-Item $Jit $CoreCLRRuntime\LLILCJit.dll
}
# Protect old value and set the new value for DUMPLLVMIR
$DumpExists = Test-Path Env:\COMPLus_DUMPLLVMIR
if ($DumpExists) {
$OldDump = $Env:COMPlus_DUMPLLVMIR
}
$Env:COMPlus_DUMPLLVMIR = $Dump
# The set of test cases that are currently ignored
$Env:SkipTestAssemblies = "Common;Exceptions;GC;Loader;managed;packages;Regressions;runtime;Tests;TestWrappers_x64_release;Threading"
# Run the test
pushd .
cd $CoreCLRSource\tests
.\runtest $Arch $Build Exclude $LLILCTest\exclusion.targets TestEnv $LLILCTest\LLILCTestEnv.cmd $CoreCLRRuntime | Write-Host
popd
# Restore old value for DUMPLLVMIR
if ($DumpExists) {
$Env:COMPlus_DUMPLLVMIR = $OldDump;
}
# Restore the old jit
if ($Jit -ne "") {
Remove-Item $CoreCLRRuntime\LLILCJit.dll | Out-Null
Rename-Item $CoreCLRRuntime\LLILCJit.dll.backupcopy $CoreCLRRuntime\LLILCJit.dll | Out-Null
}
# Copy out result, normalize it in case of verbose dump.
if ($Result -ne "") {
$ResultExists = Test-Path $LLILCTestResult\$Result
if ($ResuLtExists) {
Remove-Item -recurse -force $LLILCTestResult\$Result | Out-Null
}
New-Item -itemtype directory $LLILCTestResult\$Result | Out-Null
Copy-Item -recurse "$CoreCLRTestTargetBinaries\Reports\*" -Destination $LLILCTestResult\$Result
Get-ChildItem -recurse -path $LLILCTestResult\$Result | Where {$_.FullName -match "output.txt"} | Remove-Item -force
if ($Dump -eq "Verbose") {
Write-Host ("Applying filter on verbose LLVM IR dump...")
Get-ChildItem -recurse -path $LLILCTestResult\$Result | Where {$_.FullName -match "error.txt"} | ApplyFilterAll
}
}
$NumFailures = CheckFailure -Arch $Arch -Build $Build
# If there aren't any failures, return $True to say we passed
# Otherwise return false
if ($NumFailures -eq 0) {
return $True
}
else {
return $False
}
}
# -------------------------------------------------------------------------
#
# Check the LLVM IR dump difference against baseline.
#
# -------------------------------------------------------------------------
function Global:CheckDiff
{
Param(
[Parameter(Mandatory=$True)][string]$Base,
[Parameter(Mandatory=$True)][string]$Diff,
[Parameter(Mandatory=$False)][switch]$Summary,
[Parameter(Mandatory=$False)][switch]$UseDiffTool
)
$LLILCTestResult = LLILCTestResult
Write-Host ("Checking diff...")
if ($UseDiffTool) {
# Validate Diff Tool
IsOnPath -executable "sgdm.exe" -software "DiffMerge"
}
$CompareExists = Test-Path $LLILCTestResult\Compare
# Refresh a new Compare subdirectory
if ($CompareExists) {
Remove-Item -recurse -force $LLILCTestResult\Compare | Out-Null
}
New-Item -itemtype directory $LLILCTestResult\Compare | Out-Null
New-Item -itemtype directory $LLILCTestResult\Compare\$Base | Out-Null
New-Item -itemtype directory $LLILCTestResult\Compare\$Diff | Out-Null
if (!$Summary) {
# Deal with verbose LLVM IR comparison
$TotalCount = 0
$DiffCount = 0
Get-ChildItem -recurse -path $LLILCTestResult\$Diff | Where {$_.FullName -match "error.txt"} | `
Foreach-Object {
$TotalCount = $TotalCount + 1
$DiffFile = $_.FullName
$PartialPathMatch = $_.FullName -match "$Diff\\(.*)"
$PartialPath = $matches[1]
$BaseFile = "$LLILCTestResult\$Base\$PartialPath"
$DiffResult = Compare-Object -Ref (Get-Content $BaseFile) -Diff (Get-Content $DiffFile)
if ($DiffResult.Count -ne 0) {
Copy-Item $BaseFile $LLILCTestResult\Compare\$Base
Copy-Item $DiffFile $LLILCTestResult\Compare\$Diff
$DiffCount = $DiffCount + 1
}
}
if ($DiffCount -eq 0) {
Write-Host ("There is no diff.")
Remove-Item -recurse -force $LLILCTestResult\Compare | Out-Null