Add LLVM{U}IntAsType() utility routine
This commit is contained in:
36
llvmutil.cpp
36
llvmutil.cpp
@@ -469,6 +469,42 @@ LLVMBoolVector(const bool *bvec) {
|
||||
}
|
||||
|
||||
|
||||
llvm::Constant *
|
||||
LLVMIntAsType(int64_t val, LLVM_TYPE_CONST llvm::Type *type) {
|
||||
LLVM_TYPE_CONST llvm::VectorType *vecType =
|
||||
llvm::dyn_cast<LLVM_TYPE_CONST llvm::VectorType>(type);
|
||||
|
||||
if (vecType != NULL) {
|
||||
llvm::Constant *v = llvm::ConstantInt::get(vecType->getElementType(),
|
||||
val, true /* signed */);
|
||||
std::vector<llvm::Constant *> vals;
|
||||
for (int i = 0; i < (int)vecType->getNumElements(); ++i)
|
||||
vals.push_back(v);
|
||||
return llvm::ConstantVector::get(vals);
|
||||
}
|
||||
else
|
||||
return llvm::ConstantInt::get(type, val, true /* signed */);
|
||||
}
|
||||
|
||||
|
||||
llvm::Constant *
|
||||
LLVMUIntAsType(uint64_t val, LLVM_TYPE_CONST llvm::Type *type) {
|
||||
LLVM_TYPE_CONST llvm::VectorType *vecType =
|
||||
llvm::dyn_cast<LLVM_TYPE_CONST llvm::VectorType>(type);
|
||||
|
||||
if (vecType != NULL) {
|
||||
llvm::Constant *v = llvm::ConstantInt::get(vecType->getElementType(),
|
||||
val, false /* unsigned */);
|
||||
std::vector<llvm::Constant *> vals;
|
||||
for (int i = 0; i < (int)vecType->getNumElements(); ++i)
|
||||
vals.push_back(v);
|
||||
return llvm::ConstantVector::get(vals);
|
||||
}
|
||||
else
|
||||
return llvm::ConstantInt::get(type, val, false /* unsigned */);
|
||||
}
|
||||
|
||||
|
||||
/** Conservative test to see if two llvm::Values are equal. There are
|
||||
(potentially many) cases where the two values actually are equal but
|
||||
this will return false. However, if it does return true, the two
|
||||
|
||||
@@ -173,6 +173,14 @@ extern llvm::Constant *LLVMFloatVector(float f);
|
||||
across all elements */
|
||||
extern llvm::Constant *LLVMDoubleVector(double f);
|
||||
|
||||
/** Returns a constant integer or vector (according to the given type) of
|
||||
the given signed integer value. */
|
||||
extern llvm::Constant *LLVMIntAsType(int64_t, LLVM_TYPE_CONST llvm::Type *t);
|
||||
|
||||
/** Returns a constant integer or vector (according to the given type) of
|
||||
the given unsigned integer value. */
|
||||
extern llvm::Constant *LLVMUIntAsType(uint64_t, LLVM_TYPE_CONST llvm::Type *t);
|
||||
|
||||
/** Returns an LLVM boolean vector based on the given array of values.
|
||||
The array should have g->target.vectorWidth elements. */
|
||||
extern llvm::Constant *LLVMBoolVector(const bool *v);
|
||||
|
||||
Reference in New Issue
Block a user