Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/AMDGPU/AMDGPUMachineModuleInfo.h
Line
Count
Source
1
//===--- AMDGPUMachineModuleInfo.h ------------------------------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
/// \file
10
/// AMDGPU Machine Module Info.
11
///
12
//
13
//===----------------------------------------------------------------------===//
14
15
#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUMACHINEMODULEINFO_H
16
#define LLVM_LIB_TARGET_AMDGPU_AMDGPUMACHINEMODULEINFO_H
17
18
#include "llvm/ADT/None.h"
19
#include "llvm/ADT/Optional.h"
20
#include "llvm/CodeGen/MachineModuleInfo.h"
21
#include "llvm/CodeGen/MachineModuleInfoImpls.h"
22
#include "llvm/IR/LLVMContext.h"
23
24
namespace llvm {
25
26
class AMDGPUMachineModuleInfo final : public MachineModuleInfoELF {
27
private:
28
29
  // All supported memory/synchronization scopes can be found here:
30
  //   http://llvm.org/docs/AMDGPUUsage.html#memory-scopes
31
32
  /// Agent synchronization scope ID (cross address space).
33
  SyncScope::ID AgentSSID;
34
  /// Workgroup synchronization scope ID (cross address space).
35
  SyncScope::ID WorkgroupSSID;
36
  /// Wavefront synchronization scope ID (cross address space).
37
  SyncScope::ID WavefrontSSID;
38
  /// System synchronization scope ID (single address space).
39
  SyncScope::ID SystemOneAddressSpaceSSID;
40
  /// Agent synchronization scope ID (single address space).
41
  SyncScope::ID AgentOneAddressSpaceSSID;
42
  /// Workgroup synchronization scope ID (single address space).
43
  SyncScope::ID WorkgroupOneAddressSpaceSSID;
44
  /// Wavefront synchronization scope ID (single address space).
45
  SyncScope::ID WavefrontOneAddressSpaceSSID;
46
  /// Single thread synchronization scope ID (single address space).
47
  SyncScope::ID SingleThreadOneAddressSpaceSSID;
48
49
  /// In AMDGPU target synchronization scopes are inclusive, meaning a
50
  /// larger synchronization scope is inclusive of a smaller synchronization
51
  /// scope.
52
  ///
53
  /// \returns \p SSID's inclusion ordering, or "None" if \p SSID is not
54
  /// supported by the AMDGPU target.
55
6.43k
  Optional<uint8_t> getSyncScopeInclusionOrdering(SyncScope::ID SSID) const {
56
6.43k
    if (SSID == SyncScope::SingleThread ||
57
6.43k
        
SSID == getSingleThreadOneAddressSpaceSSID()3.11k
)
58
3.46k
      return 0;
59
2.97k
    else if (SSID == getWavefrontSSID() ||
60
2.97k
             
SSID == getWavefrontOneAddressSpaceSSID()2.86k
)
61
234
      return 1;
62
2.74k
    else if (SSID == getWorkgroupSSID() ||
63
2.74k
             
SSID == getWorkgroupOneAddressSpaceSSID()2.58k
)
64
323
      return 2;
65
2.41k
    else if (SSID == getAgentSSID() ||
66
2.41k
             
SSID == getAgentOneAddressSpaceSSID()2.26k
)
67
324
      return 3;
68
2.09k
    else if (SSID == SyncScope::System ||
69
2.09k
             
SSID == getSystemOneAddressSpaceSSID()186
)
70
2.08k
      return 4;
71
12
72
12
    return None;
73
12
  }
74
75
  /// \returns True if \p SSID is restricted to single address space, false
76
  /// otherwise
77
6.41k
  bool isOneAddressSpace(SyncScope::ID SSID) const {
78
6.41k
    return SSID == getSingleThreadOneAddressSpaceSSID() ||
79
6.41k
        
SSID == getWavefrontOneAddressSpaceSSID()6.27k
||
80
6.41k
        
SSID == getWorkgroupOneAddressSpaceSSID()6.15k
||
81
6.41k
        
SSID == getAgentOneAddressSpaceSSID()5.98k
||
82
6.41k
        
SSID == getSystemOneAddressSpaceSSID()5.81k
;
83
6.41k
  }
84
85
public:
86
  AMDGPUMachineModuleInfo(const MachineModuleInfo &MMI);
87
88
  /// \returns Agent synchronization scope ID (cross address space).
89
4.42k
  SyncScope::ID getAgentSSID() const {
90
4.42k
    return AgentSSID;
91
4.42k
  }
92
  /// \returns Workgroup synchronization scope ID (cross address space).
93
4.52k
  SyncScope::ID getWorkgroupSSID() const {
94
4.52k
    return WorkgroupSSID;
95
4.52k
  }
96
  /// \returns Wavefront synchronization scope ID (cross address space).
97
4.51k
  SyncScope::ID getWavefrontSSID() const {
98
4.51k
    return WavefrontSSID;
99
4.51k
  }
100
  /// \returns System synchronization scope ID (single address space).
101
7.00k
  SyncScope::ID getSystemOneAddressSpaceSSID() const {
102
7.00k
    return SystemOneAddressSpaceSSID;
103
7.00k
  }
104
  /// \returns Agent synchronization scope ID (single address space).
105
9.00k
  SyncScope::ID getAgentOneAddressSpaceSSID() const {
106
9.00k
    return AgentOneAddressSpaceSSID;
107
9.00k
  }
108
  /// \returns Workgroup synchronization scope ID (single address space).
109
9.25k
  SyncScope::ID getWorkgroupOneAddressSpaceSSID() const {
110
9.25k
    return WorkgroupOneAddressSpaceSSID;
111
9.25k
  }
112
  /// \returns Wavefront synchronization scope ID (single address space).
113
9.41k
  SyncScope::ID getWavefrontOneAddressSpaceSSID() const {
114
9.41k
    return WavefrontOneAddressSpaceSSID;
115
9.41k
  }
116
  /// \returns Single thread synchronization scope ID (single address space).
117
9.60k
  SyncScope::ID getSingleThreadOneAddressSpaceSSID() const {
118
9.60k
    return SingleThreadOneAddressSpaceSSID;
119
9.60k
  }
120
121
  /// In AMDGPU target synchronization scopes are inclusive, meaning a
122
  /// larger synchronization scope is inclusive of a smaller synchronization
123
  /// scope.
124
  ///
125
  /// \returns True if synchronization scope \p A is larger than or equal to
126
  /// synchronization scope \p B, false if synchronization scope \p A is smaller
127
  /// than synchronization scope \p B, or "None" if either synchronization scope
128
  /// \p A or \p B is not supported by the AMDGPU target.
129
3.21k
  Optional<bool> isSyncScopeInclusion(SyncScope::ID A, SyncScope::ID B) const {
130
3.21k
    const auto &AIO = getSyncScopeInclusionOrdering(A);
131
3.21k
    const auto &BIO = getSyncScopeInclusionOrdering(B);
132
3.21k
    if (!AIO || !BIO)
133
12
      return None;
134
3.20k
135
3.20k
    bool IsAOneAddressSpace = isOneAddressSpace(A);
136
3.20k
    bool IsBOneAddressSpace = isOneAddressSpace(B);
137
3.20k
138
3.20k
    return AIO.getValue() >= BIO.getValue() &&
139
3.20k
        
(245
IsAOneAddressSpace == IsBOneAddressSpace245
||
!IsAOneAddressSpace136
);
140
3.20k
  }
141
};
142
143
} // end namespace llvm
144
145
#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUMACHINEMODULEINFO_H