mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-21 21:29:41 +00:00
Add support for undef and unreachable
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17051 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
289a49ab7d
commit
5a083b81c4
@ -315,7 +315,7 @@ void AsmPrinter::printSingleConstantValue(const Constant* CV) {
|
|||||||
|
|
||||||
if (const GlobalValue* GV = dyn_cast<GlobalValue>(CV)) {
|
if (const GlobalValue* GV = dyn_cast<GlobalValue>(CV)) {
|
||||||
O << getID(GV) << "\n";
|
O << getID(GV) << "\n";
|
||||||
} else if (isa<ConstantPointerNull>(CV)) {
|
} else if (isa<ConstantPointerNull>(CV) || isa<UndefValue>(CV)) {
|
||||||
// Null pointer value
|
// Null pointer value
|
||||||
O << "0\n";
|
O << "0\n";
|
||||||
} else if (const ConstantExpr* CE = dyn_cast<ConstantExpr>(CV)) {
|
} else if (const ConstantExpr* CE = dyn_cast<ConstantExpr>(CV)) {
|
||||||
@ -482,7 +482,7 @@ std::string AsmPrinter::valToExprString(const Value* V,
|
|||||||
S += utostr(CI->getValue());
|
S += utostr(CI->getValue());
|
||||||
else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV))
|
else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV))
|
||||||
S += ftostr(CFP->getValue());
|
S += ftostr(CFP->getValue());
|
||||||
else if (isa<ConstantPointerNull>(CV))
|
else if (isa<ConstantPointerNull>(CV) || isa<UndefValue>(CV))
|
||||||
S += "0";
|
S += "0";
|
||||||
else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV))
|
else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV))
|
||||||
S += ConstantExprToString(CE, target);
|
S += ConstantExprToString(CE, target);
|
||||||
@ -750,7 +750,9 @@ void SparcV9AsmPrinter::printGlobalVariable(const GlobalVariable* GV) {
|
|||||||
if (GV->hasExternalLinkage())
|
if (GV->hasExternalLinkage())
|
||||||
O << "\t.global\t" << getID(GV) << "\n";
|
O << "\t.global\t" << getID(GV) << "\n";
|
||||||
|
|
||||||
if (GV->hasInitializer() && ! GV->getInitializer()->isNullValue()) {
|
if (GV->hasInitializer() &&
|
||||||
|
!(GV->getInitializer()->isNullValue() ||
|
||||||
|
isa<UndefValue>(GV->getInitializer()))) {
|
||||||
printConstant(GV->getInitializer(), getID(GV));
|
printConstant(GV->getInitializer(), getID(GV));
|
||||||
} else {
|
} else {
|
||||||
O << "\t.align\t" << TypeToAlignment(GV->getType()->getElementType(),
|
O << "\t.align\t" << TypeToAlignment(GV->getType()->getElementType(),
|
||||||
@ -769,7 +771,8 @@ void SparcV9AsmPrinter::emitGlobals(const Module &M) {
|
|||||||
assert(GI->hasInitializer());
|
assert(GI->hasInitializer());
|
||||||
if (GI->isConstant())
|
if (GI->isConstant())
|
||||||
enterSection(ReadOnlyData); // read-only, initialized data
|
enterSection(ReadOnlyData); // read-only, initialized data
|
||||||
else if (GI->getInitializer()->isNullValue())
|
else if (GI->getInitializer()->isNullValue() ||
|
||||||
|
isa<UndefValue>(GI->getInitializer()))
|
||||||
enterSection(ZeroInitRWData); // read-write zero data
|
enterSection(ZeroInitRWData); // read-write zero data
|
||||||
else
|
else
|
||||||
enterSection(InitRWData); // read-write non-zero data
|
enterSection(InitRWData); // read-write non-zero data
|
||||||
|
@ -397,9 +397,13 @@ InstructionNode* InstrForest::buildTreeForInstruction(Instruction *instr) {
|
|||||||
} else if (Constant *CPV = dyn_cast<Constant>(operand)) {
|
} else if (Constant *CPV = dyn_cast<Constant>(operand)) {
|
||||||
if (isa<GlobalValue>(CPV))
|
if (isa<GlobalValue>(CPV))
|
||||||
opTreeNode = new VRegNode(operand);
|
opTreeNode = new VRegNode(operand);
|
||||||
else
|
else if (isa<UndefValue>(CPV)) {
|
||||||
|
opTreeNode = new
|
||||||
|
ConstantNode(Constant::getNullValue(CPV->getType()));
|
||||||
|
} else {
|
||||||
// Create a leaf node for a constant
|
// Create a leaf node for a constant
|
||||||
opTreeNode = new ConstantNode(CPV);
|
opTreeNode = new ConstantNode(CPV);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Create a leaf node for the virtual register
|
// Create a leaf node for the virtual register
|
||||||
opTreeNode = new VRegNode(operand);
|
opTreeNode = new VRegNode(operand);
|
||||||
@ -541,7 +545,7 @@ uint64_t ConvertConstantToIntType(const TargetMachine &target, const Value *V,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ConstantPointerNull: it's really just a big, shiny version of zero.
|
// ConstantPointerNull: it's really just a big, shiny version of zero.
|
||||||
if (const ConstantPointerNull *CPN = dyn_cast<ConstantPointerNull>(V)) {
|
if (isa<ConstantPointerNull>(V)) {
|
||||||
isValidConstant = true;
|
isValidConstant = true;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -565,6 +569,9 @@ uint64_t ConvertConstantToIntType(const TargetMachine &target, const Value *V,
|
|||||||
double fC = CFP->getValue();
|
double fC = CFP->getValue();
|
||||||
C = (destType->isSigned()? (uint64_t) (int64_t) fC
|
C = (destType->isSigned()? (uint64_t) (int64_t) fC
|
||||||
: (uint64_t) fC);
|
: (uint64_t) fC);
|
||||||
|
} else if (isa<UndefValue>(V)) {
|
||||||
|
isValidConstant = true;
|
||||||
|
C = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now if a valid value was found, convert it to destType.
|
// Now if a valid value was found, convert it to destType.
|
||||||
@ -839,7 +846,8 @@ bool ConstantMayNotFitInImmedField(const Constant* CV, const Instruction* I) {
|
|||||||
if (I->getOpcode() >= MaxConstantsTable.size()) // user-defined op (or bug!)
|
if (I->getOpcode() >= MaxConstantsTable.size()) // user-defined op (or bug!)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (isa<ConstantPointerNull>(CV)) // can always use %g0
|
// can always use %g0
|
||||||
|
if (isa<ConstantPointerNull>(CV) || isa<UndefValue>(CV))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (isa<SwitchInst>(I)) // Switch instructions will be lowered!
|
if (isa<SwitchInst>(I)) // Switch instructions will be lowered!
|
||||||
@ -1561,7 +1569,8 @@ static inline void Add3OperandInstr(unsigned Opcode, InstructionNode* Node,
|
|||||||
/// IsZero - Check for a constant 0.
|
/// IsZero - Check for a constant 0.
|
||||||
///
|
///
|
||||||
static inline bool IsZero(Value* idx) {
|
static inline bool IsZero(Value* idx) {
|
||||||
return (idx == ConstantSInt::getNullValue(idx->getType()));
|
return (isa<Constant>(idx) && cast<Constant>(idx)->isNullValue()) ||
|
||||||
|
isa<UndefValue>(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// FoldGetElemChain - Fold a chain of GetElementPtr instructions containing
|
/// FoldGetElemChain - Fold a chain of GetElementPtr instructions containing
|
||||||
|
@ -55,6 +55,15 @@ namespace {
|
|||||||
void visitCallInst(CallInst &I);
|
void visitCallInst(CallInst &I);
|
||||||
void visitPHINode(PHINode &PN);
|
void visitPHINode(PHINode &PN);
|
||||||
|
|
||||||
|
void visitBasicBlock(BasicBlock &BB) {
|
||||||
|
if (isa<UnreachableInst>(BB.getTerminator())) {
|
||||||
|
BB.getInstList().pop_back();
|
||||||
|
const Type *RetTy = BB.getParent()->getReturnType();
|
||||||
|
Value *RetVal = RetTy == Type::VoidTy ? 0 : UndefValue::get(RetTy);
|
||||||
|
new ReturnInst(RetVal, &BB);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Helper functions for visiting operands of every instruction
|
// Helper functions for visiting operands of every instruction
|
||||||
//
|
//
|
||||||
// visitOperands() works on every operand in [firstOp, lastOp-1].
|
// visitOperands() works on every operand in [firstOp, lastOp-1].
|
||||||
|
Loading…
x
Reference in New Issue
Block a user