Devirtualizing Value destructor (PR889). Patch by Pawel Kunio!
[oota-llvm.git] / include / llvm / InlineAsm.h
1 //===-- llvm/InlineAsm.h - Class to represent inline asm strings-*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Chris Lattner and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This class represents the inline asm strings, which are Value*'s that are
11 // used as the callee operand of call instructions.  InlineAsm's are uniqued
12 // like constants, and created via InlineAsm::get(...).
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_INLINEASM_H
17 #define LLVM_INLINEASM_H
18
19 #include "llvm/Value.h"
20 #include "llvm/System/IncludeFile.h"
21 #include <vector>
22
23 namespace llvm {
24
25 struct AssemblyAnnotationWriter;
26 class PointerType;
27 class FunctionType;
28 class Module;
29
30 class InlineAsm : public Value {
31   InlineAsm(const InlineAsm &);             // do not implement
32   void operator=(const InlineAsm&);         // do not implement
33
34   std::string AsmString, Constraints;
35   bool HasSideEffects;
36   
37   InlineAsm(const FunctionType *Ty, const std::string &AsmString,
38             const std::string &Constraints, bool hasSideEffects);
39 protected:
40   static void destroyThis(InlineAsm*v) {
41     Value::destroyThis(v);
42   }
43   friend class Value;
44 public:
45   /// InlineAsm::get - Return the the specified uniqued inline asm string.
46   ///
47   static InlineAsm *get(const FunctionType *Ty, const std::string &AsmString,
48                         const std::string &Constraints, bool hasSideEffects);
49   
50   bool hasSideEffects() const { return HasSideEffects; }
51   
52   /// getType - InlineAsm's are always pointers.
53   ///
54   const PointerType *getType() const {
55     return reinterpret_cast<const PointerType*>(Value::getType());
56   }
57   
58   /// getFunctionType - InlineAsm's are always pointers to functions.
59   ///
60   const FunctionType *getFunctionType() const;
61   
62   const std::string &getAsmString() const { return AsmString; }
63   const std::string &getConstraintString() const { return Constraints; }
64
65   virtual void print(std::ostream &O) const { print(O, 0); }
66   void print(std::ostream *O) const { if (O) print(*O); }
67   void print(std::ostream &OS, AssemblyAnnotationWriter *AAW) const;
68
69   /// Verify - This static method can be used by the parser to check to see if
70   /// the specified constraint string is legal for the type.  This returns true
71   /// if legal, false if not.
72   ///
73   static bool Verify(const FunctionType *Ty, const std::string &Constraints);
74
75   // Constraint String Parsing 
76   enum ConstraintPrefix {
77     isInput,            // 'x'
78     isOutput,           // '=x'
79     isClobber           // '~x'
80   };
81   
82   struct ConstraintInfo {
83     /// Type - The basic type of the constraint: input/output/clobber
84     ///
85     ConstraintPrefix Type;
86     
87     /// isEarlyClobber - "&": output operand writes result before inputs are all
88     /// read.  This is only ever set for an output operand.
89     bool isEarlyClobber; 
90     
91     /// hasMatchingInput - This is set to true for an output constraint iff
92     /// there is an input constraint that is required to match it (e.g. "0").
93     bool hasMatchingInput;
94     
95     /// isCommutative - This is set to true for a constraint that is commutative
96     /// with the next operand.
97     bool isCommutative;
98     
99     /// isIndirect - True if this operand is an indirect operand.  This means
100     /// that the address of the source or destination is present in the call
101     /// instruction, instead of it being returned or passed in explicitly.  This
102     /// is represented with a '*' in the asm string.
103     bool isIndirect;
104     
105     /// Code - The constraint code, either the register name (in braces) or the
106     /// constraint letter/number.
107     std::vector<std::string> Codes;
108     
109     /// Parse - Analyze the specified string (e.g. "=*&{eax}") and fill in the
110     /// fields in this structure.  If the constraint string is not understood,
111     /// return true, otherwise return false.
112     bool Parse(const std::string &Str, 
113                std::vector<InlineAsm::ConstraintInfo> &ConstraintsSoFar);
114   };
115   
116   /// ParseConstraints - Split up the constraint string into the specific
117   /// constraints and their prefixes.  If this returns an empty vector, and if
118   /// the constraint string itself isn't empty, there was an error parsing.
119   static std::vector<ConstraintInfo> 
120     ParseConstraints(const std::string &ConstraintString);
121   
122   /// ParseConstraints - Parse the constraints of this inlineasm object, 
123   /// returning them the same way that ParseConstraints(str) does.
124   std::vector<ConstraintInfo> 
125   ParseConstraints() const {
126     return ParseConstraints(Constraints);
127   }
128   
129   // Methods for support type inquiry through isa, cast, and dyn_cast:
130   static inline bool classof(const InlineAsm *) { return true; }
131   static inline bool classof(const Value *V) {
132     return V->getValueID() == Value::InlineAsmVal;
133   }
134 };
135
136 } // End llvm namespace
137
138 // Make sure the InlineAsm.cpp file is linked when this one is #included.
139 FORCE_DEFINING_FILE_TO_BE_LINKED(InlineAsm)
140
141 #endif