llvm

Identify array type in IR

社会主义新天地 提交于 2019-12-07 15:00:37
问题 I have been trying to identify array access in IR by making use of following code: for (BasicBlock::iterator ii = BB->begin(), ii2; ii != BB->end(); ii++) { Instruction *I=ii; if(GetElementPtrInst *getElePntr = dyn_cast<GetElementPtrInst>(&*I)) { Value *valAlloc = (getElePntr->getOperand(0)); if(getElePntr->getOperand(0)->getType()->isArrayTy()) { errs()<<"\tarray found"; } } } This code identifies getElementPtr instruction but it does not identify whether it's first operand is an array type

Issues running a simple out of source LLVM pass

社会主义新天地 提交于 2019-12-07 13:54:37
问题 I have been trying to write an LLVM Pass Following a mixture of this and this part of the documentation. I am assuming that since Mac comes with Clang and LLVM I should be able to use their installation to create plugins. So I made a directory layout as follows: optimizations CMakeLists.txt (--> outer) Hello CMakeLists.txt (--> inner) Hello.cpp The contents of "outer" is: find_package(LLVM REQUIRED CONFIG) list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") include(AddLLVM) add_definitions($

Run LLVM pass with opt

三世轮回 提交于 2019-12-07 12:14:45
问题 I have just started to work with LLVM. I have wrote my own Hello pass, which worked fine. Now I want to run opt with the stack protector pass, from StackProtector.cpp, but I am having trouble with that. When I look at the source code, it looks like I should use the flag -stack-protector: INITIALIZE_PASS(StackProtector, "stack-protector", "Insert stack protectors", false, false) But this flag is not recognized by opt. I am not sure which file to "load", as it is not as simple as loading my own

Building LLVM fails with empty error message

≯℡__Kan透↙ 提交于 2019-12-07 12:08:57
问题 I'm trying to build LLVM 3.1 and Clang 3.1. I followed the Getting Started guide from Clang's website- check out the repositories in the requisite places, get Python, etc. If I have Python 3.3 installed, it gives a Python semantic error- from main import main , no module called main . If I have Python 2.7 installed, it gives CMake Error at CMakeLists.txt:307 (message): Unexpected failure executing llvm-build: Configuring incomplete, errors occurred! This is most unhelpful. Any suggestions as

Getting actual value of local variables in llvm

旧城冷巷雨未停 提交于 2019-12-07 11:45:21
问题 If I have this example: int a=0, b=0; a and b are local variables and make any modifications in their values, such as: a++; b++; I need to get the value in this line code during running MCJIT. I mean by value not Value class, but the actual integer or any type value. 回答1: You need to return the value from a JITed LLVM function in order to retrieve it from the code invoking MCJIT. Check out this Kaleidoscope example. The relevant code is in HandleTopLevelExpression(): if (FunctionAST *F =

Generate call to intrinsic using LLVM C API

我只是一个虾纸丫 提交于 2019-12-07 11:12:50
问题 I'm working on some code that uses the LLVM C API. How do I use intrinsics, such as llvm.cos.f64 or llvm.sadd.with.overflow.i32 ? Whenever I try to do it by generating a global with LLVMAddGlobal (with the correct type signature), I just get this error message during the JIT linking stage: LLVM ERROR: Could not resolve external global address: llvm.cos.f64 I'm not using the LLVM C++ interface , so the advice in LLVM insert intrinsic function Cos does not seem to apply. I presume I need

Why don't LLVM passes optimize floating point instructions? [duplicate]

巧了我就是萌 提交于 2019-12-07 11:05:15
问题 This question already has answers here : Why doesn't GCC optimize a*a*a*a*a*a to (a*a*a)*(a*a*a)? (12 answers) Closed 6 years ago . See above. I wrote to sample functions: source.ll: define i32 @bleh(i32 %x) { entry: %addtmp = add i32 %x, %x %addtmp1 = add i32 %addtmp, %x %addtmp2 = add i32 %addtmp1, %x %addtmp3 = add i32 %addtmp2, %x %addtmp4 = add i32 %addtmp3, 1 %addtmp5 = add i32 %addtmp4, 2 %addtmp6 = add i32 %addtmp5, 3 %multmp = mul i32 %x, 3 %addtmp7 = add i32 %addtmp6, %multmp ret

LLVM tail call optimization

放肆的年华 提交于 2019-12-07 07:58:59
问题 Here is my understanding of things: A function "f" is tail recursive when calling itself is its last action. Tail-recursion can be significantly optimized by forming a loop instead of calling the function again; the function's parameters are updated in place, and the body is ran again. This is called recursive tail call optimization. LLVM implements recursive tail call optimization when using fastcc, GHC, or the HiPE calling convention. http://llvm.org/docs/CodeGenerator.html#tail-call

Xcode warning: … is a GNU extension

半腔热情 提交于 2019-12-07 07:31:19
问题 I use a C++ library for an iOS app. With Apple LLVM 3.1 compiler configured (default), I get a lot of warnings for this C++ code, most of them saying: ... is a GNU extension The introduction of clang's user manual says: The Clang driver and language features are intentionally designed to be as compatible with the GNU GCC compiler as reasonably possible, easing migration from GCC to Clang. In most cases, code "just works". So, is it save to just look for a switch to disable this warnings (btw.

Reducing GCC target EXE code size?

不打扰是莪最后的温柔 提交于 2019-12-07 06:45:08
问题 When I compiled a no-op program: int main(void) { return 0; } with various compilers: GCC (similar result to LLVM as well): Gave a 10-KiB executable (compiled with -s ) Sections: .CRT , .bss , .data , .idata , .rdata , .text , .tls Depends on msvcrt.dll and kernel32.dll MSVC 2010: Gave a 5.5 KiB executable (compiled with /MD /Ox ) Sections: .data , .rdata , .reloc , .text Depends on msvcr100.dll and kernel32.dll Could have been further reduced by merging .rdata with .text Windows Driver Kit 7