<div dir="ltr"><div>+Aliases have a name and an aliasee that is either a global value or a<br></div><div>+constant expressision.</div><div><br></div><div>"expression"</div><div><div><br></div><div>+ // It is unfortunate that we have to use "char *" in here since this is</div>
<div>+ // always non NULL, but:</div><div>+ // * The C API expects a null terminated string, so we cannot use StringRef.<br></div><div>+ // * The C API expects us to own it, so we cannot use a std:string.</div><div>+ // * For GlobalAliases we can fail to find the section and we have to<br>
</div><div>+ // return "", so we cannot use a "const String &".</div><div><br></div><div>"String" is confusing, I'd spell out std::string. Don't sweat this API, because David is going to replace it soon with section IR.</div>
<div><br></div><div>+ const char *getSection() const;</div></div><div><br></div><div><div>+static GlobalValue *getSimpleAliasee(Constant *C) {</div></div><div><br></div><div>Can this be simplified with cast<Constant>(C->stripPointerCasts())? I wonder if we should have a Constant::stripPointerCasts() to hide the cast.</div>
<div><br></div><div><div>+const GlobalObject *getBaseObject(const Constant &C) {</div></div><div><br></div><div>ditto</div><div><br></div><div><div>- const GlobalValue *UnderlyingGV = GV;</div><div>- // If GV is an alias then use the aliasee to determine the wrapper type</div>
<div>- if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(GV))</div><div>- UnderlyingGV = GA->getAliasee();</div><div>- if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(UnderlyingGV)) {</div><div>
- if ((GVar->isConstant() && GV->hasLocalLinkage()) ||</div><div>- (GVar->hasSection() &&</div><div>- StringRef(GVar->getSection()).startswith(".cp.")))</div><div>- return DAG.getNode(XCoreISD::CPRelativeWrapper, dl, MVT::i32, GA);</div>
<div>- return DAG.getNode(XCoreISD::DPRelativeWrapper, dl, MVT::i32, GA);</div><div>- }</div><div>- return DAG.getNode(XCoreISD::PCRelativeWrapper, dl, MVT::i32, GA);</div></div><div><div>+</div></div><div><div>+ if (GV->getType()->getElementType()->isFunctionTy())</div>
<div>+ return DAG.getNode(XCoreISD::PCRelativeWrapper, dl, MVT::i32, GA);</div><div>+</div><div>+ const auto *GVar = dyn_cast<GlobalVariable>(GV);</div><div>+ if ((GV->hasSection() && StringRef(GV->getSection()).startswith(".cp.")) ||</div>
<div>+ (GVar && GVar->isConstant() && GV->hasLocalLinkage()))</div><div>+ return DAG.getNode(XCoreISD::CPRelativeWrapper, dl, MVT::i32, GA);</div><div>+</div><div>+ return DAG.getNode(XCoreISD::DPRelativeWrapper, dl, MVT::i32, GA);</div>
</div><div><br></div><div>Just to check, there should be no behavioral change here, because getSection now looks through aliases for us.</div><div><br></div><div><div>+// This is only used in aliases that we created and we know they have a</div>
<div>+// linear structure.</div><div>+static const llvm::GlobalObject *getAliasedGlobal(const llvm::GlobalAlias &GA) {</div></div><div><br></div><div>Can this be simplified with stripPointerCastsNoFollowAliases() wrapped with a loop that follows getAliasee while inserting aliases into Visited? For that matter, does stripPointerCasts infloop on an alias cycle?</div>
<div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jun 2, 2014 at 5:36 AM, Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Rebased patches attached.<br>
<div class="HOEnZb"><div class="h5"><br>
On 29 May 2014 12:44, Rafael Espíndola <<a href="mailto:rafael.espindola@gmail.com">rafael.espindola@gmail.com</a>> wrote:<br>
> Moving from llvm-dev to llvm-commits now that all the dependencies<br>
> have been committed and the direction seems agreed upon.<br>
><br>
> The attached patch changes GlobalAlias to point to an arbitrary<br>
> ConstantExpr and it is up to MC (or the system assembler) to decide if<br>
> that expression is valid or not.<br>
><br>
> This reduces our ability to diagnose invalid uses and how early we can<br>
> spot them, but it also lets us do things like<br>
><br>
> @test5 = alias inttoptr(i32 sub (i32 ptrtoint (i32* @test2 to i32),<br>
> i32 ptrtoint (i32* @bar to i32)) to i32*)<br>
><br>
><br>
> An important implication of this patch is that the notion of aliased<br>
> global doesn't exist any more. The alias has to encode the information<br>
> needed to access it in its metadata (linkage, visibility, type, etc).<br>
><br>
> The clang patch includes a walk of alias chains, but that should be OK<br>
> since clang knows the form of every alias it creates.<br>
><br>
> The llvm patch also includes one as a local hack in the old JIT. That<br>
> is hopefully OK since we are about to delete it and it should handle<br>
> as many cases as before.<br>
><br>
> Another consequence to notice is that getSection has to return a<br>
> "const char *". It could return a NullTerminatedStringRef if there was<br>
> such a thing, but when that was proposed the decision was to just uses<br>
> "const char*" for that.<br>
><br>
> Cheers,<br>
> Rafael<br>
</div></div></blockquote></div><br></div>