[commit: ghc] master: LLVM: Tweak TBAA metadata codegen (9d67f04)

git at git.haskell.org git at git.haskell.org
Sun Jan 15 19:18:38 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/9d67f04d4892ea399631fd67ce91782b821a127e/ghc

>---------------------------------------------------------------

commit 9d67f04d4892ea399631fd67ce91782b821a127e
Author: Erik de Castro Lopo <erik.decastrolopo at ambiata.com>
Date:   Mon Jan 16 06:17:17 2017 +1100

    LLVM: Tweak TBAA metadata codegen
    
    This change is requred for llvm 4.0. GHC doesn't use that version yet,
    but this change is just as valid for versions eariler than 4.0.
    
    Two changes needed:
    
    * Previously, GHC defined a `topN` node in the TBAA heiarchy and some IR
      instructions referenced that node. With LLVM 4.0 the root node can no
      longer be referenced by IR instructions, so we introduce a new element
      `rootN` and make `topN` a child of that.
    
    * Previously the root TBAA node was rendered as "!0 = !{!"root", null}".
      With LLVM 4.0 that needs to be "!0 = !{!"root"}" which is also
      accepted by earlier versions.
    
    Test Plan: Build with quick-llvm BuildFlavor and run tests
    
    Reviewers: bgamari, drbo, austin, angerman, michalt, DemiMarie
    
    Reviewed By: DemiMarie
    
    Subscribers: mpickering, DemiMarie, thomie
    
    Differential Revision: https://phabricator.haskell.org/D2975


>---------------------------------------------------------------

9d67f04d4892ea399631fd67ce91782b821a127e
 compiler/llvmGen/LlvmCodeGen.hs      | 13 +++++++------
 compiler/llvmGen/LlvmCodeGen/Regs.hs |  9 +++++++--
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/compiler/llvmGen/LlvmCodeGen.hs b/compiler/llvmGen/LlvmCodeGen.hs
index c240d09..5596d59 100644
--- a/compiler/llvmGen/LlvmCodeGen.hs
+++ b/compiler/llvmGen/LlvmCodeGen.hs
@@ -188,12 +188,13 @@ cmmMetaLlvmPrelude = do
     setUniqMeta uniq tbaaId
     parentId <- maybe (return Nothing) getUniqMeta parent
     -- Build definition
-    return $ MetaUnnamed tbaaId $ MetaStruct
-        [ MetaStr name
-        , case parentId of
-          Just p  -> MetaNode p
-          Nothing -> MetaVar $ LMLitVar $ LMNullLit i8Ptr
-        ]
+    return $ MetaUnnamed tbaaId $ MetaStruct $
+          case parentId of
+              Just p  -> [ MetaStr name, MetaNode p ]
+              -- As of LLVM 4.0, a node without parents should be rendered as
+              -- just a name on its own. Previously `null` was accepted as the
+              -- name.
+              Nothing -> [ MetaStr name ]
   renderLlvm $ ppLlvmMetas metas
 
 -- -----------------------------------------------------------------------------
diff --git a/compiler/llvmGen/LlvmCodeGen/Regs.hs b/compiler/llvmGen/LlvmCodeGen/Regs.hs
index 186eda3..e09ab80 100644
--- a/compiler/llvmGen/LlvmCodeGen/Regs.hs
+++ b/compiler/llvmGen/LlvmCodeGen/Regs.hs
@@ -97,7 +97,8 @@ alwaysLive = [BaseReg, Sp, Hp, SpLim, HpLim, node]
 -- | STG Type Based Alias Analysis hierarchy
 stgTBAA :: [(Unique, LMString, Maybe Unique)]
 stgTBAA
-  = [ (topN,   fsLit "top",   Nothing)
+  = [ (rootN,  fsLit "root",   Nothing)
+    , (topN,   fsLit "top",   Just rootN)
     , (stackN, fsLit "stack", Just topN)
     , (heapN,  fsLit "heap",  Just topN)
     , (rxN,    fsLit "rx",    Just heapN)
@@ -109,7 +110,11 @@ stgTBAA
     ]
 
 -- | Id values
-topN, stackN, heapN, rxN, baseN :: Unique
+-- The `rootN` node is the root (there can be more than one) of the TBAA
+-- hierarchy and as of LLVM 4.0 should *only* be referenced by other nodes. It
+-- should never occur in any LLVM instruction statement.
+rootN, topN, stackN, heapN, rxN, baseN :: Unique
+rootN  = getUnique (fsLit "LlvmCodeGen.Regs.rootN")
 topN   = getUnique (fsLit "LlvmCodeGen.Regs.topN")
 stackN = getUnique (fsLit "LlvmCodeGen.Regs.stackN")
 heapN  = getUnique (fsLit "LlvmCodeGen.Regs.heapN")



More information about the ghc-commits mailing list