Path: utzoo!mnetor!uunet!husc6!cmcl2!rutgers!iuvax!pur-ee!j.cc.purdue.edu!ksb From: ksb@j.cc.purdue.edu (Kevin Braunsdorf) Newsgroups: comp.lang.c Subject: noalias, ordinary, volatile Message-ID: <6006@j.cc.purdue.edu> Date: 18 Dec 87 16:42:31 GMT References: <8712170057.AA17035@decwrl.dec.com> Reply-To: ksb@j.cc.purdue.edu.UUCP (Kevin Braunsdorf) Distribution: na Organization: The K Project Lines: 97 Keywords: noalias -> exclusive ordinary volatile I have been working on an optimizer that would take advantage of the "noalias" concept (here we call it "exclusive" access, rather than "noalias" data). We are interested in three access restriction: exclusive, volatile, and ordinary. The "exclusive" access restriction tells the optimizer something very strong: no reference through any handle other than this one leads to this data. The "volatile" access restriction tells the optimizer the opposite: there are data references that you cannot see that change this data. The "ordinary" access restriction states that: only references to this type may effect this data; it is the default. Looking at the ordinary case first char *pch; int *pi; .... *pi = 0; *pch = 'a'; one would expect *pi to contain a zero. However if we change char *pch; to int *pch; /* broken name, example only */ then we can clearly see that *pi could be (int)'a'. If we change int *pi; to volatile int *pi; then we also can see that *pi could have changed (asynchronously even). Consider: #define exclusive noalias /* so we all see the same thing */ exclusive int *pi1; int *pi2; .... *pi1 = 100; *pi2 = 200; Here we know that *pi1 has to be 100, *pi2 must refer to a distinct int from *pi1 because the int is exclusive. Look at the loop /* ??? */ int i; i = 1; while (i) /*empty*/; Tell me, what happens if i is access restricted to volatile -- ordinary -- exclusive -- volatile: We loop reading i, until an asynchronous event changes it. ordinary: We see no side effect that could change i, we bitch a little but generate code that does the volatile thing. exclusive: We scream and die, i cannot change in the loop (if you want to loop forever you have to use spin(); for our flow analysis to pass your code.). Is that clear enough? What if we wanted a pointer to be exclusive? typedef char *char_pointer; exclusive char_pointer ep; or exclusive (char *) ep; maybe... I'm not telling. Think about that pointer type you should get when you have: typedef union { int i; float f; char ch; } dummy; /* ??? */ int *pi = & dummy.i; Shouldn't this be volatile? How stringly should the compiler "feel" about this? KLANG!! Kevin Braunsdorf ksb@j.cc.purdue.edu K Project pur-ee!gawk!klang