[LLVMdev] bitwise AND
Tobias Grosser
tobias at grosser.es
Tue Sep 6 03:14:26 PDT 2011
On 09/06/2011 10:40 AM, Jimborean Alexandra wrote:
> Hi,
>
> I want to compute the bitwise 'and' between two values of type int1: %x
> = and %a, %b .
> Which is the LLVM instruction that creates this?
The LLVM-IR instruction for this is:
http://llvm.org/docs/LangRef.html#i_and
'and' Instruction
-----------------
Syntax: <result> = and <ty> <op1>, <op2> ; yields {ty}:result
Overview: The 'and' instruction returns the bitwise logical and of its
two operands.
For your example this would be: %x = and i1 %a, %b
> I only found the APInt class, whose constructor is:
> APInt(unsigned numBits, uint64_t val, bool isSigned = false)
>
> and which provides the bitwise AND operation:
>
> APInt llvm::APIntOps::And
> <http://llvm.org/docs/doxygen/html/namespacellvm_1_1APIntOps.html#a684cfe02c582e8d75cd6d457e63e6c25>
> (const APInt &LHS, const APInt &RHS)
> Bitwise AND function for APInt
> <http://llvm.org/docs/doxygen/html/classllvm_1_1APInt.html>.
>
>
> Is this the best way to build the 'and' instruction that I need?
I am not sure why you look into APInt. APInt is an abstract data type
for arbitrary, fixed width integer calculations and is (except of being
used by LLVM) independent of LLVM and LLVM-IR. You would use APInt
'and', if you want to perform calculations on data that is already of
type APInt or int.
If you want to perform the 'and' operation in an LLVM-IR program, you
can just add the 'and' instruction into the LLVM-IR source. You can
either do this by changing the file with a text editor, or, if you write
e.g. a LLVM pass, by construction a new 'and' instruction using the
IRBuilder()->CreateAnd(Value *A, Value *B) function.
> If so, how can I send the value uint64_t stored in the values %a , %b
> of type int1 ?
I did not get this one. Could you try to rephrase?
Cheers
Tobi
More information about the llvm-dev
mailing list