llvm.org GIT mirror llvm / 0aef12a
Move the GraphTraits for MachineBasicBlocks to the MachineBasicBlock file. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13299 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 16 years ago
2 changed file(s) with 70 addition(s) and 124 deletion(s). Raw diff Collapse all Expand all
1414 #define LLVM_CODEGEN_MACHINEBASICBLOCK_H
1515
1616 #include "llvm/CodeGen/MachineInstr.h"
17 #include "Support/GraphTraits.h"
1718 #include "Support/ilist"
1819 #include
1920
196197 }
197198 };
198199
200
201 //===--------------------------------------------------------------------===//
202 // GraphTraits specializations for machine basic block graphs (machine-CFGs)
203 //===--------------------------------------------------------------------===//
204
205 // Provide specializations of GraphTraits to be able to treat a
206 // MachineFunction as a graph of MachineBasicBlocks...
207 //
208
209 template <> struct GraphTraits {
210 typedef MachineBasicBlock NodeType;
211 typedef MachineBasicBlock::succ_iterator ChildIteratorType;
212
213 static NodeType *getEntryNode(MachineBasicBlock *BB) { return BB; }
214 static inline ChildIteratorType child_begin(NodeType *N) {
215 return N->succ_begin();
216 }
217 static inline ChildIteratorType child_end(NodeType *N) {
218 return N->succ_end();
219 }
220 };
221
222 template <> struct GraphTraits {
223 typedef const MachineBasicBlock NodeType;
224 typedef MachineBasicBlock::const_succ_iterator ChildIteratorType;
225
226 static NodeType *getEntryNode(const MachineBasicBlock *BB) { return BB; }
227 static inline ChildIteratorType child_begin(NodeType *N) {
228 return N->succ_begin();
229 }
230 static inline ChildIteratorType child_end(NodeType *N) {
231 return N->succ_end();
232 }
233 };
234
235 // Provide specializations of GraphTraits to be able to treat a
236 // MachineFunction as a graph of MachineBasicBlocks... and to walk it
237 // in inverse order. Inverse order for a function is considered
238 // to be when traversing the predecessor edges of a MBB
239 // instead of the successor edges.
240 //
241 template <> struct GraphTraits > {
242 typedef MachineBasicBlock NodeType;
243 typedef MachineBasicBlock::pred_iterator ChildIteratorType;
244 static NodeType *getEntryNode(Inverse G) {
245 return G.Graph;
246 }
247 static inline ChildIteratorType child_begin(NodeType *N) {
248 return N->pred_begin();
249 }
250 static inline ChildIteratorType child_end(NodeType *N) {
251 return N->pred_end();
252 }
253 };
254
255 template <> struct GraphTraits > {
256 typedef const MachineBasicBlock NodeType;
257 typedef MachineBasicBlock::const_pred_iterator ChildIteratorType;
258 static NodeType *getEntryNode(Inverse G) {
259 return G.Graph;
260 }
261 static inline ChildIteratorType child_begin(NodeType *N) {
262 return N->pred_begin();
263 }
264 static inline ChildIteratorType child_end(NodeType *N) {
265 return N->pred_end();
266 }
267 };
268
199269 } // End llvm namespace
200270
201271 #endif
1616
1717 #include "Support/GraphTraits.h"
1818 #include "llvm/Function.h"
19 #include "llvm/CodeGen/MachineFunction.h"
2019 #include "llvm/InstrTypes.h"
2120 #include "Support/iterator"
2221
266265 }
267266 };
268267
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
392268 } // End llvm namespace
393269
394270 #endif