Bug fix: cast (bool) has higher precedence than %... who knew!
[oota-llvm.git] / include / llvm / CodeGen / MachineInstrAnnot.h
1 // $Id$ -*-c++-*-
2 //***************************************************************************
3 // File:
4 //      MachineInstrAnnot.h
5 // 
6 // Purpose:
7 //      Annotations used to pass information between code generation phases.
8 // 
9 // History:
10 //      5/10/02  -  Vikram Adve  -  Created
11 //**************************************************************************/
12
13 #ifndef MACHINE_INSTR_ANNOT_h
14 #define MACHINE_INSTR_ANNOT_h
15
16 #include "llvm/Annotation.h"
17 #include "llvm/CodeGen/MachineInstr.h"
18 #include <vector>
19
20 class Value;
21 class TmpInstruction;
22 class CallInst;
23
24
25 class CallArgInfo {
26 private:
27   // Flag values for different argument passing methods
28   static const unsigned char IntArgReg = 0x1;
29   static const unsigned char FPArgReg  = 0x2;
30   static const unsigned char StackSlot = 0x4;
31   
32   const Value* argVal;                  // this argument
33   const Value* argValCopy;              // second copy of arg. when multiple 
34                                         // copies must be passed in registers
35   unsigned char passingMethod;          // flags recording passing methods
36   
37 public:
38   // Constructors
39   CallArgInfo(const Value* _argVal)
40     : argVal(_argVal), argValCopy(NULL), passingMethod(0x0) {}
41   
42   CallArgInfo(const CallArgInfo& obj)
43     : argVal(obj.argVal), argValCopy(obj.argValCopy),
44       passingMethod(obj.passingMethod) {}
45   
46   // Accessor methods
47   const Value*  getArgVal()       { return argVal; }
48   const Value*  getArgCopy()      { return argValCopy; }
49   bool          usesIntArgReg()   { return (bool) (passingMethod & IntArgReg);} 
50   bool          usesFPArgReg()    { return (bool) (passingMethod & FPArgReg); } 
51   bool          usesStackSlot()   { return (bool) (passingMethod & StackSlot);} 
52   
53   // Modifier methods
54   void          replaceArgVal(const Value* newVal) { argVal = newVal; }
55   void          setUseIntArgReg() { passingMethod |= IntArgReg; }
56   void          setUseFPArgReg()  { passingMethod |= FPArgReg; }
57   void          setUseStackSlot() { passingMethod |= StackSlot; }
58   void          setArgCopy(const Value* tmp) { argValCopy = tmp; }
59 };
60
61
62 class CallArgsDescriptor: public Annotation { // Annotation for a MachineInstr
63 private:
64   static AnnotationID AID;              // AnnotationID for this class
65   std::vector<CallArgInfo> argInfoVec;       // Descriptor for each argument
66   const CallInst* callInstr;            // The call instruction == result value
67   const Value* funcPtr;                 // Pointer for indirect calls 
68   TmpInstruction* retAddrReg;           // Tmp value for return address reg.
69   bool isVarArgs;                       // Is this a varargs call?
70   bool noPrototype;                     // Is this a call with no prototype?
71   
72 public:
73   CallArgsDescriptor(const CallInst* _callInstr, TmpInstruction* _retAddrReg,
74                      bool _isVarArgs, bool _noPrototype);
75   
76   // Accessor methods to retrieve information about the call
77   // Note that operands are numbered 1..#CallArgs
78   unsigned int    getNumArgs() const          { return argInfoVec.size(); }
79   CallArgInfo&    getArgInfo(unsigned int op) { assert(op < argInfoVec.size());
80                                                 return argInfoVec[op]; }
81   const CallInst* getReturnValue() const      { return callInstr; }
82   const Value*    getIndirectFuncPtr() const  { return funcPtr; }
83   TmpInstruction* getReturnAddrReg() const    { return retAddrReg; }
84   bool            isVarArgsFunc() const       { return isVarArgs; }
85   bool            hasNoPrototype() const      { return noPrototype; }
86   
87   // Annotation mechanism to annotate a MachineInstr with the descriptor.
88   // This is not demand-driven because annotations can only be created
89   // at restricted points during code generation.
90   static inline CallArgsDescriptor *get(const MachineInstr* MI) {
91     return (CallArgsDescriptor *) MI->getAnnotation(AID);
92   }
93 };
94
95
96 #endif MACHINE_INSTR_ANNOT_h