For PR950:

Three changes:
1. Convert signed integer types to signless versions.
2. Implement the @sext and @zext parameter attributes. Previously the
   type of an function parameter was used to determine whether it should
   be sign extended or zero extended before the call. This information is
   now communicated via the function type's parameter attributes.
3. The interface to LowerCallTo had to be changed in order to accommodate
   the parameter attribute information. Although it would have been
   convenient to pass in the FunctionType itself, there isn't always one
   present in the caller. Consequently, a signedness indication for the
   result type and for each parameter was provided for in the interface
   to this method. All implementations were changed to make the adjustment
   necessary.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32788 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Reid Spencer 2006-12-31 05:55:36 +00:00
parent e49661bdf5
commit 47857812e2
18 changed files with 288 additions and 343 deletions

View File

@ -607,7 +607,7 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
<< "\t" << TAI->getCommentString() << " float " << Val << "\n"; << "\t" << TAI->getCommentString() << " float " << Val << "\n";
return; return;
} }
} else if (CV->getType() == Type::ULongTy || CV->getType() == Type::LongTy) { } else if (CV->getType() == Type::Int64Ty) {
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) { if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
uint64_t Val = CI->getZExtValue(); uint64_t Val = CI->getZExtValue();
@ -918,10 +918,10 @@ void AsmPrinter::printDataDirective(const Type *type) {
const TargetData *TD = TM.getTargetData(); const TargetData *TD = TM.getTargetData();
switch (type->getTypeID()) { switch (type->getTypeID()) {
case Type::BoolTyID: case Type::BoolTyID:
case Type::UByteTyID: case Type::SByteTyID: case Type::Int8TyID:
O << TAI->getData8bitsDirective(); O << TAI->getData8bitsDirective();
break; break;
case Type::UShortTyID: case Type::ShortTyID: case Type::Int16TyID:
O << TAI->getData16bitsDirective(); O << TAI->getData16bitsDirective();
break; break;
case Type::PointerTyID: case Type::PointerTyID:
@ -932,10 +932,10 @@ void AsmPrinter::printDataDirective(const Type *type) {
break; break;
} }
//Fall through for pointer size == int size //Fall through for pointer size == int size
case Type::UIntTyID: case Type::IntTyID: case Type::Int32TyID:
O << TAI->getData32bitsDirective(); O << TAI->getData32bitsDirective();
break; break;
case Type::ULongTyID: case Type::LongTyID: case Type::Int64TyID:
assert(TAI->getData64bitsDirective() && assert(TAI->getData64bitsDirective() &&
"Target cannot handle 64-bit constant exprs!"); "Target cannot handle 64-bit constant exprs!");
O << TAI->getData64bitsDirective(); O << TAI->getData64bitsDirective();

View File

@ -95,7 +95,7 @@ void IntrinsicLowering::AddPrototypes(Module &M) {
default: break; default: break;
case Intrinsic::setjmp: case Intrinsic::setjmp:
EnsureFunctionExists(M, "setjmp", I->arg_begin(), I->arg_end(), EnsureFunctionExists(M, "setjmp", I->arg_begin(), I->arg_end(),
Type::IntTy); Type::Int32Ty);
break; break;
case Intrinsic::longjmp: case Intrinsic::longjmp:
EnsureFunctionExists(M, "longjmp", I->arg_begin(), I->arg_end(), EnsureFunctionExists(M, "longjmp", I->arg_begin(), I->arg_end(),
@ -117,9 +117,9 @@ void IntrinsicLowering::AddPrototypes(Module &M) {
break; break;
case Intrinsic::memset_i32: case Intrinsic::memset_i32:
case Intrinsic::memset_i64: case Intrinsic::memset_i64:
M.getOrInsertFunction("memset", PointerType::get(Type::SByteTy), M.getOrInsertFunction("memset", PointerType::get(Type::Int8Ty),
PointerType::get(Type::SByteTy), PointerType::get(Type::Int8Ty),
Type::IntTy, (--(--I->arg_end()))->getType(), Type::Int32Ty, (--(--I->arg_end()))->getType(),
(Type *)0); (Type *)0);
break; break;
case Intrinsic::isunordered_f32: case Intrinsic::isunordered_f32:
@ -150,26 +150,26 @@ static Value *LowerBSWAP(Value *V, Instruction *IP) {
default: assert(0 && "Unhandled type size of value to byteswap!"); default: assert(0 && "Unhandled type size of value to byteswap!");
case 16: { case 16: {
Value *Tmp1 = new ShiftInst(Instruction::Shl, V, Value *Tmp1 = new ShiftInst(Instruction::Shl, V,
ConstantInt::get(Type::UByteTy,8),"bswap.2",IP); ConstantInt::get(Type::Int8Ty,8),"bswap.2",IP);
Value *Tmp2 = new ShiftInst(Instruction::LShr, V, Value *Tmp2 = new ShiftInst(Instruction::LShr, V,
ConstantInt::get(Type::UByteTy,8),"bswap.1",IP); ConstantInt::get(Type::Int8Ty,8),"bswap.1",IP);
V = BinaryOperator::createOr(Tmp1, Tmp2, "bswap.i16", IP); V = BinaryOperator::createOr(Tmp1, Tmp2, "bswap.i16", IP);
break; break;
} }
case 32: { case 32: {
Value *Tmp4 = new ShiftInst(Instruction::Shl, V, Value *Tmp4 = new ShiftInst(Instruction::Shl, V,
ConstantInt::get(Type::UByteTy,24),"bswap.4", IP); ConstantInt::get(Type::Int8Ty,24),"bswap.4", IP);
Value *Tmp3 = new ShiftInst(Instruction::Shl, V, Value *Tmp3 = new ShiftInst(Instruction::Shl, V,
ConstantInt::get(Type::UByteTy,8),"bswap.3",IP); ConstantInt::get(Type::Int8Ty,8),"bswap.3",IP);
Value *Tmp2 = new ShiftInst(Instruction::LShr, V, Value *Tmp2 = new ShiftInst(Instruction::LShr, V,
ConstantInt::get(Type::UByteTy,8),"bswap.2",IP); ConstantInt::get(Type::Int8Ty,8),"bswap.2",IP);
Value *Tmp1 = new ShiftInst(Instruction::LShr, V, Value *Tmp1 = new ShiftInst(Instruction::LShr, V,
ConstantInt::get(Type::UByteTy,24),"bswap.1", IP); ConstantInt::get(Type::Int8Ty,24),"bswap.1", IP);
Tmp3 = BinaryOperator::createAnd(Tmp3, Tmp3 = BinaryOperator::createAnd(Tmp3,
ConstantInt::get(Type::UIntTy, 0xFF0000), ConstantInt::get(Type::Int32Ty, 0xFF0000),
"bswap.and3", IP); "bswap.and3", IP);
Tmp2 = BinaryOperator::createAnd(Tmp2, Tmp2 = BinaryOperator::createAnd(Tmp2,
ConstantInt::get(Type::UIntTy, 0xFF00), ConstantInt::get(Type::Int32Ty, 0xFF00),
"bswap.and2", IP); "bswap.and2", IP);
Tmp4 = BinaryOperator::createOr(Tmp4, Tmp3, "bswap.or1", IP); Tmp4 = BinaryOperator::createOr(Tmp4, Tmp3, "bswap.or1", IP);
Tmp2 = BinaryOperator::createOr(Tmp2, Tmp1, "bswap.or2", IP); Tmp2 = BinaryOperator::createOr(Tmp2, Tmp1, "bswap.or2", IP);
@ -178,39 +178,39 @@ static Value *LowerBSWAP(Value *V, Instruction *IP) {
} }
case 64: { case 64: {
Value *Tmp8 = new ShiftInst(Instruction::Shl, V, Value *Tmp8 = new ShiftInst(Instruction::Shl, V,
ConstantInt::get(Type::UByteTy,56),"bswap.8", IP); ConstantInt::get(Type::Int8Ty,56),"bswap.8", IP);
Value *Tmp7 = new ShiftInst(Instruction::Shl, V, Value *Tmp7 = new ShiftInst(Instruction::Shl, V,
ConstantInt::get(Type::UByteTy,40),"bswap.7", IP); ConstantInt::get(Type::Int8Ty,40),"bswap.7", IP);
Value *Tmp6 = new ShiftInst(Instruction::Shl, V, Value *Tmp6 = new ShiftInst(Instruction::Shl, V,
ConstantInt::get(Type::UByteTy,24),"bswap.6", IP); ConstantInt::get(Type::Int8Ty,24),"bswap.6", IP);
Value *Tmp5 = new ShiftInst(Instruction::Shl, V, Value *Tmp5 = new ShiftInst(Instruction::Shl, V,
ConstantInt::get(Type::UByteTy,8),"bswap.5", IP); ConstantInt::get(Type::Int8Ty,8),"bswap.5", IP);
Value* Tmp4 = new ShiftInst(Instruction::LShr, V, Value* Tmp4 = new ShiftInst(Instruction::LShr, V,
ConstantInt::get(Type::UByteTy,8),"bswap.4", IP); ConstantInt::get(Type::Int8Ty,8),"bswap.4", IP);
Value* Tmp3 = new ShiftInst(Instruction::LShr, V, Value* Tmp3 = new ShiftInst(Instruction::LShr, V,
ConstantInt::get(Type::UByteTy,24),"bswap.3", IP); ConstantInt::get(Type::Int8Ty,24),"bswap.3", IP);
Value* Tmp2 = new ShiftInst(Instruction::LShr, V, Value* Tmp2 = new ShiftInst(Instruction::LShr, V,
ConstantInt::get(Type::UByteTy,40),"bswap.2", IP); ConstantInt::get(Type::Int8Ty,40),"bswap.2", IP);
Value* Tmp1 = new ShiftInst(Instruction::LShr, V, Value* Tmp1 = new ShiftInst(Instruction::LShr, V,
ConstantInt::get(Type::UByteTy,56),"bswap.1", IP); ConstantInt::get(Type::Int8Ty,56),"bswap.1", IP);
Tmp7 = BinaryOperator::createAnd(Tmp7, Tmp7 = BinaryOperator::createAnd(Tmp7,
ConstantInt::get(Type::ULongTy, ConstantInt::get(Type::Int64Ty,
0xFF000000000000ULL), 0xFF000000000000ULL),
"bswap.and7", IP); "bswap.and7", IP);
Tmp6 = BinaryOperator::createAnd(Tmp6, Tmp6 = BinaryOperator::createAnd(Tmp6,
ConstantInt::get(Type::ULongTy, 0xFF0000000000ULL), ConstantInt::get(Type::Int64Ty, 0xFF0000000000ULL),
"bswap.and6", IP); "bswap.and6", IP);
Tmp5 = BinaryOperator::createAnd(Tmp5, Tmp5 = BinaryOperator::createAnd(Tmp5,
ConstantInt::get(Type::ULongTy, 0xFF00000000ULL), ConstantInt::get(Type::Int64Ty, 0xFF00000000ULL),
"bswap.and5", IP); "bswap.and5", IP);
Tmp4 = BinaryOperator::createAnd(Tmp4, Tmp4 = BinaryOperator::createAnd(Tmp4,
ConstantInt::get(Type::ULongTy, 0xFF000000ULL), ConstantInt::get(Type::Int64Ty, 0xFF000000ULL),
"bswap.and4", IP); "bswap.and4", IP);
Tmp3 = BinaryOperator::createAnd(Tmp3, Tmp3 = BinaryOperator::createAnd(Tmp3,
ConstantInt::get(Type::ULongTy, 0xFF0000ULL), ConstantInt::get(Type::Int64Ty, 0xFF0000ULL),
"bswap.and3", IP); "bswap.and3", IP);
Tmp2 = BinaryOperator::createAnd(Tmp2, Tmp2 = BinaryOperator::createAnd(Tmp2,
ConstantInt::get(Type::ULongTy, 0xFF00ULL), ConstantInt::get(Type::Int64Ty, 0xFF00ULL),
"bswap.and2", IP); "bswap.and2", IP);
Tmp8 = BinaryOperator::createOr(Tmp8, Tmp7, "bswap.or1", IP); Tmp8 = BinaryOperator::createOr(Tmp8, Tmp7, "bswap.or1", IP);
Tmp6 = BinaryOperator::createOr(Tmp6, Tmp5, "bswap.or2", IP); Tmp6 = BinaryOperator::createOr(Tmp6, Tmp5, "bswap.or2", IP);
@ -242,7 +242,7 @@ static Value *LowerCTPOP(Value *V, Instruction *IP) {
Value *MaskCst = ConstantInt::get(V->getType(), MaskValues[ct]); Value *MaskCst = ConstantInt::get(V->getType(), MaskValues[ct]);
Value *LHS = BinaryOperator::createAnd(V, MaskCst, "cppop.and1", IP); Value *LHS = BinaryOperator::createAnd(V, MaskCst, "cppop.and1", IP);
Value *VShift = new ShiftInst(Instruction::LShr, V, Value *VShift = new ShiftInst(Instruction::LShr, V,
ConstantInt::get(Type::UByteTy, i), "ctpop.sh", IP); ConstantInt::get(Type::Int8Ty, i), "ctpop.sh", IP);
Value *RHS = BinaryOperator::createAnd(VShift, MaskCst, "cppop.and2", IP); Value *RHS = BinaryOperator::createAnd(VShift, MaskCst, "cppop.and2", IP);
V = BinaryOperator::createAdd(LHS, RHS, "ctpop.step", IP); V = BinaryOperator::createAdd(LHS, RHS, "ctpop.step", IP);
} }
@ -256,7 +256,7 @@ static Value *LowerCTLZ(Value *V, Instruction *IP) {
unsigned BitSize = V->getType()->getPrimitiveSizeInBits(); unsigned BitSize = V->getType()->getPrimitiveSizeInBits();
for (unsigned i = 1; i != BitSize; i <<= 1) { for (unsigned i = 1; i != BitSize; i <<= 1) {
Value *ShVal = ConstantInt::get(Type::UByteTy, i); Value *ShVal = ConstantInt::get(Type::Int8Ty, i);
ShVal = new ShiftInst(Instruction::LShr, V, ShVal, "ctlz.sh", IP); ShVal = new ShiftInst(Instruction::LShr, V, ShVal, "ctlz.sh", IP);
V = BinaryOperator::createOr(V, ShVal, "ctlz.step", IP); V = BinaryOperator::createOr(V, ShVal, "ctlz.step", IP);
} }
@ -289,7 +289,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
static Function *SetjmpFCache = 0; static Function *SetjmpFCache = 0;
static const unsigned castOpcodes[] = { Instruction::BitCast }; static const unsigned castOpcodes[] = { Instruction::BitCast };
Value *V = ReplaceCallWith("setjmp", CI, CI->op_begin()+1, CI->op_end(), Value *V = ReplaceCallWith("setjmp", CI, CI->op_begin()+1, CI->op_end(),
castOpcodes, Type::IntTy, SetjmpFCache); castOpcodes, Type::Int32Ty, SetjmpFCache);
if (CI->getType() != Type::VoidTy) if (CI->getType() != Type::VoidTy)
CI->replaceAllUsesWith(V); CI->replaceAllUsesWith(V);
break; break;
@ -381,7 +381,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
case Intrinsic::readcyclecounter: { case Intrinsic::readcyclecounter: {
cerr << "WARNING: this target does not support the llvm.readcyclecoun" cerr << "WARNING: this target does not support the llvm.readcyclecoun"
<< "ter intrinsic. It is being lowered to a constant 0\n"; << "ter intrinsic. It is being lowered to a constant 0\n";
CI->replaceAllUsesWith(ConstantInt::get(Type::ULongTy, 0)); CI->replaceAllUsesWith(ConstantInt::get(Type::Int64Ty, 0));
break; break;
} }

View File

@ -730,20 +730,17 @@ void MachOWriter::InitMem(const Constant *C, void *Addr, intptr_t Offset,
switch (PC->getType()->getTypeID()) { switch (PC->getType()->getTypeID()) {
case Type::BoolTyID: case Type::BoolTyID:
case Type::UByteTyID: case Type::Int8TyID:
case Type::SByteTyID:
ptr[0] = cast<ConstantInt>(PC)->getZExtValue(); ptr[0] = cast<ConstantInt>(PC)->getZExtValue();
break; break;
case Type::UShortTyID: case Type::Int16TyID:
case Type::ShortTyID:
val = cast<ConstantInt>(PC)->getZExtValue(); val = cast<ConstantInt>(PC)->getZExtValue();
if (TD->isBigEndian()) if (TD->isBigEndian())
val = ByteSwap_16(val); val = ByteSwap_16(val);
ptr[0] = val; ptr[0] = val;
ptr[1] = val >> 8; ptr[1] = val >> 8;
break; break;
case Type::UIntTyID: case Type::Int32TyID:
case Type::IntTyID:
case Type::FloatTyID: case Type::FloatTyID:
if (PC->getType()->getTypeID() == Type::FloatTyID) { if (PC->getType()->getTypeID() == Type::FloatTyID) {
val = FloatToBits(cast<ConstantFP>(PC)->getValue()); val = FloatToBits(cast<ConstantFP>(PC)->getValue());
@ -758,8 +755,7 @@ void MachOWriter::InitMem(const Constant *C, void *Addr, intptr_t Offset,
ptr[3] = val >> 24; ptr[3] = val >> 24;
break; break;
case Type::DoubleTyID: case Type::DoubleTyID:
case Type::ULongTyID: case Type::Int64TyID:
case Type::LongTyID:
if (PC->getType()->getTypeID() == Type::DoubleTyID) { if (PC->getType()->getTypeID() == Type::DoubleTyID) {
val = DoubleToBits(cast<ConstantFP>(PC)->getValue()); val = DoubleToBits(cast<ConstantFP>(PC)->getValue());
} else { } else {

View File

@ -55,8 +55,8 @@ getGlobalVariablesUsing(Module &M, const std::string &RootName) {
std::vector<GlobalVariable*> Result; // GlobalVariables matching criteria. std::vector<GlobalVariable*> Result; // GlobalVariables matching criteria.
std::vector<const Type*> FieldTypes; std::vector<const Type*> FieldTypes;
FieldTypes.push_back(Type::UIntTy); FieldTypes.push_back(Type::Int32Ty);
FieldTypes.push_back(Type::UIntTy); FieldTypes.push_back(Type::Int32Ty);
// Get the GlobalVariable root. // Get the GlobalVariable root.
GlobalVariable *UseRoot = M.getGlobalVariable(RootName, GlobalVariable *UseRoot = M.getGlobalVariable(RootName,
@ -264,16 +264,16 @@ public:
/// Apply - Set the value of each of the fields. /// Apply - Set the value of each of the fields.
/// ///
virtual void Apply(int &Field) { virtual void Apply(int &Field) {
Elements.push_back(ConstantInt::get(Type::IntTy, int32_t(Field))); Elements.push_back(ConstantInt::get(Type::Int32Ty, int32_t(Field)));
} }
virtual void Apply(unsigned &Field) { virtual void Apply(unsigned &Field) {
Elements.push_back(ConstantInt::get(Type::UIntTy, uint32_t(Field))); Elements.push_back(ConstantInt::get(Type::Int32Ty, uint32_t(Field)));
} }
virtual void Apply(int64_t &Field) { virtual void Apply(int64_t &Field) {
Elements.push_back(ConstantInt::get(Type::LongTy, int64_t(Field))); Elements.push_back(ConstantInt::get(Type::Int64Ty, int64_t(Field)));
} }
virtual void Apply(uint64_t &Field) { virtual void Apply(uint64_t &Field) {
Elements.push_back(ConstantInt::get(Type::ULongTy, uint64_t(Field))); Elements.push_back(ConstantInt::get(Type::Int64Ty, uint64_t(Field)));
} }
virtual void Apply(bool &Field) { virtual void Apply(bool &Field) {
Elements.push_back(ConstantBool::get(Field)); Elements.push_back(ConstantBool::get(Field));
@ -351,16 +351,16 @@ public:
/// Apply - Set the value of each of the fields. /// Apply - Set the value of each of the fields.
/// ///
virtual void Apply(int &Field) { virtual void Apply(int &Field) {
Fields.push_back(Type::IntTy); Fields.push_back(Type::Int32Ty);
} }
virtual void Apply(unsigned &Field) { virtual void Apply(unsigned &Field) {
Fields.push_back(Type::UIntTy); Fields.push_back(Type::Int32Ty);
} }
virtual void Apply(int64_t &Field) { virtual void Apply(int64_t &Field) {
Fields.push_back(Type::LongTy); Fields.push_back(Type::Int64Ty);
} }
virtual void Apply(uint64_t &Field) { virtual void Apply(uint64_t &Field) {
Fields.push_back(Type::ULongTy); Fields.push_back(Type::Int64Ty);
} }
virtual void Apply(bool &Field) { virtual void Apply(bool &Field) {
Fields.push_back(Type::BoolTy); Fields.push_back(Type::BoolTy);
@ -1259,7 +1259,7 @@ const PointerType *DISerializer::getStrPtrType() {
// If not already defined. // If not already defined.
if (!StrPtrTy) { if (!StrPtrTy) {
// Construct the pointer to signed bytes. // Construct the pointer to signed bytes.
StrPtrTy = PointerType::get(Type::SByteTy); StrPtrTy = PointerType::get(Type::Int8Ty);
} }
return StrPtrTy; return StrPtrTy;

View File

@ -186,7 +186,7 @@ private:
SDOperand CreateStackTemporary(MVT::ValueType VT); SDOperand CreateStackTemporary(MVT::ValueType VT);
SDOperand ExpandLibCall(const char *Name, SDNode *Node, SDOperand ExpandLibCall(const char *Name, SDNode *Node, bool isSigned,
SDOperand &Hi); SDOperand &Hi);
SDOperand ExpandIntToFP(bool isSigned, MVT::ValueType DestTy, SDOperand ExpandIntToFP(bool isSigned, MVT::ValueType DestTy,
SDOperand Source); SDOperand Source);
@ -2122,33 +2122,42 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
// operation to an explicit libcall as appropriate. // operation to an explicit libcall as appropriate.
MVT::ValueType IntPtr = TLI.getPointerTy(); MVT::ValueType IntPtr = TLI.getPointerTy();
const Type *IntPtrTy = TLI.getTargetData()->getIntPtrType(); const Type *IntPtrTy = TLI.getTargetData()->getIntPtrType();
std::vector<std::pair<SDOperand, const Type*> > Args; TargetLowering::ArgListTy Args;
TargetLowering::ArgListEntry Entry;
const char *FnName = 0; const char *FnName = 0;
if (Node->getOpcode() == ISD::MEMSET) { if (Node->getOpcode() == ISD::MEMSET) {
Args.push_back(std::make_pair(Tmp2, IntPtrTy)); Entry.Node = Tmp2;
Entry.Ty = IntPtrTy;
Entry.isSigned = false;
Args.push_back(Entry);
// Extend the (previously legalized) ubyte argument to be an int value // Extend the (previously legalized) ubyte argument to be an int value
// for the call. // for the call.
if (Tmp3.getValueType() > MVT::i32) if (Tmp3.getValueType() > MVT::i32)
Tmp3 = DAG.getNode(ISD::TRUNCATE, MVT::i32, Tmp3); Tmp3 = DAG.getNode(ISD::TRUNCATE, MVT::i32, Tmp3);
else else
Tmp3 = DAG.getNode(ISD::ZERO_EXTEND, MVT::i32, Tmp3); Tmp3 = DAG.getNode(ISD::ZERO_EXTEND, MVT::i32, Tmp3);
Args.push_back(std::make_pair(Tmp3, Type::IntTy)); Entry.Node = Tmp3; Entry.Ty = Type::Int32Ty; Entry.isSigned = true;
Args.push_back(std::make_pair(Tmp4, IntPtrTy)); Args.push_back(Entry);
Entry.Node = Tmp4; Entry.Ty = IntPtrTy; Entry.isSigned = false;
Args.push_back(Entry);
FnName = "memset"; FnName = "memset";
} else if (Node->getOpcode() == ISD::MEMCPY || } else if (Node->getOpcode() == ISD::MEMCPY ||
Node->getOpcode() == ISD::MEMMOVE) { Node->getOpcode() == ISD::MEMMOVE) {
Args.push_back(std::make_pair(Tmp2, IntPtrTy)); Entry.Node = Tmp2; Entry.Ty = IntPtrTy; Entry.isSigned = false;
Args.push_back(std::make_pair(Tmp3, IntPtrTy)); Args.push_back(Entry);
Args.push_back(std::make_pair(Tmp4, IntPtrTy)); Entry.Node = Tmp3; Entry.Ty = IntPtrTy; Entry.isSigned = false;
Args.push_back(Entry);
Entry.Node = Tmp4; Entry.Ty = IntPtrTy; Entry.isSigned = false;
Args.push_back(Entry);
FnName = Node->getOpcode() == ISD::MEMMOVE ? "memmove" : "memcpy"; FnName = Node->getOpcode() == ISD::MEMMOVE ? "memmove" : "memcpy";
} else { } else {
assert(0 && "Unknown op!"); assert(0 && "Unknown op!");
} }
std::pair<SDOperand,SDOperand> CallResult = std::pair<SDOperand,SDOperand> CallResult =
TLI.LowerCallTo(Tmp1, Type::VoidTy, false, CallingConv::C, false, TLI.LowerCallTo(Tmp1, Type::VoidTy, false, false, CallingConv::C, false,
DAG.getExternalSymbol(FnName, IntPtr), Args, DAG); DAG.getExternalSymbol(FnName, IntPtr), Args, DAG);
Result = CallResult.second; Result = CallResult.second;
break; break;
@ -2243,7 +2252,8 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
const char *FnName = Node->getOpcode() == ISD::UDIV const char *FnName = Node->getOpcode() == ISD::UDIV
? "__udivsi3" : "__divsi3"; ? "__udivsi3" : "__divsi3";
SDOperand Dummy; SDOperand Dummy;
Result = ExpandLibCall(FnName, Node, Dummy); bool isSigned = Node->getOpcode() == ISD::SDIV;
Result = ExpandLibCall(FnName, Node, isSigned, Dummy);
}; };
break; break;
} }
@ -2346,7 +2356,7 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
DAG.getNode(ISD::FP_EXTEND, MVT::f64, Tmp2)); DAG.getNode(ISD::FP_EXTEND, MVT::f64, Tmp2));
} }
SDOperand Dummy; SDOperand Dummy;
Result = ExpandLibCall(FnName, Node, Dummy); Result = ExpandLibCall(FnName, Node, false, Dummy);
break; break;
} }
break; break;
@ -2419,6 +2429,7 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
break; break;
case TargetLowering::Expand: case TargetLowering::Expand:
unsigned DivOpc= (Node->getOpcode() == ISD::UREM) ? ISD::UDIV : ISD::SDIV; unsigned DivOpc= (Node->getOpcode() == ISD::UREM) ? ISD::UDIV : ISD::SDIV;
bool isSigned = DivOpc == ISD::SDIV;
if (MVT::isInteger(Node->getValueType(0))) { if (MVT::isInteger(Node->getValueType(0))) {
if (TLI.getOperationAction(DivOpc, Node->getValueType(0)) == if (TLI.getOperationAction(DivOpc, Node->getValueType(0)) ==
TargetLowering::Legal) { TargetLowering::Legal) {
@ -2433,13 +2444,13 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
const char *FnName = Node->getOpcode() == ISD::UREM const char *FnName = Node->getOpcode() == ISD::UREM
? "__umodsi3" : "__modsi3"; ? "__umodsi3" : "__modsi3";
SDOperand Dummy; SDOperand Dummy;
Result = ExpandLibCall(FnName, Node, Dummy); Result = ExpandLibCall(FnName, Node, isSigned, Dummy);
} }
} else { } else {
// Floating point mod -> fmod libcall. // Floating point mod -> fmod libcall.
const char *FnName = Node->getValueType(0) == MVT::f32 ? "fmodf":"fmod"; const char *FnName = Node->getValueType(0) == MVT::f32 ? "fmodf":"fmod";
SDOperand Dummy; SDOperand Dummy;
Result = ExpandLibCall(FnName, Node, Dummy); Result = ExpandLibCall(FnName, Node, false, Dummy);
} }
break; break;
} }
@ -2688,7 +2699,7 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
default: assert(0 && "Unreachable!"); default: assert(0 && "Unreachable!");
} }
SDOperand Dummy; SDOperand Dummy;
Result = ExpandLibCall(FnName, Node, Dummy); Result = ExpandLibCall(FnName, Node, false, Dummy);
break; break;
} }
} }
@ -2700,7 +2711,7 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
const char *FnName = Node->getValueType(0) == MVT::f32 const char *FnName = Node->getValueType(0) == MVT::f32
? "__powisf2" : "__powidf2"; ? "__powisf2" : "__powidf2";
SDOperand Dummy; SDOperand Dummy;
Result = ExpandLibCall(FnName, Node, Dummy); Result = ExpandLibCall(FnName, Node, false, Dummy);
break; break;
} }
case ISD::BIT_CONVERT: case ISD::BIT_CONVERT:
@ -2886,7 +2897,7 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
default: assert(0 && "Unreachable!"); default: assert(0 && "Unreachable!");
} }
SDOperand Dummy; SDOperand Dummy;
Result = ExpandLibCall(FnName, Node, Dummy); Result = ExpandLibCall(FnName, Node, false, Dummy);
break; break;
} }
case Promote: case Promote:
@ -3609,13 +3620,15 @@ void SelectionDAGLegalize::LegalizeSetCCOperands(SDOperand &LHS,
SDOperand Dummy; SDOperand Dummy;
Tmp1 = ExpandLibCall(FnName1, Tmp1 = ExpandLibCall(FnName1,
DAG.getNode(ISD::MERGE_VALUES, VT, LHS, RHS).Val, Dummy); DAG.getNode(ISD::MERGE_VALUES, VT, LHS, RHS).Val,
false, Dummy);
Tmp2 = DAG.getConstant(0, MVT::i32); Tmp2 = DAG.getConstant(0, MVT::i32);
CC = DAG.getCondCode(CC1); CC = DAG.getCondCode(CC1);
if (FnName2) { if (FnName2) {
Tmp1 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultTy(), Tmp1, Tmp2, CC); Tmp1 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultTy(), Tmp1, Tmp2, CC);
LHS = ExpandLibCall(FnName2, LHS = ExpandLibCall(FnName2,
DAG.getNode(ISD::MERGE_VALUES, VT, LHS, RHS).Val, Dummy); DAG.getNode(ISD::MERGE_VALUES, VT, LHS, RHS).Val,
false, Dummy);
Tmp2 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultTy(), LHS, Tmp2, Tmp2 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultTy(), LHS, Tmp2,
DAG.getCondCode(CC2)); DAG.getCondCode(CC2));
Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp2); Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp2);
@ -4051,7 +4064,7 @@ bool SelectionDAGLegalize::ExpandShift(unsigned Opc, SDOperand Op,SDOperand Amt,
// by-reg argument. If it does fit into a single register, return the result // by-reg argument. If it does fit into a single register, return the result
// and leave the Hi part unset. // and leave the Hi part unset.
SDOperand SelectionDAGLegalize::ExpandLibCall(const char *Name, SDNode *Node, SDOperand SelectionDAGLegalize::ExpandLibCall(const char *Name, SDNode *Node,
SDOperand &Hi) { bool isSigned, SDOperand &Hi) {
assert(!IsLegalizingCall && "Cannot overlap legalization of calls!"); assert(!IsLegalizingCall && "Cannot overlap legalization of calls!");
// The input chain to this libcall is the entry node of the function. // The input chain to this libcall is the entry node of the function.
// Legalizing the call will automatically add the previous call to the // Legalizing the call will automatically add the previous call to the
@ -4059,17 +4072,20 @@ SDOperand SelectionDAGLegalize::ExpandLibCall(const char *Name, SDNode *Node,
SDOperand InChain = DAG.getEntryNode(); SDOperand InChain = DAG.getEntryNode();
TargetLowering::ArgListTy Args; TargetLowering::ArgListTy Args;
TargetLowering::ArgListEntry Entry;
for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) {
MVT::ValueType ArgVT = Node->getOperand(i).getValueType(); MVT::ValueType ArgVT = Node->getOperand(i).getValueType();
const Type *ArgTy = MVT::getTypeForValueType(ArgVT); const Type *ArgTy = MVT::getTypeForValueType(ArgVT);
Args.push_back(std::make_pair(Node->getOperand(i), ArgTy)); Entry.Node = Node->getOperand(i); Entry.Ty = ArgTy;
Entry.isSigned = isSigned;
Args.push_back(Entry);
} }
SDOperand Callee = DAG.getExternalSymbol(Name, TLI.getPointerTy()); SDOperand Callee = DAG.getExternalSymbol(Name, TLI.getPointerTy());
// Splice the libcall in wherever FindInputOutputChains tells us to. // Splice the libcall in wherever FindInputOutputChains tells us to.
const Type *RetTy = MVT::getTypeForValueType(Node->getValueType(0)); const Type *RetTy = MVT::getTypeForValueType(Node->getValueType(0));
std::pair<SDOperand,SDOperand> CallInfo = std::pair<SDOperand,SDOperand> CallInfo =
TLI.LowerCallTo(InChain, RetTy, false, CallingConv::C, false, TLI.LowerCallTo(InChain, RetTy, isSigned, false, CallingConv::C, false,
Callee, Args, DAG); Callee, Args, DAG);
// Legalize the call sequence, starting with the chain. This will advance // Legalize the call sequence, starting with the chain. This will advance
@ -4121,7 +4137,7 @@ ExpandIntToFP(bool isSigned, MVT::ValueType DestTy, SDOperand Source) {
SignSet, Four, Zero); SignSet, Four, Zero);
uint64_t FF = 0x5f800000ULL; uint64_t FF = 0x5f800000ULL;
if (TLI.isLittleEndian()) FF <<= 32; if (TLI.isLittleEndian()) FF <<= 32;
static Constant *FudgeFactor = ConstantInt::get(Type::ULongTy, FF); static Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF);
SDOperand CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy()); SDOperand CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy());
CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset); CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset);
@ -4167,7 +4183,7 @@ ExpandIntToFP(bool isSigned, MVT::ValueType DestTy, SDOperand Source) {
Source = DAG.getNode(ISD::SINT_TO_FP, DestTy, Source); Source = DAG.getNode(ISD::SINT_TO_FP, DestTy, Source);
SDOperand UnusedHiPart; SDOperand UnusedHiPart;
return ExpandLibCall(FnName, Source.Val, UnusedHiPart); return ExpandLibCall(FnName, Source.Val, isSigned, UnusedHiPart);
} }
/// ExpandLegalINT_TO_FP - This function is responsible for legalizing a /// ExpandLegalINT_TO_FP - This function is responsible for legalizing a
@ -4252,7 +4268,7 @@ SDOperand SelectionDAGLegalize::ExpandLegalINT_TO_FP(bool isSigned,
case MVT::i64: FF = 0x5F800000ULL; break; // 2^64 (as a float) case MVT::i64: FF = 0x5F800000ULL; break; // 2^64 (as a float)
} }
if (TLI.isLittleEndian()) FF <<= 32; if (TLI.isLittleEndian()) FF <<= 32;
static Constant *FudgeFactor = ConstantInt::get(Type::ULongTy, FF); static Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF);
SDOperand CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy()); SDOperand CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy());
CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset); CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset);
@ -4820,9 +4836,9 @@ void SelectionDAGLegalize::ExpandOp(SDOperand Op, SDOperand &Lo, SDOperand &Hi){
} }
if (Node->getOperand(0).getValueType() == MVT::f32) if (Node->getOperand(0).getValueType() == MVT::f32)
Lo = ExpandLibCall("__fixsfdi", Node, Hi); Lo = ExpandLibCall("__fixsfdi", Node, false, Hi);
else else
Lo = ExpandLibCall("__fixdfdi", Node, Hi); Lo = ExpandLibCall("__fixdfdi", Node, false, Hi);
break; break;
case ISD::FP_TO_UINT: case ISD::FP_TO_UINT:
@ -4844,9 +4860,9 @@ void SelectionDAGLegalize::ExpandOp(SDOperand Op, SDOperand &Lo, SDOperand &Hi){
} }
if (Node->getOperand(0).getValueType() == MVT::f32) if (Node->getOperand(0).getValueType() == MVT::f32)
Lo = ExpandLibCall("__fixunssfdi", Node, Hi); Lo = ExpandLibCall("__fixunssfdi", Node, false, Hi);
else else
Lo = ExpandLibCall("__fixunsdfdi", Node, Hi); Lo = ExpandLibCall("__fixunsdfdi", Node, false, Hi);
break; break;
case ISD::SHL: { case ISD::SHL: {
@ -4895,7 +4911,7 @@ void SelectionDAGLegalize::ExpandOp(SDOperand Op, SDOperand &Lo, SDOperand &Hi){
} }
// Otherwise, emit a libcall. // Otherwise, emit a libcall.
Lo = ExpandLibCall("__ashldi3", Node, Hi); Lo = ExpandLibCall("__ashldi3", Node, false, Hi);
break; break;
} }
@ -4927,7 +4943,7 @@ void SelectionDAGLegalize::ExpandOp(SDOperand Op, SDOperand &Lo, SDOperand &Hi){
} }
// Otherwise, emit a libcall. // Otherwise, emit a libcall.
Lo = ExpandLibCall("__ashrdi3", Node, Hi); Lo = ExpandLibCall("__ashrdi3", Node, true, Hi);
break; break;
} }
@ -4959,7 +4975,7 @@ void SelectionDAGLegalize::ExpandOp(SDOperand Op, SDOperand &Lo, SDOperand &Hi){
} }
// Otherwise, emit a libcall. // Otherwise, emit a libcall.
Lo = ExpandLibCall("__lshrdi3", Node, Hi); Lo = ExpandLibCall("__lshrdi3", Node, false, Hi);
break; break;
} }
@ -5046,31 +5062,35 @@ void SelectionDAGLegalize::ExpandOp(SDOperand Op, SDOperand &Lo, SDOperand &Hi){
} }
} }
Lo = ExpandLibCall("__muldi3" , Node, Hi); Lo = ExpandLibCall("__muldi3" , Node, false, Hi);
break; break;
} }
case ISD::SDIV: Lo = ExpandLibCall("__divdi3" , Node, Hi); break; case ISD::SDIV: Lo = ExpandLibCall("__divdi3" , Node, true, Hi); break;
case ISD::UDIV: Lo = ExpandLibCall("__udivdi3", Node, Hi); break; case ISD::UDIV: Lo = ExpandLibCall("__udivdi3", Node, false, Hi); break;
case ISD::SREM: Lo = ExpandLibCall("__moddi3" , Node, Hi); break; case ISD::SREM: Lo = ExpandLibCall("__moddi3" , Node, true, Hi); break;
case ISD::UREM: Lo = ExpandLibCall("__umoddi3", Node, Hi); break; case ISD::UREM: Lo = ExpandLibCall("__umoddi3", Node, false, Hi); break;
case ISD::FADD: case ISD::FADD:
Lo = ExpandLibCall(((VT == MVT::f32) ? "__addsf3" : "__adddf3"), Node, Hi); Lo = ExpandLibCall(((VT == MVT::f32) ? "__addsf3" : "__adddf3"), Node,
false, Hi);
break; break;
case ISD::FSUB: case ISD::FSUB:
Lo = ExpandLibCall(((VT == MVT::f32) ? "__subsf3" : "__subdf3"), Node, Hi); Lo = ExpandLibCall(((VT == MVT::f32) ? "__subsf3" : "__subdf3"), Node,
false, Hi);
break; break;
case ISD::FMUL: case ISD::FMUL:
Lo = ExpandLibCall(((VT == MVT::f32) ? "__mulsf3" : "__muldf3"), Node, Hi); Lo = ExpandLibCall(((VT == MVT::f32) ? "__mulsf3" : "__muldf3"), Node,
false, Hi);
break; break;
case ISD::FDIV: case ISD::FDIV:
Lo = ExpandLibCall(((VT == MVT::f32) ? "__divsf3" : "__divdf3"), Node, Hi); Lo = ExpandLibCall(((VT == MVT::f32) ? "__divsf3" : "__divdf3"), Node,
false, Hi);
break; break;
case ISD::FP_EXTEND: case ISD::FP_EXTEND:
Lo = ExpandLibCall("__extendsfdf2", Node, Hi); Lo = ExpandLibCall("__extendsfdf2", Node, false, Hi);
break; break;
case ISD::FP_ROUND: case ISD::FP_ROUND:
Lo = ExpandLibCall("__truncdfsf2", Node, Hi); Lo = ExpandLibCall("__truncdfsf2", Node, false, Hi);
break; break;
case ISD::FSQRT: case ISD::FSQRT:
case ISD::FSIN: case ISD::FSIN:
@ -5082,7 +5102,7 @@ void SelectionDAGLegalize::ExpandOp(SDOperand Op, SDOperand &Lo, SDOperand &Hi){
case ISD::FCOS: FnName = (VT == MVT::f32) ? "cosf" : "cos"; break; case ISD::FCOS: FnName = (VT == MVT::f32) ? "cosf" : "cos"; break;
default: assert(0 && "Unreachable!"); default: assert(0 && "Unreachable!");
} }
Lo = ExpandLibCall(FnName, Node, Hi); Lo = ExpandLibCall(FnName, Node, false, Hi);
break; break;
} }
case ISD::FABS: { case ISD::FABS: {
@ -5133,7 +5153,7 @@ void SelectionDAGLegalize::ExpandOp(SDOperand Op, SDOperand &Lo, SDOperand &Hi){
: DAG.getZeroExtendInReg(Tmp, SrcVT); : DAG.getZeroExtendInReg(Tmp, SrcVT);
Node = DAG.UpdateNodeOperands(Op, Tmp).Val; Node = DAG.UpdateNodeOperands(Op, Tmp).Val;
} }
Lo = ExpandLibCall(FnName, Node, Hi); Lo = ExpandLibCall(FnName, Node, isSigned, Hi);
break; break;
} }
} }

View File

@ -396,13 +396,9 @@ class SelectionDAGLowering {
/// The comparison function for sorting Case values. /// The comparison function for sorting Case values.
struct CaseCmp { struct CaseCmp {
bool operator () (const Case& C1, const Case& C2) { bool operator () (const Case& C1, const Case& C2) {
if (const ConstantInt* I1 = dyn_cast<const ConstantInt>(C1.first)) assert(isa<ConstantInt>(C1.first) && isa<ConstantInt>(C2.first));
if (I1->getType()->isUnsigned()) return cast<const ConstantInt>(C1.first)->getZExtValue() <
return I1->getZExtValue() < cast<const ConstantInt>(C2.first)->getZExtValue();
cast<const ConstantInt>(C2.first)->getZExtValue();
return cast<const ConstantInt>(C1.first)->getSExtValue() <
cast<const ConstantInt>(C2.first)->getSExtValue();
} }
}; };
@ -756,7 +752,6 @@ void SelectionDAGLowering::visitRet(ReturnInst &I) {
NewValues.push_back(getRoot()); NewValues.push_back(getRoot());
for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i) { for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i) {
SDOperand RetOp = getValue(I.getOperand(i)); SDOperand RetOp = getValue(I.getOperand(i));
bool isSigned = I.getOperand(i)->getType()->isSigned();
// If this is an integer return value, we need to promote it ourselves to // If this is an integer return value, we need to promote it ourselves to
// the full width of a register, since LegalizeOp will use ANY_EXTEND rather // the full width of a register, since LegalizeOp will use ANY_EXTEND rather
@ -770,14 +765,14 @@ void SelectionDAGLowering::visitRet(ReturnInst &I) {
TmpVT = TLI.getTypeToTransformTo(MVT::i32); TmpVT = TLI.getTypeToTransformTo(MVT::i32);
else else
TmpVT = MVT::i32; TmpVT = MVT::i32;
const FunctionType *FTy = I.getParent()->getParent()->getFunctionType();
if (isSigned) ISD::NodeType ExtendKind = ISD::SIGN_EXTEND;
RetOp = DAG.getNode(ISD::SIGN_EXTEND, TmpVT, RetOp); if (FTy->paramHasAttr(0, FunctionType::ZExtAttribute))
else ExtendKind = ISD::ZERO_EXTEND;
RetOp = DAG.getNode(ISD::ZERO_EXTEND, TmpVT, RetOp); RetOp = DAG.getNode(ExtendKind, TmpVT, RetOp);
} }
NewValues.push_back(RetOp); NewValues.push_back(RetOp);
NewValues.push_back(DAG.getConstant(isSigned, MVT::i32)); NewValues.push_back(DAG.getConstant(false, MVT::i32));
} }
DAG.setRoot(DAG.getNode(ISD::RET, MVT::Other, DAG.setRoot(DAG.getNode(ISD::RET, MVT::Other,
&NewValues[0], NewValues.size())); &NewValues[0], NewValues.size()));
@ -1383,7 +1378,7 @@ void SelectionDAGLowering::visitSwitch(SwitchInst &I) {
// Create a CaseBlock record representing a conditional branch to // Create a CaseBlock record representing a conditional branch to
// the LHS node if the value being switched on SV is less than C. // the LHS node if the value being switched on SV is less than C.
// Otherwise, branch to LHS. // Otherwise, branch to LHS.
ISD::CondCode CC = C->getType()->isSigned() ? ISD::SETLT : ISD::SETULT; ISD::CondCode CC = ISD::SETULT;
SelectionDAGISel::CaseBlock CB(CC, SV, C, TrueBB, FalseBB, CR.CaseBB); SelectionDAGISel::CaseBlock CB(CC, SV, C, TrueBB, FalseBB, CR.CaseBB);
if (CR.CaseBB == CurMBB) if (CR.CaseBB == CurMBB)
@ -1705,12 +1700,7 @@ void SelectionDAGLowering::visitGetElementPtr(User &I) {
// If this is a constant subscript, handle it quickly. // If this is a constant subscript, handle it quickly.
if (ConstantInt *CI = dyn_cast<ConstantInt>(Idx)) { if (ConstantInt *CI = dyn_cast<ConstantInt>(Idx)) {
if (CI->getZExtValue() == 0) continue; if (CI->getZExtValue() == 0) continue;
uint64_t Offs; uint64_t Offs =
if (CI->getType()->isSigned())
Offs = (int64_t)
TD->getTypeSize(Ty)*cast<ConstantInt>(CI)->getSExtValue();
else
Offs =
TD->getTypeSize(Ty)*cast<ConstantInt>(CI)->getZExtValue(); TD->getTypeSize(Ty)*cast<ConstantInt>(CI)->getZExtValue();
N = DAG.getNode(ISD::ADD, N.getValueType(), N, getIntPtrConstant(Offs)); N = DAG.getNode(ISD::ADD, N.getValueType(), N, getIntPtrConstant(Offs));
continue; continue;
@ -1723,10 +1713,7 @@ void SelectionDAGLowering::visitGetElementPtr(User &I) {
// If the index is smaller or larger than intptr_t, truncate or extend // If the index is smaller or larger than intptr_t, truncate or extend
// it. // it.
if (IdxN.getValueType() < N.getValueType()) { if (IdxN.getValueType() < N.getValueType()) {
if (Idx->getType()->isSigned()) IdxN = DAG.getNode(ISD::SIGN_EXTEND, N.getValueType(), IdxN);
IdxN = DAG.getNode(ISD::SIGN_EXTEND, N.getValueType(), IdxN);
else
IdxN = DAG.getNode(ISD::ZERO_EXTEND, N.getValueType(), IdxN);
} else if (IdxN.getValueType() > N.getValueType()) } else if (IdxN.getValueType() > N.getValueType())
IdxN = DAG.getNode(ISD::TRUNCATE, N.getValueType(), IdxN); IdxN = DAG.getNode(ISD::TRUNCATE, N.getValueType(), IdxN);
@ -2185,25 +2172,30 @@ void SelectionDAGLowering::visitCall(CallInst &I) {
return; return;
} }
const PointerType *PT = cast<PointerType>(I.getCalledValue()->getType());
const FunctionType *FTy = cast<FunctionType>(PT->getElementType());
SDOperand Callee; SDOperand Callee;
if (!RenameFn) if (!RenameFn)
Callee = getValue(I.getOperand(0)); Callee = getValue(I.getOperand(0));
else else
Callee = DAG.getExternalSymbol(RenameFn, TLI.getPointerTy()); Callee = DAG.getExternalSymbol(RenameFn, TLI.getPointerTy());
std::vector<std::pair<SDOperand, const Type*> > Args; TargetLowering::ArgListTy Args;
TargetLowering::ArgListEntry Entry;
Args.reserve(I.getNumOperands()); Args.reserve(I.getNumOperands());
for (unsigned i = 1, e = I.getNumOperands(); i != e; ++i) { for (unsigned i = 1, e = I.getNumOperands(); i != e; ++i) {
Value *Arg = I.getOperand(i); Value *Arg = I.getOperand(i);
SDOperand ArgNode = getValue(Arg); SDOperand ArgNode = getValue(Arg);
Args.push_back(std::make_pair(ArgNode, Arg->getType())); Entry.Node = ArgNode; Entry.Ty = Arg->getType();
Entry.isSigned = FTy->paramHasAttr(i, FunctionType::SExtAttribute);
Args.push_back(Entry);
} }
const PointerType *PT = cast<PointerType>(I.getCalledValue()->getType());
const FunctionType *FTy = cast<FunctionType>(PT->getElementType());
std::pair<SDOperand,SDOperand> Result = std::pair<SDOperand,SDOperand> Result =
TLI.LowerCallTo(getRoot(), I.getType(), FTy->isVarArg(), I.getCallingConv(), TLI.LowerCallTo(getRoot(), I.getType(),
I.isTailCall(), Callee, Args, DAG); FTy->paramHasAttr(0,FunctionType::SExtAttribute),
FTy->isVarArg(), I.getCallingConv(), I.isTailCall(),
Callee, Args, DAG);
if (I.getType() != Type::VoidTy) if (I.getType() != Type::VoidTy)
setValue(&I, Result.first); setValue(&I, Result.first);
DAG.setRoot(Result.second); DAG.setRoot(Result.second);
@ -2785,11 +2777,15 @@ void SelectionDAGLowering::visitMalloc(MallocInst &I) {
Src = DAG.getNode(ISD::MUL, Src.getValueType(), Src = DAG.getNode(ISD::MUL, Src.getValueType(),
Src, getIntPtrConstant(ElementSize)); Src, getIntPtrConstant(ElementSize));
std::vector<std::pair<SDOperand, const Type*> > Args; TargetLowering::ArgListTy Args;
Args.push_back(std::make_pair(Src, TLI.getTargetData()->getIntPtrType())); TargetLowering::ArgListEntry Entry;
Entry.Node = Src;
Entry.Ty = TLI.getTargetData()->getIntPtrType();
Entry.isSigned = false;
Args.push_back(Entry);
std::pair<SDOperand,SDOperand> Result = std::pair<SDOperand,SDOperand> Result =
TLI.LowerCallTo(getRoot(), I.getType(), false, CallingConv::C, true, TLI.LowerCallTo(getRoot(), I.getType(), false, false, CallingConv::C, true,
DAG.getExternalSymbol("malloc", IntPtr), DAG.getExternalSymbol("malloc", IntPtr),
Args, DAG); Args, DAG);
setValue(&I, Result.first); // Pointers always fit in registers setValue(&I, Result.first); // Pointers always fit in registers
@ -2797,12 +2793,15 @@ void SelectionDAGLowering::visitMalloc(MallocInst &I) {
} }
void SelectionDAGLowering::visitFree(FreeInst &I) { void SelectionDAGLowering::visitFree(FreeInst &I) {
std::vector<std::pair<SDOperand, const Type*> > Args; TargetLowering::ArgListTy Args;
Args.push_back(std::make_pair(getValue(I.getOperand(0)), TargetLowering::ArgListEntry Entry;
TLI.getTargetData()->getIntPtrType())); Entry.Node = getValue(I.getOperand(0));
Entry.Ty = TLI.getTargetData()->getIntPtrType();
Entry.isSigned = false;
Args.push_back(Entry);
MVT::ValueType IntPtr = TLI.getPointerTy(); MVT::ValueType IntPtr = TLI.getPointerTy();
std::pair<SDOperand,SDOperand> Result = std::pair<SDOperand,SDOperand> Result =
TLI.LowerCallTo(getRoot(), Type::VoidTy, false, CallingConv::C, true, TLI.LowerCallTo(getRoot(), Type::VoidTy, false, false, CallingConv::C, true,
DAG.getExternalSymbol("free", IntPtr), Args, DAG); DAG.getExternalSymbol("free", IntPtr), Args, DAG);
DAG.setRoot(Result.second); DAG.setRoot(Result.second);
} }
@ -2939,8 +2938,11 @@ TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
// Set up the return result vector. // Set up the return result vector.
Ops.clear(); Ops.clear();
const FunctionType *FTy = F.getFunctionType();
unsigned i = 0; unsigned i = 0;
for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I) { unsigned Idx = 1;
for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E;
++I, ++Idx) {
MVT::ValueType VT = getValueType(I->getType()); MVT::ValueType VT = getValueType(I->getType());
switch (getTypeAction(VT)) { switch (getTypeAction(VT)) {
@ -2951,8 +2953,9 @@ TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
case Promote: { case Promote: {
SDOperand Op(Result, i++); SDOperand Op(Result, i++);
if (MVT::isInteger(VT)) { if (MVT::isInteger(VT)) {
unsigned AssertOp = I->getType()->isSigned() ? ISD::AssertSext unsigned AssertOp = ISD::AssertSext;
: ISD::AssertZext; if (FTy->paramHasAttr(Idx, FunctionType::ZExtAttribute))
AssertOp = ISD::AssertZext;
Op = DAG.getNode(AssertOp, Op.getValueType(), Op, DAG.getValueType(VT)); Op = DAG.getNode(AssertOp, Op.getValueType(), Op, DAG.getValueType(VT));
Op = DAG.getNode(ISD::TRUNCATE, VT, Op); Op = DAG.getNode(ISD::TRUNCATE, VT, Op);
} else { } else {
@ -3035,7 +3038,8 @@ static void ExpandScalarCallArgs(MVT::ValueType VT, SDOperand Arg,
/// lowered by the target to something concrete. FIXME: When all targets are /// lowered by the target to something concrete. FIXME: When all targets are
/// migrated to using ISD::CALL, this hook should be integrated into SDISel. /// migrated to using ISD::CALL, this hook should be integrated into SDISel.
std::pair<SDOperand, SDOperand> std::pair<SDOperand, SDOperand>
TargetLowering::LowerCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg, TargetLowering::LowerCallTo(SDOperand Chain, const Type *RetTy,
bool RetTyIsSigned, bool isVarArg,
unsigned CallingConv, bool isTailCall, unsigned CallingConv, bool isTailCall,
SDOperand Callee, SDOperand Callee,
ArgListTy &Args, SelectionDAG &DAG) { ArgListTy &Args, SelectionDAG &DAG) {
@ -3048,9 +3052,9 @@ TargetLowering::LowerCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg,
// Handle all of the outgoing arguments. // Handle all of the outgoing arguments.
for (unsigned i = 0, e = Args.size(); i != e; ++i) { for (unsigned i = 0, e = Args.size(); i != e; ++i) {
MVT::ValueType VT = getValueType(Args[i].second); MVT::ValueType VT = getValueType(Args[i].Ty);
SDOperand Op = Args[i].first; SDOperand Op = Args[i].Node;
bool isSigned = Args[i].second->isSigned(); bool isSigned = Args[i].isSigned;
switch (getTypeAction(VT)) { switch (getTypeAction(VT)) {
default: assert(0 && "Unknown type action!"); default: assert(0 && "Unknown type action!");
case Legal: case Legal:
@ -3077,7 +3081,7 @@ TargetLowering::LowerCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg,
} else { } else {
// Otherwise, this is a vector type. We only support legal vectors // Otherwise, this is a vector type. We only support legal vectors
// right now. // right now.
const PackedType *PTy = cast<PackedType>(Args[i].second); const PackedType *PTy = cast<PackedType>(Args[i].Ty);
unsigned NumElems = PTy->getNumElements(); unsigned NumElems = PTy->getNumElements();
const Type *EltTy = PTy->getElementType(); const Type *EltTy = PTy->getElementType();
@ -3177,8 +3181,9 @@ TargetLowering::LowerCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg,
abort(); abort();
} }
} else if (MVT::isInteger(VT)) { } else if (MVT::isInteger(VT)) {
unsigned AssertOp = RetTy->isSigned() ? unsigned AssertOp = ISD::AssertSext;
ISD::AssertSext : ISD::AssertZext; if (!RetTyIsSigned)
AssertOp = ISD::AssertZext;
ResVal = DAG.getNode(AssertOp, ResVal.getValueType(), ResVal, ResVal = DAG.getNode(AssertOp, ResVal.getValueType(), ResVal,
DAG.getValueType(VT)); DAG.getValueType(VT));
ResVal = DAG.getNode(ISD::TRUNCATE, VT, ResVal); ResVal = DAG.getNode(ISD::TRUNCATE, VT, ResVal);
@ -3673,10 +3678,7 @@ static bool OptimizeGEPExpression(GetElementPtrInst *GEPI,
// Handle constant subscripts. // Handle constant subscripts.
if (ConstantInt *CI = dyn_cast<ConstantInt>(Idx)) { if (ConstantInt *CI = dyn_cast<ConstantInt>(Idx)) {
if (CI->getZExtValue() == 0) continue; if (CI->getZExtValue() == 0) continue;
if (CI->getType()->isSigned()) ConstantOffset += (int64_t)TD->getTypeSize(Ty)*CI->getSExtValue();
ConstantOffset += (int64_t)TD->getTypeSize(Ty)*CI->getSExtValue();
else
ConstantOffset += TD->getTypeSize(Ty)*CI->getZExtValue();
continue; continue;
} }

View File

@ -915,7 +915,7 @@ bool ARMDAGToDAGISel::SelectAddrMode1(SDOperand Op,
SDOperand C = CurDAG->getTargetConstant(~val, MVT::i32); SDOperand C = CurDAG->getTargetConstant(~val, MVT::i32);
n = CurDAG->getTargetNode(ARM::MVN, MVT::i32, C, Z, Z); n = CurDAG->getTargetNode(ARM::MVN, MVT::i32, C, Z, Z);
} else { } else {
Constant *C = ConstantInt::get(Type::UIntTy, val); Constant *C = ConstantInt::get(Type::Int32Ty, val);
int alignment = 2; int alignment = 2;
SDOperand Addr = CurDAG->getTargetConstantPool(C, MVT::i32, alignment); SDOperand Addr = CurDAG->getTargetConstantPool(C, MVT::i32, alignment);
n = CurDAG->getTargetNode(ARM::LDR, MVT::i32, Addr, Z); n = CurDAG->getTargetNode(ARM::LDR, MVT::i32, Addr, Z);

View File

@ -322,7 +322,7 @@ SDNode *AlphaDAGToDAGISel::Select(SDOperand Op) {
// val32 >= IMM_LOW + IMM_LOW * IMM_MULT) //always true // val32 >= IMM_LOW + IMM_LOW * IMM_MULT) //always true
break; //(zext (LDAH (LDA))) break; //(zext (LDAH (LDA)))
//Else use the constant pool //Else use the constant pool
ConstantInt *C = ConstantInt::get(Type::ULongTy, uval); ConstantInt *C = ConstantInt::get(Type::Int64Ty, uval);
SDOperand CPI = CurDAG->getTargetConstantPool(C, MVT::i64); SDOperand CPI = CurDAG->getTargetConstantPool(C, MVT::i64);
SDNode *Tmp = CurDAG->getTargetNode(Alpha::LDAHr, MVT::i64, CPI, SDNode *Tmp = CurDAG->getTargetNode(Alpha::LDAHr, MVT::i64, CPI,
getGlobalBaseReg()); getGlobalBaseReg());

View File

@ -317,8 +317,8 @@ static SDOperand LowerRET(SDOperand Op, SelectionDAG &DAG) {
} }
std::pair<SDOperand, SDOperand> std::pair<SDOperand, SDOperand>
AlphaTargetLowering::LowerCallTo(SDOperand Chain, AlphaTargetLowering::LowerCallTo(SDOperand Chain, const Type *RetTy,
const Type *RetTy, bool isVarArg, bool RetTyIsSigned, bool isVarArg,
unsigned CallingConv, bool isTailCall, unsigned CallingConv, bool isTailCall,
SDOperand Callee, ArgListTy &Args, SDOperand Callee, ArgListTy &Args,
SelectionDAG &DAG) { SelectionDAG &DAG) {
@ -331,7 +331,7 @@ AlphaTargetLowering::LowerCallTo(SDOperand Chain,
std::vector<SDOperand> args_to_use; std::vector<SDOperand> args_to_use;
for (unsigned i = 0, e = Args.size(); i != e; ++i) for (unsigned i = 0, e = Args.size(); i != e; ++i)
{ {
switch (getValueType(Args[i].second)) { switch (getValueType(Args[i].Ty)) {
default: assert(0 && "Unexpected ValueType for argument!"); default: assert(0 && "Unexpected ValueType for argument!");
case MVT::i1: case MVT::i1:
case MVT::i8: case MVT::i8:
@ -339,17 +339,17 @@ AlphaTargetLowering::LowerCallTo(SDOperand Chain,
case MVT::i32: case MVT::i32:
// Promote the integer to 64 bits. If the input type is signed use a // Promote the integer to 64 bits. If the input type is signed use a
// sign extend, otherwise use a zero extend. // sign extend, otherwise use a zero extend.
if (Args[i].second->isSigned()) if (Args[i].isSigned)
Args[i].first = DAG.getNode(ISD::SIGN_EXTEND, MVT::i64, Args[i].first); Args[i].Node = DAG.getNode(ISD::SIGN_EXTEND, MVT::i64, Args[i].Node);
else else
Args[i].first = DAG.getNode(ISD::ZERO_EXTEND, MVT::i64, Args[i].first); Args[i].Node = DAG.getNode(ISD::ZERO_EXTEND, MVT::i64, Args[i].Node);
break; break;
case MVT::i64: case MVT::i64:
case MVT::f64: case MVT::f64:
case MVT::f32: case MVT::f32:
break; break;
} }
args_to_use.push_back(Args[i].first); args_to_use.push_back(Args[i].Node);
} }
std::vector<MVT::ValueType> RetVals; std::vector<MVT::ValueType> RetVals;
@ -373,7 +373,7 @@ AlphaTargetLowering::LowerCallTo(SDOperand Chain,
SDOperand RetVal = TheCall; SDOperand RetVal = TheCall;
if (RetTyVT != ActualRetTyVT) { if (RetTyVT != ActualRetTyVT) {
RetVal = DAG.getNode(RetTy->isSigned() ? ISD::AssertSext : ISD::AssertZext, RetVal = DAG.getNode(RetTyIsSigned ? ISD::AssertSext : ISD::AssertZext,
MVT::i64, RetVal, DAG.getValueType(RetTyVT)); MVT::i64, RetVal, DAG.getValueType(RetTyVT));
RetVal = DAG.getNode(ISD::TRUNCATE, RetTyVT, RetVal); RetVal = DAG.getNode(ISD::TRUNCATE, RetTyVT, RetVal);
} }

View File

@ -77,9 +77,9 @@ namespace llvm {
/// LowerCallTo - This hook lowers an abstract call to a function into an /// LowerCallTo - This hook lowers an abstract call to a function into an
/// actual call. /// actual call.
virtual std::pair<SDOperand, SDOperand> virtual std::pair<SDOperand, SDOperand>
LowerCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg, unsigned CC, LowerCallTo(SDOperand Chain, const Type *RetTy, bool RetTyIsSigned,
bool isTailCall, SDOperand Callee, ArgListTy &Args, bool isVarArg, unsigned CC, bool isTailCall, SDOperand Callee,
SelectionDAG &DAG); ArgListTy &Args, SelectionDAG &DAG);
ConstraintType getConstraintType(char ConstraintLetter) const; ConstraintType getConstraintType(char ConstraintLetter) const;

View File

@ -365,17 +365,13 @@ CWriter::printPrimitiveType(std::ostream &Out, const Type *Ty, bool isSigned,
switch (Ty->getTypeID()) { switch (Ty->getTypeID()) {
case Type::VoidTyID: return Out << "void " << NameSoFar; case Type::VoidTyID: return Out << "void " << NameSoFar;
case Type::BoolTyID: return Out << "bool " << NameSoFar; case Type::BoolTyID: return Out << "bool " << NameSoFar;
case Type::UByteTyID: case Type::Int8TyID:
case Type::SByteTyID:
return Out << (isSigned?"signed":"unsigned") << " char " << NameSoFar; return Out << (isSigned?"signed":"unsigned") << " char " << NameSoFar;
case Type::UShortTyID: case Type::Int16TyID:
case Type::ShortTyID:
return Out << (isSigned?"signed":"unsigned") << " short " << NameSoFar; return Out << (isSigned?"signed":"unsigned") << " short " << NameSoFar;
case Type::UIntTyID: case Type::Int32TyID:
case Type::IntTyID:
return Out << (isSigned?"signed":"unsigned") << " int " << NameSoFar; return Out << (isSigned?"signed":"unsigned") << " int " << NameSoFar;
case Type::ULongTyID: case Type::Int64TyID:
case Type::LongTyID:
return Out << (isSigned?"signed":"unsigned") << " long long " << NameSoFar; return Out << (isSigned?"signed":"unsigned") << " long long " << NameSoFar;
case Type::FloatTyID: return Out << "float " << NameSoFar; case Type::FloatTyID: return Out << "float " << NameSoFar;
case Type::DoubleTyID: return Out << "double " << NameSoFar; case Type::DoubleTyID: return Out << "double " << NameSoFar;
@ -488,7 +484,7 @@ void CWriter::printConstantArray(ConstantArray *CPA) {
// ubytes or an array of sbytes with positive values. // ubytes or an array of sbytes with positive values.
// //
const Type *ETy = CPA->getType()->getElementType(); const Type *ETy = CPA->getType()->getElementType();
bool isString = (ETy == Type::SByteTy || ETy == Type::UByteTy); bool isString = (ETy == Type::Int8Ty || ETy == Type::Int8Ty);
// Make sure the last character is a null char, as automatically added by C // Make sure the last character is a null char, as automatically added by C
if (isString && (CPA->getNumOperands() == 0 || if (isString && (CPA->getNumOperands() == 0 ||
@ -810,50 +806,19 @@ void CWriter::printConstant(Constant *CPV) {
case Type::BoolTyID: case Type::BoolTyID:
Out << (cast<ConstantBool>(CPV)->getValue() ? '1' : '0'); Out << (cast<ConstantBool>(CPV)->getValue() ? '1' : '0');
break; break;
case Type::SByteTyID: case Type::Int8TyID:
case Type::UByteTyID:
Out << "((char)" << cast<ConstantInt>(CPV)->getSExtValue() << ")"; Out << "((char)" << cast<ConstantInt>(CPV)->getSExtValue() << ")";
break; break;
case Type::ShortTyID: case Type::Int16TyID:
case Type::UShortTyID:
Out << "((short)" << cast<ConstantInt>(CPV)->getSExtValue() << ")"; Out << "((short)" << cast<ConstantInt>(CPV)->getSExtValue() << ")";
break; break;
case Type::IntTyID: case Type::Int32TyID:
case Type::UIntTyID:
Out << "((int)" << cast<ConstantInt>(CPV)->getSExtValue() << ")"; Out << "((int)" << cast<ConstantInt>(CPV)->getSExtValue() << ")";
break; break;
case Type::LongTyID: case Type::Int64TyID:
case Type::ULongTyID:
Out << "((long long)" << cast<ConstantInt>(CPV)->getSExtValue() << "ll)"; Out << "((long long)" << cast<ConstantInt>(CPV)->getSExtValue() << "ll)";
break; break;
#if 0
case Type::IntTyID:
if ((int)cast<ConstantInt>(CPV)->getSExtValue() == (int)0x80000000)
Out << "((int)0x80000000U)"; // Handle MININT specially to avoid warning
else
Out << cast<ConstantInt>(CPV)->getSExtValue();
break;
case Type::LongTyID:
if (cast<ConstantInt>(CPV)->isMinValue(true))
Out << "(/*INT64_MIN*/(-9223372036854775807LL)-1)";
else
Out << cast<ConstantInt>(CPV)->getSExtValue() << "ll";
break;
case Type::UByteTyID:
case Type::UShortTyID:
Out << cast<ConstantInt>(CPV)->getZExtValue();
break;
case Type::UIntTyID:
Out << cast<ConstantInt>(CPV)->getZExtValue() << 'u';
break;
case Type::ULongTyID:
Out << cast<ConstantInt>(CPV)->getZExtValue() << "ull";
break;
#endif
case Type::FloatTyID: case Type::FloatTyID:
case Type::DoubleTyID: { case Type::DoubleTyID: {
ConstantFP *FPC = cast<ConstantFP>(CPV); ConstantFP *FPC = cast<ConstantFP>(CPV);
@ -1627,10 +1592,8 @@ void CWriter::printFloatingPointConstants(Function &F) {
void CWriter::printModuleTypes(const SymbolTable &ST) { void CWriter::printModuleTypes(const SymbolTable &ST) {
Out << "/* Helper union for bitcasts */\n"; Out << "/* Helper union for bitcasts */\n";
Out << "typedef union {\n"; Out << "typedef union {\n";
Out << " unsigned int UInt;\n"; Out << " unsigned int Int32;\n";
Out << " signed int SInt;\n"; Out << " unsigned long long Int64;\n";
Out << " unsigned long long ULong;\n";
Out << " signed long long SLong;\n";
Out << " float Float;\n"; Out << " float Float;\n";
Out << " double Double;\n"; Out << " double Double;\n";
Out << "} llvmBitCastUnion;\n"; Out << "} llvmBitCastUnion;\n";
@ -2060,8 +2023,7 @@ void CWriter::visitBinaryOperator(Instruction &I) {
// We must cast the results of binary operations which might be promoted. // We must cast the results of binary operations which might be promoted.
bool needsCast = false; bool needsCast = false;
if ((I.getType() == Type::UByteTy) || (I.getType() == Type::SByteTy) if ((I.getType() == Type::Int8Ty) || (I.getType() == Type::Int16Ty)
|| (I.getType() == Type::UShortTy) || (I.getType() == Type::ShortTy)
|| (I.getType() == Type::FloatTy)) { || (I.getType() == Type::FloatTy)) {
needsCast = true; needsCast = true;
Out << "(("; Out << "((";
@ -2192,12 +2154,10 @@ void CWriter::visitFCmpInst(FCmpInst &I) {
static const char * getFloatBitCastField(const Type *Ty) { static const char * getFloatBitCastField(const Type *Ty) {
switch (Ty->getTypeID()) { switch (Ty->getTypeID()) {
default: assert(0 && "Invalid Type"); default: assert(0 && "Invalid Type");
case Type::FloatTyID: return "Float"; case Type::FloatTyID: return "Float";
case Type::UIntTyID: return "UInt"; case Type::Int32TyID: return "Int32";
case Type::IntTyID: return "SInt"; case Type::DoubleTyID: return "Double";
case Type::DoubleTyID:return "Double"; case Type::Int64TyID: return "Int64";
case Type::ULongTyID: return "ULong";
case Type::LongTyID: return "SLong";
} }
} }

View File

@ -365,17 +365,13 @@ CWriter::printPrimitiveType(std::ostream &Out, const Type *Ty, bool isSigned,
switch (Ty->getTypeID()) { switch (Ty->getTypeID()) {
case Type::VoidTyID: return Out << "void " << NameSoFar; case Type::VoidTyID: return Out << "void " << NameSoFar;
case Type::BoolTyID: return Out << "bool " << NameSoFar; case Type::BoolTyID: return Out << "bool " << NameSoFar;
case Type::UByteTyID: case Type::Int8TyID:
case Type::SByteTyID:
return Out << (isSigned?"signed":"unsigned") << " char " << NameSoFar; return Out << (isSigned?"signed":"unsigned") << " char " << NameSoFar;
case Type::UShortTyID: case Type::Int16TyID:
case Type::ShortTyID:
return Out << (isSigned?"signed":"unsigned") << " short " << NameSoFar; return Out << (isSigned?"signed":"unsigned") << " short " << NameSoFar;
case Type::UIntTyID: case Type::Int32TyID:
case Type::IntTyID:
return Out << (isSigned?"signed":"unsigned") << " int " << NameSoFar; return Out << (isSigned?"signed":"unsigned") << " int " << NameSoFar;
case Type::ULongTyID: case Type::Int64TyID:
case Type::LongTyID:
return Out << (isSigned?"signed":"unsigned") << " long long " << NameSoFar; return Out << (isSigned?"signed":"unsigned") << " long long " << NameSoFar;
case Type::FloatTyID: return Out << "float " << NameSoFar; case Type::FloatTyID: return Out << "float " << NameSoFar;
case Type::DoubleTyID: return Out << "double " << NameSoFar; case Type::DoubleTyID: return Out << "double " << NameSoFar;
@ -488,7 +484,7 @@ void CWriter::printConstantArray(ConstantArray *CPA) {
// ubytes or an array of sbytes with positive values. // ubytes or an array of sbytes with positive values.
// //
const Type *ETy = CPA->getType()->getElementType(); const Type *ETy = CPA->getType()->getElementType();
bool isString = (ETy == Type::SByteTy || ETy == Type::UByteTy); bool isString = (ETy == Type::Int8Ty || ETy == Type::Int8Ty);
// Make sure the last character is a null char, as automatically added by C // Make sure the last character is a null char, as automatically added by C
if (isString && (CPA->getNumOperands() == 0 || if (isString && (CPA->getNumOperands() == 0 ||
@ -810,50 +806,19 @@ void CWriter::printConstant(Constant *CPV) {
case Type::BoolTyID: case Type::BoolTyID:
Out << (cast<ConstantBool>(CPV)->getValue() ? '1' : '0'); Out << (cast<ConstantBool>(CPV)->getValue() ? '1' : '0');
break; break;
case Type::SByteTyID: case Type::Int8TyID:
case Type::UByteTyID:
Out << "((char)" << cast<ConstantInt>(CPV)->getSExtValue() << ")"; Out << "((char)" << cast<ConstantInt>(CPV)->getSExtValue() << ")";
break; break;
case Type::ShortTyID: case Type::Int16TyID:
case Type::UShortTyID:
Out << "((short)" << cast<ConstantInt>(CPV)->getSExtValue() << ")"; Out << "((short)" << cast<ConstantInt>(CPV)->getSExtValue() << ")";
break; break;
case Type::IntTyID: case Type::Int32TyID:
case Type::UIntTyID:
Out << "((int)" << cast<ConstantInt>(CPV)->getSExtValue() << ")"; Out << "((int)" << cast<ConstantInt>(CPV)->getSExtValue() << ")";
break; break;
case Type::LongTyID: case Type::Int64TyID:
case Type::ULongTyID:
Out << "((long long)" << cast<ConstantInt>(CPV)->getSExtValue() << "ll)"; Out << "((long long)" << cast<ConstantInt>(CPV)->getSExtValue() << "ll)";
break; break;
#if 0
case Type::IntTyID:
if ((int)cast<ConstantInt>(CPV)->getSExtValue() == (int)0x80000000)
Out << "((int)0x80000000U)"; // Handle MININT specially to avoid warning
else
Out << cast<ConstantInt>(CPV)->getSExtValue();
break;
case Type::LongTyID:
if (cast<ConstantInt>(CPV)->isMinValue(true))
Out << "(/*INT64_MIN*/(-9223372036854775807LL)-1)";
else
Out << cast<ConstantInt>(CPV)->getSExtValue() << "ll";
break;
case Type::UByteTyID:
case Type::UShortTyID:
Out << cast<ConstantInt>(CPV)->getZExtValue();
break;
case Type::UIntTyID:
Out << cast<ConstantInt>(CPV)->getZExtValue() << 'u';
break;
case Type::ULongTyID:
Out << cast<ConstantInt>(CPV)->getZExtValue() << "ull";
break;
#endif
case Type::FloatTyID: case Type::FloatTyID:
case Type::DoubleTyID: { case Type::DoubleTyID: {
ConstantFP *FPC = cast<ConstantFP>(CPV); ConstantFP *FPC = cast<ConstantFP>(CPV);
@ -1627,10 +1592,8 @@ void CWriter::printFloatingPointConstants(Function &F) {
void CWriter::printModuleTypes(const SymbolTable &ST) { void CWriter::printModuleTypes(const SymbolTable &ST) {
Out << "/* Helper union for bitcasts */\n"; Out << "/* Helper union for bitcasts */\n";
Out << "typedef union {\n"; Out << "typedef union {\n";
Out << " unsigned int UInt;\n"; Out << " unsigned int Int32;\n";
Out << " signed int SInt;\n"; Out << " unsigned long long Int64;\n";
Out << " unsigned long long ULong;\n";
Out << " signed long long SLong;\n";
Out << " float Float;\n"; Out << " float Float;\n";
Out << " double Double;\n"; Out << " double Double;\n";
Out << "} llvmBitCastUnion;\n"; Out << "} llvmBitCastUnion;\n";
@ -2060,8 +2023,7 @@ void CWriter::visitBinaryOperator(Instruction &I) {
// We must cast the results of binary operations which might be promoted. // We must cast the results of binary operations which might be promoted.
bool needsCast = false; bool needsCast = false;
if ((I.getType() == Type::UByteTy) || (I.getType() == Type::SByteTy) if ((I.getType() == Type::Int8Ty) || (I.getType() == Type::Int16Ty)
|| (I.getType() == Type::UShortTy) || (I.getType() == Type::ShortTy)
|| (I.getType() == Type::FloatTy)) { || (I.getType() == Type::FloatTy)) {
needsCast = true; needsCast = true;
Out << "(("; Out << "((";
@ -2192,12 +2154,10 @@ void CWriter::visitFCmpInst(FCmpInst &I) {
static const char * getFloatBitCastField(const Type *Ty) { static const char * getFloatBitCastField(const Type *Ty) {
switch (Ty->getTypeID()) { switch (Ty->getTypeID()) {
default: assert(0 && "Invalid Type"); default: assert(0 && "Invalid Type");
case Type::FloatTyID: return "Float"; case Type::FloatTyID: return "Float";
case Type::UIntTyID: return "UInt"; case Type::Int32TyID: return "Int32";
case Type::IntTyID: return "SInt"; case Type::DoubleTyID: return "Double";
case Type::DoubleTyID:return "Double"; case Type::Int64TyID: return "Int64";
case Type::ULongTyID: return "ULong";
case Type::LongTyID: return "SLong";
} }
} }

View File

@ -290,10 +290,10 @@ IA64TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
std::pair<SDOperand, SDOperand> std::pair<SDOperand, SDOperand>
IA64TargetLowering::LowerCallTo(SDOperand Chain, IA64TargetLowering::LowerCallTo(SDOperand Chain,
const Type *RetTy, bool isVarArg, const Type *RetTy, bool RetTyIsSigned,
unsigned CallingConv, bool isTailCall, bool isVarArg, unsigned CallingConv,
SDOperand Callee, ArgListTy &Args, bool isTailCall, SDOperand Callee,
SelectionDAG &DAG) { ArgListTy &Args, SelectionDAG &DAG) {
MachineFunction &MF = DAG.getMachineFunction(); MachineFunction &MF = DAG.getMachineFunction();
@ -315,7 +315,8 @@ IA64TargetLowering::LowerCallTo(SDOperand Chain,
std::max(outRegsUsed, MF.getInfo<IA64FunctionInfo>()->outRegsUsed); std::max(outRegsUsed, MF.getInfo<IA64FunctionInfo>()->outRegsUsed);
// keep stack frame 16-byte aligned // keep stack frame 16-byte aligned
//assert(NumBytes==((NumBytes+15) & ~15) && "stack frame not 16-byte aligned!"); // assert(NumBytes==((NumBytes+15) & ~15) &&
// "stack frame not 16-byte aligned!");
NumBytes = (NumBytes+15) & ~15; NumBytes = (NumBytes+15) & ~15;
Chain = DAG.getCALLSEQ_START(Chain,DAG.getConstant(NumBytes, getPointerTy())); Chain = DAG.getCALLSEQ_START(Chain,DAG.getConstant(NumBytes, getPointerTy()));
@ -328,7 +329,7 @@ IA64TargetLowering::LowerCallTo(SDOperand Chain,
for (unsigned i = 0, e = Args.size(); i != e; ++i) for (unsigned i = 0, e = Args.size(); i != e; ++i)
{ {
SDOperand Val = Args[i].first; SDOperand Val = Args[i].Node;
MVT::ValueType ObjectVT = Val.getValueType(); MVT::ValueType ObjectVT = Val.getValueType();
SDOperand ValToStore(0, 0), ValToConvert(0, 0); SDOperand ValToStore(0, 0), ValToConvert(0, 0);
unsigned ObjSize=8; unsigned ObjSize=8;
@ -337,14 +338,15 @@ IA64TargetLowering::LowerCallTo(SDOperand Chain,
case MVT::i1: case MVT::i1:
case MVT::i8: case MVT::i8:
case MVT::i16: case MVT::i16:
case MVT::i32: case MVT::i32: {
//promote to 64-bits, sign/zero extending based on type //promote to 64-bits, sign/zero extending based on type
//of the argument //of the argument
if(Args[i].second->isSigned()) ISD::NodeType ExtendKind = ISD::ZERO_EXTEND;
Val = DAG.getNode(ISD::SIGN_EXTEND, MVT::i64, Val); if (Args[i].isSigned)
else ExtendKind = ISD::SIGN_EXTEND;
Val = DAG.getNode(ISD::ZERO_EXTEND, MVT::i64, Val); Val = DAG.getNode(ExtendKind, MVT::i64, Val);
// XXX: fall through // XXX: fall through
}
case MVT::i64: case MVT::i64:
//ObjSize = 8; //ObjSize = 8;
if(RegValuesToPass.size() >= 8) { if(RegValuesToPass.size() >= 8) {
@ -422,7 +424,8 @@ IA64TargetLowering::LowerCallTo(SDOperand Chain,
unsigned seenConverts = 0; unsigned seenConverts = 0;
for (unsigned i = 0, e = RegValuesToPass.size(); i != e; ++i) { for (unsigned i = 0, e = RegValuesToPass.size(); i != e; ++i) {
if(MVT::isFloatingPoint(RegValuesToPass[i].getValueType())) { if(MVT::isFloatingPoint(RegValuesToPass[i].getValueType())) {
Chain = DAG.getCopyToReg(Chain, IntArgRegs[i], Converts[seenConverts++], InFlag); Chain = DAG.getCopyToReg(Chain, IntArgRegs[i], Converts[seenConverts++],
InFlag);
InFlag = Chain.getValue(1); InFlag = Chain.getValue(1);
} }
} }
@ -432,8 +435,7 @@ IA64TargetLowering::LowerCallTo(SDOperand Chain,
for (unsigned i = 0, e = RegValuesToPass.size(); i != e; ++i) { for (unsigned i = 0, e = RegValuesToPass.size(); i != e; ++i) {
Chain = DAG.getCopyToReg(Chain, Chain = DAG.getCopyToReg(Chain,
MVT::isInteger(RegValuesToPass[i].getValueType()) ? MVT::isInteger(RegValuesToPass[i].getValueType()) ?
IntArgRegs[i] : FPArgRegs[usedFPArgs++], IntArgRegs[i] : FPArgRegs[usedFPArgs++], RegValuesToPass[i], InFlag);
RegValuesToPass[i], InFlag);
InFlag = Chain.getValue(1); InFlag = Chain.getValue(1);
} }
@ -483,7 +485,7 @@ IA64TargetLowering::LowerCallTo(SDOperand Chain,
case MVT::i1: { // bools are just like other integers (returned in r8) case MVT::i1: { // bools are just like other integers (returned in r8)
// we *could* fall through to the truncate below, but this saves a // we *could* fall through to the truncate below, but this saves a
// few redundant predicate ops // few redundant predicate ops
SDOperand boolInR8 = DAG.getCopyFromReg(Chain, IA64::r8, MVT::i64, InFlag); SDOperand boolInR8 = DAG.getCopyFromReg(Chain, IA64::r8, MVT::i64,InFlag);
InFlag = boolInR8.getValue(2); InFlag = boolInR8.getValue(2);
Chain = boolInR8.getValue(1); Chain = boolInR8.getValue(1);
SDOperand zeroReg = DAG.getCopyFromReg(Chain, IA64::r0, MVT::i64, InFlag); SDOperand zeroReg = DAG.getCopyFromReg(Chain, IA64::r0, MVT::i64, InFlag);

View File

@ -58,10 +58,9 @@ namespace llvm {
/// LowerCallTo - This hook lowers an abstract call to a function into an /// LowerCallTo - This hook lowers an abstract call to a function into an
/// actual call. /// actual call.
virtual std::pair<SDOperand, SDOperand> virtual std::pair<SDOperand, SDOperand>
LowerCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg, LowerCallTo(SDOperand Chain, const Type *RetTy, bool RetTyIsSigned,
unsigned CC, bool isVarArg, unsigned CC, bool isTailCall,
bool isTailCall, SDOperand Callee, ArgListTy &Args, SDOperand Callee, ArgListTy &Args, SelectionDAG &DAG);
SelectionDAG &DAG);
/// LowerOperation - for custom lowering specific ops /// LowerOperation - for custom lowering specific ops
/// (currently, only "ret void") /// (currently, only "ret void")

View File

@ -117,10 +117,9 @@ namespace {
virtual std::vector<SDOperand> virtual std::vector<SDOperand>
LowerArguments(Function &F, SelectionDAG &DAG); LowerArguments(Function &F, SelectionDAG &DAG);
virtual std::pair<SDOperand, SDOperand> virtual std::pair<SDOperand, SDOperand>
LowerCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg, LowerCallTo(SDOperand Chain, const Type *RetTy, bool RetTyIsSigned,
unsigned CC, bool isVarArg, unsigned CC, bool isTailCall, SDOperand Callee,
bool isTailCall, SDOperand Callee, ArgListTy &Args, ArgListTy &Args, SelectionDAG &DAG);
SelectionDAG &DAG);
virtual MachineBasicBlock *InsertAtEndOfBasicBlock(MachineInstr *MI, virtual MachineBasicBlock *InsertAtEndOfBasicBlock(MachineInstr *MI,
MachineBasicBlock *MBB); MachineBasicBlock *MBB);
@ -318,8 +317,7 @@ SparcTargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
MF.addLiveIn(*CurArgReg++, VReg); MF.addLiveIn(*CurArgReg++, VReg);
SDOperand Arg = DAG.getCopyFromReg(Root, VReg, MVT::i32); SDOperand Arg = DAG.getCopyFromReg(Root, VReg, MVT::i32);
if (ObjectVT != MVT::i32) { if (ObjectVT != MVT::i32) {
unsigned AssertOp = I->getType()->isSigned() ? ISD::AssertSext unsigned AssertOp = ISD::AssertSext;
: ISD::AssertZext;
Arg = DAG.getNode(AssertOp, MVT::i32, Arg, Arg = DAG.getNode(AssertOp, MVT::i32, Arg,
DAG.getValueType(ObjectVT)); DAG.getValueType(ObjectVT));
Arg = DAG.getNode(ISD::TRUNCATE, ObjectVT, Arg); Arg = DAG.getNode(ISD::TRUNCATE, ObjectVT, Arg);
@ -332,8 +330,7 @@ SparcTargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
if (ObjectVT == MVT::i32) { if (ObjectVT == MVT::i32) {
Load = DAG.getLoad(MVT::i32, Root, FIPtr, NULL, 0); Load = DAG.getLoad(MVT::i32, Root, FIPtr, NULL, 0);
} else { } else {
ISD::LoadExtType LoadOp = ISD::LoadExtType LoadOp = ISD::SEXTLOAD;
I->getType()->isSigned() ? ISD::SEXTLOAD : ISD::ZEXTLOAD;
// Sparc is big endian, so add an offset based on the ObjectVT. // Sparc is big endian, so add an offset based on the ObjectVT.
unsigned Offset = 4-std::max(1U, MVT::getSizeInBits(ObjectVT)/8); unsigned Offset = 4-std::max(1U, MVT::getSizeInBits(ObjectVT)/8);
@ -472,13 +469,13 @@ SparcTargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
std::pair<SDOperand, SDOperand> std::pair<SDOperand, SDOperand>
SparcTargetLowering::LowerCallTo(SDOperand Chain, const Type *RetTy, SparcTargetLowering::LowerCallTo(SDOperand Chain, const Type *RetTy,
bool isVarArg, unsigned CC, bool RetTyIsSigned, bool isVarArg, unsigned CC,
bool isTailCall, SDOperand Callee, bool isTailCall, SDOperand Callee,
ArgListTy &Args, SelectionDAG &DAG) { ArgListTy &Args, SelectionDAG &DAG) {
// Count the size of the outgoing arguments. // Count the size of the outgoing arguments.
unsigned ArgsSize = 0; unsigned ArgsSize = 0;
for (unsigned i = 0, e = Args.size(); i != e; ++i) { for (unsigned i = 0, e = Args.size(); i != e; ++i) {
switch (getValueType(Args[i].second)) { switch (getValueType(Args[i].Ty)) {
default: assert(0 && "Unknown value type!"); default: assert(0 && "Unknown value type!");
case MVT::i1: case MVT::i1:
case MVT::i8: case MVT::i8:
@ -508,7 +505,7 @@ SparcTargetLowering::LowerCallTo(SDOperand Chain, const Type *RetTy,
std::vector<SDOperand> RegValuesToPass; std::vector<SDOperand> RegValuesToPass;
unsigned ArgOffset = 68; unsigned ArgOffset = 68;
for (unsigned i = 0, e = Args.size(); i != e; ++i) { for (unsigned i = 0, e = Args.size(); i != e; ++i) {
SDOperand Val = Args[i].first; SDOperand Val = Args[i].Node;
MVT::ValueType ObjectVT = Val.getValueType(); MVT::ValueType ObjectVT = Val.getValueType();
SDOperand ValToStore(0, 0); SDOperand ValToStore(0, 0);
unsigned ObjSize; unsigned ObjSize;
@ -516,14 +513,15 @@ SparcTargetLowering::LowerCallTo(SDOperand Chain, const Type *RetTy,
default: assert(0 && "Unhandled argument type!"); default: assert(0 && "Unhandled argument type!");
case MVT::i1: case MVT::i1:
case MVT::i8: case MVT::i8:
case MVT::i16: case MVT::i16: {
// Promote the integer to 32-bits. If the input type is signed, use a // Promote the integer to 32-bits. If the input type is signed, use a
// sign extend, otherwise use a zero extend. // sign extend, otherwise use a zero extend.
if (Args[i].second->isSigned()) ISD::NodeType ExtendKind = ISD::ZERO_EXTEND;
Val = DAG.getNode(ISD::SIGN_EXTEND, MVT::i32, Val); if (Args[i].isSigned)
else ExtendKind = ISD::SIGN_EXTEND;
Val = DAG.getNode(ISD::ZERO_EXTEND, MVT::i32, Val); Val = DAG.getNode(ExtendKind, MVT::i32, Val);
// FALL THROUGH // FALL THROUGH
}
case MVT::i32: case MVT::i32:
ObjSize = 4; ObjSize = 4;
@ -629,15 +627,19 @@ SparcTargetLowering::LowerCallTo(SDOperand Chain, const Type *RetTy,
default: assert(0 && "Unknown value type to return!"); default: assert(0 && "Unknown value type to return!");
case MVT::i1: case MVT::i1:
case MVT::i8: case MVT::i8:
case MVT::i16: case MVT::i16: {
RetVal = DAG.getCopyFromReg(Chain, SP::O0, MVT::i32, InFlag); RetVal = DAG.getCopyFromReg(Chain, SP::O0, MVT::i32, InFlag);
Chain = RetVal.getValue(1); Chain = RetVal.getValue(1);
// Add a note to keep track of whether it is sign or zero extended. // Add a note to keep track of whether it is sign or zero extended.
RetVal = DAG.getNode(RetTy->isSigned() ? ISD::AssertSext :ISD::AssertZext, ISD::NodeType AssertKind = ISD::AssertZext;
MVT::i32, RetVal, DAG.getValueType(RetTyVT)); if (RetTyIsSigned)
AssertKind = ISD::AssertSext;
RetVal = DAG.getNode(AssertKind, MVT::i32, RetVal,
DAG.getValueType(RetTyVT));
RetVal = DAG.getNode(ISD::TRUNCATE, RetTyVT, RetVal); RetVal = DAG.getNode(ISD::TRUNCATE, RetTyVT, RetVal);
break; break;
}
case MVT::i32: case MVT::i32:
RetVal = DAG.getCopyFromReg(Chain, SP::O0, MVT::i32, InFlag); RetVal = DAG.getCopyFromReg(Chain, SP::O0, MVT::i32, InFlag);
Chain = RetVal.getValue(1); Chain = RetVal.getValue(1);

View File

@ -243,14 +243,10 @@ static inline void getTypeInfo(const Type *Ty, const TargetData *TD,
switch (Ty->getTypeID()) { switch (Ty->getTypeID()) {
case Type::BoolTyID: Size = 1; Alignment = TD->getBoolAlignment(); return; case Type::BoolTyID: Size = 1; Alignment = TD->getBoolAlignment(); return;
case Type::VoidTyID: case Type::VoidTyID:
case Type::UByteTyID: case Type::Int8TyID: Size = 1; Alignment = TD->getByteAlignment(); return;
case Type::SByteTyID: Size = 1; Alignment = TD->getByteAlignment(); return; case Type::Int16TyID: Size = 2; Alignment = TD->getShortAlignment(); return;
case Type::UShortTyID: case Type::Int32TyID: Size = 4; Alignment = TD->getIntAlignment(); return;
case Type::ShortTyID: Size = 2; Alignment = TD->getShortAlignment(); return; case Type::Int64TyID: Size = 8; Alignment = TD->getLongAlignment(); return;
case Type::UIntTyID:
case Type::IntTyID: Size = 4; Alignment = TD->getIntAlignment(); return;
case Type::ULongTyID:
case Type::LongTyID: Size = 8; Alignment = TD->getLongAlignment(); return;
case Type::FloatTyID: Size = 4; Alignment = TD->getFloatAlignment(); return; case Type::FloatTyID: Size = 4; Alignment = TD->getFloatAlignment(); return;
case Type::DoubleTyID: Size = 8; Alignment = TD->getDoubleAlignment(); return; case Type::DoubleTyID: Size = 8; Alignment = TD->getDoubleAlignment(); return;
case Type::LabelTyID: case Type::LabelTyID:
@ -312,9 +308,9 @@ unsigned char TargetData::getTypeAlignmentShift(const Type *Ty) const {
const Type *TargetData::getIntPtrType() const { const Type *TargetData::getIntPtrType() const {
switch (getPointerSize()) { switch (getPointerSize()) {
default: assert(0 && "Unknown pointer size!"); default: assert(0 && "Unknown pointer size!");
case 2: return Type::UShortTy; case 2: return Type::Int16Ty;
case 4: return Type::UIntTy; case 4: return Type::Int32Ty;
case 8: return Type::ULongTy; case 8: return Type::Int64Ty;
} }
} }
@ -329,7 +325,7 @@ uint64_t TargetData::getIndexedOffset(const Type *ptrTy,
TI = gep_type_begin(ptrTy, Idx.begin(), Idx.end()); TI = gep_type_begin(ptrTy, Idx.begin(), Idx.end());
for (unsigned CurIDX = 0; CurIDX != Idx.size(); ++CurIDX, ++TI) { for (unsigned CurIDX = 0; CurIDX != Idx.size(); ++CurIDX, ++TI) {
if (const StructType *STy = dyn_cast<StructType>(*TI)) { if (const StructType *STy = dyn_cast<StructType>(*TI)) {
assert(Idx[CurIDX]->getType() == Type::UIntTy && "Illegal struct idx"); assert(Idx[CurIDX]->getType() == Type::Int32Ty && "Illegal struct idx");
unsigned FieldNo = cast<ConstantInt>(Idx[CurIDX])->getZExtValue(); unsigned FieldNo = cast<ConstantInt>(Idx[CurIDX])->getZExtValue();
// Get structure layout information... // Get structure layout information...

View File

@ -4447,14 +4447,21 @@ SDOperand X86TargetLowering::LowerMEMSET(SDOperand Op, SelectionDAG &DAG) {
(I && I->getValue() < Subtarget->getMinRepStrSizeThreshold())) { (I && I->getValue() < Subtarget->getMinRepStrSizeThreshold())) {
MVT::ValueType IntPtr = getPointerTy(); MVT::ValueType IntPtr = getPointerTy();
const Type *IntPtrTy = getTargetData()->getIntPtrType(); const Type *IntPtrTy = getTargetData()->getIntPtrType();
std::vector<std::pair<SDOperand, const Type*> > Args; TargetLowering::ArgListTy Args;
Args.push_back(std::make_pair(Op.getOperand(1), IntPtrTy)); TargetLowering::ArgListEntry Entry;
Entry.Node = Op.getOperand(1);
Entry.Ty = IntPtrTy;
Entry.isSigned = false;
Args.push_back(Entry);
// Extend the ubyte argument to be an int value for the call. // Extend the ubyte argument to be an int value for the call.
SDOperand Val = DAG.getNode(ISD::ZERO_EXTEND, MVT::i32, Op.getOperand(2)); Entry.Node = DAG.getNode(ISD::ZERO_EXTEND, MVT::i32, Op.getOperand(2));
Args.push_back(std::make_pair(Val, IntPtrTy)); Entry.Ty = IntPtrTy;
Args.push_back(std::make_pair(Op.getOperand(3), IntPtrTy)); Entry.isSigned = false;
Args.push_back(Entry);
Entry.Node = Op.getOperand(3);
Args.push_back(Entry);
std::pair<SDOperand,SDOperand> CallResult = std::pair<SDOperand,SDOperand> CallResult =
LowerCallTo(Chain, Type::VoidTy, false, CallingConv::C, false, LowerCallTo(Chain, Type::VoidTy, false, false, CallingConv::C, false,
DAG.getExternalSymbol("memset", IntPtr), Args, DAG); DAG.getExternalSymbol("memset", IntPtr), Args, DAG);
return CallResult.second; return CallResult.second;
} }
@ -4601,13 +4608,14 @@ SDOperand X86TargetLowering::LowerMEMCPY(SDOperand Op, SelectionDAG &DAG) {
if ((Align & 3) != 0 || if ((Align & 3) != 0 ||
(I && I->getValue() < Subtarget->getMinRepStrSizeThreshold())) { (I && I->getValue() < Subtarget->getMinRepStrSizeThreshold())) {
MVT::ValueType IntPtr = getPointerTy(); MVT::ValueType IntPtr = getPointerTy();
const Type *IntPtrTy = getTargetData()->getIntPtrType(); TargetLowering::ArgListTy Args;
std::vector<std::pair<SDOperand, const Type*> > Args; TargetLowering::ArgListEntry Entry;
Args.push_back(std::make_pair(Op.getOperand(1), IntPtrTy)); Entry.Ty = getTargetData()->getIntPtrType(); Entry.isSigned = false;
Args.push_back(std::make_pair(Op.getOperand(2), IntPtrTy)); Entry.Node = Op.getOperand(1); Args.push_back(Entry);
Args.push_back(std::make_pair(Op.getOperand(3), IntPtrTy)); Entry.Node = Op.getOperand(2); Args.push_back(Entry);
Entry.Node = Op.getOperand(3); Args.push_back(Entry);
std::pair<SDOperand,SDOperand> CallResult = std::pair<SDOperand,SDOperand> CallResult =
LowerCallTo(Chain, Type::VoidTy, false, CallingConv::C, false, LowerCallTo(Chain, Type::VoidTy, false, false, CallingConv::C, false,
DAG.getExternalSymbol("memcpy", IntPtr), Args, DAG); DAG.getExternalSymbol("memcpy", IntPtr), Args, DAG);
return CallResult.second; return CallResult.second;
} }

View File

@ -172,13 +172,13 @@ bool X86TargetAsmInfo::LowerToBSwap(CallInst *CI) const {
!CI->getType()->isInteger()) !CI->getType()->isInteger())
return false; return false;
const Type *Ty = CI->getType()->getUnsignedVersion(); const Type *Ty = CI->getType();
const char *IntName; const char *IntName;
switch (Ty->getTypeID()) { switch (Ty->getTypeID()) {
default: return false; default: return false;
case Type::UShortTyID: IntName = "llvm.bswap.i16"; break; case Type::Int16TyID: IntName = "llvm.bswap.i16"; break;
case Type::UIntTyID: IntName = "llvm.bswap.i32"; break; case Type::Int32TyID: IntName = "llvm.bswap.i32"; break;
case Type::ULongTyID: IntName = "llvm.bswap.i64"; break; case Type::Int64TyID: IntName = "llvm.bswap.i64"; break;
} }
// Okay, we can do this xform, do so now. // Okay, we can do this xform, do so now.
@ -226,7 +226,7 @@ bool X86TargetAsmInfo::ExpandInlineAsm(CallInst *CI) const {
} }
break; break;
case 3: case 3:
if (CI->getType() == Type::ULongTy && Constraints.size() >= 2 && if (CI->getType() == Type::Int64Ty && Constraints.size() >= 2 &&
Constraints[0].Codes.size() == 1 && Constraints[0].Codes[0] == "A" && Constraints[0].Codes.size() == 1 && Constraints[0].Codes[0] == "A" &&
Constraints[1].Codes.size() == 1 && Constraints[1].Codes[0] == "0") { Constraints[1].Codes.size() == 1 && Constraints[1].Codes[0] == "0") {
// bswap %eax / bswap %edx / xchgl %eax, %edx -> llvm.bswap.i64 // bswap %eax / bswap %edx / xchgl %eax, %edx -> llvm.bswap.i64