llvm

Adding intrinsics using an LLVM pass

北战南征 提交于 2019-12-08 20:06:56
问题 I've added an intrinsic to an input code using an LLVM pass. I'm able to see the intrinsic call, yet I can't figure out how to compile the code to my target architecture (x86_64). I'm running the following command: clang++ $(llvm-config --ldflags --libs all) ff.s -o foo But the linker complains about undefined references: /tmp/ff-2ada42.o: In function `fact(unsigned int)': /home/rubens/Desktop/ff.cpp:9: undefined reference to `llvm.x86.sse3.mwait.i32.i32' /tmp/ff-2ada42.o: In function `fib

Clang producing executable with illegal instruction

天涯浪子 提交于 2019-12-08 19:21:24
问题 I boiled the problem I'm seeing down to a small example. Here is the LLVM assembler code I'm using (in foo.ll): target datalayout = "e-p:64:64:64-S128-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f16:16:16-f32:32:32-f64:64:64-f128:128:128-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" target triple = "x86_64-pc-linux-gnu" define fastcc i32 @foo(i32) { entry: %x = add i32 %0, 1 ret i32 %x } define i32 @main(i32, i8**) { entry: %2 = call i32 @foo(i32 %0) ret i32 %2 } I then

How do you handle 'require( …, bail)' statements with ARC?

帅比萌擦擦* 提交于 2019-12-08 19:20:49
问题 I'm looking through some of the sample code for the Square Cam in Apple's sample code. I want to replicate some of it's functionality in a modern project using ARC. However, there are a ton of require statements such as: BOOL success = (destination != NULL); require(success, bail); Which generates the compiler error: Goto into protected scope. My question is -- what is the appropriate way to handle such statements in a project using ARC? 回答1: I had the same problem (with the same sample code)

What are the difference between byte code and bit code [duplicate]

风格不统一 提交于 2019-12-08 18:56:31
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: What are the differences between LLVM and java bytecode? For example, in LLVM, it said.. What is commonly known as the LLVM bitcode file format (also, sometimes anachronistically known as bytecode) is actually two things: a bitstream container format and an encoding of LLVM IR into the container format. I only know Java Bytecode which is platform independent which can be run by the JVM But for the LLVM bit code,

dynamic_cast on llvm clang compiler failing

折月煮酒 提交于 2019-12-08 17:47:10
问题 I am seeing a strange failure where the dynamic_cast is returning NULL on clang compiler. But the same code is working with gcc environment. Could you please point me what might be the root cause? What might the difference between the dynamic_cast on llvm and gcc. I am using the default behavior of both the compiler where i think the RTTI is enable by default. template<typename T> T* find_msg_of_type( MsgList *list ) { T* msg = NULL; if (list) { for (std::vector<MsgList*>::iterator it = list-

How to check if instruction is a PHI instruction in LLVM IR

我的梦境 提交于 2019-12-08 17:07:53
问题 I am writing an LLVM pass. For an instruction (llvm::Instruction Class), how can I check if an instruction is a PHI instruction? 回答1: I found the solution. You can check for a PHI node like this, isa<PHINode>(inst) . 回答2: Instruction* I; if(I->getOpcode()==Instruction::PHI){ //code } 来源: https://stackoverflow.com/questions/9470505/how-to-check-if-instruction-is-a-phi-instruction-in-llvm-ir

Can Haskell optimize function calls the same way Clang / GCC does?

瘦欲@ 提交于 2019-12-08 16:01:30
问题 I want to ask you if Haskell and C++ compilers can optimize function calls the same way. Please look at following codes. In the following example Haskell is significantly faster than C++. I have heard that Haskell can compile to LLVM and can be optimized by the LLVM passes. Additionally I have heard that Haskell has some heavy optimizations under the hood. But the following examples should be able to work with the same performance. I want to ask: Why my sample benchmark in C++ is slower than

LLVM ERROR: Cannot yet select: error

笑着哭i 提交于 2019-12-08 15:09:18
问题 Hello i am getting the following error when I am running my app in the simulator. LLVM ERROR: Cannot yet select: ... It seems that other have reported similar issues for the same combo: * New sandy bridge MBP * Iphone 4.3 Simulator * opengl Anyone have some clue? Here is a short excerpt from the log: LLVM ERROR: Cannot yet select: 0xa0237d8: v16i8 = bit_convert 0xa02aa48 [ORD=259] [ID=170] 0xa02aa48: v8i16 = X86ISD::PSHUFLW 0xa02a828, 0xa02a608 [ID=166] 0xa02a828: v8i16 = X86ISD::PSHUFHW

LLVM equivalent of gcc -D macro definition on commandline

ぃ、小莉子 提交于 2019-12-08 14:43:52
问题 I am looking for LLVM (or clang) equivalent of gcc's -D flag which enables macro definition at commandline. Any pointers would be great. 回答1: From clang --cc1 --help : ... -D <macro> Predefine the specified macro ... As a rule of thumb, assume that Clang emulates GCC, unless proven otherwise! 回答2: The default clang invocation is a gcc-like compiler driver, supporting the same options as gcc, including -D : : ~$ cat test/z.c int foo() { return FOOBAR; } : ~$ clang -DFOOBAR -E -c test/z.c # 1

Clang IfStmt with shortcut binary operator in condition

为君一笑 提交于 2019-12-08 12:43:12
问题 I am trying to detect if there is a function call inside an if statement as part of condition; like following: if (cmp(a, b)){ \\do something } I have found I could do this with AST matcher in following manner: Matcher.addMatcher(ifStmt(hasCondition(callExpr().bind("call_expr"))) .bind("call_if_stmt"),&handleMatch); But the problem is condition could have shortcuts like &&, ||; like following: if(a != b && cmp(a,b) || c == 10){ \\ do something } Now this condition has binaryoperator && and ||