Fix for pr2093: direct operands aren't necessarily addresses, so don't
[oota-llvm.git] / include / llvm / ParameterAttributes.h
1 //===-- llvm/ParameterAttributes.h - Container for ParamAttrs ---*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the simple types necessary to represent the parameter
11 // attributes associated with functions and their calls.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_PARAMETER_ATTRIBUTES_H
16 #define LLVM_PARAMETER_ATTRIBUTES_H
17
18 #include "llvm/Support/DataTypes.h"
19 #include <cassert>
20
21 namespace llvm {
22 class Type;
23
24 namespace ParamAttr {
25
26 /// Function parameters and results can have attributes to indicate how they 
27 /// should be treated by optimizations and code generation. This enumeration 
28 /// lists the attributes that can be associated with parameters or function 
29 /// results.
30 /// @brief Function parameter attributes.
31
32 /// @brief A more friendly way to reference the attributes.
33 typedef uint32_t Attributes;
34
35 const Attributes None      = 0;     ///< No attributes have been set
36 const Attributes ZExt      = 1<<0;  ///< Zero extended before/after call
37 const Attributes SExt      = 1<<1;  ///< Sign extended before/after call
38 const Attributes NoReturn  = 1<<2;  ///< Mark the function as not returning
39 const Attributes InReg     = 1<<3;  ///< Force argument to be passed in register
40 const Attributes StructRet = 1<<4;  ///< Hidden pointer to structure to return
41 const Attributes NoUnwind  = 1<<5;  ///< Function doesn't unwind stack
42 const Attributes NoAlias   = 1<<6;  ///< Considered to not alias after call
43 const Attributes ByVal     = 1<<7;  ///< Pass structure by value
44 const Attributes Nest      = 1<<8;  ///< Nested function static chain
45 const Attributes ReadNone  = 1<<9;  ///< Function does not access memory
46 const Attributes ReadOnly  = 1<<10; ///< Function only reads from memory
47 const Attributes Alignment = 0xffff<<16; ///< Alignment of parameter (16 bits)
48                                     // 0 = unknown, else in clear (not log)
49
50 /// @brief Attributes that only apply to function parameters.
51 const Attributes ParameterOnly = ByVal | InReg | Nest | StructRet;
52
53 /// @brief Attributes that only apply to function return values.
54 const Attributes ReturnOnly = NoReturn | NoUnwind | ReadNone | ReadOnly;
55
56 /// @brief Parameter attributes that do not apply to vararg call arguments.
57 const Attributes VarArgsIncompatible = StructRet;
58
59 /// @brief Attributes that are mutually incompatible.
60 const Attributes MutuallyIncompatible[3] = {
61   ByVal | InReg | Nest  | StructRet,
62   ZExt  | SExt,
63   ReadNone | ReadOnly
64 };
65
66 /// @brief Which attributes cannot be applied to a type.
67 Attributes typeIncompatible (const Type *Ty);
68
69 /// This turns an int alignment (a power of 2, normally) into the
70 /// form used internally in ParameterAttributes.
71 ParamAttr::Attributes inline constructAlignmentFromInt(uint32_t i) {
72   return (i << 16);
73 }
74
75 } // end namespace ParamAttr
76
77 /// @brief A more friendly way to reference the attributes.
78 typedef ParamAttr::Attributes ParameterAttributes;
79
80 /// This is just a pair of values to associate a set of parameter attributes
81 /// with a parameter index. 
82 /// @brief ParameterAttributes with a parameter index.
83 struct ParamAttrsWithIndex {
84   ParameterAttributes attrs; ///< The attributes that are set, or'd together
85   uint16_t index; ///< Index of the parameter for which the attributes apply
86   
87   static ParamAttrsWithIndex get(uint16_t idx, ParameterAttributes attrs) {
88     ParamAttrsWithIndex P;
89     P.index = idx;
90     P.attrs = attrs;
91     return P;
92   }
93 };
94
95 } // End llvm namespace
96
97 #endif