| author | |
| committer | |
| log | 1046ead0cc409287b88554a90c2f80718e1af46d |
| tree | eac81f83fe2955c0107e1cda684b1a2abc39b6d3 |
| parent | 7cea8f063f710d5fb2fb10723c3e6485b3e2b31d |
Previously, we did this so that we could insert a debug variable
declaration intrinsic on the alloca. But there is a dbg.value intrinsic
for declaring variables that are values.4 files changed, 41 insertions(+), 18 deletions(-)
src/codegen/llvm.zig+6-12| ... | @@ -5117,16 +5117,6 @@ pub const FuncGen = struct { | ... | @@ -5117,16 +5117,6 @@ pub const FuncGen = struct { |
| 5117 | self.arg_index += 1; | 5117 | self.arg_index += 1; |
| 5118 | 5118 | ||
| 5119 | const inst_ty = self.air.typeOfIndex(inst); | 5119 | const inst_ty = self.air.typeOfIndex(inst); |
| 5120 | const result: struct { ptr: *const llvm.Value, operand: *const llvm.Value } = r: { | ||
| 5121 | if (isByRef(inst_ty)) { | ||
| 5122 | break :r .{ .ptr = arg_val, .operand = arg_val }; | ||
| 5123 | } else { | ||
| 5124 | const ptr_val = self.buildAlloca(try self.dg.llvmType(inst_ty)); | ||
| 5125 | _ = self.builder.buildStore(arg_val, ptr_val); | ||
| 5126 | break :r .{ .ptr = ptr_val, .operand = arg_val }; | ||
| 5127 | } | ||
| 5128 | }; | ||
| 5129 | |||
| 5130 | if (self.dg.object.di_builder) |dib| { | 5120 | if (self.dg.object.di_builder) |dib| { |
| 5131 | const src_index = self.getSrcArgIndex(self.arg_index - 1); | 5121 | const src_index = self.getSrcArgIndex(self.arg_index - 1); |
| 5132 | const func = self.dg.decl.getFunction().?; | 5122 | const func = self.dg.decl.getFunction().?; |
| ... | @@ -5145,10 +5135,14 @@ pub const FuncGen = struct { | ... | @@ -5145,10 +5135,14 @@ pub const FuncGen = struct { |
| 5145 | 5135 | ||
| 5146 | const debug_loc = llvm.getDebugLoc(lbrace_line, lbrace_col, self.di_scope.?); | 5136 | const debug_loc = llvm.getDebugLoc(lbrace_line, lbrace_col, self.di_scope.?); |
| 5147 | const insert_block = self.builder.getInsertBlock(); | 5137 | const insert_block = self.builder.getInsertBlock(); |
| 5148 | _ = dib.insertDeclareAtEnd(result.ptr, di_local_var, debug_loc, insert_block); | 5138 | if (isByRef(inst_ty)) { |
| 5139 | _ = dib.insertDeclareAtEnd(arg_val, di_local_var, debug_loc, insert_block); | ||
| 5140 | } else { | ||
| 5141 | _ = dib.insertDbgValueIntrinsicAtEnd(arg_val, di_local_var, debug_loc, insert_block); | ||
| 5142 | } | ||
| 5149 | } | 5143 | } |
| 5150 | 5144 | ||
| 5151 | return result.operand; | 5145 | return arg_val; |
| 5152 | } | 5146 | } |
| 5153 | 5147 | ||
| 5154 | fn getSrcArgIndex(self: *FuncGen, runtime_index: u32) u32 { | 5148 | fn getSrcArgIndex(self: *FuncGen, runtime_index: u32) u32 { |
src/codegen/llvm/bindings.zig+9| ... | @@ -1700,6 +1700,15 @@ pub const DIBuilder = opaque { | ... | @@ -1700,6 +1700,15 @@ pub const DIBuilder = opaque { |
| 1700 | debug_loc: *DILocation, | 1700 | debug_loc: *DILocation, |
| 1701 | insert_before_instr: *const Value, | 1701 | insert_before_instr: *const Value, |
| 1702 | ) *const Value; | 1702 | ) *const Value; |
| 1703 | |||
| 1704 | pub const insertDbgValueIntrinsicAtEnd = ZigLLVMInsertDbgValueIntrinsicAtEnd; | ||
| 1705 | extern fn ZigLLVMInsertDbgValueIntrinsicAtEnd( | ||
| 1706 | dib: *DIBuilder, | ||
| 1707 | val: *const Value, | ||
| 1708 | var_info: *DILocalVariable, | ||
| 1709 | debug_loc: *DILocation, | ||
| 1710 | basic_block_ref: *const BasicBlock, | ||
| 1711 | ) *const Value; | ||
| 1703 | }; | 1712 | }; |
| 1704 | 1713 | ||
| 1705 | pub const DIFlags = opaque { | 1714 | pub const DIFlags = opaque { |
src/zig_llvm.cpp+13| ... | @@ -942,6 +942,19 @@ LLVMValueRef ZigLLVMInsertDeclareAtEnd(ZigLLVMDIBuilder *dibuilder, LLVMValueRef | ... | @@ -942,6 +942,19 @@ LLVMValueRef ZigLLVMInsertDeclareAtEnd(ZigLLVMDIBuilder *dibuilder, LLVMValueRef |
| 942 | return wrap(result); | 942 | return wrap(result); |
| 943 | } | 943 | } |
| 944 | 944 | ||
| 945 | LLVMValueRef ZigLLVMInsertDbgValueIntrinsicAtEnd(ZigLLVMDIBuilder *dib, LLVMValueRef val, | ||
| 946 | ZigLLVMDILocalVariable *var_info, ZigLLVMDILocation *debug_loc, | ||
| 947 | LLVMBasicBlockRef basic_block_ref) | ||
| 948 | { | ||
| 949 | Instruction *result = reinterpret_cast<DIBuilder*>(dib)->insertDbgValueIntrinsic( | ||
| 950 | unwrap(val), | ||
| 951 | reinterpret_cast<DILocalVariable *>(var_info), | ||
| 952 | reinterpret_cast<DIBuilder*>(dib)->createExpression(), | ||
| 953 | reinterpret_cast<DILocation*>(debug_loc), | ||
| 954 | static_cast<BasicBlock*>(unwrap(basic_block_ref))); | ||
| 955 | return wrap(result); | ||
| 956 | } | ||
| 957 | |||
| 945 | LLVMValueRef ZigLLVMInsertDeclare(ZigLLVMDIBuilder *dibuilder, LLVMValueRef storage, | 958 | LLVMValueRef ZigLLVMInsertDeclare(ZigLLVMDIBuilder *dibuilder, LLVMValueRef storage, |
| 946 | ZigLLVMDILocalVariable *var_info, ZigLLVMDILocation *debug_loc, LLVMValueRef insert_before_instr) | 959 | ZigLLVMDILocalVariable *var_info, ZigLLVMDILocation *debug_loc, LLVMValueRef insert_before_instr) |
| 947 | { | 960 | { |
src/zig_llvm.h+13-6| ... | @@ -273,13 +273,20 @@ ZIG_EXTERN_C void ZigLLVMFnSetSubprogram(LLVMValueRef fn, struct ZigLLVMDISubpro | ... | @@ -273,13 +273,20 @@ ZIG_EXTERN_C void ZigLLVMFnSetSubprogram(LLVMValueRef fn, struct ZigLLVMDISubpro |
| 273 | 273 | ||
| 274 | ZIG_EXTERN_C void ZigLLVMDIBuilderFinalize(struct ZigLLVMDIBuilder *dibuilder); | 274 | ZIG_EXTERN_C void ZigLLVMDIBuilderFinalize(struct ZigLLVMDIBuilder *dibuilder); |
| 275 | 275 | ||
| 276 | ZIG_EXTERN_C LLVMValueRef ZigLLVMInsertDeclareAtEnd(struct ZigLLVMDIBuilder *dibuilder, LLVMValueRef storage, | 276 | ZIG_EXTERN_C struct ZigLLVMDILocation *ZigLLVMGetDebugLoc(unsigned line, unsigned col, |
| 277 | struct ZigLLVMDILocalVariable *var_info, struct ZigLLVMDILocation *debug_loc, | 277 | struct ZigLLVMDIScope *scope); |
| 278 | LLVMBasicBlockRef basic_block_ref); | 278 | |
| 279 | ZIG_EXTERN_C LLVMValueRef ZigLLVMInsertDeclareAtEnd(struct ZigLLVMDIBuilder *dib, | ||
| 280 | LLVMValueRef storage, struct ZigLLVMDILocalVariable *var_info, | ||
| 281 | struct ZigLLVMDILocation *debug_loc, LLVMBasicBlockRef basic_block_ref); | ||
| 282 | |||
| 283 | ZIG_EXTERN_C LLVMValueRef ZigLLVMInsertDeclare(struct ZigLLVMDIBuilder *dib, | ||
| 284 | LLVMValueRef storage, struct ZigLLVMDILocalVariable *var_info, | ||
| 285 | struct ZigLLVMDILocation *debug_loc, LLVMValueRef insert_before_instr); | ||
| 279 | 286 | ||
| 280 | ZIG_EXTERN_C LLVMValueRef ZigLLVMInsertDeclare(struct ZigLLVMDIBuilder *dibuilder, LLVMValueRef storage, | 287 | ZIG_EXTERN_C LLVMValueRef ZigLLVMInsertDbgValueIntrinsicAtEnd(struct ZigLLVMDIBuilder *dib, |
| 281 | struct ZigLLVMDILocalVariable *var_info, struct ZigLLVMDILocation *debug_loc, LLVMValueRef insert_before_instr); | 288 | LLVMValueRef val, struct ZigLLVMDILocalVariable *var_info, |
| 282 | ZIG_EXTERN_C struct ZigLLVMDILocation *ZigLLVMGetDebugLoc(unsigned line, unsigned col, struct ZigLLVMDIScope *scope); | 289 | struct ZigLLVMDILocation *debug_loc, LLVMBasicBlockRef basic_block_ref); |
| 283 | 290 | ||
| 284 | ZIG_EXTERN_C void ZigLLVMSetFastMath(LLVMBuilderRef builder_wrapped, bool on_state); | 291 | ZIG_EXTERN_C void ZigLLVMSetFastMath(LLVMBuilderRef builder_wrapped, bool on_state); |
| 285 | ZIG_EXTERN_C void ZigLLVMSetTailCall(LLVMValueRef Call); | 292 | ZIG_EXTERN_C void ZigLLVMSetTailCall(LLVMValueRef Call); |