<div dir="ltr">So, I know I approved this, but I just thought (and by "I just thought" I mean someone said "hey, what about") about older bitcode that has a target that changed their DataLayout representation? Now they'll get an assert. Perhaps a better thing would be to do a warning in -debug mode and set the module DL to the TargetMachine DL in this case?<div><br></div><div>-eric</div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Jul 30, 2015 at 1:43 PM Mehdi Amini <<a href="mailto:mehdi.amini@apple.com">mehdi.amini@apple.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: mehdi_amini<br>
Date: Thu Jul 30 15:33:18 2015<br>
New Revision: 243682<br>
<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D243682-26view-3Drev&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=Sfe5nTXPDzhw0LzegLiuTR3F6ZtHA0UE-ottALwoG5Q&s=Q4vwk-pcTPVWu7LEJdIRHayE-XJjIULmVlzHn_F1_uc&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=243682&view=rev</a><br>
Log:<br>
Add a TargetMachine hook that verifies DataLayout compatibility<br>
<br>
Summary: Also provide the associated assertion when CodeGen starts.<br>
<br>
Reviewers: echristo<br>
<br>
Subscribers: llvm-commits<br>
<br>
Differential Revision: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D11654&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=Sfe5nTXPDzhw0LzegLiuTR3F6ZtHA0UE-ottALwoG5Q&s=PVPjA_WAHHUyyLSnVrfOn9FdADVW8nLpKz-A2WuBbfY&e=" rel="noreferrer" target="_blank">http://reviews.llvm.org/D11654</a><br>
<br>
From: Mehdi Amini <<a href="mailto:mehdi.amini@apple.com" target="_blank">mehdi.amini@apple.com</a>><br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/Target/TargetMachine.h<br>
    llvm/trunk/lib/CodeGen/MachineFunction.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/Target/TargetMachine.h<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_include_llvm_Target_TargetMachine.h-3Frev-3D243682-26r1-3D243681-26r2-3D243682-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=Sfe5nTXPDzhw0LzegLiuTR3F6ZtHA0UE-ottALwoG5Q&s=-8CWRGM3-XIkdi2c6XQiaGlVG3krLzL45ymkOPNa_vE&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetMachine.h?rev=243682&r1=243681&r2=243682&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Target/TargetMachine.h (original)<br>
+++ llvm/trunk/include/llvm/Target/TargetMachine.h Thu Jul 30 15:33:18 2015<br>
@@ -133,6 +133,15 @@ public:<br>
   /// Create a DataLayout.<br>
   const DataLayout createDataLayout() const { return DL; }<br>
<br>
+  /// Test if a DataLayout if compatible with the CodeGen for this target.<br>
+  ///<br>
+  /// The LLVM Module owns a DataLayout that is used for the target independent<br>
+  /// optimizations and code generation. This hook provides a target specific<br>
+  /// check on the validity of this DataLayout.<br>
+  bool isCompatibleDataLayout(const DataLayout &Candidate) const {<br>
+    return DL == Candidate;<br>
+  }<br>
+<br>
   /// Get the pointer size for this target.<br>
   ///<br>
   /// This is the only time the DataLayout in the TargetMachine is used.<br>
<br>
Modified: llvm/trunk/lib/CodeGen/MachineFunction.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_lib_CodeGen_MachineFunction.cpp-3Frev-3D243682-26r1-3D243681-26r2-3D243682-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=Sfe5nTXPDzhw0LzegLiuTR3F6ZtHA0UE-ottALwoG5Q&s=hxHqgMu6g38C5eqfUc_GAw3tPd6aU0VrVTz0wEsWvvE&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineFunction.cpp?rev=243682&r1=243681&r2=243682&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/MachineFunction.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/MachineFunction.cpp Thu Jul 30 15:33:18 2015<br>
@@ -85,6 +85,10 @@ MachineFunction::MachineFunction(const F<br>
<br>
   FunctionNumber = FunctionNum;<br>
   JumpTableInfo = nullptr;<br>
+<br>
+  assert(TM.isCompatibleDataLayout(getDataLayout()) &&<br>
+         "Can't create a MachineFunction using a Module with a "<br>
+         "Target-incompatible DataLayout attached\n");<br>
 }<br>
<br>
 MachineFunction::~MachineFunction() {<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>