llvm.org GIT mirror llvm / 8c53472
Add machine-CFG graph traits specializations. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13288 91177308-0d34-0410-b5e6-96231b3b80d8 Brian Gaeke 16 years ago
1 changed file(s) with 124 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
1616
1717 #include "Support/GraphTraits.h"
1818 #include "llvm/Function.h"
19 #include "llvm/CodeGen/MachineFunction.h"
1920 #include "llvm/InstrTypes.h"
2021 #include "Support/iterator"
2122
265266 }
266267 };
267268
269 //===--------------------------------------------------------------------===//
270 // GraphTraits specializations for machine basic block graphs (machine-CFGs)
271 //===--------------------------------------------------------------------===//
272
273 // Provide specializations of GraphTraits to be able to treat a
274 // MachineFunction as a graph of MachineBasicBlocks...
275 //
276
277 template <> struct GraphTraits {
278 typedef MachineBasicBlock NodeType;
279 typedef MachineBasicBlock::succ_iterator ChildIteratorType;
280
281 static NodeType *getEntryNode(MachineBasicBlock *BB) { return BB; }
282 static inline ChildIteratorType child_begin(NodeType *N) {
283 return N->succ_begin();
284 }
285 static inline ChildIteratorType child_end(NodeType *N) {
286 return N->succ_end();
287 }
288 };
289
290 template <> struct GraphTraits {
291 typedef const MachineBasicBlock NodeType;
292 typedef MachineBasicBlock::const_succ_iterator ChildIteratorType;
293
294 static NodeType *getEntryNode(const MachineBasicBlock *BB) { return BB; }
295 static inline ChildIteratorType child_begin(NodeType *N) {
296 return N->succ_begin();
297 }
298 static inline ChildIteratorType child_end(NodeType *N) {
299 return N->succ_end();
300 }
301 };
302
303 // Provide specializations of GraphTraits to be able to treat a
304 // MachineFunction as a graph of MachineBasicBlocks... and to walk it
305 // in inverse order. Inverse order for a function is considered
306 // to be when traversing the predecessor edges of a MBB
307 // instead of the successor edges.
308 //
309 template <> struct GraphTraits > {
310 typedef MachineBasicBlock NodeType;
311 typedef MachineBasicBlock::pred_iterator ChildIteratorType;
312 static NodeType *getEntryNode(Inverse G) {
313 return G.Graph;
314 }
315 static inline ChildIteratorType child_begin(NodeType *N) {
316 return N->pred_begin();
317 }
318 static inline ChildIteratorType child_end(NodeType *N) {
319 return N->pred_end();
320 }
321 };
322
323 template <> struct GraphTraits > {
324 typedef const MachineBasicBlock NodeType;
325 typedef MachineBasicBlock::const_pred_iterator ChildIteratorType;
326 static NodeType *getEntryNode(Inverse G) {
327 return G.Graph;
328 }
329 static inline ChildIteratorType child_begin(NodeType *N) {
330 return N->pred_begin();
331 }
332 static inline ChildIteratorType child_end(NodeType *N) {
333 return N->pred_end();
334 }
335 };
336
337
338 //===--------------------------------------------------------------------===//
339 // GraphTraits specializations for MachineFunction bb graphs (machine-CFGs)
340 //===--------------------------------------------------------------------===//
341
342 // Provide specializations of GraphTraits to be able to treat a
343 // MachineFunction as a graph of MachineBasicBlocks... these are the
344 // same as the MachineBasicBlock iterators, except that the root node
345 // is implicitly the first node of the MachineFunction.
346 //
347 template <> struct GraphTraits :
348 public GraphTraits {
349 static NodeType *getEntryNode(MachineFunction *F) {
350 return &F->front();
351 }
352 // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
353 typedef MachineFunction::iterator nodes_iterator;
354 static nodes_iterator nodes_begin(MachineFunction *F) { return F->begin(); }
355 static nodes_iterator nodes_end (MachineFunction *F) { return F->end(); }
356 };
357 template <> struct GraphTraits :
358 public GraphTraits {
359 static NodeType *getEntryNode(const MachineFunction *F) {
360 return &F->front();
361 }
362 // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
363 typedef MachineFunction::const_iterator nodes_iterator;
364 static nodes_iterator nodes_begin(const MachineFunction *F) {
365 return F->begin();
366 }
367 static nodes_iterator nodes_end (const MachineFunction *F) {
368 return F->end();
369 }
370 };
371
372
373 // Provide specializations of GraphTraits to be able to treat a
374 // MachineFunction as a graph of MachineBasicBlocks... and to walk it
375 // in inverse order. Inverse order for a MachineFunction is considered
376 // to be when traversing the predecessor edges of a MBB instead of the
377 // successor edges.
378 //
379 template <> struct GraphTraits > :
380 public GraphTraits > {
381 static NodeType *getEntryNode(Inverse G) {
382 return &G.Graph->front();
383 }
384 };
385 template <> struct GraphTraits > :
386 public GraphTraits > {
387 static NodeType *getEntryNode(Inverse G) {
388 return &G.Graph->front();
389 }
390 };
391
268392 } // End llvm namespace
269393
270394 #endif