diff options
author | Gabor Greif <ggreif@gmail.com> | 2010-03-24 13:21:49 +0000 |
---|---|---|
committer | Gabor Greif <ggreif@gmail.com> | 2010-03-24 13:21:49 +0000 |
commit | c9f7500d1752feac7cece26d20007a99d21f677c (patch) | |
tree | 855c74f792cd3e5ba272a2a73df5a17feb2729ab /include | |
parent | 6d6aaeca4f50e1ce101b71b33a52cbd66db01c52 (diff) | |
download | llvm-c9f7500d1752feac7cece26d20007a99d21f677c.tar.gz llvm-c9f7500d1752feac7cece26d20007a99d21f677c.tar.bz2 llvm-c9f7500d1752feac7cece26d20007a99d21f677c.tar.xz |
Finally land the InvokeInst operand reordering.
I have audited all getOperandNo calls now, fixing
hidden assumptions. CallSite related uglyness will
be eliminated successively.
Note this patch has a long and griveous history,
for all the back-and-forths have a look at
CallSite.h's log.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@99399 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/Function.h | 7 | ||||
-rw-r--r-- | include/llvm/Instructions.h | 20 | ||||
-rw-r--r-- | include/llvm/Support/CallSite.h | 33 |
3 files changed, 42 insertions, 18 deletions
diff --git a/include/llvm/Function.h b/include/llvm/Function.h index 38822332c4..2b19fa5a7f 100644 --- a/include/llvm/Function.h +++ b/include/llvm/Function.h @@ -409,8 +409,11 @@ public: void dropAllReferences(); /// hasAddressTaken - returns true if there are any uses of this function - /// other than direct calls or invokes to it. - bool hasAddressTaken() const; + /// other than direct calls or invokes to it. Optionally passes back the + /// offending user for diagnostic purposes. + /// + bool hasAddressTaken(const User** = 0) const; + private: // Shadow Value::setValueSubclassData with a private forwarding method so that // subclasses cannot accidentally use it. diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h index b382f0c912..413a595ab3 100644 --- a/include/llvm/Instructions.h +++ b/include/llvm/Instructions.h @@ -2522,32 +2522,31 @@ public: /// indirect function invocation. /// Function *getCalledFunction() const { - return dyn_cast<Function>(getOperand(0)); + return dyn_cast<Function>(Op<-3>()); } /// getCalledValue - Get a pointer to the function that is invoked by this /// instruction - const Value *getCalledValue() const { return getOperand(0); } - Value *getCalledValue() { return getOperand(0); } + const Value *getCalledValue() const { return Op<-3>(); } + Value *getCalledValue() { return Op<-3>(); } /// setCalledFunction - Set the function called. void setCalledFunction(Value* Fn) { - Op<0>() = Fn; + Op<-3>() = Fn; } // get*Dest - Return the destination basic blocks... BasicBlock *getNormalDest() const { - return cast<BasicBlock>(getOperand(1)); + return cast<BasicBlock>(Op<-2>()); } BasicBlock *getUnwindDest() const { - return cast<BasicBlock>(getOperand(2)); + return cast<BasicBlock>(Op<-1>()); } void setNormalDest(BasicBlock *B) { - setOperand(1, (Value*)B); + Op<-2>() = reinterpret_cast<Value*>(B); } - void setUnwindDest(BasicBlock *B) { - setOperand(2, (Value*)B); + Op<-1>() = reinterpret_cast<Value*>(B); } BasicBlock *getSuccessor(unsigned i) const { @@ -2557,7 +2556,7 @@ public: void setSuccessor(unsigned idx, BasicBlock *NewSucc) { assert(idx < 2 && "Successor # out of range for invoke!"); - setOperand(idx+1, (Value*)NewSucc); + *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc); } unsigned getNumSuccessors() const { return 2; } @@ -2570,6 +2569,7 @@ public: static inline bool classof(const Value *V) { return isa<Instruction>(V) && classof(cast<Instruction>(V)); } + private: virtual BasicBlock *getSuccessorV(unsigned idx) const; virtual unsigned getNumSuccessorsV() const; diff --git a/include/llvm/Support/CallSite.h b/include/llvm/Support/CallSite.h index 23d24e7c5e..9d9a30e6ad 100644 --- a/include/llvm/Support/CallSite.h +++ b/include/llvm/Support/CallSite.h @@ -122,7 +122,7 @@ public: /// Value *getCalledValue() const { assert(getInstruction() && "Not a call or invoke instruction!"); - return getInstruction()->getOperand(0); + return *getCallee(); } /// getCalledFunction - Return the function being called if this is a direct @@ -136,7 +136,7 @@ public: /// void setCalledFunction(Value *V) { assert(getInstruction() && "Not a call or invoke instruction!"); - getInstruction()->setOperand(0, V); + *getCallee() = V; } Value *getArgument(unsigned ArgNo) const { @@ -150,6 +150,16 @@ public: getInstruction()->setOperand(getArgumentOffset() + ArgNo, newVal); } + /// Given a value use iterator, returns the argument that corresponds to it. + /// Iterator must actually correspond to an argument. + unsigned getArgumentNo(Value::use_iterator I) const { + assert(getInstruction() && "Not a call or invoke instruction!"); + assert(arg_begin() <= &I.getUse() && &I.getUse() < arg_end() + && "Argument # out of range!"); + + return &I.getUse() - arg_begin(); + } + /// Given an operand number, returns the argument that corresponds to it. /// OperandNo must be a valid operand number that actually corresponds to an /// argument. @@ -175,7 +185,7 @@ public: return getInstruction()->op_begin() + getArgumentOffset(); } - arg_iterator arg_end() const { return getInstruction()->op_end(); } + arg_iterator arg_end() const { return getInstruction()->op_end() - getArgumentEndOffset(); } bool arg_empty() const { return arg_end() == arg_begin(); } unsigned arg_size() const { return unsigned(arg_end() - arg_begin()); } @@ -184,17 +194,28 @@ public: } bool isCallee(Value::use_iterator UI) const { - return getInstruction()->op_begin() == &UI.getUse(); + return getCallee() == &UI.getUse(); + } + bool isCallee(Value::use_const_iterator UI) const { + return getCallee() == &UI.getUse(); } - private: /// Returns the operand number of the first argument unsigned getArgumentOffset() const { if (isCall()) return 1; // Skip Function else - return 3; // Skip Function, BB, BB + return 0; // Args are at the front } + + unsigned getArgumentEndOffset() const { + if (isCall()) + return 0; // Unchanged + else + return 3; // Skip BB, BB, Function + } + + User::op_iterator getCallee() const; }; } // End llvm namespace |