Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Pull some upstream patches related to LVI mitigations compile time #74

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions llvm/include/llvm/CodeGen/RDFLiveness.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "llvm/MC/LaneBitmask.h"
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <utility>

namespace llvm {
Expand All @@ -28,6 +30,30 @@ class MachineDominatorTree;
class MachineRegisterInfo;
class TargetRegisterInfo;

} // namespace llvm

namespace llvm {
namespace rdf {
namespace detail {

using NodeRef = std::pair<NodeId, LaneBitmask>;

} // namespace detail
} // namespace rdf
} // namespace llvm

namespace std {

template <> struct hash<llvm::rdf::detail::NodeRef> {
std::size_t operator()(llvm::rdf::detail::NodeRef R) const {
return std::hash<llvm::rdf::NodeId>{}(R.first) ^
std::hash<llvm::LaneBitmask::Type>{}(R.second.getAsInteger());
}
};

} // namespace std

namespace llvm {
namespace rdf {

struct Liveness {
Expand All @@ -46,10 +72,9 @@ namespace rdf {
std::map<MachineBasicBlock*,RegisterAggr> Map;
};

using NodeRef = std::pair<NodeId, LaneBitmask>;
using NodeRefSet = std::set<NodeRef>;
// RegisterId in RefMap must be normalized.
using RefMap = std::map<RegisterId, NodeRefSet>;
using NodeRef = detail::NodeRef;
using NodeRefSet = std::unordered_set<NodeRef>;
using RefMap = std::unordered_map<RegisterId, NodeRefSet>;

Liveness(MachineRegisterInfo &mri, const DataFlowGraph &g)
: DFG(g), TRI(g.getTRI()), PRI(g.getPRI()), MDT(g.getDT()),
Expand Down Expand Up @@ -110,15 +135,14 @@ namespace rdf {
// Cache of mapping from node ids (for RefNodes) to the containing
// basic blocks. Not computing it each time for each node reduces
// the liveness calculation time by a large fraction.
using NodeBlockMap = DenseMap<NodeId, MachineBasicBlock *>;
NodeBlockMap NBMap;
DenseMap<NodeId, MachineBasicBlock *> NBMap;

// Phi information:
//
// RealUseMap
// map: NodeId -> (map: RegisterId -> NodeRefSet)
// phi id -> (map: register -> set of reached non-phi uses)
std::map<NodeId, RefMap> RealUseMap;
DenseMap<NodeId, RefMap> RealUseMap;

// Inverse iterated dominance frontier.
std::map<MachineBasicBlock*,std::set<MachineBasicBlock*>> IIDF;
Expand Down
47 changes: 45 additions & 2 deletions llvm/include/llvm/CodeGen/RDFRegisters.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ namespace rdf {
bool operator< (const RegisterRef &RR) const {
return Reg < RR.Reg || (Reg == RR.Reg && Mask < RR.Mask);
}

size_t hash() const {
return std::hash<RegisterId>{}(Reg) ^
std::hash<LaneBitmask::Type>{}(Mask.getAsInteger());
}
};


Expand All @@ -110,7 +115,11 @@ namespace rdf {
return RegMasks.get(Register::stackSlot2Index(R));
}

RegisterRef normalize(RegisterRef RR) const;
LLVM_ATTRIBUTE_DEPRECATED(RegisterRef normalize(RegisterRef RR),
"This function is now an identity function");
RegisterRef normalize(RegisterRef RR) const {
return RR;
}

bool alias(RegisterRef RA, RegisterRef RB) const {
if (!isRegMaskId(RA.Reg))
Expand All @@ -128,6 +137,10 @@ namespace rdf {
return MaskInfos[Register::stackSlot2Index(MaskId)].Units;
}

const BitVector &getUnitAliases(uint32_t U) const {
return AliasInfos[U].Regs;
}

RegisterRef mapTo(RegisterRef RR, unsigned R) const;
const TargetRegisterInfo &getTRI() const { return TRI; }

Expand All @@ -142,12 +155,16 @@ namespace rdf {
struct MaskInfo {
BitVector Units;
};
struct AliasInfo {
BitVector Regs;
};

const TargetRegisterInfo &TRI;
IndexedSet<const uint32_t*> RegMasks;
std::vector<RegInfo> RegInfos;
std::vector<UnitInfo> UnitInfos;
std::vector<MaskInfo> MaskInfos;
std::vector<AliasInfo> AliasInfos;

bool aliasRR(RegisterRef RA, RegisterRef RB) const;
bool aliasRM(RegisterRef RR, RegisterRef RM) const;
Expand All @@ -159,10 +176,15 @@ namespace rdf {
: Units(pri.getTRI().getNumRegUnits()), PRI(pri) {}
RegisterAggr(const RegisterAggr &RG) = default;

unsigned count() const { return Units.count(); }
bool empty() const { return Units.none(); }
bool hasAliasOf(RegisterRef RR) const;
bool hasCoverOf(RegisterRef RR) const;

bool operator==(const RegisterAggr &A) const {
return DenseMapInfo<BitVector>::isEqual(Units, A.Units);
}

static bool isCoverOf(RegisterRef RA, RegisterRef RB,
const PhysicalRegisterInfo &PRI) {
return RegisterAggr(PRI).insert(RA).hasCoverOf(RB);
Expand All @@ -179,6 +201,10 @@ namespace rdf {
RegisterRef clearIn(RegisterRef RR) const;
RegisterRef makeRegRef() const;

size_t hash() const {
return DenseMapInfo<BitVector>::getHashValue(Units);
}

void print(raw_ostream &OS) const;

struct rr_iterator {
Expand Down Expand Up @@ -232,9 +258,26 @@ namespace rdf {
LaneBitmask Mask;
};
raw_ostream &operator<< (raw_ostream &OS, const PrintLaneMaskOpt &P);

} // end namespace rdf

} // end namespace llvm

namespace std {
template <> struct hash<llvm::rdf::RegisterRef> {
size_t operator()(llvm::rdf::RegisterRef A) const {
return A.hash();
}
};
template <> struct hash<llvm::rdf::RegisterAggr> {
size_t operator()(const llvm::rdf::RegisterAggr &A) const {
return A.hash();
}
};
template <> struct equal_to<llvm::rdf::RegisterAggr> {
bool operator()(const llvm::rdf::RegisterAggr &A,
const llvm::rdf::RegisterAggr &B) const {
return A == B;
}
};
}
#endif // LLVM_LIB_TARGET_HEXAGON_RDFREGISTERS_H
5 changes: 0 additions & 5 deletions llvm/lib/CodeGen/RDFGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -984,11 +984,6 @@ RegisterRef DataFlowGraph::restrictRef(RegisterRef AR, RegisterRef BR) const {
LaneBitmask M = AR.Mask & BR.Mask;
return M.any() ? RegisterRef(AR.Reg, M) : RegisterRef();
}
#ifndef NDEBUG
// RegisterRef NAR = PRI.normalize(AR);
// RegisterRef NBR = PRI.normalize(BR);
// assert(NAR.Reg != NBR.Reg);
#endif
// This isn't strictly correct, because the overlap may happen in the
// part masked out.
if (PRI.alias(AR, BR))
Expand Down
Loading