-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[NO MERGE] implement realloc_ref SIL instruction [INCOMPLETE] #17902
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -500,6 +500,11 @@ SILCloner<ImplClass>::visitAllocRefInst(AllocRefInst *Inst) { | |
doPostProcess(Inst, NewInst); | ||
} | ||
|
||
template <typename ImplClass> | ||
void SILCloner<ImplClass>::visitReallocRefInst(ReallocRefInst *Inst) { | ||
llvm_unreachable("unimplemented: incomplete realloc_ref implementation"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking about this part of the code this morning and this is really a mid-level infrastructure sort of thing. We should do it in this commit. I would just (again) copy what realloc ref does. |
||
} | ||
|
||
template<typename ImplClass> | ||
void | ||
SILCloner<ImplClass>::visitAllocRefDynamicInst(AllocRefDynamicInst *Inst) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1446,6 +1446,55 @@ class AllocRefInst final | |
} | ||
}; | ||
|
||
/// ReallocRefInst - This represents the reallocation primitive of a reference | ||
/// type. If the reallocation was successfully the reference is returned with | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was "successful" |
||
/// the altered size. If the reallocation failed the reference is returned at | ||
/// a new address in an allocation with the altered size and the contents are | ||
/// bit-wise copied. | ||
/// This is only useful for tail-allocated arrays and the new size must always | ||
/// be larger than the original size. | ||
class ReallocRefInst final | ||
: public InstructionBaseWithTrailingOperands< | ||
SILInstructionKind::ReallocRefInst, | ||
ReallocRefInst, | ||
AllocRefInstBase, SILType> { | ||
friend AllocRefInstBase; | ||
friend SILBuilder; | ||
|
||
ReallocRefInst(SILDebugLocation DebugLoc, SILFunction &F, SILType ObjectType, | ||
SILValue ExistingRef, ArrayRef<SILType> ElementTypes, | ||
ArrayRef<SILValue> AllOperands) | ||
: InstructionBaseWithTrailingOperands(AllOperands, DebugLoc, ObjectType, | ||
false, false, ElementTypes) { | ||
assert(AllOperands.size() >= ElementTypes.size()); | ||
std::uninitialized_copy(ElementTypes.begin(), ElementTypes.end(), | ||
getTrailingObjects<SILType>()); | ||
} | ||
|
||
static ReallocRefInst *create(SILDebugLocation DebugLoc, SILFunction &F, | ||
SILType ObjectType, SILValue ExistingRef, | ||
ArrayRef<SILType> ElementTypes, | ||
ArrayRef<SILValue> ElementCountOperands, | ||
SILOpenedArchetypesState &OpenedArchetypes); | ||
|
||
public: | ||
ArrayRef<Operand> getTypeDependentOperands() const { | ||
return getAllOperands().slice(getNumTailTypes()); | ||
} | ||
|
||
MutableArrayRef<Operand> getTypeDependentOperands() { | ||
return getAllOperands().slice(getNumTailTypes()); | ||
} | ||
|
||
SILValue getReallocPointer() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Btw, I just made up these names, feel free to use your intuition for better names. The names here that I made up I feel fail the DRY test since realloc is in the class name. Also, generally the way that this sort of thing is implemented is that you define an enum that defines the index and then use that with getOperand(unsigned) to get the right value. See StoreInst which follows that pattern. |
||
llvm_unreachable("Unimplemented! realloc_ref implementation incomplete"); | ||
} | ||
|
||
SILValue getReallocSize() { | ||
llvm_unreachable("Unimplemented! realloc_ref implementation incomplete"); | ||
} | ||
}; | ||
|
||
/// AllocRefDynamicInst - This represents the primitive allocation of | ||
/// an instance of a reference type whose runtime type is provided by | ||
/// the given metatype value. Aside from the reference count, the | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -367,6 +367,8 @@ namespace { | |
return true; | ||
} | ||
|
||
bool visitReallocRefInst(const ReallocRefInst *RHS) { return true; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You were right here. You should copy what alloc_ref tail does. I was wrong. |
||
|
||
bool visitAllocRefDynamicInst(const AllocRefDynamicInst *RHS) { | ||
return true; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you an drop the comment. The assert works well enough as docs. Sorry if I was unclear.