| author | |
| committer | |
| log | 5c04730534ea7933855429c5fc5dc7b22eba7bc2 |
| tree | 6270702f9aefc48a6a1eabfa61c3e8209d020569 |
| parent | fd634f3db35791ea904e82a525e4f49f4c5b67a8 |
closes #2425 files changed, 41 insertions(+), 24 deletions(-)
src/codegen.cpp+3-2| ... | ... | @@ -1772,9 +1772,10 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru |
| 1772 | 1772 | } |
| 1773 | 1773 | LLVMTypeRef function_type = LLVMFunctionType(ret_type, param_types, input_and_output_count, false); |
| 1774 | 1774 | |
| 1775 | bool is_x86 = (g->zig_target.arch.arch == ZigLLVM_x86 || g->zig_target.arch.arch == ZigLLVM_x86_64); | |
| 1775 | 1776 | bool is_volatile = asm_expr->is_volatile || (asm_expr->output_list.length == 0); |
| 1776 | LLVMValueRef asm_fn = LLVMConstInlineAsm(function_type, buf_ptr(&llvm_template), | |
| 1777 | buf_ptr(&constraint_buf), is_volatile, false); | |
| 1777 | LLVMValueRef asm_fn = ZigLLVMConstInlineAsm(function_type, buf_ptr(&llvm_template), | |
| 1778 | buf_ptr(&constraint_buf), is_volatile, false, is_x86); | |
| 1778 | 1779 | |
| 1779 | 1780 | return LLVMBuildCall(g->builder, asm_fn, param_values, input_and_output_count, ""); |
| 1780 | 1781 | } |
src/zig_llvm.cpp+24-11| ... | ... | @@ -22,22 +22,23 @@ |
| 22 | 22 | * 3. Prevent C++ from infecting the rest of the project. |
| 23 | 23 | */ |
| 24 | 24 | |
| 25 | #include <llvm/Analysis/TargetLibraryInfo.h> | |
| 26 | #include <llvm/Analysis/TargetTransformInfo.h> | |
| 27 | #include <llvm/IR/DIBuilder.h> | |
| 28 | #include <llvm/IR/DiagnosticInfo.h> | |
| 29 | #include <llvm/IR/IRBuilder.h> | |
| 30 | #include <llvm/IR/InlineAsm.h> | |
| 31 | #include <llvm/IR/Instructions.h> | |
| 32 | #include <llvm/IR/LegacyPassManager.h> | |
| 33 | #include <llvm/IR/Module.h> | |
| 34 | #include <llvm/IR/Verifier.h> | |
| 25 | 35 | #include <llvm/InitializePasses.h> |
| 26 | #include <llvm/PassRegistry.h> | |
| 27 | 36 | #include <llvm/MC/SubtargetFeature.h> |
| 28 | #include <llvm/Support/raw_ostream.h> | |
| 37 | #include <llvm/PassRegistry.h> | |
| 29 | 38 | #include <llvm/Support/FileSystem.h> |
| 30 | 39 | #include <llvm/Support/TargetParser.h> |
| 40 | #include <llvm/Support/raw_ostream.h> | |
| 31 | 41 | #include <llvm/Target/TargetMachine.h> |
| 32 | #include <llvm/IR/LegacyPassManager.h> | |
| 33 | #include <llvm/IR/Module.h> | |
| 34 | #include <llvm/IR/Verifier.h> | |
| 35 | #include <llvm/IR/Instructions.h> | |
| 36 | #include <llvm/IR/IRBuilder.h> | |
| 37 | #include <llvm/IR/DIBuilder.h> | |
| 38 | #include <llvm/IR/DiagnosticInfo.h> | |
| 39 | #include <llvm/Analysis/TargetLibraryInfo.h> | |
| 40 | #include <llvm/Analysis/TargetTransformInfo.h> | |
| 41 | 42 | #include <llvm/Transforms/IPO.h> |
| 42 | 43 | #include <llvm/Transforms/IPO/PassManagerBuilder.h> |
| 43 | 44 | #include <llvm/Transforms/Scalar.h> |
| ... | ... | @@ -139,6 +140,18 @@ LLVMValueRef ZigLLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *A |
| 139 | 140 | return wrap(unwrap(B)->Insert(call_inst)); |
| 140 | 141 | } |
| 141 | 142 | |
| 143 | LLVMValueRef ZigLLVMConstInlineAsm(LLVMTypeRef Ty, const char *AsmString, | |
| 144 | const char *Constraints, bool HasSideEffects, bool IsAlignStack, bool is_x86) | |
| 145 | { | |
| 146 | if (is_x86) { | |
| 147 | return wrap(InlineAsm::get(dyn_cast<FunctionType>(unwrap(Ty)), AsmString, | |
| 148 | Constraints, HasSideEffects, IsAlignStack, InlineAsm::AD_Intel)); | |
| 149 | } else { | |
| 150 | return wrap(InlineAsm::get(dyn_cast<FunctionType>(unwrap(Ty)), AsmString, | |
| 151 | Constraints, HasSideEffects, IsAlignStack)); | |
| 152 | } | |
| 153 | } | |
| 154 | ||
| 142 | 155 | void ZigLLVMFnSetSubprogram(LLVMValueRef fn, ZigLLVMDISubprogram *subprogram) { |
| 143 | 156 | assert( isa<Function>(unwrap(fn)) ); |
| 144 | 157 | Function *unwrapped_function = reinterpret_cast<Function*>(unwrap(fn)); |
src/zig_llvm.hpp+3| ... | ... | @@ -39,6 +39,9 @@ void ZigLLVMOptimizeModule(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef |
| 39 | 39 | LLVMValueRef ZigLLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args, |
| 40 | 40 | unsigned NumArgs, unsigned CC, const char *Name); |
| 41 | 41 | |
| 42 | LLVMValueRef ZigLLVMConstInlineAsm(LLVMTypeRef Ty, const char *AsmString, | |
| 43 | const char *Constraints, bool HasSideEffects, bool IsAlignStack, bool is_x86); | |
| 44 | ||
| 42 | 45 | LLVMValueRef ZigLLVMBuildCmpXchg(LLVMBuilderRef builder, LLVMValueRef ptr, LLVMValueRef cmp, |
| 43 | 46 | LLVMValueRef new_val, LLVMAtomicOrdering success_ordering, |
| 44 | 47 | LLVMAtomicOrdering failure_ordering); |
std/bootstrap.zig+4-4| ... | ... | @@ -24,12 +24,12 @@ export nakedcc fn _start() -> unreachable { |
| 24 | 24 | |
| 25 | 25 | switch (@compileVar("arch")) { |
| 26 | 26 | Arch.x86_64 => { |
| 27 | argc = asm("mov (%%rsp), %[argc]": [argc] "=r" (-> usize)); | |
| 28 | argv = asm("lea 0x8(%%rsp), %[argv]": [argv] "=r" (-> &&u8)); | |
| 27 | argc = asm("mov %[argc], [rsp]": [argc] "=r" (-> usize)); | |
| 28 | argv = asm("lea %[argv], [rsp + 8h]": [argv] "=r" (-> &&u8)); | |
| 29 | 29 | }, |
| 30 | 30 | Arch.i386 => { |
| 31 | argc = asm("mov (%%esp), %[argc]": [argc] "=r" (-> usize)); | |
| 32 | argv = asm("lea 0x4(%%esp), %[argv]": [argv] "=r" (-> &&u8)); | |
| 31 | argc = asm("mov %[argc], [esp]": [argc] "=r" (-> usize)); | |
| 32 | argv = asm("lea %[argv], [esp + 4h]": [argv] "=r" (-> &&u8)); | |
| 33 | 33 | }, |
| 34 | 34 | else => @compileError("unsupported arch"), |
| 35 | 35 | } |
std/linux_i386.zig+7-7| ... | ... | @@ -420,20 +420,20 @@ pub const F_GETOWN_EX = 16; |
| 420 | 420 | pub const F_GETOWNER_UIDS = 17; |
| 421 | 421 | |
| 422 | 422 | pub inline fn syscall0(number: usize) -> usize { |
| 423 | asm volatile ("int $0x80" | |
| 423 | asm volatile ("int 80h" | |
| 424 | 424 | : [ret] "={eax}" (-> usize) |
| 425 | 425 | : [number] "{eax}" (number)) |
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | pub inline fn syscall1(number: usize, arg1: usize) -> usize { |
| 429 | asm volatile ("int $0x80" | |
| 429 | asm volatile ("int 80h" | |
| 430 | 430 | : [ret] "={eax}" (-> usize) |
| 431 | 431 | : [number] "{eax}" (number), |
| 432 | 432 | [arg1] "{ebx}" (arg1)) |
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize { |
| 436 | asm volatile ("int $0x80" | |
| 436 | asm volatile ("int 80h" | |
| 437 | 437 | : [ret] "={eax}" (-> usize) |
| 438 | 438 | : [number] "{eax}" (number), |
| 439 | 439 | [arg1] "{ebx}" (arg1), |
| ... | ... | @@ -441,7 +441,7 @@ pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize { |
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize { |
| 444 | asm volatile ("int $0x80" | |
| 444 | asm volatile ("int 80h" | |
| 445 | 445 | : [ret] "={eax}" (-> usize) |
| 446 | 446 | : [number] "{eax}" (number), |
| 447 | 447 | [arg1] "{ebx}" (arg1), |
| ... | ... | @@ -450,7 +450,7 @@ pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> |
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize { |
| 453 | asm volatile ("int $0x80" | |
| 453 | asm volatile ("int 80h" | |
| 454 | 454 | : [ret] "={eax}" (-> usize) |
| 455 | 455 | : [number] "{eax}" (number), |
| 456 | 456 | [arg1] "{ebx}" (arg1), |
| ... | ... | @@ -462,7 +462,7 @@ pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg |
| 462 | 462 | pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, |
| 463 | 463 | arg4: usize, arg5: usize) -> usize |
| 464 | 464 | { |
| 465 | asm volatile ("int $0x80" | |
| 465 | asm volatile ("int 80h" | |
| 466 | 466 | : [ret] "={eax}" (-> usize) |
| 467 | 467 | : [number] "{eax}" (number), |
| 468 | 468 | [arg1] "{ebx}" (arg1), |
| ... | ... | @@ -475,7 +475,7 @@ pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, |
| 475 | 475 | pub inline fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, |
| 476 | 476 | arg4: usize, arg5: usize, arg6: usize) -> usize |
| 477 | 477 | { |
| 478 | asm volatile ("int $0x80" | |
| 478 | asm volatile ("int 80h" | |
| 479 | 479 | : [ret] "={eax}" (-> usize) |
| 480 | 480 | : [number] "{eax}" (number), |
| 481 | 481 | [arg1] "{ebx}" (arg1), |