-
Notifications
You must be signed in to change notification settings - Fork 7
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
Process ptradd instructions and global operands. #975
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -340,18 +340,12 @@ impl LoadArgInstruction { | |
pub struct LoadGlobalInstruction { | ||
/// The pointer to load from. | ||
global_idx: GlobalIdx, | ||
/// The type of the pointee. | ||
ty_idx: TypeIdx, | ||
} | ||
|
||
impl LoadGlobalInstruction { | ||
pub(crate) fn new( | ||
global_idx: aot_ir::GlobalIdx, | ||
ty_idx: TypeIdx, | ||
) -> Result<Self, CompilationError> { | ||
pub(crate) fn new(global_idx: aot_ir::GlobalIdx) -> Result<Self, CompilationError> { | ||
Ok(Self { | ||
global_idx: GlobalIdx::from_aot(global_idx)?, | ||
ty_idx, | ||
}) | ||
} | ||
} | ||
|
@@ -380,7 +374,7 @@ pub struct CallInstruction { | |
|
||
impl fmt::Display for CallInstruction { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "LoadArg") | ||
write!(f, "Call") | ||
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. Oops :) |
||
} | ||
} | ||
|
||
|
@@ -520,9 +514,17 @@ impl PtrAddInstruction { | |
let ptr = self.ptr; | ||
ptr.get() | ||
} | ||
|
||
fn offset(&self) -> u32 { | ||
self.off | ||
} | ||
|
||
pub(crate) fn new(ptr: Operand, off: u32) -> Self { | ||
Self { | ||
ptr: PackedOperand::new(&ptr), | ||
off, | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Display for PtrAddInstruction { | ||
|
@@ -675,7 +677,7 @@ mod tests { | |
assert_eq!(mem::size_of::<CallInstruction>(), 7); | ||
assert_eq!(mem::size_of::<StoreInstruction>(), 4); | ||
assert_eq!(mem::size_of::<LoadInstruction>(), 6); | ||
assert_eq!(mem::size_of::<LoadGlobalInstruction>(), 6); | ||
assert_eq!(mem::size_of::<LoadGlobalInstruction>(), 3); | ||
assert_eq!(mem::size_of::<StoreGlobalInstruction>(), 6); | ||
assert_eq!(mem::size_of::<PtrAddInstruction>(), 6); | ||
assert!(mem::size_of::<Instruction>() <= mem::size_of::<u64>()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
How comes this goes?
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.
When we emit the instruction manually from a global (which currently doesn't have a type), what should we put here? I believe the return type of all globals is
ptr
anyway, so there's probably no point. We do need to somehow work out the actual type later on when codegenning this, but I believe that can be retrieved from the use site. E.g. when we pass the ptr into a call, the call arg will tell us what type it expects.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.
That depends on the semantics of your load.
In LLVM you'd always get the type that's pointed to.
Let's roll with what you have and see what happens later.
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 wonder if "load global" is a load at all?)
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 assumed loading a global returns the ptr stored in the global, not the data that ptr points to. But I might be wrong. It's hard to say without looking at examples I guess.
Agreed, let's deal with it when we need to codegen to know exactly what we are dealing with.
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.
Yes, I think in our case loading a global is more akin to a lookup where a global name maps to some pointer.
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.
In the meantime, here's an example of how LLVM does it:
https://llvm.org/docs/LangRef.html#id210
i.e. a load is a bit like a deref.
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.
Yes.
Maye later (or now, whenever) we should rename the
LoadGlobal
to something likeGlobalAddr
?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.
No preference. Though maybe waiting until we know for sure how globals need to be codegenned isn't a bad idea.