[llvm] r220814 - [C API] PR19859: Add LLVMGetFCmpPredicate and LLVMConstRealGetDouble.
Peter Zotov
whitequark at whitequark.org
Tue Oct 28 12:46:44 PDT 2014
Author: whitequark
Date: Tue Oct 28 14:46:44 2014
New Revision: 220814
URL: http://llvm.org/viewvc/llvm-project?rev=220814&view=rev
Log:
[C API] PR19859: Add LLVMGetFCmpPredicate and LLVMConstRealGetDouble.
Patch by Gabriel Radanne <drupyog at zoho.com>.
Modified:
llvm/trunk/include/llvm-c/Core.h
llvm/trunk/lib/IR/Core.cpp
Modified: llvm/trunk/include/llvm-c/Core.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/Core.h?rev=220814&r1=220813&r2=220814&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/Core.h (original)
+++ llvm/trunk/include/llvm-c/Core.h Tue Oct 28 14:46:44 2014
@@ -1549,6 +1549,14 @@ unsigned long long LLVMConstIntGetZExtVa
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);
+
+/**
* @}
*/
@@ -2409,6 +2417,16 @@ LLVMOpcode LLVMGetInstructionOpcode(LL
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:
* * The instruction has no parent
Modified: llvm/trunk/lib/IR/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Core.cpp?rev=220814&r1=220813&r2=220814&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Core.cpp (original)
+++ llvm/trunk/lib/IR/Core.cpp Tue Oct 28 14:46:44 2014
@@ -774,6 +774,27 @@ long long LLVMConstIntGetSExtValue(LLVMV
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(LL
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 mapFromLLVMOrderin
case LLVMAtomicOrderingSequentiallyConsistent:
return SequentiallyConsistent;
}
-
+
llvm_unreachable("Invalid LLVMAtomicOrdering value!");
}
More information about the llvm-commits
mailing list