llvm.org GIT mirror llvm / d09d3d9
[llvm-mca] Account for buffered resources when analyzing "Super" resources. This was noticed when working on PR3946. By construction, a group cannot be used as a "Super" resource. That constraint is enforced by method `SubtargetEmitter::ExpandProcResource()`. A Super resource S can be part of a group G. However, method `SubtargetEmitter::ExpandProcResource()` would not update the number of consumed resource cycles in G based on S. In practice, this is perfectly fine because the resource usage is correctly computed for processor resource units. However, llvm-mca should still check if G is a buffered resource. Before this patch, llvm-mca didn't correctly check if S was part of a group that defines a buffer. So, the instruction descriptor was not correctly set. For now, the semantic change introduced by this patch doesn't affect any of the upstream scheduling models. However, it will allow to make some progress on PR3946. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346545 91177308-0d34-0410-b5e6-96231b3b80d8 Andrea Di Biagio 10 months ago
1 changed file(s) with 28 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
5454 // part of a "Super" resource. The key value is the "Super" resource mask ID.
5555 DenseMap SuperResources;
5656
57 unsigned NumProcResources = SM.getNumProcResourceKinds();
58 APInt Buffers(NumProcResources, 0);
59
5760 for (unsigned I = 0, E = SCDesc.NumWriteProcResEntries; I < E; ++I) {
5861 const MCWriteProcResEntry *PRE = STI.getWriteProcResBegin(&SCDesc) + I;
5962 const MCProcResourceDesc &PR = *SM.getProcResource(PRE->ProcResourceIdx);
6063 uint64_t Mask = ProcResourceMasks[PRE->ProcResourceIdx];
6164 if (PR.BufferSize != -1)
62 ID.Buffers.push_back(Mask);
65 Buffers.setBit(PRE->ProcResourceIdx);
6366 CycleSegment RCy(0, PRE->Cycles, false);
6467 Worklist.emplace_back(ResourcePlusCycles(Mask, ResourceUsage(RCy)));
6568 if (PR.SuperIdx) {
134137 uint64_t Mask = RPC.first ^ PowerOf2Floor(RPC.first);
135138 if ((Mask & UsedResourceUnits) == Mask)
136139 RPC.second.setReserved();
140 }
141 }
142
143 // Identify extra buffers that are consumed through super resources.
144 for (const std::pair &SR : SuperResources) {
145 for (unsigned I = 1, E = NumProcResources; I < E; ++I) {
146 const MCProcResourceDesc &PR = *SM.getProcResource(I);
147 if (PR.BufferSize == -1)
148 continue;
149
150 uint64_t Mask = ProcResourceMasks[I];
151 if (Mask != SR.first && ((Mask & SR.first) == SR.first))
152 Buffers.setBit(I);
153 }
154 }
155
156 // Now set the buffers.
157 if (unsigned NumBuffers = Buffers.countPopulation()) {
158 ID.Buffers.resize(NumBuffers);
159 for (unsigned I = 0, E = NumProcResources; I < E && NumBuffers; ++I) {
160 if (Buffers[I]) {
161 --NumBuffers;
162 ID.Buffers[NumBuffers] = ProcResourceMasks[I];
163 }
137164 }
138165 }
139166