forked from OSchip/llvm-project
[C API] PR19859: Add LLVMGetFCmpPredicate and LLVMConstRealGetDouble.
Patch by Gabriel Radanne <drupyog@zoho.com>. llvm-svn: 220814
This commit is contained in:
parent
f0c809a19b
commit
1d98e6ddef
|
@ -1548,6 +1548,14 @@ unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
|
|||
*/
|
||||
long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
|
||||
|
||||
/**
|
||||
* Obtain the double value for an floating point constant value.
|
||||
* losesInfo indicates if some precision was lost in the conversion.
|
||||
*
|
||||
* @see llvm::ConstantFP::getDoubleValue
|
||||
*/
|
||||
double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *losesInfo);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
@ -2408,6 +2416,16 @@ LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
|
|||
*/
|
||||
LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
|
||||
|
||||
/**
|
||||
* Obtain the float predicate of an instruction.
|
||||
*
|
||||
* This is only valid for instructions that correspond to llvm::FCmpInst
|
||||
* or llvm::ConstantExpr whose opcode is llvm::Instruction::FCmp.
|
||||
*
|
||||
* @see llvm::FCmpInst::getPredicate()
|
||||
*/
|
||||
LLVMRealPredicate LLVMGetFCmpPredicate(LLVMValueRef Inst);
|
||||
|
||||
/**
|
||||
* Create a copy of 'this' instruction that is identical in all ways
|
||||
* except the following:
|
||||
|
|
|
@ -774,6 +774,27 @@ long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal) {
|
|||
return unwrap<ConstantInt>(ConstantVal)->getSExtValue();
|
||||
}
|
||||
|
||||
double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *LosesInfo) {
|
||||
ConstantFP *cFP = unwrap<ConstantFP>(ConstantVal) ;
|
||||
Type *Ty = cFP->getType();
|
||||
|
||||
if (Ty->isFloatTy()) {
|
||||
*LosesInfo = false;
|
||||
return cFP->getValueAPF().convertToFloat();
|
||||
}
|
||||
|
||||
if (Ty->isDoubleTy()) {
|
||||
*LosesInfo = false;
|
||||
return cFP->getValueAPF().convertToDouble();
|
||||
}
|
||||
|
||||
bool APFLosesInfo;
|
||||
APFloat APF = cFP->getValueAPF();
|
||||
APF.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven, &APFLosesInfo);
|
||||
*LosesInfo = APFLosesInfo;
|
||||
return APF.convertToDouble();
|
||||
}
|
||||
|
||||
/*--.. Operations on composite constants ...................................--*/
|
||||
|
||||
LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
|
||||
|
@ -1882,6 +1903,15 @@ LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst) {
|
|||
return (LLVMIntPredicate)0;
|
||||
}
|
||||
|
||||
LLVMRealPredicate LLVMGetFCmpPredicate(LLVMValueRef Inst) {
|
||||
if (FCmpInst *I = dyn_cast<FCmpInst>(unwrap(Inst)))
|
||||
return (LLVMRealPredicate)I->getPredicate();
|
||||
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(unwrap(Inst)))
|
||||
if (CE->getOpcode() == Instruction::FCmp)
|
||||
return (LLVMRealPredicate)CE->getPredicate();
|
||||
return (LLVMRealPredicate)0;
|
||||
}
|
||||
|
||||
LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst) {
|
||||
if (Instruction *C = dyn_cast<Instruction>(unwrap(Inst)))
|
||||
return map_to_llvmopcode(C->getOpcode());
|
||||
|
@ -2342,7 +2372,7 @@ static AtomicOrdering mapFromLLVMOrdering(LLVMAtomicOrdering Ordering) {
|
|||
case LLVMAtomicOrderingSequentiallyConsistent:
|
||||
return SequentiallyConsistent;
|
||||
}
|
||||
|
||||
|
||||
llvm_unreachable("Invalid LLVMAtomicOrdering value!");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue