Fix legalization of heap_addrs with 32-bit indices. (#480)

This makes several changes:
 - It adds an index_type to heap declarations, allowing heaps to specify the
   type for indexing. This also anticipates 64-bit heap support.

 - It adds a memory_type to deref global values, allowing deref globals to
   have types other than pointers. This is used to allow the bound variable
   in dynamic heaps to have type i32, to match the index type in heaps
   with i32 index type.

 - And, it fixes heap legalization to do the bounds check in the heap's
   index type.
This commit is contained in:
Dan Gohman
2018-08-28 13:37:33 -07:00
committed by GitHub
parent 00ddf3a7a6
commit eb439c9a68
13 changed files with 396 additions and 70 deletions

View File

@@ -174,6 +174,7 @@ impl<'a> Context<'a> {
style: HeapStyle::Static {
bound: Imm64::new(0),
},
index_type: VOID,
});
}
self.function.heaps[heap] = data;
@@ -1128,7 +1129,13 @@ impl<'a> Parser<'a> {
let base = self.match_gv("expected global value: gv«n»")?;
self.match_token(Token::RPar, "expected ')' in 'deref' global value decl")?;
let offset = self.optional_offset32()?;
GlobalValueData::Deref { base, offset }
self.match_token(Token::Colon, "expected ':' in 'deref' global value decl")?;
let memory_type = self.match_type("expected deref type")?;
GlobalValueData::Deref {
base,
offset,
memory_type,
}
}
"globalsym" => {
let colocated = self.optional(Token::Identifier("colocated"));
@@ -1177,6 +1184,7 @@ impl<'a> Parser<'a> {
min_size: 0.into(),
guard_size: 0.into(),
style: HeapStyle::Static { bound: 0.into() },
index_type: ir::types::I32,
};
// heap-desc ::= heap-style heap-base * { "," heap-attr }
@@ -1199,6 +1207,9 @@ impl<'a> Parser<'a> {
"guard" => {
data.guard_size = self.match_imm64("expected integer guard size")?;
}
"index_type" => {
data.index_type = self.match_type("expected index type")?;
}
t => return err!(self.loc, "unknown heap attribute '{}'", t),
}
}