Skip to content

Commit

Permalink
[ScheduleDAGInstrs] Re-factor for based on review feedback. NFC.
Browse files Browse the repository at this point in the history
Summary:
Re-factor some code to improve clarity and style based on review
comments from http://reviews.llvm.org/D18093.

Reviewers: MatzeB, mcrosier

Subscribers: MatzeB, mcrosier, llvm-commits

Differential Revision: http://reviews.llvm.org/D19128

llvm-svn: 266372
  • Loading branch information
geoffberry committed Apr 14, 2016
1 parent 9e09355 commit 6381713
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 54 deletions.
9 changes: 7 additions & 2 deletions llvm/include/llvm/CodeGen/ScheduleDAGInstrs.h
Expand Up @@ -87,8 +87,13 @@ namespace llvm {
VReg2SUnitOperIdxMultiMap;

typedef PointerUnion<const Value *, const PseudoSourceValue *> ValueType;
typedef SmallVector<PointerIntPair<ValueType, 1, bool>, 4>
UnderlyingObjectsVector;
struct UnderlyingObject : PointerIntPair<ValueType, 1, bool> {
UnderlyingObject(ValueType V, bool MayAlias)
: PointerIntPair<ValueType, 1, bool>(V, MayAlias) {}
ValueType getValue() const { return getPointer(); }
bool mayAlias() const { return getInt(); }
};
typedef SmallVector<UnderlyingObject, 4> UnderlyingObjectsVector;

/// ScheduleDAGInstrs - A ScheduleDAG subclass for scheduling lists of
/// MachineInstrs.
Expand Down
97 changes: 45 additions & 52 deletions llvm/lib/CodeGen/ScheduleDAGInstrs.cpp
Expand Up @@ -159,49 +159,46 @@ static void getUnderlyingObjectsForInstr(const MachineInstr *MI,
const MachineFrameInfo *MFI,
UnderlyingObjectsVector &Objects,
const DataLayout &DL) {
for (auto *MMO : MI->memoperands()) {
if (MMO->isVolatile()) {
Objects.clear();
return;
}
auto allMMOsOkay = [&]() {
for (const MachineMemOperand *MMO : MI->memoperands()) {
if (MMO->isVolatile())
return false;

if (const PseudoSourceValue *PSV = MMO->getPseudoValue()) {
// Function that contain tail calls don't have unique PseudoSourceValue
// objects. Two PseudoSourceValues might refer to the same or
// overlapping locations. The client code calling this function assumes
// this is not the case. So return a conservative answer of no known
// object.
if (MFI->hasTailCall())
return false;

if (const PseudoSourceValue *PSV = MMO->getPseudoValue()) {
// Function that contain tail calls don't have unique PseudoSourceValue
// objects. Two PseudoSourceValues might refer to the same or overlapping
// locations. The client code calling this function assumes this is not the
// case. So return a conservative answer of no known object.
if (MFI->hasTailCall()) {
Objects.clear();
return;
}
// For now, ignore PseudoSourceValues which may alias LLVM IR values
// because the code that uses this function has no way to cope with
// such aliases.
if (PSV->isAliased(MFI))
return false;

// For now, ignore PseudoSourceValues which may alias LLVM IR values
// because the code that uses this function has no way to cope with
// such aliases.
if (PSV->isAliased(MFI)) {
Objects.clear();
return;
}
bool MayAlias = PSV->mayAlias(MFI);
Objects.push_back(UnderlyingObjectsVector::value_type(PSV, MayAlias));
} else if (const Value *V = MMO->getValue()) {
SmallVector<Value *, 4> Objs;
getUnderlyingObjects(V, Objs, DL);

bool MayAlias = PSV->mayAlias(MFI);
Objects.push_back(UnderlyingObjectsVector::value_type(PSV, MayAlias));
} else if (const Value *V = MMO->getValue()) {
SmallVector<Value *, 4> Objs;
getUnderlyingObjects(V, Objs, DL);
for (Value *V : Objs) {
if (!isIdentifiedObject(V))
return false;

for (Value *V : Objs) {
if (!isIdentifiedObject(V)) {
Objects.clear();
return;
Objects.push_back(UnderlyingObjectsVector::value_type(V, true));
}

Objects.push_back(UnderlyingObjectsVector::value_type(V, true));
}
} else {
Objects.clear();
return;
} else
return false;
}
}
return true;
};

if (!allMMOsOkay())
Objects.clear();
}

void ScheduleDAGInstrs::startBlock(MachineBasicBlock *bb) {
Expand Down Expand Up @@ -1031,26 +1028,22 @@ void ScheduleDAGInstrs::buildSchedGraph(AliasAnalysis *AA,
} else {
// Add precise dependencies against all previously seen memory
// accesses mapped to the same Value(s).
for (auto &underlObj : Objs) {
ValueType V = underlObj.getPointer();
bool ThisMayAlias = underlObj.getInt();

Value2SUsMap &stores_ = (ThisMayAlias ? Stores : NonAliasStores);
for (const UnderlyingObject &UnderlObj : Objs) {
ValueType V = UnderlObj.getValue();
bool ThisMayAlias = UnderlObj.mayAlias();

// Add dependencies to previous stores and loads mapped to V.
addChainDependencies(SU, stores_, V);
addChainDependencies(SU, (ThisMayAlias ? Stores : NonAliasStores), V);
addChainDependencies(SU, (ThisMayAlias ? Loads : NonAliasLoads), V);
}
// Update the store map after all chains have been added to avoid adding
// self-loop edge if multiple underlying objects are present.
for (auto &underlObj : Objs) {
ValueType V = underlObj.getPointer();
bool ThisMayAlias = underlObj.getInt();

Value2SUsMap &stores_ = (ThisMayAlias ? Stores : NonAliasStores);
for (const UnderlyingObject &UnderlObj : Objs) {
ValueType V = UnderlObj.getValue();
bool ThisMayAlias = UnderlObj.mayAlias();

// Map this store to V.
stores_.insert(SU, V);
(ThisMayAlias ? Stores : NonAliasStores).insert(SU, V);
}
// The store may have dependencies to unanalyzable loads and
// stores.
Expand All @@ -1065,9 +1058,9 @@ void ScheduleDAGInstrs::buildSchedGraph(AliasAnalysis *AA,

Loads.insert(SU, UnknownValue);
} else {
for (auto &underlObj : Objs) {
ValueType V = underlObj.getPointer();
bool ThisMayAlias = underlObj.getInt();
for (const UnderlyingObject &UnderlObj : Objs) {
ValueType V = UnderlObj.getValue();
bool ThisMayAlias = UnderlObj.mayAlias();

// Add precise dependencies against all previously seen stores
// mapping to the same Value(s).
Expand Down

0 comments on commit 6381713

Please sign in to comment.