llvm.org GIT mirror llvm / 5c31015
[llvm-mca] LSUnit: use a SmallSet to model load/store queues. NFCI Also, try to minimize the number of queries to the memory queues to speedup the analysis. On average, this change gives a small 2% speedup. For memcpy-like kernels, the speedup is up to 5.5%. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347469 91177308-0d34-0410-b5e6-96231b3b80d8 Andrea Di Biagio 9 months ago
2 changed file(s) with 32 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
1616 #define LLVM_TOOLS_LLVM_MCA_LSUNIT_H
1717
1818 #include "HardwareUnits/HardwareUnit.h"
19 #include
19 #include "llvm/ADT/SmallSet.h"
2020
2121 namespace llvm {
2222 namespace mca {
9898 // If true, loads will never alias with stores. This is the default.
9999 bool NoAlias;
100100
101 std::set LoadQueue;
102 std::set StoreQueue;
101 SmallSet LoadQueue;
102 SmallSet StoreQueue;
103103
104104 void assignLQSlot(unsigned Index);
105105 void assignSQSlot(unsigned Index);
108108 // An instruction that both 'mayStore' and 'HasUnmodeledSideEffects' is
109109 // conservatively treated as a store barrier. It forces older store to be
110110 // executed before newer stores are issued.
111 std::set> StoreBarriers;
111 SmallSet> StoreBarriers;
112112
113113 // An instruction that both 'MayLoad' and 'HasUnmodeledSideEffects' is
114114 // conservatively treated as a load barrier. It forces older loads to execute
115115 // before newer loads are issued.
116 std::set> LoadBarriers;
116 SmallSet> LoadBarriers;
117117
118118 bool isSQEmpty() const { return StoreQueue.empty(); }
119119 bool isLQEmpty() const { return LoadQueue.empty(); }
135135 }
136136
137137 void LSUnit::onInstructionExecuted(const InstRef &IR) {
138 const InstrDesc &Desc = IR.getInstruction()->getDesc();
138139 const unsigned Index = IR.getSourceIndex();
139 std::set::iterator it = LoadQueue.find(Index);
140 if (it != LoadQueue.end()) {
141 LLVM_DEBUG(dbgs() << "[LSUnit]: Instruction idx=" << Index
142 << " has been removed from the load queue.\n");
143 LoadQueue.erase(it);
140 bool IsALoad = Desc.MayLoad;
141 bool IsAStore = Desc.MayStore;
142
143 if (IsALoad) {
144 if (LoadQueue.erase(Index)) {
145 LLVM_DEBUG(dbgs() << "[LSUnit]: Instruction idx=" << Index
146 << " has been removed from the load queue.\n");
147 }
148 if (!LoadBarriers.empty() && Index == *LoadBarriers.begin()) {
149 LLVM_DEBUG(
150 dbgs() << "[LSUnit]: Instruction idx=" << Index
151 << " has been removed from the set of load barriers.\n");
152 LoadBarriers.erase(Index);
153 }
144154 }
145155
146 it = StoreQueue.find(Index);
147 if (it != StoreQueue.end()) {
148 LLVM_DEBUG(dbgs() << "[LSUnit]: Instruction idx=" << Index
149 << " has been removed from the store queue.\n");
150 StoreQueue.erase(it);
151 }
156 if (IsAStore) {
157 if (StoreQueue.erase(Index)) {
158 LLVM_DEBUG(dbgs() << "[LSUnit]: Instruction idx=" << Index
159 << " has been removed from the store queue.\n");
160 }
152161
153 if (!StoreBarriers.empty() && Index == *StoreBarriers.begin()) {
154 LLVM_DEBUG(dbgs() << "[LSUnit]: Instruction idx=" << Index
155 << " has been removed from the set of store barriers.\n");
156 StoreBarriers.erase(StoreBarriers.begin());
157 }
158 if (!LoadBarriers.empty() && Index == *LoadBarriers.begin()) {
159 LLVM_DEBUG(dbgs() << "[LSUnit]: Instruction idx=" << Index
160 << " has been removed from the set of load barriers.\n");
161 LoadBarriers.erase(LoadBarriers.begin());
162 if (!StoreBarriers.empty() && Index == *StoreBarriers.begin()) {
163 LLVM_DEBUG(
164 dbgs() << "[LSUnit]: Instruction idx=" << Index
165 << " has been removed from the set of store barriers.\n");
166 StoreBarriers.erase(Index);
167 }
162168 }
163169 }
170
164171 } // namespace mca
165172 } // namespace llvm