[llvm-commits] [dragonegg] r153405 - in /dragonegg/trunk: src/Convert.cpp test/validator/c++/2012-03-25-LoadRange.cpp
Duncan Sands
baldrick at free.fr
Mon Mar 26 04:33:38 PDT 2012
Hi Jay,
>> --- dragonegg/trunk/src/Convert.cpp (original)
>> +++ dragonegg/trunk/src/Convert.cpp Sun Mar 25 00:52:05 2012
>> @@ -285,6 +285,30 @@
>> llvm_unreachable("Don't know how to turn this into memory!");
>> }
>>
>> +/// describeTypeRange - Given two integer types, return metadata describing the
>> +/// set obtained by extending all values of the smaller type to the larger.
>> +static MDNode *describeTypeRange(Type *SmallTy, Type *LargeTy, bool isSigned) {
>> + assert(isa<IntegerType>(SmallTy)&& isa<IntegerType>(LargeTy)&&
>> + "Expected integer types!");
>> + unsigned ActiveBits = SmallTy->getIntegerBitWidth();
>> + unsigned TotalBits = LargeTy->getIntegerBitWidth();
>> + assert(ActiveBits< TotalBits&& "Full range not allowed!");
>> + assert(ActiveBits> 0&& "Empty range not allowed!");
>
> I think this assert is reasonable but "empty range" doesn't sound
> right -- a 0-bit type should be able to represent exactly one value.
good point, I will change the message. As I think you realize GCC doesn't
support types with zero precision, so it's pretty theoretical anyway.
> (If it's unsigned the value is zero, but if it's signed I don't think
> it's well defined what the value is.)
>
>> + APInt First, Last;
>> + if (isSigned) {
>> + Last = APInt::getOneBitSet(TotalBits, ActiveBits - 1);
>> + First = -Last;
>> + } else {
>> + First = APInt::getNullValue(TotalBits);
>> + Last = APInt::getOneBitSet(TotalBits, ActiveBits);
>> + }
>> +
>> + Value *Range[2] = {
>> + ConstantInt::get(LargeTy, First), ConstantInt::get(LargeTy, Last)
>> + };
>> + return MDNode::get(Context, Range);
>> +}
>> +
>> /// isDirectMemoryAccessSafe - Whether directly storing/loading a value of the
>> /// given register type generates the correct in-memory representation for the
>> /// type. Eg, if a 32 bit wide integer type has only one bit of precision then
>> @@ -369,6 +393,8 @@
>> unsigned Size = GET_MODE_BITSIZE(TYPE_MODE(type));
>> Type *MemTy = IntegerType::get(Context, Size);
>> LoadInst *LI = LoadFromLocation(Loc, MemTy, Builder);
>> + MDNode *Range = describeTypeRange(RegTy, MemTy, !TYPE_UNSIGNED(type));
>> + LI->setMetadata(LLVMContext::MD_range, Range);
>
> Shouldn't you only do this when optimizing? See:
>
> http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20120319/139436.html
No, I don't think so. The fact that it isn't being optimized now doesn't mean
it won't be optimized later.
Ciao, Duncan.
More information about the llvm-commits
mailing list