Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 8e9339f

Browse files
committed
[ScheduleDAGInstrs::buildSchedGraph()] Handling of memory dependecies rewritten.
Recommited, after some fixing with test cases. Updated test cases: test/CodeGen/AArch64/arm64-misched-memdep-bug.ll test/CodeGen/AArch64/tailcall_misched_graph.ll Temporarily disabled test cases: test/CodeGen/AMDGPU/split-vector-memoperand-offsets.ll test/CodeGen/PowerPC/ppc64-fastcc.ll (partially updated) test/CodeGen/PowerPC/vsx-fma-m.ll test/CodeGen/PowerPC/vsx-fma-sp.ll http://reviews.llvm.org/D8705 Reviewers: Hal Finkel, Andy Trick. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@259673 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 23ddc6e commit 8e9339f

File tree

10 files changed

+458
-355
lines changed

10 files changed

+458
-355
lines changed

include/llvm/CodeGen/PseudoSourceValue.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class MachineMemOperand;
2727
class raw_ostream;
2828

2929
raw_ostream &operator<<(raw_ostream &OS, const MachineMemOperand &MMO);
30+
class PseudoSourceValue;
31+
raw_ostream &operator<<(raw_ostream &OS, const PseudoSourceValue* PSV);
3032

3133
/// Special value supplied for machine level alias analysis. It indicates that
3234
/// a memory access references the functions stack frame (e.g., a spill slot),
@@ -45,6 +47,8 @@ class PseudoSourceValue {
4547

4648
private:
4749
PSVKind Kind;
50+
friend raw_ostream &llvm::operator<<(raw_ostream &OS,
51+
const PseudoSourceValue* PSV);
4852

4953
friend class MachineMemOperand; // For printCustom().
5054

include/llvm/CodeGen/ScheduleDAG.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,17 @@ namespace llvm {
396396
/// specified node.
397397
bool addPred(const SDep &D, bool Required = true);
398398

399+
/// addPredBarrier - This adds a barrier edge to SU by calling
400+
/// addPred(), with latency 0 generally or latency 1 for a store
401+
/// followed by a load.
402+
bool addPredBarrier(SUnit *SU) {
403+
SDep Dep(SU, SDep::Barrier);
404+
unsigned TrueMemOrderLatency =
405+
((SU->getInstr()->mayStore() && this->getInstr()->mayLoad()) ? 1 : 0);
406+
Dep.setLatency(TrueMemOrderLatency);
407+
return addPred(Dep);
408+
}
409+
399410
/// removePred - This removes the specified edge as a pred of the current
400411
/// node if it exists. It also removes the current node as a successor of
401412
/// the specified node.

include/llvm/CodeGen/ScheduleDAGInstrs.h

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
#ifndef LLVM_CODEGEN_SCHEDULEDAGINSTRS_H
1616
#define LLVM_CODEGEN_SCHEDULEDAGINSTRS_H
1717

18+
#include "llvm/ADT/MapVector.h"
1819
#include "llvm/ADT/SparseMultiSet.h"
1920
#include "llvm/ADT/SparseSet.h"
2021
#include "llvm/CodeGen/ScheduleDAG.h"
2122
#include "llvm/CodeGen/TargetSchedule.h"
2223
#include "llvm/Support/Compiler.h"
2324
#include "llvm/Target/TargetRegisterInfo.h"
25+
#include <list>
2426

2527
namespace llvm {
2628
class MachineFrameInfo;
@@ -84,6 +86,10 @@ namespace llvm {
8486
typedef SparseMultiSet<VReg2SUnitOperIdx, VirtReg2IndexFunctor>
8587
VReg2SUnitOperIdxMultiMap;
8688

89+
typedef PointerUnion<const Value *, const PseudoSourceValue *> ValueType;
90+
typedef SmallVector<PointerIntPair<ValueType, 1, bool>, 4>
91+
UnderlyingObjectsVector;
92+
8793
/// ScheduleDAGInstrs - A ScheduleDAG subclass for scheduling lists of
8894
/// MachineInstrs.
8995
class ScheduleDAGInstrs : public ScheduleDAG {
@@ -149,10 +155,66 @@ namespace llvm {
149155
/// Tracks the last instructions in this region using each virtual register.
150156
VReg2SUnitOperIdxMultiMap CurrentVRegUses;
151157

152-
/// PendingLoads - Remember where unknown loads are after the most recent
153-
/// unknown store, as we iterate. As with Defs and Uses, this is here
154-
/// to minimize construction/destruction.
155-
std::vector<SUnit *> PendingLoads;
158+
AliasAnalysis *AAForDep;
159+
160+
/// Remember a generic side-effecting instruction as we proceed.
161+
/// No other SU ever gets scheduled around it (except in the special
162+
/// case of a huge region that gets reduced).
163+
SUnit *BarrierChain;
164+
165+
public:
166+
167+
/// A list of SUnits, used in Value2SUsMap, during DAG construction.
168+
/// Note: to gain speed it might be worth investigating an optimized
169+
/// implementation of this data structure, such as a singly linked list
170+
/// with a memory pool (SmallVector was tried but slow and SparseSet is not
171+
/// applicable).
172+
typedef std::list<SUnit *> SUList;
173+
protected:
174+
/// A map from ValueType to SUList, used during DAG construction,
175+
/// as a means of remembering which SUs depend on which memory
176+
/// locations.
177+
class Value2SUsMap;
178+
179+
/// Remove in FIFO order some SUs from huge maps.
180+
void reduceHugeMemNodeMaps(Value2SUsMap &stores,
181+
Value2SUsMap &loads, unsigned N);
182+
183+
/// Add a chain edge between SUa and SUb, but only if both AliasAnalysis
184+
/// and Target fail to deny the dependency.
185+
void addChainDependency(SUnit *SUa, SUnit *SUb,
186+
unsigned Latency = 0);
187+
188+
/// Add dependencies as needed from all SUs in list to SU.
189+
void addChainDependencies(SUnit *SU, SUList &sus, unsigned Latency) {
190+
for (auto *su : sus)
191+
addChainDependency(SU, su, Latency);
192+
}
193+
194+
/// Add dependencies as needed from all SUs in map, to SU.
195+
void addChainDependencies(SUnit *SU, Value2SUsMap &Val2SUsMap);
196+
197+
/// Add dependencies as needed to SU, from all SUs mapped to V.
198+
void addChainDependencies(SUnit *SU, Value2SUsMap &Val2SUsMap,
199+
ValueType V);
200+
201+
/// Add barrier chain edges from all SUs in map, and then clear
202+
/// the map. This is equivalent to insertBarrierChain(), but
203+
/// optimized for the common case where the new BarrierChain (a
204+
/// global memory object) has a higher NodeNum than all SUs in
205+
/// map. It is assumed BarrierChain has been set before calling
206+
/// this.
207+
void addBarrierChain(Value2SUsMap &map);
208+
209+
/// Insert a barrier chain in a huge region, far below current
210+
/// SU. Add barrier chain edges from all SUs in map with higher
211+
/// NodeNums than this new BarrierChain, and remove them from
212+
/// map. It is assumed BarrierChain has been set before calling
213+
/// this.
214+
void insertBarrierChain(Value2SUsMap &map);
215+
216+
/// For an unanalyzable memory access, this Value is used in maps.
217+
UndefValue *UnknownValue;
156218

157219
/// DbgValues - Remember instruction that precedes DBG_VALUE.
158220
/// These are generated by buildSchedGraph but persist so they can be

0 commit comments

Comments
 (0)