5 #ifndef DISTRIBUTED_MEMORY_ANALYSIS_H
6 #define DISTRIBUTED_MEMORY_ANALYSIS_H
14 void initializeDistributedMemoryProcessing(
int *argc,
char ***argv);
15 void finalizeDistributedMemoryProcessing();
17 template <
class InheritedAttributeType>
18 class DistributedMemoryAnalysisBase
21 bool isRootProcess()
const {
return (my_rank == root_process);}
22 DistributedMemoryAnalysisBase() {
23 MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
24 MPI_Comm_size(MPI_COMM_WORLD, &processes);
27 virtual ~DistributedMemoryAnalysisBase() {}
30 int myID()
const {
return my_rank; }
31 int numberOfProcesses()
const {
return processes; }
34 std::vector<size_t> myNodeCounts;
35 std::vector<size_t> myFuncWeights;
37 std::vector<SgFunctionDeclaration *> funcDecls;
38 std::vector<InheritedAttributeType> initialInheritedValues;
39 std::vector<int> functionsPerProcess;
40 static const int root_process = 0;
41 std::pair<int, int> computeFunctionIndices(
SgNode *root,
42 InheritedAttributeType rootInheritedValue,
44 void computeFunctionIndicesPerNode(
SgNode *root, std::vector<int>& functionToProcessor,
45 InheritedAttributeType rootInheritedValue,
47 void sortFunctions(std::vector<SgFunctionDeclaration*>& funcDecls, std::vector<InheritedAttributeType>& inhertiedValues,
48 std::vector<size_t>& nodeCounts, std::vector<size_t>& funcWeights);
58 template <
class InheritedAttributeType,
class SynthesizedAttributeType>
59 class DistributedMemoryTraversal:
public DistributedMemoryAnalysisBase<InheritedAttributeType>
62 void performAnalysis(
SgNode *root, InheritedAttributeType rootInheritedValue,
65 SynthesizedAttributeType getFinalResults() {
return finalResults;}
66 DistributedMemoryTraversal() {}
67 virtual ~DistributedMemoryTraversal() {}
71 InheritedAttributeType initialInheritedValue) = 0;
72 virtual std::pair<int, void *> serializeAttribute(SynthesizedAttributeType attribute)
const = 0;
73 virtual SynthesizedAttributeType deserializeAttribute(std::pair<int, void *> serializedAttribute)
const = 0;
74 virtual void deleteSerializedAttribute(std::pair<int, void *> serializedAttribute)
const {}
77 SynthesizedAttributeType finalResults;
78 std::vector<SynthesizedAttributeType> functionResults;
80 DistributedMemoryTraversal(
const DistributedMemoryTraversal &);
81 const DistributedMemoryTraversal &operator=(
const DistributedMemoryTraversal &);
98 template <
class InheritedAttributeType>
104 : preTraversal(preTraversal), inFunc(false), nodeCount(0), stdFunc(false), weightNullDeref(1),
107 std::vector<SgFunctionDeclaration *> &get_funcDecls() {
return funcDecls;}
108 std::vector<InheritedAttributeType> &get_initialInheritedValues() {
return initialInheritedValues;}
109 std::vector<size_t> &get_nodeCounts() {
return nodeCounts;}
110 std::vector<size_t> &get_funcWeights() {
return funcWeights;}
113 InheritedAttributeType evaluateInheritedAttribute(
SgNode *, InheritedAttributeType);
114 void destroyInheritedValue(
SgNode *, InheritedAttributeType);
121 size_t weightNullDeref;
122 size_t weightAssignOp;
124 std::vector<SgFunctionDeclaration *> funcDecls;
125 std::vector<InheritedAttributeType> initialInheritedValues;
126 std::vector<size_t> nodeCounts;
127 std::vector<size_t> funcWeights;
137 template <
class SynthesizedAttributeType>
143 const std::vector<SynthesizedAttributeType> &functionResults)
144 : postTraversal(postTraversal), functionResults(functionResults), functionCounter(0), stdFunc(false) {}
149 bool evaluateInheritedAttribute(
SgNode *node,
bool inFunction);
153 SynthesizedAttributeType evaluateSynthesizedAttribute(
SgNode *,
bool, SynthesizedAttributesList);
154 SynthesizedAttributeType defaultSynthesizedAttribute(
bool) {
return postTraversal->defaultSynthesizedAttribute();}
158 const std::vector<SynthesizedAttributeType> &functionResults;