mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-16 14:31:59 +00:00
eliminate CallInst::ArgOffset
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@108522 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
10bb4211d6
commit
a6aac4c5bc
@ -964,10 +964,9 @@ public:
|
||||
# undef protected
|
||||
public:
|
||||
|
||||
enum { ArgOffset = 0 }; ///< temporary, do not use for new code!
|
||||
unsigned getNumArgOperands() const { return getNumOperands() - 1; }
|
||||
Value *getArgOperand(unsigned i) const { return getOperand(i + ArgOffset); }
|
||||
void setArgOperand(unsigned i, Value *v) { setOperand(i + ArgOffset, v); }
|
||||
Value *getArgOperand(unsigned i) const { return getOperand(i); }
|
||||
void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
|
||||
|
||||
/// getCallingConv/setCallingConv - Get or set the calling convention of this
|
||||
/// function call.
|
||||
@ -1056,17 +1055,17 @@ public:
|
||||
/// indirect function invocation.
|
||||
///
|
||||
Function *getCalledFunction() const {
|
||||
return dyn_cast<Function>(Op<ArgOffset -1>());
|
||||
return dyn_cast<Function>(Op<-1>());
|
||||
}
|
||||
|
||||
/// getCalledValue - Get a pointer to the function that is invoked by this
|
||||
/// instruction.
|
||||
const Value *getCalledValue() const { return Op<ArgOffset -1>(); }
|
||||
Value *getCalledValue() { return Op<ArgOffset -1>(); }
|
||||
const Value *getCalledValue() const { return Op<-1>(); }
|
||||
Value *getCalledValue() { return Op<-1>(); }
|
||||
|
||||
/// setCalledFunction - Set the function called.
|
||||
void setCalledFunction(Value* Fn) {
|
||||
Op<ArgOffset -1>() = Fn;
|
||||
Op<-1>() = Fn;
|
||||
}
|
||||
|
||||
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||
|
@ -254,18 +254,16 @@ public:
|
||||
|
||||
private:
|
||||
/// Returns the operand number of the first argument
|
||||
/// FIXME: remove this func!
|
||||
unsigned getArgumentOffset() const {
|
||||
if (isCall())
|
||||
return CallInst::ArgOffset; // Skip Function (ATM)
|
||||
else
|
||||
return 0; // Args are at the front
|
||||
return 0; // Args are at the front
|
||||
}
|
||||
|
||||
unsigned getArgumentEndOffset() const {
|
||||
if (isCall())
|
||||
return CallInst::ArgOffset ? 0 : 1; // Unchanged (ATM)
|
||||
return 1; // Skip Callee
|
||||
else
|
||||
return 3; // Skip BB, BB, Function
|
||||
return 3; // Skip BB, BB, Callee
|
||||
}
|
||||
|
||||
IterTy getCallee() const {
|
||||
@ -273,11 +271,9 @@ private:
|
||||
// of the op_*() functions here. See CallSite::getCallee.
|
||||
//
|
||||
if (isCall())
|
||||
return CallInst::ArgOffset
|
||||
? getInstruction()->op_begin() // Unchanged
|
||||
: getInstruction()->op_end() - 1; // Skip Function
|
||||
return getInstruction()->op_end() - 1; // Skip Callee
|
||||
else
|
||||
return getInstruction()->op_end() - 3; // Skip BB, BB, Function
|
||||
return getInstruction()->op_end() - 3; // Skip BB, BB, Callee
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -778,9 +778,9 @@ Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy,
|
||||
case Instruction::ICmp:
|
||||
case Instruction::FCmp: assert(0 && "Invalid for compares");
|
||||
case Instruction::Call:
|
||||
if (Function *F = dyn_cast<Function>(Ops[CallInst::ArgOffset ? 0:NumOps-1]))
|
||||
if (Function *F = dyn_cast<Function>(Ops[NumOps - 1]))
|
||||
if (canConstantFoldCallTo(F))
|
||||
return ConstantFoldCall(F, Ops+CallInst::ArgOffset, NumOps-1);
|
||||
return ConstantFoldCall(F, Ops, NumOps - 1);
|
||||
return 0;
|
||||
case Instruction::PtrToInt:
|
||||
// If the input is a inttoptr, eliminate the pair. This requires knowing
|
||||
|
@ -772,13 +772,13 @@ protected:
|
||||
NewInstruction = IC->ReplaceInstUsesWith(*CI, With);
|
||||
}
|
||||
bool isFoldable(unsigned SizeCIOp, unsigned SizeArgOp, bool isString) const {
|
||||
if (ConstantInt *SizeCI = dyn_cast<ConstantInt>(CI->getArgOperand(SizeCIOp - CallInst::ArgOffset))) {
|
||||
if (ConstantInt *SizeCI = dyn_cast<ConstantInt>(CI->getArgOperand(SizeCIOp))) {
|
||||
if (SizeCI->isAllOnesValue())
|
||||
return true;
|
||||
if (isString)
|
||||
return SizeCI->getZExtValue() >=
|
||||
GetStringLength(CI->getArgOperand(SizeArgOp - CallInst::ArgOffset));
|
||||
if (ConstantInt *Arg = dyn_cast<ConstantInt>(CI->getArgOperand(SizeArgOp - CallInst::ArgOffset)))
|
||||
GetStringLength(CI->getArgOperand(SizeArgOp));
|
||||
if (ConstantInt *Arg = dyn_cast<ConstantInt>(CI->getArgOperand(SizeArgOp)))
|
||||
return SizeCI->getZExtValue() >= Arg->getZExtValue();
|
||||
}
|
||||
return false;
|
||||
|
@ -548,9 +548,9 @@ protected:
|
||||
CI->eraseFromParent();
|
||||
}
|
||||
bool isFoldable(unsigned SizeCIOp, unsigned, bool) const {
|
||||
if (ConstantInt *SizeCI = dyn_cast<ConstantInt>(CI->getArgOperand(SizeCIOp
|
||||
- CallInst::ArgOffset)))
|
||||
return SizeCI->isAllOnesValue();
|
||||
if (ConstantInt *SizeCI =
|
||||
dyn_cast<ConstantInt>(CI->getArgOperand(SizeCIOp)))
|
||||
return SizeCI->isAllOnesValue();
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
@ -969,7 +969,7 @@ void SROA::isSafeForScalarRepl(Instruction *I, AllocaInst *AI, uint64_t Offset,
|
||||
ConstantInt *Length = dyn_cast<ConstantInt>(MI->getLength());
|
||||
if (Length)
|
||||
isSafeMemAccess(AI, Offset, Length->getZExtValue(), 0,
|
||||
UI.getOperandNo() == CallInst::ArgOffset, Info);
|
||||
UI.getOperandNo() == 0, Info);
|
||||
else
|
||||
MarkUnsafe(Info);
|
||||
} else if (LoadInst *LI = dyn_cast<LoadInst>(User)) {
|
||||
@ -1787,7 +1787,7 @@ static bool isOnlyCopiedFromConstantGlobal(Value *V, MemTransferInst *&TheCopy,
|
||||
if (isOffset) return false;
|
||||
|
||||
// If the memintrinsic isn't using the alloca as the dest, reject it.
|
||||
if (UI.getOperandNo() != CallInst::ArgOffset) return false;
|
||||
if (UI.getOperandNo() != 0) return false;
|
||||
|
||||
// If the source of the memcpy/move is not a constant global, reject it.
|
||||
if (!PointsToConstantGlobal(MI->getSource()))
|
||||
|
@ -421,7 +421,7 @@ bool SimplifyFortifiedLibCalls::fold(CallInst *CI, const TargetData *TD) {
|
||||
FT->getParamType(3) != TD->getIntPtrType(Context))
|
||||
return false;
|
||||
|
||||
if (isFoldable(3 + CallInst::ArgOffset, 2 + CallInst::ArgOffset, false)) {
|
||||
if (isFoldable(3, 2, false)) {
|
||||
EmitMemCpy(CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(2),
|
||||
1, false, B, TD);
|
||||
replaceCall(CI->getArgOperand(0));
|
||||
@ -444,7 +444,7 @@ bool SimplifyFortifiedLibCalls::fold(CallInst *CI, const TargetData *TD) {
|
||||
FT->getParamType(3) != TD->getIntPtrType(Context))
|
||||
return false;
|
||||
|
||||
if (isFoldable(3 + CallInst::ArgOffset, 2 + CallInst::ArgOffset, false)) {
|
||||
if (isFoldable(3, 2, false)) {
|
||||
EmitMemMove(CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(2),
|
||||
1, false, B, TD);
|
||||
replaceCall(CI->getArgOperand(0));
|
||||
@ -462,7 +462,7 @@ bool SimplifyFortifiedLibCalls::fold(CallInst *CI, const TargetData *TD) {
|
||||
FT->getParamType(3) != TD->getIntPtrType(Context))
|
||||
return false;
|
||||
|
||||
if (isFoldable(3 + CallInst::ArgOffset, 2 + CallInst::ArgOffset, false)) {
|
||||
if (isFoldable(3, 2, false)) {
|
||||
Value *Val = B.CreateIntCast(CI->getArgOperand(1), B.getInt8Ty(),
|
||||
false);
|
||||
EmitMemSet(CI->getArgOperand(0), Val, CI->getArgOperand(2), false, B, TD);
|
||||
@ -487,7 +487,7 @@ bool SimplifyFortifiedLibCalls::fold(CallInst *CI, const TargetData *TD) {
|
||||
// st[rp]cpy_chk call which may fail at runtime if the size is too long.
|
||||
// TODO: It might be nice to get a maximum length out of the possible
|
||||
// string lengths for varying.
|
||||
if (isFoldable(2 + CallInst::ArgOffset, 1 + CallInst::ArgOffset, true)) {
|
||||
if (isFoldable(2, 1, true)) {
|
||||
Value *Ret = EmitStrCpy(CI->getArgOperand(0), CI->getArgOperand(1), B, TD,
|
||||
Name.substr(2, 6));
|
||||
replaceCall(Ret);
|
||||
@ -505,7 +505,7 @@ bool SimplifyFortifiedLibCalls::fold(CallInst *CI, const TargetData *TD) {
|
||||
FT->getParamType(3) != TD->getIntPtrType(Context))
|
||||
return false;
|
||||
|
||||
if (isFoldable(3 + CallInst::ArgOffset, 2 + CallInst::ArgOffset, false)) {
|
||||
if (isFoldable(3, 2, false)) {
|
||||
Value *Ret = EmitStrNCpy(CI->getArgOperand(0), CI->getArgOperand(1),
|
||||
CI->getArgOperand(2), B, TD, Name.substr(2, 7));
|
||||
replaceCall(Ret);
|
||||
|
@ -33,10 +33,8 @@ using namespace llvm;
|
||||
User::op_iterator CallSite::getCallee() const {
|
||||
Instruction *II(getInstruction());
|
||||
return isCall()
|
||||
? (CallInst::ArgOffset
|
||||
? cast</*FIXME: CallInst*/User>(II)->op_begin()
|
||||
: cast</*FIXME: CallInst*/User>(II)->op_end() - 1)
|
||||
: cast<InvokeInst>(II)->op_end() - 3; // Skip BB, BB, Function
|
||||
? cast</*FIXME: CallInst*/User>(II)->op_end() - 1 // Skip Callee
|
||||
: cast<InvokeInst>(II)->op_end() - 3; // Skip BB, BB, Callee
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
@ -233,7 +231,7 @@ CallInst::~CallInst() {
|
||||
|
||||
void CallInst::init(Value *Func, Value* const *Params, unsigned NumParams) {
|
||||
assert(NumOperands == NumParams+1 && "NumOperands not set up?");
|
||||
Op<ArgOffset -1>() = Func;
|
||||
Op<-1>() = Func;
|
||||
|
||||
const FunctionType *FTy =
|
||||
cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
|
||||
@ -246,15 +244,15 @@ void CallInst::init(Value *Func, Value* const *Params, unsigned NumParams) {
|
||||
assert((i >= FTy->getNumParams() ||
|
||||
FTy->getParamType(i) == Params[i]->getType()) &&
|
||||
"Calling a function with a bad signature!");
|
||||
OperandList[i + ArgOffset] = Params[i];
|
||||
OperandList[i] = Params[i];
|
||||
}
|
||||
}
|
||||
|
||||
void CallInst::init(Value *Func, Value *Actual1, Value *Actual2) {
|
||||
assert(NumOperands == 3 && "NumOperands not set up?");
|
||||
Op<ArgOffset -1>() = Func;
|
||||
Op<ArgOffset + 0>() = Actual1;
|
||||
Op<ArgOffset + 1>() = Actual2;
|
||||
Op<-1>() = Func;
|
||||
Op<0>() = Actual1;
|
||||
Op<1>() = Actual2;
|
||||
|
||||
const FunctionType *FTy =
|
||||
cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
|
||||
@ -273,8 +271,8 @@ void CallInst::init(Value *Func, Value *Actual1, Value *Actual2) {
|
||||
|
||||
void CallInst::init(Value *Func, Value *Actual) {
|
||||
assert(NumOperands == 2 && "NumOperands not set up?");
|
||||
Op<ArgOffset -1>() = Func;
|
||||
Op<ArgOffset + 0>() = Actual;
|
||||
Op<-1>() = Func;
|
||||
Op<0>() = Actual;
|
||||
|
||||
const FunctionType *FTy =
|
||||
cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
|
||||
@ -290,7 +288,7 @@ void CallInst::init(Value *Func, Value *Actual) {
|
||||
|
||||
void CallInst::init(Value *Func) {
|
||||
assert(NumOperands == 1 && "NumOperands not set up?");
|
||||
Op<ArgOffset -1>() = Func;
|
||||
Op<-1>() = Func;
|
||||
|
||||
const FunctionType *FTy =
|
||||
cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
|
||||
|
Loading…
x
Reference in New Issue
Block a user