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