llvmllvm-irllvm-c++-api

What's the difference between `ConstantInt::getTrue (LLVMContext &Context)` and `ConstantInt::getTrue (Type *Ty)`?


I found 2 APIs in llvm::ConstantInt document:

  1. static ConstantInt *ConstantInt::getTrue (LLVMContext &Context): https://llvm.org/doxygen/classllvm_1_1ConstantInt.html#a82dbbd8e3688b0bc1eedb338864d0d0c

  2. static Constant *ConstantInt::getTrue (Type *Ty): https://llvm.org/doxygen/classllvm_1_1ConstantInt.html#a1d728e83e9e0fa85b0b58b33ec9c3197

But I don't know what's the difference between these 2 APIs ?


Solution

  • The former constructs a ConstantInt which has i1 type, while the latter allows you to specify the type yourself. This type, however, can only be either a scalar i1 or a vector of i1s.