mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-25 13:24:46 +00:00
For PR950:
This patch implements the first increment for the Signless Types feature. All changes pertain to removing the ConstantSInt and ConstantUInt classes in favor of just using ConstantInt. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31063 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -305,7 +305,7 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
|
||||
if (AggregateArgs) {
|
||||
std::vector<Value*> Indices;
|
||||
Indices.push_back(Constant::getNullValue(Type::UIntTy));
|
||||
Indices.push_back(ConstantUInt::get(Type::UIntTy, i));
|
||||
Indices.push_back(ConstantInt::get(Type::UIntTy, i));
|
||||
std::string GEPname = "gep_" + inputs[i]->getName();
|
||||
TerminatorInst *TI = newFunction->begin()->getTerminator();
|
||||
GetElementPtrInst *GEP = new GetElementPtrInst(AI, Indices, GEPname, TI);
|
||||
@@ -392,7 +392,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
|
||||
for (unsigned i = 0, e = inputs.size(); i != e; ++i) {
|
||||
std::vector<Value*> Indices;
|
||||
Indices.push_back(Constant::getNullValue(Type::UIntTy));
|
||||
Indices.push_back(ConstantUInt::get(Type::UIntTy, i));
|
||||
Indices.push_back(ConstantInt::get(Type::UIntTy, i));
|
||||
GetElementPtrInst *GEP =
|
||||
new GetElementPtrInst(Struct, Indices,
|
||||
"gep_" + StructValues[i]->getName());
|
||||
@@ -418,7 +418,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
|
||||
if (AggregateArgs) {
|
||||
std::vector<Value*> Indices;
|
||||
Indices.push_back(Constant::getNullValue(Type::UIntTy));
|
||||
Indices.push_back(ConstantUInt::get(Type::UIntTy, FirstOut + i));
|
||||
Indices.push_back(ConstantInt::get(Type::UIntTy, FirstOut + i));
|
||||
GetElementPtrInst *GEP
|
||||
= new GetElementPtrInst(Struct, Indices,
|
||||
"gep_reload_" + outputs[i]->getName());
|
||||
@@ -439,7 +439,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
|
||||
|
||||
// Now we can emit a switch statement using the call as a value.
|
||||
SwitchInst *TheSwitch =
|
||||
new SwitchInst(ConstantUInt::getNullValue(Type::UShortTy),
|
||||
new SwitchInst(ConstantInt::getNullValue(Type::UShortTy),
|
||||
codeReplacer, 0, codeReplacer);
|
||||
|
||||
// Since there may be multiple exits from the original region, make the new
|
||||
@@ -473,14 +473,14 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
|
||||
brVal = ConstantBool::get(!SuccNum);
|
||||
break;
|
||||
default:
|
||||
brVal = ConstantUInt::get(Type::UShortTy, SuccNum);
|
||||
brVal = ConstantInt::get(Type::UShortTy, SuccNum);
|
||||
break;
|
||||
}
|
||||
|
||||
ReturnInst *NTRet = new ReturnInst(brVal, NewTarget);
|
||||
|
||||
// Update the switch instruction.
|
||||
TheSwitch->addCase(ConstantUInt::get(Type::UShortTy, SuccNum),
|
||||
TheSwitch->addCase(ConstantInt::get(Type::UShortTy, SuccNum),
|
||||
OldTarget);
|
||||
|
||||
// Restore values just before we exit
|
||||
@@ -519,7 +519,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
|
||||
if (AggregateArgs) {
|
||||
std::vector<Value*> Indices;
|
||||
Indices.push_back(Constant::getNullValue(Type::UIntTy));
|
||||
Indices.push_back(ConstantUInt::get(Type::UIntTy,FirstOut+out));
|
||||
Indices.push_back(ConstantInt::get(Type::UIntTy,FirstOut+out));
|
||||
GetElementPtrInst *GEP =
|
||||
new GetElementPtrInst(OAI, Indices,
|
||||
"gep_" + outputs[out]->getName(),
|
||||
|
@@ -272,10 +272,10 @@ Constant *llvm::ConstantFoldLoadThroughGEPConstantExpr(Constant *C,
|
||||
gep_type_iterator I = gep_type_begin(CE), E = gep_type_end(CE);
|
||||
for (++I; I != E; ++I)
|
||||
if (const StructType *STy = dyn_cast<StructType>(*I)) {
|
||||
ConstantUInt *CU = cast<ConstantUInt>(I.getOperand());
|
||||
assert(CU->getValue() < STy->getNumElements() &&
|
||||
ConstantInt *CU = cast<ConstantInt>(I.getOperand());
|
||||
assert(CU->getZExtValue() < STy->getNumElements() &&
|
||||
"Struct index out of range!");
|
||||
unsigned El = (unsigned)CU->getValue();
|
||||
unsigned El = (unsigned)CU->getZExtValue();
|
||||
if (ConstantStruct *CS = dyn_cast<ConstantStruct>(C)) {
|
||||
C = CS->getOperand(El);
|
||||
} else if (isa<ConstantAggregateZero>(C)) {
|
||||
@@ -287,10 +287,10 @@ Constant *llvm::ConstantFoldLoadThroughGEPConstantExpr(Constant *C,
|
||||
}
|
||||
} else if (ConstantInt *CI = dyn_cast<ConstantInt>(I.getOperand())) {
|
||||
if (const ArrayType *ATy = dyn_cast<ArrayType>(*I)) {
|
||||
if ((uint64_t)CI->getRawValue() >= ATy->getNumElements())
|
||||
if (CI->getZExtValue() >= ATy->getNumElements())
|
||||
return 0;
|
||||
if (ConstantArray *CA = dyn_cast<ConstantArray>(C))
|
||||
C = CA->getOperand((unsigned)CI->getRawValue());
|
||||
C = CA->getOperand(CI->getZExtValue());
|
||||
else if (isa<ConstantAggregateZero>(C))
|
||||
C = Constant::getNullValue(ATy->getElementType());
|
||||
else if (isa<UndefValue>(C))
|
||||
@@ -298,10 +298,10 @@ Constant *llvm::ConstantFoldLoadThroughGEPConstantExpr(Constant *C,
|
||||
else
|
||||
return 0;
|
||||
} else if (const PackedType *PTy = dyn_cast<PackedType>(*I)) {
|
||||
if ((uint64_t)CI->getRawValue() >= PTy->getNumElements())
|
||||
if (CI->getZExtValue() >= PTy->getNumElements())
|
||||
return 0;
|
||||
if (ConstantPacked *CP = dyn_cast<ConstantPacked>(C))
|
||||
C = CP->getOperand((unsigned)CI->getRawValue());
|
||||
C = CP->getOperand(CI->getZExtValue());
|
||||
else if (isa<ConstantAggregateZero>(C))
|
||||
C = Constant::getNullValue(PTy->getElementType());
|
||||
else if (isa<UndefValue>(C))
|
||||
|
@@ -119,14 +119,14 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) {
|
||||
// malloc(type) becomes sbyte *malloc(size)
|
||||
Value *MallocArg;
|
||||
if (LowerMallocArgToInteger)
|
||||
MallocArg = ConstantUInt::get(Type::ULongTy, TD.getTypeSize(AllocTy));
|
||||
MallocArg = ConstantInt::get(Type::ULongTy, TD.getTypeSize(AllocTy));
|
||||
else
|
||||
MallocArg = ConstantExpr::getSizeOf(AllocTy);
|
||||
MallocArg = ConstantExpr::getCast(cast<Constant>(MallocArg), IntPtrTy);
|
||||
|
||||
if (MI->isArrayAllocation()) {
|
||||
if (isa<ConstantInt>(MallocArg) &&
|
||||
cast<ConstantInt>(MallocArg)->getRawValue() == 1) {
|
||||
cast<ConstantInt>(MallocArg)->getZExtValue() == 1) {
|
||||
MallocArg = MI->getOperand(0); // Operand * 1 = Operand
|
||||
} else if (Constant *CO = dyn_cast<Constant>(MI->getOperand(0))) {
|
||||
CO = ConstantExpr::getCast(CO, IntPtrTy);
|
||||
|
@@ -269,7 +269,7 @@ bool LowerInvoke::insertCheapEHSupport(Function &F) {
|
||||
void LowerInvoke::rewriteExpensiveInvoke(InvokeInst *II, unsigned InvokeNo,
|
||||
AllocaInst *InvokeNum,
|
||||
SwitchInst *CatchSwitch) {
|
||||
ConstantUInt *InvokeNoC = ConstantUInt::get(Type::UIntTy, InvokeNo);
|
||||
ConstantInt *InvokeNoC = ConstantInt::get(Type::UIntTy, InvokeNo);
|
||||
|
||||
// Insert a store of the invoke num before the invoke and store zero into the
|
||||
// location afterward.
|
||||
@@ -461,7 +461,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
|
||||
|
||||
std::vector<Value*> Idx;
|
||||
Idx.push_back(Constant::getNullValue(Type::IntTy));
|
||||
Idx.push_back(ConstantUInt::get(Type::UIntTy, 1));
|
||||
Idx.push_back(ConstantInt::get(Type::UIntTy, 1));
|
||||
OldJmpBufPtr = new GetElementPtrInst(JmpBuf, Idx, "OldBuf",
|
||||
EntryBB->getTerminator());
|
||||
|
||||
@@ -500,7 +500,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
|
||||
BasicBlock *ContBlock = EntryBB->splitBasicBlock(EntryBB->getTerminator(),
|
||||
"setjmp.cont");
|
||||
|
||||
Idx[1] = ConstantUInt::get(Type::UIntTy, 0);
|
||||
Idx[1] = ConstantInt::get(Type::UIntTy, 0);
|
||||
Value *JmpBufPtr = new GetElementPtrInst(JmpBuf, Idx, "TheJmpBuf",
|
||||
EntryBB->getTerminator());
|
||||
Value *SJRet = new CallInst(SetJmpFn, JmpBufPtr, "sjret",
|
||||
@@ -550,7 +550,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
|
||||
// Get a pointer to the jmpbuf and longjmp.
|
||||
std::vector<Value*> Idx;
|
||||
Idx.push_back(Constant::getNullValue(Type::IntTy));
|
||||
Idx.push_back(ConstantUInt::get(Type::UIntTy, 0));
|
||||
Idx.push_back(ConstantInt::get(Type::UIntTy, 0));
|
||||
Idx[0] = new GetElementPtrInst(BufPtr, Idx, "JmpBuf", UnwindBlock);
|
||||
Idx[1] = ConstantInt::get(Type::IntTy, 1);
|
||||
new CallInst(LongJmpFn, Idx, "", UnwindBlock);
|
||||
|
@@ -60,11 +60,12 @@ namespace {
|
||||
struct CaseCmp {
|
||||
bool operator () (const LowerSwitch::Case& C1,
|
||||
const LowerSwitch::Case& C2) {
|
||||
if (const ConstantUInt* U1 = dyn_cast<const ConstantUInt>(C1.first))
|
||||
return U1->getValue() < cast<const ConstantUInt>(C2.first)->getValue();
|
||||
|
||||
const ConstantSInt* S1 = dyn_cast<const ConstantSInt>(C1.first);
|
||||
return S1->getValue() < cast<const ConstantSInt>(C2.first)->getValue();
|
||||
const ConstantInt* CI1 = cast<const ConstantInt>(C1.first);
|
||||
const ConstantInt* CI2 = cast<const ConstantInt>(C2.first);
|
||||
if (CI1->getType()->isUnsigned())
|
||||
return CI1->getZExtValue() < CI2->getZExtValue();
|
||||
return CI1->getSExtValue() < CI2->getSExtValue();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -129,7 +130,7 @@ BasicBlock* LowerSwitch::switchConvert(CaseItr Begin, CaseItr End,
|
||||
|
||||
Case& Pivot = *(Begin + Mid);
|
||||
DEBUG(std::cerr << "Pivot ==> "
|
||||
<< (int64_t)cast<ConstantInt>(Pivot.first)->getRawValue()
|
||||
<< cast<ConstantInt>(Pivot.first)->getSExtValue()
|
||||
<< "\n");
|
||||
|
||||
BasicBlock* LBranch = switchConvert(LHS.begin(), LHS.end(), Val,
|
||||
|
@@ -1160,7 +1160,7 @@ namespace {
|
||||
/// applications that sort ConstantInt's to ensure uniqueness.
|
||||
struct ConstantIntOrdering {
|
||||
bool operator()(const ConstantInt *LHS, const ConstantInt *RHS) const {
|
||||
return LHS->getRawValue() < RHS->getRawValue();
|
||||
return LHS->getZExtValue() < RHS->getZExtValue();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user