From b363b98211b80f6f74349d9357d19ce69aff1fe8 Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Fri, 6 Jul 2012 12:51:17 -0700 Subject: [PATCH] Improve handling of datalayout for generic targets. Flag 32-bit vector types as only requiring 32-bit alignment (preemptive bug fix for 32xi1 vectors). Force module datalayouts to be the same before linking them to silence an LLVM warning. Finishes issue #309. --- builtins.cpp | 8 ++++++++ builtins/target-generic-common.ll | 2 ++ module.cpp | 8 +++++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/builtins.cpp b/builtins.cpp index d42ef4b2..b2fb64c2 100644 --- a/builtins.cpp +++ b/builtins.cpp @@ -619,6 +619,14 @@ AddBitcodeToModule(const unsigned char *bitcode, int length, mTriple.getVendor() == bcTriple.getVendor()); bcModule->setTargetTriple(mTriple.str()); + // This is also suboptimal; LLVM issues a warning about linking + // modules with different datalayouts, due to things like + // bulitins-c.c having the regular IA layout, but the generic + // targets having a layout with 16-bit alignment for 16xi1 vectors. + // As long as builtins-c.c doesn't have any 16xi1 vector types + // (which it shouldn't!), then this override is safe. + bcModule->setDataLayout(module->getDataLayout()); + std::string(linkError); if (llvm::Linker::LinkModules(module, bcModule, llvm::Linker::DestroySource, diff --git a/builtins/target-generic-common.ll b/builtins/target-generic-common.ll index 9cedf4e4..cfbe6678 100644 --- a/builtins/target-generic-common.ll +++ b/builtins/target-generic-common.ll @@ -29,6 +29,8 @@ ;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128-v16:16:16-v32:32:32"; + define(`MASK',`i1') include(`util.m4') diff --git a/module.cpp b/module.cpp index d98fa609..ba0deac5 100644 --- a/module.cpp +++ b/module.cpp @@ -241,9 +241,11 @@ Module::Module(const char *fn) { module->setTargetTriple(g->target.GetTripleString()); if (g->target.isa == Target::GENERIC) { - // <16 x i1> vectors only need 16 bit / 2 byte alignment - std::string datalayout = module->getDataLayout(); - datalayout += "v16:16:16"; + // <16 x i1> vectors only need 16 bit / 2 byte alignment, so add + // that to the regular datalayout string for IA.. + std::string datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" + "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-" + "f80:128:128-n8:16:32:64-S128-v16:16:16-v32:32:32"; module->setDataLayout(datalayout); }