[PATCH 6/7] kds: shortcut for kill_dead_stores()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In kill_dead_stores(), instructions must be scanned backward
in order to check if the store is dead and can be removed.

However, if the corresponding pseudo has a single user,
this user is a store and the it correspond to a local symbol,
then it's not needed to scan, the store can be directly be removed.

This is somehow important for some semi-pathological case where
some BB contains a lot of dead stores because the current way is
annoyingly O(n^2).

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 flow.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/flow.c b/flow.c
index cc6158723..2c685cee6 100644
--- a/flow.c
+++ b/flow.c
@@ -770,11 +770,38 @@ void simplify_symbol_usage(struct entrypoint *ep)
 	} END_FOR_EACH_PTR(pseudo);
 }
 
+static struct pseudo_user *first_user(pseudo_t p)
+{
+	struct pseudo_user *pu;
+	FOR_EACH_PTR(p->users, pu) {
+		if (!pu)
+			continue;
+		return pu;
+	} END_FOR_EACH_PTR(pu);
+	return NULL;
+}
+
 void kill_dead_stores(struct entrypoint *ep, pseudo_t addr, int local)
 {
 	unsigned long generation;
 	struct basic_block *bb;
 
+	switch (pseudo_user_list_size(addr->users)) {
+	case 0:
+		return;
+	case 1:
+		if (local) {
+			struct pseudo_user *pu = first_user(addr);
+			struct instruction *insn = pu->insn;
+			if (insn->opcode == OP_STORE) {
+				kill_instruction_force(insn);
+				return;
+			}
+		}
+	default:
+		break;
+	}
+
 	generation = ++bb_generation;
 	FOR_EACH_PTR(ep->bbs, bb) {
 		if (bb->children)
-- 
2.16.2

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux