mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-23 01:24:30 +00:00
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
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user