Alexander Poddey
2015-Jan-22 10:07 UTC
[LLVMdev] access IntegerType::getSignBit from Type *
Hi,
I have a Type * which may come from an IntegerType as shown below:
Type.getIntegerBitWidth() tells me numBits.
But how to extract the IntegerType.getSignBit?
If pType isIntegerType, I need to know if it is signed or unsigned...
How to achieve this?
Thx
Alex
llvm::Type * getRandomValid_IntegerType(llvm::LLVMContext &C)
{
using namespace llvm;
//--- determine num of bits between allowed bits
int rI=randInt(IntegerType::MIN_INT_BITS,IntegerType::MAX_INT_BITS);
return IntegerType::get(C, rI);
}
llvm::Type * pType=getRandomValid_IntegerType(llvm::LLVMContext &C);
if(pType.isIntegerTy)
{
pType->getIntegerBitWidth(); // ok
pType->HOWTOGET_SIGN_INFO; //?
}
You will need to do soemthing like:
IntegerType* pInt = dyn_cast<IntegerType>(pType);
if (pInt) ... use pInt->getSignBit() ...
Of course, you have already checked isIntegerTy, so it's probably fine
to not check if the conversion was good. So you could do
dyn_cast<IntegerType>(pType)->getSignBit()
But if you are going to dyn_cast, you could as well do :
if (IntegerType* pInt = dyn_cast<IntegerType>(pType))
{
...
}
instead of if (pType.isIntegerTy) ...
--
Mats
On 22 January 2015 at 10:07, Alexander Poddey <alexander.poddey at
gmx.net> wrote:> Hi,
>
> I have a Type * which may come from an IntegerType as shown below:
>
> Type.getIntegerBitWidth() tells me numBits.
> But how to extract the IntegerType.getSignBit?
>
> If pType isIntegerType, I need to know if it is signed or unsigned...
>
> How to achieve this?
>
> Thx
> Alex
>
>
>
> llvm::Type * getRandomValid_IntegerType(llvm::LLVMContext &C)
> {
> using namespace llvm;
>
> //--- determine num of bits between allowed bits
> int rI=randInt(IntegerType::MIN_INT_BITS,IntegerType::MAX_INT_BITS);
>
> return IntegerType::get(C, rI);
>
>
> }
>
>
> llvm::Type * pType=getRandomValid_IntegerType(llvm::LLVMContext &C);
>
> if(pType.isIntegerTy)
> {
> pType->getIntegerBitWidth(); // ok
> pType->HOWTOGET_SIGN_INFO; //?
> }
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Alexander Poddey
2015-Jan-23 08:16 UTC
[LLVMdev] access IntegerType::getSignBit from Type *
Hi mats, :smiting my forehead: Sure! thats it, thanks a lot. Alex mats petersson wrote:> You will need to do soemthing like: > > IntegerType* pInt = dyn_cast<IntegerType>(pType); > if (pInt) ... use pInt->getSignBit() ... > > Of course, you have already checked isIntegerTy, so it's probably fine > to not check if the conversion was good. So you could do > dyn_cast<IntegerType>(pType)->getSignBit() > > But if you are going to dyn_cast, you could as well do : > if (IntegerType* pInt = dyn_cast<IntegerType>(pType)) > { > ... > } > > instead of if (pType.isIntegerTy) ... > > -- > Mats > > On 22 January 2015 at 10:07, Alexander Poddey <alexander.poddey at gmx.net> > wrote: >> Hi, >> >> I have a Type * which may come from an IntegerType as shown below: >> >> Type.getIntegerBitWidth() tells me numBits. >> But how to extract the IntegerType.getSignBit? >> >> If pType isIntegerType, I need to know if it is signed or unsigned... >> >> How to achieve this? >> >> Thx >> Alex >> >> >> >> llvm::Type * getRandomValid_IntegerType(llvm::LLVMContext &C) >> { >> using namespace llvm; >> >> //--- determine num of bits between allowed bits >> int rI=randInt(IntegerType::MIN_INT_BITS,IntegerType::MAX_INT_BITS); >> >> return IntegerType::get(C, rI); >> >> >> } >> >> >> llvm::Type * pType=getRandomValid_IntegerType(llvm::LLVMContext &C); >> >> if(pType.isIntegerTy) >> { >> pType->getIntegerBitWidth(); // ok >> pType->HOWTOGET_SIGN_INFO; //? >> } >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev