mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-18 12:29:21 +00:00
A bitcast of a global variable may have been constant folded to a GEP -
handle this case too. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36745 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e5b01bea7b
commit
3b346368de
@ -2457,6 +2457,24 @@ void SelectionDAGLowering::visitTargetIntrinsic(CallInst &I,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// ExtractGlobalVariable - If C is a global variable, or a bitcast of one
|
||||||
|
/// (possibly constant folded), return it. Otherwise return NULL.
|
||||||
|
static GlobalVariable *ExtractGlobalVariable (Constant *C) {
|
||||||
|
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C))
|
||||||
|
return GV;
|
||||||
|
else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
|
||||||
|
if (CE->getOpcode() == Instruction::BitCast)
|
||||||
|
return dyn_cast<GlobalVariable>(CE->getOperand(0));
|
||||||
|
else if (CE->getOpcode() == Instruction::GetElementPtr) {
|
||||||
|
for (unsigned i = 1, e = CE->getNumOperands(); i != e; ++i)
|
||||||
|
if (!CE->getOperand(i)->isNullValue())
|
||||||
|
return NULL;
|
||||||
|
return dyn_cast<GlobalVariable>(CE->getOperand(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/// visitIntrinsicCall - Lower the call to the specified intrinsic function. If
|
/// visitIntrinsicCall - Lower the call to the specified intrinsic function. If
|
||||||
/// we want to emit this as a call to a named external function, return the name
|
/// we want to emit this as a call to a named external function, return the name
|
||||||
/// otherwise lower it and return null.
|
/// otherwise lower it and return null.
|
||||||
@ -2610,20 +2628,12 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
|
|||||||
// MachineModuleInfo.
|
// MachineModuleInfo.
|
||||||
std::vector<GlobalVariable *> TyInfo;
|
std::vector<GlobalVariable *> TyInfo;
|
||||||
for (unsigned i = 3, N = I.getNumOperands(); i < N; ++i) {
|
for (unsigned i = 3, N = I.getNumOperands(); i < N; ++i) {
|
||||||
Constant *C = cast<Constant>(I.getOperand(i));
|
Constant *C = cast<Constant>(I.getOperand(i));
|
||||||
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) {
|
GlobalVariable *GV = ExtractGlobalVariable(C);
|
||||||
TyInfo.push_back(GV);
|
assert (GV || (isa<ConstantInt>(C) &&
|
||||||
} else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
|
cast<ConstantInt>(C)->isNullValue()) &&
|
||||||
assert(CE->getOpcode() == Instruction::BitCast &&
|
"TypeInfo must be a global variable or NULL");
|
||||||
isa<GlobalVariable>(CE->getOperand(0))
|
TyInfo.push_back(GV);
|
||||||
&& "TypeInfo must be a global variable or NULL");
|
|
||||||
TyInfo.push_back(cast<GlobalVariable>(CE->getOperand(0)));
|
|
||||||
} else {
|
|
||||||
ConstantInt *CI = dyn_cast<ConstantInt>(C);
|
|
||||||
assert(CI && CI->isNullValue() &&
|
|
||||||
"TypeInfo must be a global variable or NULL");
|
|
||||||
TyInfo.push_back(NULL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
MMI->addCatchTypeInfo(CurMBB, TyInfo);
|
MMI->addCatchTypeInfo(CurMBB, TyInfo);
|
||||||
|
|
||||||
@ -2651,18 +2661,12 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
|
|||||||
|
|
||||||
if (MMI) {
|
if (MMI) {
|
||||||
// Find the type id for the given typeinfo.
|
// Find the type id for the given typeinfo.
|
||||||
GlobalVariable *GV = NULL;
|
Constant *C = cast<Constant>(I.getOperand(1));
|
||||||
ConstantExpr *CE = dyn_cast<ConstantExpr>(I.getOperand(1));
|
GlobalVariable *GV = ExtractGlobalVariable(C);
|
||||||
if (CE && CE->getOpcode() == Instruction::BitCast &&
|
assert (GV || (isa<ConstantInt>(C) &&
|
||||||
isa<GlobalVariable>(CE->getOperand(0))) {
|
cast<ConstantInt>(C)->isNullValue()) &&
|
||||||
GV = cast<GlobalVariable>(CE->getOperand(0));
|
"TypeInfo must be a global variable or NULL");
|
||||||
} else {
|
|
||||||
ConstantInt *CI = dyn_cast<ConstantInt>(I.getOperand(1));
|
|
||||||
assert(CI && CI->getZExtValue() == 0 &&
|
|
||||||
"TypeInfo must be a global variable typeinfo or NULL");
|
|
||||||
GV = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned TypeID = MMI->getTypeIDFor(GV);
|
unsigned TypeID = MMI->getTypeIDFor(GV);
|
||||||
setValue(&I, DAG.getConstant(TypeID, MVT::i32));
|
setValue(&I, DAG.getConstant(TypeID, MVT::i32));
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user