summaryrefslogtreecommitdiffstats
path: root/third_party/python/gyp/test/win/linker-flags/pgo.gyp
blob: da32639973c9300eae72c81d323cb5f1977799c7 (plain)
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
# Copyright (c) 2013 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

{
  'variables': {
    'pgd_basename': 'test_pgo',
  },
  'targets': [
    # In the PGO (Profile-Guided Optimization) build flow, we need to build the
    # target binary multiple times. To implement this flow with gyp, here we
    # define multiple 'executable' targets, each of which represents one build
    # particular build/profile stage. On tricky part to do this is that these
    # 'executable' targets should share the code itself so that profile data
    # can be reused among these 'executable' files. In other words, the only
    # differences among below 'executable' targets are:
    #   1) PGO (Profile-Guided Optimization) database, and
    #   2) linker options.
    # The following static library contains all the logic including entry point.
    # Basically we don't need to rebuild this target once we enter profiling
    # phase of PGO.
    {
      'target_name': 'test_pgo_main',
      'type': 'static_library',
      'msvs_settings': {
        'VCCLCompilerTool': {
          'WholeProgramOptimization': 'true',  # /GL
        },
        'VCLibrarianTool': {
          'LinkTimeCodeGeneration': 'true',
        },
      },
      'link_settings': {
        'msvs_settings': {
          'VCLinkerTool': {
            'ProfileGuidedDatabase': '$(OutDir)\\<(pgd_basename).pgd',
            'TargetMachine': '1',  # x86 - 32
            'SubSystem': '1',      # /SUBSYSTEM:CONSOLE
            # Tell ninja generator not to pass /ManifestFile:<filename> option
            # to the linker, because it causes LNK1268 error in PGO biuld.
            'GenerateManifest': 'false',
            # We need to specify 'libcmt.lib' here so that the linker can pick
            # up a valid entry point.
            'AdditionalDependencies': [
              'libcmt.lib',
            ],
          },
        },
      },
      'sources': [
        'inline_test.h',
        'inline_test.cc',
        'inline_test_main.cc',
      ],
    },
    {
      'target_name': 'test_pgo_instrument',
      'type': 'executable',
      'msvs_settings': {
        'VCLinkerTool': {
          'LinkTimeCodeGeneration': '2',
        },
      },
      'dependencies': [
        'test_pgo_main',
      ],
    },
    {
      'target_name': 'gen_profile_guided_database',
      'type': 'none',
      'msvs_cygwin_shell': 0,
      'actions': [
        {
          'action_name': 'action_main',
          'inputs': [],
          'outputs': [
            '$(OutDir)\\<(pgd_basename).pgd',
          ],
          'action': [
            'python', 'update_pgd.py',
            '--vcbindir', '$(VCInstallDir)bin',
            '--exe', '$(OutDir)\\test_pgo_instrument.exe',
            '--pgd', '$(OutDir)\\<(pgd_basename).pgd',
          ],
        },
      ],
      'dependencies': [
        'test_pgo_instrument',
      ],
    },
    {
      'target_name': 'test_pgo_optimize',
      'type': 'executable',
      'msvs_settings': {
        'VCLinkerTool': {
          'LinkTimeCodeGeneration': '3',
        },
      },
      'sources': [
        '$(OutDir)\\<(pgd_basename).pgd',
      ],
      'dependencies': [
        'test_pgo_main',
        'gen_profile_guided_database',
      ],
    },
    {
      'target_name': 'test_pgo_update',
      'type': 'executable',
      'msvs_settings': {
        'VCLinkerTool': {
          'LinkTimeCodeGeneration': '4',
        },
      },
      'sources': [
        '$(OutDir)\\<(pgd_basename).pgd',
      ],
      'dependencies': [
        'test_pgo_main',
      ],
    },
    # A helper target to dump link.exe's command line options. We can use the
    # output to determine if PGO (Profile-Guided Optimization) is available on
    # the test environment.
    {
      'target_name': 'gen_linker_option',
      'type': 'none',
      'msvs_cygwin_shell': 0,
      'actions': [
        {
          'action_name': 'action_main',
          'inputs': [],
          'outputs': [
            '$(OutDir)\\linker_options.txt',
          ],
          'action': [
            'cmd.exe', '/c link.exe > $(OutDir)\\linker_options.txt & exit 0',
          ],
        },
      ],
    },
  ]
}