2 //***************************************************************************
7 // Annotations used to pass information between code generation phases.
10 // 5/10/02 - Vikram Adve - Created
11 //**************************************************************************/
13 #ifndef MACHINE_INSTR_ANNOT_h
14 #define MACHINE_INSTR_ANNOT_h
16 #include "llvm/Annotation.h"
17 #include "llvm/CodeGen/MachineInstr.h"
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;
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
39 CallArgInfo(const Value* _argVal)
40 : argVal(_argVal), argValCopy(NULL), passingMethod(0x0) {}
42 CallArgInfo(const CallArgInfo& obj)
43 : argVal(obj.argVal), argValCopy(obj.argValCopy),
44 passingMethod(obj.passingMethod) {}
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; }
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; }
62 class CallArgsDescriptor: public Annotation { // Annotation for a MachineInstr
64 static AnnotationID AID; // AnnotationID for this class
65 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?
73 CallArgsDescriptor(const CallInst* _callInstr, TmpInstruction* _retAddrReg,
74 bool _isVarArgs, bool _noPrototype);
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; }
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);
96 #endif MACHINE_INSTR_ANNOT_h