Commits

Mattias Lundell committed 9bf2308

faster linking

Comments (0)

Files changed (7)

+syntax: glob
+
 dist/*
+*.ll
+*.ti
+*.bc
 
 import POSIX
 
-root :: World -> Cmd () ()
-root w = do
+root :: RootType
+root world = do
 
-   env = new posix w
+   env = new posix world
 
    echo str = action
       env.stdout.write str
 rm *.bc *.ll &> /dev/null
 timberc --llvm *.t
 
-# create archive
+# create archive with everything - used for slow LTO linking
 cd ../rtsPOSIX
 llvm-ar rc libTimberLLVM.a ../lib/*.bc rts.bc POSIX.extern.bc
+
+# archive run-time system - used for fast linking
+ar rc libTimberRTS.a rts.o POSIX.extern.o
+
+# create std-library archive - used together with libTimberRTS for fast linking
+llvm-ar rc libTimberLLVMLIB.a ../lib/*.bc

rtsPOSIX/config.log

 configure:3203: checking for the pthreads library -lpthreads
 configure:3246: gcc -o conftest -g -O2 -m32    conftest.c -lpthreads  >&5
 /usr/bin/ld: error: cannot find -lpthreads
-/usr/bin/ld: /tmp/ccjZmabK.o: in function main:conftest.c:12: error: undefined reference to 'pthread_join'
-/usr/bin/ld: /tmp/ccjZmabK.o: in function main:conftest.c:13: error: undefined reference to '__pthread_register_cancel'
-/usr/bin/ld: /tmp/ccjZmabK.o: in function main:conftest.c:14: error: undefined reference to 'pthread_create'
-/usr/bin/ld: /tmp/ccjZmabK.o: in function main:conftest.c:14: error: undefined reference to '__pthread_unregister_cancel'
+/usr/bin/ld: /tmp/ccmxiFBr.o: in function main:conftest.c:12: error: undefined reference to 'pthread_join'
+/usr/bin/ld: /tmp/ccmxiFBr.o: in function main:conftest.c:13: error: undefined reference to '__pthread_register_cancel'
+/usr/bin/ld: /tmp/ccmxiFBr.o: in function main:conftest.c:14: error: undefined reference to 'pthread_create'
+/usr/bin/ld: /tmp/ccmxiFBr.o: in function main:conftest.c:14: error: undefined reference to '__pthread_unregister_cancel'
 collect2: ld returned 1 exit status
 configure:3253: $? = 1
 configure: failed program was:
 configure:3276: result: no
 configure:3148: checking whether pthreads work without any flags
 configure:3246: gcc -o conftest -g -O2 -m32    conftest.c   >&5
-/usr/bin/ld: /tmp/cc4SkErO.o: in function main:conftest.c:12: error: undefined reference to 'pthread_join'
-/usr/bin/ld: /tmp/cc4SkErO.o: in function main:conftest.c:13: error: undefined reference to '__pthread_register_cancel'
-/usr/bin/ld: /tmp/cc4SkErO.o: in function main:conftest.c:14: error: undefined reference to 'pthread_create'
-/usr/bin/ld: /tmp/cc4SkErO.o: in function main:conftest.c:14: error: undefined reference to '__pthread_unregister_cancel'
+/usr/bin/ld: /tmp/cc9Mj2jt.o: in function main:conftest.c:12: error: undefined reference to 'pthread_join'
+/usr/bin/ld: /tmp/cc9Mj2jt.o: in function main:conftest.c:13: error: undefined reference to '__pthread_register_cancel'
+/usr/bin/ld: /tmp/cc9Mj2jt.o: in function main:conftest.c:14: error: undefined reference to 'pthread_create'
+/usr/bin/ld: /tmp/cc9Mj2jt.o: in function main:conftest.c:14: error: undefined reference to '__pthread_unregister_cancel'
 collect2: ld returned 1 exit status
 configure:3253: $? = 1
 configure: failed program was:
 configure:3153: checking whether pthreads work with -Kthread
 configure:3246: gcc -o conftest -g -O2 -m32 -Kthread   conftest.c   >&5
 gcc: unrecognized option '-Kthread'
-/usr/bin/ld: /tmp/ccbMqKKU.o: in function main:conftest.c:12: error: undefined reference to 'pthread_join'
-/usr/bin/ld: /tmp/ccbMqKKU.o: in function main:conftest.c:13: error: undefined reference to '__pthread_register_cancel'
-/usr/bin/ld: /tmp/ccbMqKKU.o: in function main:conftest.c:14: error: undefined reference to 'pthread_create'
-/usr/bin/ld: /tmp/ccbMqKKU.o: in function main:conftest.c:14: error: undefined reference to '__pthread_unregister_cancel'
+/usr/bin/ld: /tmp/cclmjPKx.o: in function main:conftest.c:12: error: undefined reference to 'pthread_join'
+/usr/bin/ld: /tmp/cclmjPKx.o: in function main:conftest.c:13: error: undefined reference to '__pthread_register_cancel'
+/usr/bin/ld: /tmp/cclmjPKx.o: in function main:conftest.c:14: error: undefined reference to 'pthread_create'
+/usr/bin/ld: /tmp/cclmjPKx.o: in function main:conftest.c:14: error: undefined reference to '__pthread_unregister_cancel'
 collect2: ld returned 1 exit status
 configure:3253: $? = 1
 configure: failed program was:
 configure:3153: checking whether pthreads work with -kthread
 configure:3246: gcc -o conftest -g -O2 -m32 -kthread   conftest.c   >&5
 gcc: unrecognized option '-kthread'
-/usr/bin/ld: /tmp/ccjtqjpW.o: in function main:conftest.c:12: error: undefined reference to 'pthread_join'
-/usr/bin/ld: /tmp/ccjtqjpW.o: in function main:conftest.c:13: error: undefined reference to '__pthread_register_cancel'
-/usr/bin/ld: /tmp/ccjtqjpW.o: in function main:conftest.c:14: error: undefined reference to 'pthread_create'
-/usr/bin/ld: /tmp/ccjtqjpW.o: in function main:conftest.c:14: error: undefined reference to '__pthread_unregister_cancel'
+/usr/bin/ld: /tmp/ccuYLIhE.o: in function main:conftest.c:12: error: undefined reference to 'pthread_join'
+/usr/bin/ld: /tmp/ccuYLIhE.o: in function main:conftest.c:13: error: undefined reference to '__pthread_register_cancel'
+/usr/bin/ld: /tmp/ccuYLIhE.o: in function main:conftest.c:14: error: undefined reference to 'pthread_create'
+/usr/bin/ld: /tmp/ccuYLIhE.o: in function main:conftest.c:14: error: undefined reference to '__pthread_unregister_cancel'
 collect2: ld returned 1 exit status
 configure:3253: $? = 1
 configure: failed program was:
 configure:3203: checking for the pthreads library -llthread
 configure:3246: gcc -o conftest -g -O2 -m32    conftest.c -llthread  >&5
 /usr/bin/ld: error: cannot find -llthread
-/usr/bin/ld: /tmp/cckom5X2.o: in function main:conftest.c:12: error: undefined reference to 'pthread_join'
-/usr/bin/ld: /tmp/cckom5X2.o: in function main:conftest.c:13: error: undefined reference to '__pthread_register_cancel'
-/usr/bin/ld: /tmp/cckom5X2.o: in function main:conftest.c:14: error: undefined reference to 'pthread_create'
-/usr/bin/ld: /tmp/cckom5X2.o: in function main:conftest.c:14: error: undefined reference to '__pthread_unregister_cancel'
+/usr/bin/ld: /tmp/ccu4aHOF.o: in function main:conftest.c:12: error: undefined reference to 'pthread_join'
+/usr/bin/ld: /tmp/ccu4aHOF.o: in function main:conftest.c:13: error: undefined reference to '__pthread_register_cancel'
+/usr/bin/ld: /tmp/ccu4aHOF.o: in function main:conftest.c:14: error: undefined reference to 'pthread_create'
+/usr/bin/ld: /tmp/ccu4aHOF.o: in function main:conftest.c:14: error: undefined reference to '__pthread_unregister_cancel'
 collect2: ld returned 1 exit status
 configure:3253: $? = 1
 configure: failed program was:
                                      dumpAfter    :: Pass -> Bool,
                                      stopAfter    :: Pass -> Bool,
                                      doLLVM       :: Bool,
-                                     llvmOptFlags :: String
+                                     doLLVMFast     :: Bool
                                    }
 
 options              :: [OptDescr Flag]
                                 (NoArg LLVM)
                                 "Compile to LLVM",
                          Option []
-                                ["llvmopt"]
-                                (ReqArg LLVMOptFlags "LLVM-flag")
-                                "Provide LLVM optimization flags"
+                                ["llvmfast"]
+                                (NoArg LLVMFast)
+                                "Speed up LLVM compilation"
                        ]
                        ++
                        [ Option []
                      | DumpAfter Pass
                      | StopAfter Pass
                      | LLVM
-                     | LLVMOptFlags String
+                     | LLVMFast
                      deriving (Show,Eq)
 
 data TimbercException
                   dumpAfter    = find . DumpAfter,
                   stopAfter    = find . StopAfter,
                   doLLVM       = find LLVM,
-                  llvmOptFlags = first ""
-                                 [ llvmflags | LLVMOptFlags llvmflags <- flags ]
+                  doLLVMFast   = find LLVMFast
                 }
-  where 
+  where
     first def []      = def
     first def (opt:_) = opt
     find  opt         = first False [ True | flag <- flags, flag == opt ]
              (\e -> Exception.throwIO $ emsg file)
       config <- safeRead file txt
       return config
-    where        
+    where
         safeRead :: FilePath -> String -> IO CfgOpts
         safeRead file text =
             let val = case [x | (x,t) <- reads text, ("","") <- lex t] of
                      | K2LLVM
                      | Main                  -- top level 'pass'
                      deriving (Show,Eq,Ord,Enum)
-                        
+
 allPasses            :: [Pass]
 allPasses            = [Parser .. K2LLVM]
 
       cmd2 = llvmLLVMLD cfg
              ++ " -Xlinker='-m32' "
              ++ " -native "
-             ++ " -internalize "
              ++ " -L" ++ rtsDir clo
              ++ " -o " ++ outfile clo ++ " "
              ++ " main.bc " ++ unwords bc_files ++ " "
              ++ " -b " ++ tmp_bcfile ++ " "
---             ++ " -lTimberLLVMLIB "
---             ++ " -lTimberLLVMRTS "
---             ++ " -lm "
---             ++ " -lpthread"
-             ++ llvmLinkLibs cfg
+             ++ if doLLVMFast clo
+                  then " -lTimberLLVMLIB -lTimberRTS -lpthread -lm -disable-opt"
+                  else llvmLinkLibs cfg ++ " -internalize"
   writeFile "main.ll" (llvmMain rMod)
   execCmd clo cmd1
   execCmd clo cmd2

src/LLVMKindle.hs

 words bytes = Prelude.div (bytes+4-1) 4
 
 typeSize :: LLVMType -> CodeGen Int
+typeSize (Tint 1) = return 1
 typeSize (Tint n) = return (n `Prelude.div` 8)
 typeSize (Tptr _) = return 4
 typeSize Tfloat = return 4