diff --git a/sources/libLLVMSharp/CMakeLists.txt b/sources/libLLVMSharp/CMakeLists.txt index e171ffa6..99686d05 100644 --- a/sources/libLLVMSharp/CMakeLists.txt +++ b/sources/libLLVMSharp/CMakeLists.txt @@ -30,11 +30,14 @@ target_link_libraries(LLVMSharp PRIVATE LLVM-C) target_link_libraries(LLVMSharp PRIVATE LLVMDemangle) target_link_libraries(LLVMSharp PRIVATE LLVMAggressiveInstCombine) +target_link_libraries(LLVMSharp PRIVATE LLVMAnalysis) target_link_libraries(LLVMSharp PRIVATE LLVMCFGuard) target_link_libraries(LLVMSharp PRIVATE LLVMInstCombine) target_link_libraries(LLVMSharp PRIVATE LLVMInstrumentation) target_link_libraries(LLVMSharp PRIVATE LLVMipo) +target_link_libraries(LLVMSharp PRIVATE LLVMJITLink) target_link_libraries(LLVMSharp PRIVATE LLVMObjCARCOpts) +target_link_libraries(LLVMSharp PRIVATE LLVMOrcJIT) target_link_libraries(LLVMSharp PRIVATE LLVMScalarOpts) target_link_libraries(LLVMSharp PRIVATE LLVMTransformUtils) target_link_libraries(LLVMSharp PRIVATE LLVMVectorize) diff --git a/sources/libLLVMSharp/LLVMSharp.cpp b/sources/libLLVMSharp/LLVMSharp.cpp index 5e6c4504..f1120908 100644 --- a/sources/libLLVMSharp/LLVMSharp.cpp +++ b/sources/libLLVMSharp/LLVMSharp.cpp @@ -9,21 +9,43 @@ #endif // Library includes (<> instead of "") +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include +#include #include +#include #include +#include #include +#include #include +#include #include +#include #include #include +#include +#include +#include +#include #include +#include #include #include #include #include +#include #include #ifdef _MSC_VER @@ -35,9 +57,60 @@ using namespace llvm; // Create wrappers for C Binding types (see CBindingWrapping.h). DEFINE_ISA_CONVERSION_FUNCTIONS(Pass, LLVMPassRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(orc::ExecutionSession, LLVMOrcExecutionSessionRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(orc::ObjectLayer, LLVMOrcObjectLayerRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DominatorTree, LLVMSharpDominatorTreeRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Loop, LLVMSharpLoopRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LoopInfo, LLVMSharpLoopInfoRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PostDominatorTree, LLVMSharpPostDominatorTreeRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(TargetMachine, LLVMTargetMachineRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(TargetTransformInfo, LLVMSharpTargetTransformInfoRef) // Implementation code +LLVMValueRef llvmsharp_BasicBlock_getFirstInsertionPt(LLVMBasicBlockRef basic_block) +{ + BasicBlock* unwrapped = unwrap(basic_block); + BasicBlock::iterator it = unwrapped->getFirstInsertionPt(); + if (it == unwrapped->end()) + { + return nullptr; + } + return wrap(&*it); +} + +LLVMValueRef llvmsharp_BasicBlock_getFirstNonPHI(LLVMBasicBlockRef basic_block) +{ + BasicBlock* unwrapped = unwrap(basic_block); + BasicBlock::iterator it = unwrapped->getFirstNonPHIIt(); + if (it == unwrapped->end()) + { + return nullptr; + } + return wrap(&*it); +} + +uint8_t llvmsharp_CallBase_isIndirectCall(LLVMValueRef call) +{ + CallBase* unwrapped = unwrap(call); + return unwrapped->isIndirectCall() ? 1 : 0; +} + +LLVMValueRef llvmsharp_CloneFunction(LLVMValueRef function) +{ + Function* unwrapped = unwrap(function); + ValueToValueMapTy valueMap; + return wrap(CloneFunction(unwrapped, valueMap)); +} + +const char* llvmsharp_CmpInst_getPredicateName(LLVMValueRef instruction, int32_t* out_size) +{ + CmpInst* unwrapped = unwrap(instruction); + StringRef name = CmpInst::getPredicateName(unwrapped->getPredicate()); + *out_size = (int32_t)name.size(); + return name.data(); +} + const char* llvmsharp_ConstantDataArray_getData(LLVMValueRef array, int32_t* out_size) { ConstantDataArray* unwrapped = unwrap(array); @@ -46,6 +119,46 @@ const char* llvmsharp_ConstantDataArray_getData(LLVMValueRef array, int32_t* out return stringRef.data(); } +LLVMValueRef llvmsharp_ConstantFoldCompareInstOperands(int32_t predicate, LLVMValueRef lhs, LLVMValueRef rhs, LLVMModuleRef module) +{ + Constant* lhsConstant = unwrap(lhs); + Constant* rhsConstant = unwrap(rhs); + const DataLayout& dataLayout = unwrap(module)->getDataLayout(); + return wrap(ConstantFoldCompareInstOperands((unsigned)predicate, lhsConstant, rhsConstant, dataLayout)); +} + +LLVMValueRef llvmsharp_ConstantFoldConstant(LLVMValueRef constant, LLVMModuleRef module) +{ + Constant* unwrapped = unwrap(constant); + const DataLayout& dataLayout = unwrap(module)->getDataLayout(); + return wrap(ConstantFoldConstant(unwrapped, dataLayout)); +} + +LLVMValueRef llvmsharp_ConstantFoldInstruction(LLVMValueRef instruction, LLVMModuleRef module) +{ + Instruction* unwrapped = unwrap(instruction); + const DataLayout& dataLayout = unwrap(module)->getDataLayout(); + return wrap(ConstantFoldInstruction(unwrapped, dataLayout)); +} + +uint8_t llvmsharp_Constant_isAllOnesValue(LLVMValueRef value) +{ + Constant* unwrapped = unwrap(value); + return unwrapped->isAllOnesValue() ? 1 : 0; +} + +uint8_t llvmsharp_Constant_isNegativeZeroValue(LLVMValueRef value) +{ + Constant* unwrapped = unwrap(value); + return unwrapped->isNegativeZeroValue() ? 1 : 0; +} + +uint8_t llvmsharp_Constant_isOneValue(LLVMValueRef value) +{ + Constant* unwrapped = unwrap(value); + return unwrapped->isOneValue() ? 1 : 0; +} + uint32_t llvmsharp_DIBasicType_getEncoding(LLVMMetadataRef type) { DIBasicType* unwrapped = unwrap(type); @@ -323,6 +436,51 @@ LLVMMetadataRef llvmsharp_DIVariable_getType(LLVMMetadataRef variable) return wrap(unwrapped->getType()); } +LLVMSharpDominatorTreeRef llvmsharp_DominatorTree_create(LLVMValueRef function) +{ + Function* unwrapped = unwrap(function); + return wrap(new DominatorTree(*unwrapped)); +} + +void llvmsharp_DominatorTree_dispose(LLVMSharpDominatorTreeRef dominator_tree) +{ + delete unwrap(dominator_tree); +} + +uint8_t llvmsharp_DominatorTree_dominatesBlock(LLVMSharpDominatorTreeRef dominator_tree, LLVMBasicBlockRef a, LLVMBasicBlockRef b) +{ + DominatorTree* unwrapped = unwrap(dominator_tree); + return unwrapped->dominates(unwrap(a), unwrap(b)) ? 1 : 0; +} + +uint8_t llvmsharp_DominatorTree_dominatesInstruction(LLVMSharpDominatorTreeRef dominator_tree, LLVMValueRef def, LLVMValueRef user) +{ + DominatorTree* unwrapped = unwrap(dominator_tree); + return unwrapped->dominates(unwrap(def), unwrap(user)) ? 1 : 0; +} + +LLVMBasicBlockRef llvmsharp_DominatorTree_getIDom(LLVMSharpDominatorTreeRef dominator_tree, LLVMBasicBlockRef block) +{ + DominatorTree* unwrapped = unwrap(dominator_tree); + DomTreeNode* node = unwrapped->getNode(unwrap(block)); + if (node == nullptr) + { + return nullptr; + } + DomTreeNode* immediateDominator = node->getIDom(); + if (immediateDominator == nullptr) + { + return nullptr; + } + return wrap(immediateDominator->getBlock()); +} + +uint8_t llvmsharp_DominatorTree_properlyDominatesBlock(LLVMSharpDominatorTreeRef dominator_tree, LLVMBasicBlockRef a, LLVMBasicBlockRef b) +{ + DominatorTree* unwrapped = unwrap(dominator_tree); + return unwrapped->properlyDominates(unwrap(a), unwrap(b)) ? 1 : 0; +} + LLVMTypeRef llvmsharp_Function_getFunctionType(LLVMValueRef function) { Function* unwrapped = unwrap(function); @@ -330,6 +488,12 @@ LLVMTypeRef llvmsharp_Function_getFunctionType(LLVMValueRef function) return wrap(type); } +uint32_t llvmsharp_Function_getInstructionCount(LLVMValueRef function) +{ + Function* unwrapped = unwrap(function); + return unwrapped->getInstructionCount(); +} + LLVMTypeRef llvmsharp_Function_getReturnType(LLVMValueRef function) { Function* unwrapped = unwrap(function); @@ -337,6 +501,33 @@ LLVMTypeRef llvmsharp_Function_getReturnType(LLVMValueRef function) return wrap(type); } +uint8_t llvmsharp_GEPOperator_accumulateConstantOffset(LLVMValueRef gep, LLVMModuleRef module, int64_t* out_offset) +{ + GEPOperator* unwrapped = unwrap(gep); + const DataLayout& dataLayout = unwrap(module)->getDataLayout(); + unsigned bitWidth = dataLayout.getIndexTypeSizeInBits(unwrapped->getType()); + APInt offset(bitWidth, 0); + if (!unwrapped->accumulateConstantOffset(dataLayout, offset)) + { + *out_offset = 0; + return 0; + } + *out_offset = offset.getSExtValue(); + return 1; +} + +uint32_t llvmsharp_GlobalValue_getAddressSpace(LLVMValueRef global_value) +{ + GlobalValue* unwrapped = unwrap(global_value); + return unwrapped->getAddressSpace(); +} + +uint8_t llvmsharp_GlobalValue_isDSOLocal(LLVMValueRef global_value) +{ + GlobalValue* unwrapped = unwrap(global_value); + return unwrapped->isDSOLocal() ? 1 : 0; +} + LLVMMetadataRef llvmsharp_GlobalVariable_getGlobalVariableExpression(LLVMValueRef global_variable) { LLVMMetadataRef unwrapped = llvmsharp_GlobalVariable_getMetadata(global_variable, LLVMContext::MD_dbg); @@ -356,16 +547,181 @@ LLVMMetadataRef llvmsharp_GlobalVariable_getMetadata(LLVMValueRef global_variabl return wrap(unwrapped->getMetadata(KindID)); } -uint8_t llvmsharp_Instruction_hasNoSignedWrap(LLVMValueRef instruction) +uint8_t llvmsharp_InlineFunction(LLVMValueRef call_base) +{ + CallBase* unwrapped = unwrap(call_base); + InlineFunctionInfo inlineFunctionInfo; + InlineResult result = InlineFunction(*unwrapped, inlineFunctionInfo); + return result.isSuccess() ? 1 : 0; +} + +uint8_t llvmsharp_isSafeToSpeculativelyExecute(LLVMValueRef instruction) +{ + Instruction* unwrapped = unwrap(instruction); + return isSafeToSpeculativelyExecute(unwrapped) ? 1 : 0; +} + +uint8_t llvmsharp_Instruction_comesBefore(LLVMValueRef instruction, LLVMValueRef other) +{ + Instruction* unwrapped = unwrap(instruction); + return unwrapped->comesBefore(unwrap(other)) ? 1 : 0; +} + +const char* llvmsharp_Instruction_getOpcodeName(LLVMValueRef instruction, int32_t* out_size) +{ + Instruction* unwrapped = unwrap(instruction); + const char* name = unwrapped->getOpcodeName(); + *out_size = (int32_t)strlen(name); + return name; +} + +uint8_t llvmsharp_Instruction_isCommutative(LLVMValueRef instruction) +{ + Instruction* unwrapped = unwrap(instruction); + return unwrapped->isCommutative() ? 1 : 0; +} + +uint8_t llvmsharp_Instruction_isIdenticalTo(LLVMValueRef instruction, LLVMValueRef other) +{ + Instruction* unwrapped = unwrap(instruction); + return unwrapped->isIdenticalTo(unwrap(other)) ? 1 : 0; +} + +uint8_t llvmsharp_Instruction_isSameOperationAs(LLVMValueRef instruction, LLVMValueRef other) +{ + Instruction* unwrapped = unwrap(instruction); + return unwrapped->isSameOperationAs(unwrap(other)) ? 1 : 0; +} + +uint8_t llvmsharp_Instruction_mayHaveSideEffects(LLVMValueRef instruction) +{ + Instruction* unwrapped = unwrap(instruction); + return unwrapped->mayHaveSideEffects() ? 1 : 0; +} + +uint8_t llvmsharp_Instruction_mayReadFromMemory(LLVMValueRef instruction) +{ + Instruction* unwrapped = unwrap(instruction); + return unwrapped->mayReadFromMemory() ? 1 : 0; +} + +uint8_t llvmsharp_Instruction_mayWriteToMemory(LLVMValueRef instruction) { Instruction* unwrapped = unwrap(instruction); - return unwrapped->hasNoSignedWrap() ? 1 : 0; + return unwrapped->mayWriteToMemory() ? 1 : 0; } -uint8_t llvmsharp_Instruction_hasNoUnsignedWrap(LLVMValueRef instruction) +void llvmsharp_Instruction_moveAfter(LLVMValueRef instruction, LLVMValueRef position) { Instruction* unwrapped = unwrap(instruction); - return unwrapped->hasNoUnsignedWrap() ? 1 : 0; + unwrapped->moveAfter(unwrap(position)); +} + +void llvmsharp_Instruction_moveBefore(LLVMValueRef instruction, LLVMValueRef position) +{ + Instruction* unwrapped = unwrap(instruction); + Instruction* positionInstruction = unwrap(position); + unwrapped->moveBefore(positionInstruction->getIterator()); +} + +LLVMSharpLoopInfoRef llvmsharp_LoopInfo_create(LLVMSharpDominatorTreeRef dominator_tree) +{ + DominatorTree* unwrapped = unwrap(dominator_tree); + return wrap(new LoopInfo(*unwrapped)); +} + +void llvmsharp_LoopInfo_dispose(LLVMSharpLoopInfoRef loop_info) +{ + delete unwrap(loop_info); +} + +uint32_t llvmsharp_LoopInfo_getLoopDepth(LLVMSharpLoopInfoRef loop_info, LLVMBasicBlockRef block) +{ + LoopInfo* unwrapped = unwrap(loop_info); + return unwrapped->getLoopDepth(unwrap(block)); +} + +LLVMSharpLoopRef llvmsharp_LoopInfo_getLoopFor(LLVMSharpLoopInfoRef loop_info, LLVMBasicBlockRef block) +{ + LoopInfo* unwrapped = unwrap(loop_info); + return wrap(unwrapped->getLoopFor(unwrap(block))); +} + +uint8_t llvmsharp_Loop_containsBlock(LLVMSharpLoopRef loop, LLVMBasicBlockRef block) +{ + Loop* unwrapped = unwrap(loop); + return unwrapped->contains(unwrap(block)) ? 1 : 0; +} + +LLVMValueRef llvmsharp_Loop_getCanonicalInductionVariable(LLVMSharpLoopRef loop) +{ + Loop* unwrapped = unwrap(loop); + return wrap(unwrapped->getCanonicalInductionVariable()); +} + +LLVMBasicBlockRef llvmsharp_Loop_getExitBlock(LLVMSharpLoopRef loop) +{ + Loop* unwrapped = unwrap(loop); + return wrap(unwrapped->getExitBlock()); +} + +LLVMBasicBlockRef llvmsharp_Loop_getExitingBlock(LLVMSharpLoopRef loop) +{ + Loop* unwrapped = unwrap(loop); + return wrap(unwrapped->getExitingBlock()); +} + +LLVMBasicBlockRef llvmsharp_Loop_getHeader(LLVMSharpLoopRef loop) +{ + Loop* unwrapped = unwrap(loop); + return wrap(unwrapped->getHeader()); +} + +uint32_t llvmsharp_Loop_getLoopDepth(LLVMSharpLoopRef loop) +{ + Loop* unwrapped = unwrap(loop); + return unwrapped->getLoopDepth(); +} + +LLVMBasicBlockRef llvmsharp_Loop_getLoopLatch(LLVMSharpLoopRef loop) +{ + Loop* unwrapped = unwrap(loop); + return wrap(unwrapped->getLoopLatch()); +} + +LLVMBasicBlockRef llvmsharp_Loop_getLoopPreheader(LLVMSharpLoopRef loop) +{ + Loop* unwrapped = unwrap(loop); + return wrap(unwrapped->getLoopPreheader()); +} + +LLVMSharpLoopRef llvmsharp_Loop_getParentLoop(LLVMSharpLoopRef loop) +{ + Loop* unwrapped = unwrap(loop); + return wrap(unwrapped->getParentLoop()); +} + +const char* llvmsharp_Mangler_getNameWithPrefix(LLVMValueRef global_value, int32_t* out_size) +{ + GlobalValue* unwrapped = unwrap(global_value); + std::string result; + raw_string_ostream stream(result); + Mangler mangler; + mangler.getNameWithPrefix(stream, unwrapped, false); + stream.flush(); + + int32_t size = (int32_t)result.size(); + char* buffer = (char*)malloc((size_t)size + 1); + if (buffer == nullptr) + { + *out_size = 0; + return nullptr; // Memory allocation failed + } + + memcpy(buffer, result.data(), size); + buffer[size] = '\0'; + *out_size = size; + return buffer; } uint32_t llvmsharp_MDNode_getNumOperands(LLVMMetadataRef metadata) @@ -424,11 +780,144 @@ void llvmsharp_Module_GetIdentifiedStructTypes(LLVMModuleRef module, LLVMTypeRef *out_size = (int32_t)types.size(); } +LLVMOrcObjectLayerRef llvmsharp_OrcCreateObjectLinkingLayer(LLVMOrcExecutionSessionRef execution_session) +{ + orc::ExecutionSession* unwrapped = unwrap(execution_session); + orc::ObjectLinkingLayer* layer = new orc::ObjectLinkingLayer(*unwrapped); + return wrap(static_cast(layer)); +} + void llvmsharp_PassManager_add(LLVMPassManagerRef pass_manager, LLVMPassRef pass) { unwrap(pass_manager)->add(unwrap(pass)); } +LLVMSharpPostDominatorTreeRef llvmsharp_PostDominatorTree_create(LLVMValueRef function) +{ + Function* unwrapped = unwrap(function); + return wrap(new PostDominatorTree(*unwrapped)); +} + +void llvmsharp_PostDominatorTree_dispose(LLVMSharpPostDominatorTreeRef post_dominator_tree) +{ + delete unwrap(post_dominator_tree); +} + +uint8_t llvmsharp_PostDominatorTree_dominatesBlock(LLVMSharpPostDominatorTreeRef post_dominator_tree, LLVMBasicBlockRef a, LLVMBasicBlockRef b) +{ + PostDominatorTree* unwrapped = unwrap(post_dominator_tree); + return unwrapped->dominates(unwrap(a), unwrap(b)) ? 1 : 0; +} + +LLVMValueRef llvmsharp_simplifyInstruction(LLVMValueRef instruction, LLVMModuleRef module) +{ + Instruction* unwrapped = unwrap(instruction); + const DataLayout& dataLayout = unwrap(module)->getDataLayout(); + return wrap(simplifyInstruction(unwrapped, SimplifyQuery(dataLayout))); +} + +LLVMSharpTargetTransformInfoRef llvmsharp_TargetTransformInfo_create(LLVMTargetMachineRef target_machine, LLVMValueRef function) +{ + TargetMachine* targetMachine = unwrap(target_machine); + Function* unwrapped = unwrap(function); + return wrap(new TargetTransformInfo(targetMachine->getTargetTransformInfo(*unwrapped))); +} + +void llvmsharp_TargetTransformInfo_dispose(LLVMSharpTargetTransformInfoRef target_transform_info) +{ + delete unwrap(target_transform_info); +} + +uint8_t llvmsharp_TargetTransformInfo_getInstructionCost(LLVMSharpTargetTransformInfoRef target_transform_info, LLVMValueRef user, int32_t cost_kind, int64_t* out_cost) +{ + TargetTransformInfo* unwrapped = unwrap(target_transform_info); + InstructionCost cost = unwrapped->getInstructionCost(unwrap(user), (TargetTransformInfo::TargetCostKind)cost_kind); + if (!cost.isValid()) + { + *out_cost = 0; + return 0; + } + *out_cost = cost.getValue(); + return 1; +} + +uint32_t llvmsharp_TargetTransformInfo_getNumberOfRegisters(LLVMSharpTargetTransformInfoRef target_transform_info, uint32_t class_id) +{ + TargetTransformInfo* unwrapped = unwrap(target_transform_info); + return unwrapped->getNumberOfRegisters(class_id); +} + +uint32_t llvmsharp_TargetTransformInfo_getRegisterBitWidth(LLVMSharpTargetTransformInfoRef target_transform_info, int32_t register_kind, uint8_t* out_isScalable) +{ + TargetTransformInfo* unwrapped = unwrap(target_transform_info); + TypeSize size = unwrapped->getRegisterBitWidth((TargetTransformInfo::RegisterKind)register_kind); + *out_isScalable = size.isScalable() ? 1 : 0; + return (uint32_t)size.getKnownMinValue(); +} + +uint64_t llvmsharp_Type_getPrimitiveSizeInBits(LLVMTypeRef type, uint8_t* out_isScalable) +{ + Type* unwrapped = unwrap(type); + TypeSize size = unwrapped->getPrimitiveSizeInBits(); + *out_isScalable = size.isScalable() ? 1 : 0; + return size.getKnownMinValue(); +} + +uint32_t llvmsharp_Type_getScalarSizeInBits(LLVMTypeRef type) +{ + Type* unwrapped = unwrap(type); + return unwrapped->getScalarSizeInBits(); +} + +uint32_t llvmsharp_Value_getNumUses(LLVMValueRef value) +{ + Value* unwrapped = unwrap(value); + return (uint32_t)unwrapped->getNumUses(); +} + +uint64_t llvmsharp_Value_getPointerAlignment(LLVMValueRef value, LLVMModuleRef module) +{ + Value* unwrapped = unwrap(value); + const DataLayout& dataLayout = unwrap(module)->getDataLayout(); + return unwrapped->getPointerAlignment(dataLayout).value(); +} + +uint8_t llvmsharp_Value_hasOneUse(LLVMValueRef value) +{ + Value* unwrapped = unwrap(value); + return unwrapped->hasOneUse() ? 1 : 0; +} + +uint8_t llvmsharp_Value_hasOneUser(LLVMValueRef value) +{ + Value* unwrapped = unwrap(value); + return unwrapped->hasOneUser() ? 1 : 0; +} + +uint8_t llvmsharp_Value_isUsedInBasicBlock(LLVMValueRef value, LLVMBasicBlockRef basic_block) +{ + Value* unwrapped = unwrap(value); + return unwrapped->isUsedInBasicBlock(unwrap(basic_block)) ? 1 : 0; +} + +LLVMValueRef llvmsharp_Value_stripInBoundsOffsets(LLVMValueRef value) +{ + Value* unwrapped = unwrap(value); + return wrap(unwrapped->stripInBoundsOffsets()); +} + +LLVMValueRef llvmsharp_Value_stripPointerCasts(LLVMValueRef value) +{ + Value* unwrapped = unwrap(value); + return wrap(unwrapped->stripPointerCasts()); +} + +LLVMValueRef llvmsharp_Value_stripPointerCastsAndAliases(LLVMValueRef value) +{ + Value* unwrapped = unwrap(value); + return wrap(unwrapped->stripPointerCastsAndAliases()); +} + LLVMPassRef llvmsharp_createDeadCodeEliminationPass() { return wrap((Pass*)createDeadCodeEliminationPass()); diff --git a/sources/libLLVMSharp/LLVMSharp.h b/sources/libLLVMSharp/LLVMSharp.h index 30032a1b..53a77c84 100644 --- a/sources/libLLVMSharp/LLVMSharp.h +++ b/sources/libLLVMSharp/LLVMSharp.h @@ -10,6 +10,8 @@ // Include headers #include +#include +#include #include #ifdef _MSC_VER @@ -70,6 +72,12 @@ */ typedef struct LLVMOpaquePass* LLVMPassRef; +typedef struct LLVMSharpOpaqueDominatorTree* LLVMSharpDominatorTreeRef; +typedef struct LLVMSharpOpaqueLoop* LLVMSharpLoopRef; +typedef struct LLVMSharpOpaqueLoopInfo* LLVMSharpLoopInfoRef; +typedef struct LLVMSharpOpaquePostDominatorTree* LLVMSharpPostDominatorTreeRef; +typedef struct LLVMSharpOpaqueTargetTransformInfo* LLVMSharpTargetTransformInfoRef; + // Enum definitions // Struct definitions @@ -78,8 +86,30 @@ LLVM_CLANG_C_EXTERN_C_BEGIN // Function declarations +LLVMSHARP_LINKAGE LLVMValueRef llvmsharp_BasicBlock_getFirstInsertionPt(LLVMBasicBlockRef basic_block); + +LLVMSHARP_LINKAGE LLVMValueRef llvmsharp_BasicBlock_getFirstNonPHI(LLVMBasicBlockRef basic_block); + +LLVMSHARP_LINKAGE uint8_t llvmsharp_CallBase_isIndirectCall(LLVMValueRef call); + +LLVMSHARP_LINKAGE LLVMValueRef llvmsharp_CloneFunction(LLVMValueRef function); + +LLVMSHARP_LINKAGE const char* llvmsharp_CmpInst_getPredicateName(LLVMValueRef instruction, int32_t* out_size); + LLVMSHARP_LINKAGE const char* llvmsharp_ConstantDataArray_getData(LLVMValueRef array, int32_t* out_size); +LLVMSHARP_LINKAGE LLVMValueRef llvmsharp_ConstantFoldCompareInstOperands(int32_t predicate, LLVMValueRef lhs, LLVMValueRef rhs, LLVMModuleRef module); + +LLVMSHARP_LINKAGE LLVMValueRef llvmsharp_ConstantFoldConstant(LLVMValueRef constant, LLVMModuleRef module); + +LLVMSHARP_LINKAGE LLVMValueRef llvmsharp_ConstantFoldInstruction(LLVMValueRef instruction, LLVMModuleRef module); + +LLVMSHARP_LINKAGE uint8_t llvmsharp_Constant_isAllOnesValue(LLVMValueRef value); + +LLVMSHARP_LINKAGE uint8_t llvmsharp_Constant_isNegativeZeroValue(LLVMValueRef value); + +LLVMSHARP_LINKAGE uint8_t llvmsharp_Constant_isOneValue(LLVMValueRef value); + LLVMSHARP_LINKAGE uint32_t llvmsharp_DIBasicType_getEncoding(LLVMMetadataRef type); LLVMSHARP_LINKAGE LLVMMetadataRef llvmsharp_DICompositeType_getBaseType(LLVMMetadataRef type); @@ -148,17 +178,85 @@ LLVMSHARP_LINKAGE const char* llvmsharp_DIVariable_getName(LLVMMetadataRef varia LLVMSHARP_LINKAGE LLVMMetadataRef llvmsharp_DIVariable_getType(LLVMMetadataRef variable); +LLVMSHARP_LINKAGE LLVMSharpDominatorTreeRef llvmsharp_DominatorTree_create(LLVMValueRef function); + +LLVMSHARP_LINKAGE void llvmsharp_DominatorTree_dispose(LLVMSharpDominatorTreeRef dominator_tree); + +LLVMSHARP_LINKAGE uint8_t llvmsharp_DominatorTree_dominatesBlock(LLVMSharpDominatorTreeRef dominator_tree, LLVMBasicBlockRef a, LLVMBasicBlockRef b); + +LLVMSHARP_LINKAGE uint8_t llvmsharp_DominatorTree_dominatesInstruction(LLVMSharpDominatorTreeRef dominator_tree, LLVMValueRef def, LLVMValueRef user); + +LLVMSHARP_LINKAGE LLVMBasicBlockRef llvmsharp_DominatorTree_getIDom(LLVMSharpDominatorTreeRef dominator_tree, LLVMBasicBlockRef block); + +LLVMSHARP_LINKAGE uint8_t llvmsharp_DominatorTree_properlyDominatesBlock(LLVMSharpDominatorTreeRef dominator_tree, LLVMBasicBlockRef a, LLVMBasicBlockRef b); + LLVMSHARP_LINKAGE LLVMTypeRef llvmsharp_Function_getFunctionType(LLVMValueRef function); +LLVMSHARP_LINKAGE uint32_t llvmsharp_Function_getInstructionCount(LLVMValueRef function); + LLVMSHARP_LINKAGE LLVMTypeRef llvmsharp_Function_getReturnType(LLVMValueRef function); +LLVMSHARP_LINKAGE uint8_t llvmsharp_GEPOperator_accumulateConstantOffset(LLVMValueRef gep, LLVMModuleRef module, int64_t* out_offset); + +LLVMSHARP_LINKAGE uint32_t llvmsharp_GlobalValue_getAddressSpace(LLVMValueRef global_value); + +LLVMSHARP_LINKAGE uint8_t llvmsharp_GlobalValue_isDSOLocal(LLVMValueRef global_value); + LLVMSHARP_LINKAGE LLVMMetadataRef llvmsharp_GlobalVariable_getGlobalVariableExpression(LLVMValueRef global_variable); LLVMSHARP_LINKAGE LLVMMetadataRef llvmsharp_GlobalVariable_getMetadata(LLVMValueRef global_variable, uint32_t KindID); -LLVMSHARP_LINKAGE uint8_t llvmsharp_Instruction_hasNoSignedWrap(LLVMValueRef instruction); +LLVMSHARP_LINKAGE uint8_t llvmsharp_InlineFunction(LLVMValueRef call_base); + +LLVMSHARP_LINKAGE uint8_t llvmsharp_isSafeToSpeculativelyExecute(LLVMValueRef instruction); + +LLVMSHARP_LINKAGE uint8_t llvmsharp_Instruction_comesBefore(LLVMValueRef instruction, LLVMValueRef other); + +LLVMSHARP_LINKAGE const char* llvmsharp_Instruction_getOpcodeName(LLVMValueRef instruction, int32_t* out_size); + +LLVMSHARP_LINKAGE uint8_t llvmsharp_Instruction_isCommutative(LLVMValueRef instruction); + +LLVMSHARP_LINKAGE uint8_t llvmsharp_Instruction_isIdenticalTo(LLVMValueRef instruction, LLVMValueRef other); + +LLVMSHARP_LINKAGE uint8_t llvmsharp_Instruction_isSameOperationAs(LLVMValueRef instruction, LLVMValueRef other); + +LLVMSHARP_LINKAGE uint8_t llvmsharp_Instruction_mayHaveSideEffects(LLVMValueRef instruction); + +LLVMSHARP_LINKAGE uint8_t llvmsharp_Instruction_mayReadFromMemory(LLVMValueRef instruction); + +LLVMSHARP_LINKAGE uint8_t llvmsharp_Instruction_mayWriteToMemory(LLVMValueRef instruction); + +LLVMSHARP_LINKAGE void llvmsharp_Instruction_moveAfter(LLVMValueRef instruction, LLVMValueRef position); + +LLVMSHARP_LINKAGE void llvmsharp_Instruction_moveBefore(LLVMValueRef instruction, LLVMValueRef position); -LLVMSHARP_LINKAGE uint8_t llvmsharp_Instruction_hasNoUnsignedWrap(LLVMValueRef instruction); +LLVMSHARP_LINKAGE LLVMSharpLoopInfoRef llvmsharp_LoopInfo_create(LLVMSharpDominatorTreeRef dominator_tree); + +LLVMSHARP_LINKAGE void llvmsharp_LoopInfo_dispose(LLVMSharpLoopInfoRef loop_info); + +LLVMSHARP_LINKAGE uint32_t llvmsharp_LoopInfo_getLoopDepth(LLVMSharpLoopInfoRef loop_info, LLVMBasicBlockRef block); + +LLVMSHARP_LINKAGE LLVMSharpLoopRef llvmsharp_LoopInfo_getLoopFor(LLVMSharpLoopInfoRef loop_info, LLVMBasicBlockRef block); + +LLVMSHARP_LINKAGE uint8_t llvmsharp_Loop_containsBlock(LLVMSharpLoopRef loop, LLVMBasicBlockRef block); + +LLVMSHARP_LINKAGE LLVMValueRef llvmsharp_Loop_getCanonicalInductionVariable(LLVMSharpLoopRef loop); + +LLVMSHARP_LINKAGE LLVMBasicBlockRef llvmsharp_Loop_getExitBlock(LLVMSharpLoopRef loop); + +LLVMSHARP_LINKAGE LLVMBasicBlockRef llvmsharp_Loop_getExitingBlock(LLVMSharpLoopRef loop); + +LLVMSHARP_LINKAGE LLVMBasicBlockRef llvmsharp_Loop_getHeader(LLVMSharpLoopRef loop); + +LLVMSHARP_LINKAGE uint32_t llvmsharp_Loop_getLoopDepth(LLVMSharpLoopRef loop); + +LLVMSHARP_LINKAGE LLVMBasicBlockRef llvmsharp_Loop_getLoopLatch(LLVMSharpLoopRef loop); + +LLVMSHARP_LINKAGE LLVMBasicBlockRef llvmsharp_Loop_getLoopPreheader(LLVMSharpLoopRef loop); + +LLVMSHARP_LINKAGE LLVMSharpLoopRef llvmsharp_Loop_getParentLoop(LLVMSharpLoopRef loop); + +LLVMSHARP_LINKAGE const char* llvmsharp_Mangler_getNameWithPrefix(LLVMValueRef global_value, int32_t* out_size); LLVMSHARP_LINKAGE uint32_t llvmsharp_MDNode_getNumOperands(LLVMMetadataRef metadata); @@ -174,8 +272,48 @@ LLVM_FOR_EACH_METADATA_SUBCLASS(LLVMSHARP_METADATA_ISA) LLVMSHARP_LINKAGE void llvmsharp_Module_GetIdentifiedStructTypes(LLVMModuleRef module, LLVMTypeRef** out_buffer, int32_t* out_size); +LLVMSHARP_LINKAGE LLVMOrcObjectLayerRef llvmsharp_OrcCreateObjectLinkingLayer(LLVMOrcExecutionSessionRef execution_session); + LLVMSHARP_LINKAGE void llvmsharp_PassManager_add(LLVMPassManagerRef pass_manager, LLVMPassRef pass); +LLVMSHARP_LINKAGE LLVMSharpPostDominatorTreeRef llvmsharp_PostDominatorTree_create(LLVMValueRef function); + +LLVMSHARP_LINKAGE void llvmsharp_PostDominatorTree_dispose(LLVMSharpPostDominatorTreeRef post_dominator_tree); + +LLVMSHARP_LINKAGE uint8_t llvmsharp_PostDominatorTree_dominatesBlock(LLVMSharpPostDominatorTreeRef post_dominator_tree, LLVMBasicBlockRef a, LLVMBasicBlockRef b); + +LLVMSHARP_LINKAGE LLVMValueRef llvmsharp_simplifyInstruction(LLVMValueRef instruction, LLVMModuleRef module); + +LLVMSHARP_LINKAGE LLVMSharpTargetTransformInfoRef llvmsharp_TargetTransformInfo_create(LLVMTargetMachineRef target_machine, LLVMValueRef function); + +LLVMSHARP_LINKAGE void llvmsharp_TargetTransformInfo_dispose(LLVMSharpTargetTransformInfoRef target_transform_info); + +LLVMSHARP_LINKAGE uint8_t llvmsharp_TargetTransformInfo_getInstructionCost(LLVMSharpTargetTransformInfoRef target_transform_info, LLVMValueRef user, int32_t cost_kind, int64_t* out_cost); + +LLVMSHARP_LINKAGE uint32_t llvmsharp_TargetTransformInfo_getNumberOfRegisters(LLVMSharpTargetTransformInfoRef target_transform_info, uint32_t class_id); + +LLVMSHARP_LINKAGE uint32_t llvmsharp_TargetTransformInfo_getRegisterBitWidth(LLVMSharpTargetTransformInfoRef target_transform_info, int32_t register_kind, uint8_t* out_isScalable); + +LLVMSHARP_LINKAGE uint64_t llvmsharp_Type_getPrimitiveSizeInBits(LLVMTypeRef type, uint8_t* out_isScalable); + +LLVMSHARP_LINKAGE uint32_t llvmsharp_Type_getScalarSizeInBits(LLVMTypeRef type); + +LLVMSHARP_LINKAGE uint32_t llvmsharp_Value_getNumUses(LLVMValueRef value); + +LLVMSHARP_LINKAGE uint64_t llvmsharp_Value_getPointerAlignment(LLVMValueRef value, LLVMModuleRef module); + +LLVMSHARP_LINKAGE uint8_t llvmsharp_Value_hasOneUse(LLVMValueRef value); + +LLVMSHARP_LINKAGE uint8_t llvmsharp_Value_hasOneUser(LLVMValueRef value); + +LLVMSHARP_LINKAGE uint8_t llvmsharp_Value_isUsedInBasicBlock(LLVMValueRef value, LLVMBasicBlockRef basic_block); + +LLVMSHARP_LINKAGE LLVMValueRef llvmsharp_Value_stripInBoundsOffsets(LLVMValueRef value); + +LLVMSHARP_LINKAGE LLVMValueRef llvmsharp_Value_stripPointerCasts(LLVMValueRef value); + +LLVMSHARP_LINKAGE LLVMValueRef llvmsharp_Value_stripPointerCastsAndAliases(LLVMValueRef value); + LLVMSHARP_LINKAGE LLVMPassRef llvmsharp_createDeadCodeEliminationPass(); LLVMSHARP_LINKAGE LLVMPassRef llvmsharp_createSROAPass(uint8_t PreserveCFG);