Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Part 1 of well-defined copy elision #1652

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 93 additions & 15 deletions src/all_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct ZigWindowsSDK;
struct Tld;
struct TldExport;
struct IrAnalyze;
struct IrResultLocationAlloca;

enum X64CABIClass {
X64CABIClass_Unknown,
Expand Down Expand Up @@ -614,7 +615,6 @@ enum CastOp {
CastOpNumLitToConcrete,
CastOpErrSet,
CastOpBitCast,
CastOpPtrOfArrayToSlice,
};

struct AstNodeFnCallExpr {
Expand Down Expand Up @@ -1320,7 +1320,7 @@ struct ZigFn {
AstNode *fn_no_inline_set_node;
AstNode *fn_static_eval_set_node;

ZigList<IrInstruction *> alloca_list;
ZigList<IrResultLocationAlloca *> result_loc_alloca_list;
ZigList<ZigVar *> variable_list;

Buf *section_name;
Expand Down Expand Up @@ -2029,6 +2029,66 @@ struct IrBasicBlock {
IrInstruction *must_be_comptime_source_instr;
};

enum IrResultLocationId {
IrResultLocationIdVar,
IrResultLocationIdAlloca,
IrResultLocationIdLVal,
IrResultLocationIdRet,

IrResultLocationIdOptionalUnwrap,
IrResultLocationIdErrorUnionPayload,
IrResultLocationIdErrorUnionCode,
IrResultLocationIdArrayToSlice,
};

struct IrResultLocation {
IrResultLocation *child;
IrResultLocation *parent;
IrResultLocationId id;
bool from_call;
};

struct IrResultLocationVar {
IrResultLocation base;
ZigVar *var;
};

struct IrResultLocationAlloca {
IrResultLocation base;
LLVMValueRef alloca;
ZigType *ty;
};

struct IrResultLocationLVal {
IrResultLocation base;
IrInstruction *parent_instruction;
};

struct IrResultLocationRet {
IrResultLocation base;
};

struct IrResultLocationOptionalUnwrap {
IrResultLocation base;
LLVMValueRef result;
};

struct IrResultLocationErrorUnionPayload {
IrResultLocation base;
LLVMValueRef result;
};

struct IrResultLocationErrorUnionCode {
IrResultLocation base;
LLVMValueRef result;
};

struct IrResultLocationArrayToSlice {
IrResultLocation base;
LLVMValueRef result;
uint64_t len;
};

enum IrInstructionId {
IrInstructionIdInvalid,
IrInstructionIdBr,
Expand Down Expand Up @@ -2173,10 +2233,11 @@ enum IrInstructionId {
IrInstructionIdToBytes,
IrInstructionIdFromBytes,
IrInstructionIdCheckRuntimeScope,
IrInstructionIdResultLoc,
IrInstructionIdPtrOfArrayToSlice,
};

struct IrInstruction {
IrInstructionId id;
Scope *scope;
AstNode *source_node;
ConstExprValue value;
Expand All @@ -2190,6 +2251,8 @@ struct IrInstruction {
// with this child field.
IrInstruction *child;
IrBasicBlock *owner_bb;

IrInstructionId id;
// true if this instruction was generated by zig and not from user code
bool is_gen;
};
Expand Down Expand Up @@ -2320,6 +2383,7 @@ struct IrInstructionLoadPtr {
IrInstruction base;

IrInstruction *ptr;
IrResultLocation *result_location;
};

struct IrInstructionStorePtr {
Expand Down Expand Up @@ -2369,6 +2433,7 @@ struct IrInstructionVarPtr {

ZigVar *var;
ScopeFnDef *crossed_fndef_scope;
IrResultLocation *result_location;
};

struct IrInstructionCall {
Expand All @@ -2379,9 +2444,9 @@ struct IrInstructionCall {
size_t arg_count;
IrInstruction **args;
bool is_comptime;
LLVMValueRef tmp_ptr;
FnInline fn_inline;
bool is_async;
IrResultLocation *result_location;

IrInstruction *async_allocator;
IrInstruction *new_stack;
Expand All @@ -2407,7 +2472,7 @@ struct IrInstructionCast {
IrInstruction *value;
ZigType *dest_type;
CastOp cast_op;
LLVMValueRef tmp_ptr;
IrResultLocation *result_location;
};

struct IrInstructionContainerInitList {
Expand All @@ -2416,7 +2481,7 @@ struct IrInstructionContainerInitList {
IrInstruction *container_type;
size_t item_count;
IrInstruction **items;
LLVMValueRef tmp_ptr;
IrResultLocation *result_location;
};

struct IrInstructionContainerInitFieldsField {
Expand Down Expand Up @@ -2445,7 +2510,7 @@ struct IrInstructionStructInit {
ZigType *struct_type;
size_t field_count;
IrInstructionStructInitField *fields;
LLVMValueRef tmp_ptr;
IrResultLocation *result_location;
};

struct IrInstructionUnionInit {
Expand All @@ -2454,7 +2519,7 @@ struct IrInstructionUnionInit {
ZigType *union_type;
TypeUnionField *field;
IrInstruction *init_value;
LLVMValueRef tmp_ptr;
IrResultLocation *result_location;
};

struct IrInstructionUnreachable {
Expand Down Expand Up @@ -2604,9 +2669,9 @@ struct IrInstructionRef {
IrInstruction base;

IrInstruction *value;
LLVMValueRef tmp_ptr;
bool is_const;
bool is_volatile;
IrResultLocation *result_location;
};

struct IrInstructionMinValue {
Expand Down Expand Up @@ -2678,15 +2743,14 @@ struct IrInstructionCmpxchg {
IrInstruction *new_value;
IrInstruction *success_order_value;
IrInstruction *failure_order_value;
IrResultLocation *result_location;

// if this instruction gets to runtime then we know these values:
ZigType *type;
AtomicOrder success_order;
AtomicOrder failure_order;

bool is_weak;

LLVMValueRef tmp_ptr;
};

struct IrInstructionFence {
Expand Down Expand Up @@ -2794,8 +2858,8 @@ struct IrInstructionSlice {
IrInstruction *ptr;
IrInstruction *start;
IrInstruction *end;
IrResultLocation *result_location;
bool safety_check_on;
LLVMValueRef tmp_ptr;
};

struct IrInstructionMemberCount {
Expand Down Expand Up @@ -2883,21 +2947,21 @@ struct IrInstructionOptionalWrap {
IrInstruction base;

IrInstruction *value;
LLVMValueRef tmp_ptr;
IrResultLocation *result_location;
};

struct IrInstructionErrWrapPayload {
IrInstruction base;

IrInstruction *value;
LLVMValueRef tmp_ptr;
IrResultLocation *result_location;
};

struct IrInstructionErrWrapCode {
IrInstruction base;

IrInstruction *value;
LLVMValueRef tmp_ptr;
IrResultLocation *result_location;
};

struct IrInstructionFnProto {
Expand Down Expand Up @@ -3280,6 +3344,20 @@ struct IrInstructionCheckRuntimeScope {
IrInstruction *is_comptime;
};

struct IrInstructionResultLoc {
IrInstruction base;

IrInstruction *value;
IrResultLocation *result_location;
};

struct IrInstructionPtrOfArrayToSlice {
IrInstruction base;

IrInstruction *value;
IrResultLocation *result_location;
};

static const size_t slice_ptr_index = 0;
static const size_t slice_len_index = 1;

Expand Down
Loading