[PATCH 1/3] add helper: DEF_OPCODE()

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

 



During simplification, it's a common operation to test the opcode
of some instruction defining a given pseudo. The pattern is usually
something like:
	if (old->type != PSEUDO_REG)
		return 0;
	def = old->def;
	if (!def)
		return 0;
	switch (def->opcode) {
	...
	}

This pattern is rather annoying because it's relatively long.

Change this by using a macro which does the testing and returns
the opcode when meaningful or OP_BADOP otherwise and assign
the defining instruction to a variable as its needed almost
everytime.

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

diff --git a/simplify.c b/simplify.c
index 80c3cebca..014466889 100644
--- a/simplify.c
+++ b/simplify.c
@@ -378,6 +378,13 @@ static inline int def_opcode(pseudo_t p)
 	return p->def->opcode;
 }
 
+//
+// return the opcode of the instruction defining ``SRC`` if existing
+// and OP_BADOP if not. It also assigns the defining instruction
+// to ``DEF``.
+#define DEF_OPCODE(DEF, SRC)	\
+	(((SRC)->type == PSEUDO_REG && (DEF = (SRC)->def)) ? DEF->opcode : OP_BADOP)
+
 static unsigned int value_size(long long value)
 {
 	value >>= 8;
-- 
2.18.0

--
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