+/**
+ * Adjust the size of a node representing a stack alloc or free for the minimum stack alignment.
+ *
+ * @param alignment the minimum stack alignment
+ * @param size the node containing the non-aligned size
+ * @param irg the irg where new nodes are allocated on
+ * @param irg the block where new nodes are allocated on
+ * @param dbg debug info for new nodes
+ *
+ * @return a node representing the aligned size
+ */
+static ir_node *adjust_alloc_size(unsigned stack_alignment, ir_node *size, ir_graph *irg, ir_node *block, dbg_info *dbg) {
+ if (stack_alignment > 1) {
+ ir_mode *mode = get_irn_mode(size);
+ tarval *tv = new_tarval_from_long(stack_alignment-1, mode);
+ ir_node *mask = new_r_Const(irg, block, mode, tv);
+
+ size = new_rd_Add(dbg, irg, block, size, mask, mode);
+
+ tv = new_tarval_from_long(-(long)stack_alignment, mode);
+ mask = new_r_Const(irg, block, mode, tv);
+ size = new_rd_And(dbg, irg, block, size, mask, mode);
+ }
+ return size;
+}