Don't crash on a query where the block is not in any loop. Thanks to
[oota-llvm.git] / include / llvm / Analysis / FindUnsafePointerTypes.h
1 //===- llvm/Analysis/FindUnsafePointerTypes.h - Unsafe pointers -*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines a pass that can be used to determine, interprocedurally,
11 // which pointer types are accessed unsafely in a program.  If there is an
12 // "unsafe" access to a specific pointer type, transformations that depend on
13 // type safety cannot be permitted.
14 //
15 // The result of running this analysis over a program is a set of unsafe pointer
16 // types that cannot be transformed.  Safe pointer types are not tracked.
17 //
18 // Additionally, this analysis exports a hidden command line argument that (when
19 // enabled) prints out the reasons a type was determined to be unsafe.  Just add
20 // -printunsafeptrinst to the command line of the tool you want to get it.
21 //
22 //===----------------------------------------------------------------------===//
23
24 #ifndef LLVM_ANALYSIS_UNSAFEPOINTERTYPES_H
25 #define LLVM_ANALYSIS_UNSAFEPOINTERTYPES_H
26
27 #include "llvm/Pass.h"
28 #include <set>
29
30 namespace llvm {
31
32 class PointerType;
33
34 struct FindUnsafePointerTypes : public ModulePass {
35   // UnsafeTypes - Set of types that are not safe to transform.
36   std::set<PointerType*> UnsafeTypes;
37 public:
38   // Accessor for underlying type set...
39   inline const std::set<PointerType*> &getUnsafeTypes() const {
40     return UnsafeTypes;
41   }
42
43   /// run - Inspect the operations that the specified module does on
44   /// values of various types.  If they are deemed to be 'unsafe' note that the
45   /// type is not safe to transform.
46   ///
47   virtual bool runOnModule(Module &M);
48
49   /// print - Loop over the results of the analysis, printing out unsafe types.
50   ///
51   void print(std::ostream &o, const Module *Mod) const;
52
53   /// getAnalysisUsage - Of course, we provide ourself...
54   ///
55   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
56     AU.setPreservesAll();
57   }
58 };
59
60 } // End llvm namespace
61
62 #endif