X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FVMCore%2FCore.cpp;h=30d8a9b12f8c030728fa6112447bb3986c499d88;hb=d9b0b025612992a0b724eeca8bdf10b1d7a5c355;hp=77d2e74cd223428d8305a948393bda9e2609141b;hpb=31116410de16f435d8c76c53e3d6b95fa812cd2c;p=oota-llvm.git diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp index 77d2e74cd22..30d8a9b12f8 100644 --- a/lib/VMCore/Core.cpp +++ b/lib/VMCore/Core.cpp @@ -13,6 +13,7 @@ //===----------------------------------------------------------------------===// #include "llvm-c/Core.h" +#include "llvm/Attributes.h" #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" @@ -114,6 +115,25 @@ void LLVMDumpModule(LLVMModuleRef M) { unwrap(M)->dump(); } +LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename, + char **ErrorMessage) { + std::string error; + raw_fd_ostream dest(Filename, error); + if (!error.empty()) { + *ErrorMessage = strdup(error.c_str()); + return true; + } + + unwrap(M)->print(dest, NULL); + + if (!error.empty()) { + *ErrorMessage = strdup(error.c_str()); + return true; + } + dest.flush(); + return false; +} + /*--.. Operations on inline assembler ......................................--*/ void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm) { unwrap(M)->setModuleInlineAsm(StringRef(Asm)); @@ -132,10 +152,11 @@ LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M) { LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty) { switch (unwrap(Ty)->getTypeID()) { - default: - assert(false && "Unhandled TypeID."); + default: llvm_unreachable("Unhandled TypeID."); case Type::VoidTyID: return LLVMVoidTypeKind; + case Type::HalfTyID: + return LLVMHalfTypeKind; case Type::FloatTyID: return LLVMFloatTypeKind; case Type::DoubleTyID: @@ -222,6 +243,9 @@ unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy) { /*--.. Operations on real types ............................................--*/ +LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C) { + return (LLVMTypeRef) Type::getHalfTy(*unwrap(C)); +} LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C) { return (LLVMTypeRef) Type::getFloatTy(*unwrap(C)); } @@ -241,6 +265,9 @@ LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C) { return (LLVMTypeRef) Type::getX86_MMXTy(*unwrap(C)); } +LLVMTypeRef LLVMHalfType(void) { + return LLVMHalfTypeInContext(LLVMGetGlobalContext()); +} LLVMTypeRef LLVMFloatType(void) { return LLVMFloatTypeInContext(LLVMGetGlobalContext()); } @@ -558,6 +585,17 @@ void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRe Dest[i] = wrap(N->getOperand(i)); } +void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name, + LLVMValueRef Val) +{ + NamedMDNode *N = unwrap(M)->getOrInsertNamedMetadata(name); + if (!N) + return; + MDNode *Op = Val ? unwrap(Val) : NULL; + if (Op) + N->addOperand(Op); +} + /*--.. Operations on scalar constants ......................................--*/ LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N, @@ -614,8 +652,8 @@ LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str, LLVMBool DontNullTerminate) { /* Inverted the sense of AddNull because ', 0)' is a better mnemonic for null termination than ', 1)'. */ - return wrap(ConstantArray::get(*unwrap(C), StringRef(Str, Length), - DontNullTerminate == 0)); + return wrap(ConstantDataArray::getString(*unwrap(C), StringRef(Str, Length), + DontNullTerminate == 0)); } LLVMValueRef LLVMConstStructInContext(LLVMContextRef C, LLVMValueRef *ConstantVals, @@ -660,8 +698,7 @@ LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size) { static LLVMOpcode map_to_llvmopcode(int opcode) { switch (opcode) { - default: - assert(0 && "Unhandled Opcode."); + default: llvm_unreachable("Unhandled Opcode."); #define HANDLE_INST(num, opc, clas) case num: return LLVM##opc; #include "llvm/Instruction.def" #undef HANDLE_INST @@ -671,12 +708,11 @@ static LLVMOpcode map_to_llvmopcode(int opcode) static int map_from_llvmopcode(LLVMOpcode code) { switch (code) { - default: - assert(0 && "Unhandled Opcode."); #define HANDLE_INST(num, opc, clas) case LLVM##opc: return num; #include "llvm/Instruction.def" #undef HANDLE_INST } + llvm_unreachable("Unhandled Opcode."); } /*--.. Constant expressions ................................................--*/ @@ -1040,8 +1076,6 @@ LLVMBool LLVMIsDeclaration(LLVMValueRef Global) { LLVMLinkage LLVMGetLinkage(LLVMValueRef Global) { switch (unwrap(Global)->getLinkage()) { - default: - assert(false && "Unhandled Linkage Type."); case GlobalValue::ExternalLinkage: return LLVMExternalLinkage; case GlobalValue::AvailableExternallyLinkage: @@ -1076,16 +1110,13 @@ LLVMLinkage LLVMGetLinkage(LLVMValueRef Global) { return LLVMCommonLinkage; } - // Should never get here. - return static_cast(0); + llvm_unreachable("Invalid GlobalValue linkage!"); } void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage) { GlobalValue *GV = unwrap(Global); switch (Linkage) { - default: - assert(false && "Unhandled Linkage Type."); case LLVMExternalLinkage: GV->setLinkage(GlobalValue::ExternalLinkage); break; @@ -1337,14 +1368,14 @@ void LLVMSetGC(LLVMValueRef Fn, const char *GC) { void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) { Function *Func = unwrap(Fn); const AttrListPtr PAL = Func->getAttributes(); - const AttrListPtr PALnew = PAL.addAttr(~0U, PA); + const AttrListPtr PALnew = PAL.addAttr(~0U, Attributes(PA)); Func->setAttributes(PALnew); } void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) { Function *Func = unwrap(Fn); const AttrListPtr PAL = Func->getAttributes(); - const AttrListPtr PALnew = PAL.removeAttr(~0U, PA); + const AttrListPtr PALnew = PAL.removeAttr(~0U, Attributes(PA)); Func->setAttributes(PALnew); } @@ -1352,7 +1383,7 @@ LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn) { Function *Func = unwrap(Fn); const AttrListPtr PAL = Func->getAttributes(); Attributes attr = PAL.getFnAttributes(); - return (LLVMAttribute)attr; + return (LLVMAttribute)attr.Raw(); } /*--.. Operations on parameters ............................................--*/ @@ -1414,18 +1445,18 @@ LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg) { } void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA) { - unwrap(Arg)->addAttr(PA); + unwrap(Arg)->addAttr(Attributes(PA)); } void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA) { - unwrap(Arg)->removeAttr(PA); + unwrap(Arg)->removeAttr(Attributes(PA)); } LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg) { Argument *A = unwrap(Arg); Attributes attr = A->getParent()->getAttributes().getParamAttributes( A->getArgNo()+1); - return (LLVMAttribute)attr; + return (LLVMAttribute)attr.Raw(); } @@ -1591,16 +1622,21 @@ LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst) { return (LLVMIntPredicate)0; } +LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst) { + if (Instruction *C = dyn_cast(unwrap(Inst))) + return map_to_llvmopcode(C->getOpcode()); + return (LLVMOpcode)0; +} + /*--.. Call and invoke instructions ........................................--*/ unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr) { Value *V = unwrap(Instr); if (CallInst *CI = dyn_cast(V)) return CI->getCallingConv(); - else if (InvokeInst *II = dyn_cast(V)) + if (InvokeInst *II = dyn_cast(V)) return II->getCallingConv(); llvm_unreachable("LLVMGetInstructionCallConv applies only to call and invoke!"); - return 0; } void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC) { @@ -1616,14 +1652,14 @@ void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute PA) { CallSite Call = CallSite(unwrap(Instr)); Call.setAttributes( - Call.getAttributes().addAttr(index, PA)); + Call.getAttributes().addAttr(index, Attributes(PA))); } void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute PA) { CallSite Call = CallSite(unwrap(Instr)); Call.setAttributes( - Call.getAttributes().removeAttr(index, PA)); + Call.getAttributes().removeAttr(index, Attributes(PA))); } void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index, @@ -2049,6 +2085,20 @@ LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str, return wrap(unwrap(B)->CreateGlobalStringPtr(Str, Name)); } +LLVMBool LLVMGetVolatile(LLVMValueRef MemAccessInst) { + Value *P = unwrap(MemAccessInst); + if (LoadInst *LI = dyn_cast(P)) + return LI->isVolatile(); + return cast(P)->isVolatile(); +} + +void LLVMSetVolatile(LLVMValueRef MemAccessInst, LLVMBool isVolatile) { + Value *P = unwrap(MemAccessInst); + if (LoadInst *LI = dyn_cast(P)) + return LI->setVolatile(isVolatile); + return cast(P)->setVolatile(isVolatile); +} + /*--.. Casts ...............................................................--*/ LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef B, LLVMValueRef Val,