Skip to content

Commit

Permalink
SWDEV-179954 - OpenCL/LC - Merge branch amd-master into amd-common
Browse files Browse the repository at this point in the history
Change-Id: Ied9f10b3e2698fadd404a6a8e2ce3c714c37fe24
  • Loading branch information
Jenkins committed Oct 2, 2019
2 parents aa4e4e5 + c44d2fe commit 1d82813
Show file tree
Hide file tree
Showing 75 changed files with 2,444 additions and 1,940 deletions.
68 changes: 63 additions & 5 deletions include/llvm/Analysis/DDG.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class LPMUpdater;
/// 1. Single instruction node containing just one instruction.
/// 2. Multiple instruction node where two or more instructions from
/// the same basic block are merged into one node.
/// 3. Root node is a special node that connects to all components such that
/// there is always a path from it to any node in the graph.
class DDGNode : public DDGNodeBase {
public:
using InstructionListType = SmallVectorImpl<Instruction *>;
Expand All @@ -41,6 +43,7 @@ class DDGNode : public DDGNodeBase {
Unknown,
SingleInstruction,
MultiInstruction,
Root,
};

DDGNode() = delete;
Expand Down Expand Up @@ -78,6 +81,22 @@ class DDGNode : public DDGNodeBase {
NodeKind Kind;
};

/// Subclass of DDGNode representing the root node of the graph.
/// There should only be one such node in a given graph.
class RootDDGNode : public DDGNode {
public:
RootDDGNode() : DDGNode(NodeKind::Root) {}
RootDDGNode(const RootDDGNode &N) = delete;
RootDDGNode(RootDDGNode &&N) : DDGNode(std::move(N)) {}
~RootDDGNode() {}

/// Define classof to be able to use isa<>, cast<>, dyn_cast<>, etc.
static bool classof(const DDGNode *N) {
return N->getKind() == NodeKind::Root;
}
static bool classof(const RootDDGNode *N) { return true; }
};

/// Subclass of DDGNode representing single or multi-instruction nodes.
class SimpleDDGNode : public DDGNode {
public:
Expand Down Expand Up @@ -139,10 +158,12 @@ class SimpleDDGNode : public DDGNode {
/// Data Dependency Graph Edge.
/// An edge in the DDG can represent a def-use relationship or
/// a memory dependence based on the result of DependenceAnalysis.
/// A rooted edge connects the root node to one of the components
/// of the graph.
class DDGEdge : public DDGEdgeBase {
public:
/// The kind of edge in the DDG
enum class EdgeKind { Unknown, RegisterDefUse, MemoryDependence };
enum class EdgeKind { Unknown, RegisterDefUse, MemoryDependence, Rooted };

explicit DDGEdge(DDGNode &N) = delete;
DDGEdge(DDGNode &N, EdgeKind K) : DDGEdgeBase(N), Kind(K) {}
Expand All @@ -169,6 +190,10 @@ class DDGEdge : public DDGEdgeBase {
/// Return true if this is a memory dependence edge, and false otherwise.
bool isMemoryDependence() const { return Kind == EdgeKind::MemoryDependence; }

/// Return true if this is an edge stemming from the root node, and false
/// otherwise.
bool isRooted() const { return Kind == EdgeKind::Rooted; }

private:
EdgeKind Kind;
};
Expand All @@ -182,14 +207,21 @@ template <typename NodeType> class DependenceGraphInfo {
DependenceGraphInfo() = delete;
DependenceGraphInfo(const DependenceGraphInfo &G) = delete;
DependenceGraphInfo(const std::string &N, const DependenceInfo &DepInfo)
: Name(N), DI(DepInfo) {}
: Name(N), DI(DepInfo), Root(nullptr) {}
DependenceGraphInfo(DependenceGraphInfo &&G)
: Name(std::move(G.Name)), DI(std::move(G.DI)) {}
: Name(std::move(G.Name)), DI(std::move(G.DI)), Root(G.Root) {}
virtual ~DependenceGraphInfo() {}

/// Return the label that is used to name this graph.
const StringRef getName() const { return Name; }

/// Return the root node of the graph.
NodeType &getRoot() const {
assert(Root && "Root node is not available yet. Graph construction may "
"still be in progress\n");
return *Root;
}

protected:
// Name of the graph.
std::string Name;
Expand All @@ -198,6 +230,10 @@ template <typename NodeType> class DependenceGraphInfo {
// dependencies don't need to be stored. Instead when the dependence is
// queried it is recomputed using @DI.
const DependenceInfo DI;

// A special node in the graph that has an edge to every connected component of
// the graph, to ensure all nodes are reachable in a graph walk.
NodeType *Root = nullptr;
};

using DDGInfo = DependenceGraphInfo<DDGNode>;
Expand All @@ -217,6 +253,12 @@ class DataDependenceGraph : public DDGBase, public DDGInfo {
DataDependenceGraph(Function &F, DependenceInfo &DI);
DataDependenceGraph(const Loop &L, DependenceInfo &DI);
~DataDependenceGraph();

protected:
/// Add node \p N to the graph, if it's not added yet, and keep track of
/// the root node. Return true if node is successfully added.
bool addNode(NodeType &N);

};

/// Concrete implementation of a pure data dependence graph builder. This class
Expand All @@ -230,6 +272,12 @@ class DDGBuilder : public AbstractDependenceGraphBuilder<DataDependenceGraph> {
DDGBuilder(DataDependenceGraph &G, DependenceInfo &D,
const BasicBlockListType &BBs)
: AbstractDependenceGraphBuilder(G, D, BBs) {}
DDGNode &createRootNode() final override {
auto *RN = new RootDDGNode();
assert(RN && "Failed to allocate memory for DDG root node.");
Graph.addNode(*RN);
return *RN;
}
DDGNode &createFineGrainedNode(Instruction &I) final override {
auto *SN = new SimpleDDGNode(I);
assert(SN && "Failed to allocate memory for simple DDG node.");
Expand All @@ -248,6 +296,14 @@ class DDGBuilder : public AbstractDependenceGraphBuilder<DataDependenceGraph> {
Graph.connect(Src, Tgt, *E);
return *E;
}
DDGEdge &createRootedEdge(DDGNode &Src, DDGNode &Tgt) final override {
auto *E = new DDGEdge(Tgt, DDGEdge::EdgeKind::Rooted);
assert(E && "Failed to allocate memory for edge");
assert(isa<RootDDGNode>(Src) && "Expected root node");
Graph.connect(Src, Tgt, *E);
return *E;
}

};

raw_ostream &operator<<(raw_ostream &OS, const DDGNode &N);
Expand Down Expand Up @@ -317,7 +373,9 @@ template <> struct GraphTraits<DDGNode *> {
template <>
struct GraphTraits<DataDependenceGraph *> : public GraphTraits<DDGNode *> {
using nodes_iterator = DataDependenceGraph::iterator;
static NodeRef getEntryNode(DataDependenceGraph *DG) { return *DG->begin(); }
static NodeRef getEntryNode(DataDependenceGraph *DG) {
return &DG->getRoot();
}
static nodes_iterator nodes_begin(DataDependenceGraph *DG) {
return DG->begin();
}
Expand Down Expand Up @@ -357,7 +415,7 @@ struct GraphTraits<const DataDependenceGraph *>
: public GraphTraits<const DDGNode *> {
using nodes_iterator = DataDependenceGraph::const_iterator;
static NodeRef getEntryNode(const DataDependenceGraph *DG) {
return *DG->begin();
return &DG->getRoot();
}
static nodes_iterator nodes_begin(const DataDependenceGraph *DG) {
return DG->begin();
Expand Down
11 changes: 11 additions & 0 deletions include/llvm/Analysis/DependenceGraphBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ template <class GraphType> class AbstractDependenceGraphBuilder {
createFineGrainedNodes();
createDefUseEdges();
createMemoryDependencyEdges();
createAndConnectRootNode();
}

/// Create fine grained nodes. These are typically atomic nodes that
Expand All @@ -69,7 +70,14 @@ template <class GraphType> class AbstractDependenceGraphBuilder {
/// in the graph nodes and create edges between them.
void createMemoryDependencyEdges();

/// Create a root node and add edges such that each node in the graph is
/// reachable from the root.
void createAndConnectRootNode();

protected:
/// Create the root node of the graph.
virtual NodeType &createRootNode() = 0;

/// Create an atomic node in the graph given a single instruction.
virtual NodeType &createFineGrainedNode(Instruction &I) = 0;

Expand All @@ -79,6 +87,9 @@ template <class GraphType> class AbstractDependenceGraphBuilder {
/// Create a memory dependence edge going from \p Src to \p Tgt.
virtual EdgeType &createMemoryEdge(NodeType &Src, NodeType &Tgt) = 0;

/// Create a rooted edge going from \p Src to \p Tgt .
virtual EdgeType &createRootedEdge(NodeType &Src, NodeType &Tgt) = 0;

/// Deallocate memory of edge \p E.
virtual void destroyEdge(EdgeType &E) { delete &E; }

Expand Down
53 changes: 53 additions & 0 deletions include/llvm/BinaryFormat/Dwarf.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,59 @@ enum SourceLanguage {
DW_LANG_hi_user = 0xffff
};

inline bool isCPlusPlus(SourceLanguage S) {
// Deliberately enumerate all the language options so we get a warning when
// new language options are added (-Wswitch) that'll hopefully help keep this
// switch up-to-date when new C++ versions are added.
switch (S) {
case DW_LANG_C_plus_plus:
case DW_LANG_C_plus_plus_03:
case DW_LANG_C_plus_plus_11:
case DW_LANG_C_plus_plus_14:
return true;
case DW_LANG_C89:
case DW_LANG_C:
case DW_LANG_Ada83:
case DW_LANG_Cobol74:
case DW_LANG_Cobol85:
case DW_LANG_Fortran77:
case DW_LANG_Fortran90:
case DW_LANG_Pascal83:
case DW_LANG_Modula2:
case DW_LANG_Java:
case DW_LANG_C99:
case DW_LANG_Ada95:
case DW_LANG_Fortran95:
case DW_LANG_PLI:
case DW_LANG_ObjC:
case DW_LANG_ObjC_plus_plus:
case DW_LANG_UPC:
case DW_LANG_D:
case DW_LANG_Python:
case DW_LANG_OpenCL:
case DW_LANG_Go:
case DW_LANG_Modula3:
case DW_LANG_Haskell:
case DW_LANG_OCaml:
case DW_LANG_Rust:
case DW_LANG_C11:
case DW_LANG_Swift:
case DW_LANG_Julia:
case DW_LANG_Dylan:
case DW_LANG_Fortran03:
case DW_LANG_Fortran08:
case DW_LANG_RenderScript:
case DW_LANG_BLISS:
case DW_LANG_Mips_Assembler:
case DW_LANG_GOOGLE_RenderScript:
case DW_LANG_BORLAND_Delphi:
case DW_LANG_lo_user:
case DW_LANG_hi_user:
return false;
}
llvm_unreachable("Invalid source language");
}

enum CaseSensitivity {
// Identifier case codes
DW_ID_case_sensitive = 0x00,
Expand Down
Loading

0 comments on commit 1d82813

Please sign in to comment.