Created
February 24, 2014 23:02
-
-
Save tmcdonell/9199137 to your computer and use it in GitHub Desktop.
dotp-vectorize
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad.Error | |
import LLVM.General.Context | |
import LLVM.General.Module | |
import LLVM.General.Target | |
import LLVM.General.Target.Options | |
import LLVM.General.PassManager | |
import LLVM.General.Transforms | |
import LLVM.General.Diagnostic | |
import LLVM.General.CommandLine | |
{-- The standard compiler passes: | |
-- | |
-- $ opt -O3 -disable-output -debug-pass=Arguments dotp.ll | |
Pass Arguments: | |
-datalayout -notti -basictti -x86tti -no-aa -tbaa -targetlibinfo -basicaa | |
-preverify -domtree -verify -simplifycfg -domtree -sroa -early-cse | |
-lower-expect | |
Pass Arguments: | |
-targetlibinfo -datalayout -notti -basictti -x86tti -no-aa -tbaa -basicaa | |
-globalopt -ipsccp -deadargelim -instcombine -simplifycfg -basiccg -prune-eh | |
-inline-cost -inline -functionattrs -argpromotion -sroa -domtree -early-cse | |
-lazy-value-info -jump-threading -correlated-propagation -simplifycfg | |
-instcombine -tailcallelim -simplifycfg -reassociate -domtree -loops | |
-loop-simplify -lcssa -loop-rotate -licm -lcssa -loop-unswitch -instcombine | |
-scalar-evolution -loop-simplify -lcssa -indvars -loop-idiom -loop-deletion | |
-loop-unroll -memdep -gvn -memdep -memcpyopt -sccp -instcombine | |
-lazy-value-info -jump-threading -correlated-propagation -domtree -memdep -dse | |
-loops -scalar-evolution -slp-vectorizer -adce -simplifycfg -instcombine | |
-barrier -domtree -loops -loop-simplify -lcssa -scalar-evolution | |
-loop-simplify -lcssa -loop-vectorize -instcombine -simplifycfg | |
-strip-dead-prototypes -globaldce -constmerge -preverify -domtree -verify | |
--} | |
main :: IO () | |
main = do | |
parseCommandLineOptions | |
[ "-debug" | |
-- , "-force-vector-width=2" | |
-- , "-mtriple=x86_64-apple-macosx10.9.0" | |
-- , "-mcpu=corei7-avx" | |
, "-debug-pass=Arguments" | |
, "-debug-only=loop-vectorize" | |
] | |
Nothing | |
mt <- readFile "dotp.ll" | |
r <- withContext $ \cx -> | |
runErrorT $ withModuleFromLLVMAssembly cx mt $ \mdl -> do | |
runErrorT $ withDefaultTargetMachine $ \machine -> do | |
triple <- getProcessTargetTriple | |
withTargetLibraryInfo triple $ \libinfo -> do | |
datalayout <- getTargetMachineDataLayout machine | |
let p1 = PassSetSpec prepass (Just datalayout) (Just libinfo) (Just machine) | |
p2 = PassSetSpec optpass (Just datalayout) (Just libinfo) (Just machine) | |
-- p3 = defaultCuratedPassSetSpec { optLevel = Just 3 } | |
_b1 <- withPassManager p1 $ \pm -> runPassManager pm mdl | |
_b2 <- withPassManager p2 $ \pm -> runPassManager pm mdl | |
-- _b3 <- withPassManager p3 $ \pm -> runPassManager pm mdl | |
moduleLLVMAssembly mdl >>= putStrLn | |
either (either error (putStrLn . diagnosticDisplay)) | |
(either error return) | |
r | |
prepass :: [Pass] | |
prepass = | |
[ SimplifyControlFlowGraph | |
, ScalarReplacementOfAggregates { requiresDominatorTree = True } | |
, EarlyCommonSubexpressionElimination | |
, LowerExpectIntrinsic | |
] | |
optpass :: [Pass] | |
optpass = | |
[ | |
-- -targetlibinfo | |
-- -datalayout | |
-- -notti | |
-- -basictti | |
-- -x86tti | |
-- -no-aa | |
-- -tbaa | |
-- -basicaa | |
-- -globalopt | |
InterproceduralSparseConditionalConstantPropagation -- ipsccp | |
-- -deadargelim | |
, InstructionCombining | |
, SimplifyControlFlowGraph | |
-- -basiccg | |
, PruneExceptionHandling | |
-- -inline-cost | |
-- , FunctionInlining { functionInliningThreshold = 0 } -- threshold?? | |
, FunctionAttributes | |
-- , ArgumentPromotion -- not needed? | |
, ScalarReplacementOfAggregates { requiresDominatorTree = True } -- false? | |
-- -domtree | |
, EarlyCommonSubexpressionElimination | |
-- -lazy-value-info | |
, JumpThreading | |
, CorrelatedValuePropagation | |
, SimplifyControlFlowGraph | |
, InstructionCombining | |
, TailCallElimination | |
, SimplifyControlFlowGraph | |
, Reassociate | |
-- -domtree | |
-- -loops | |
-- -loop-simplify | |
, LoopClosedSingleStaticAssignment | |
, LoopRotate | |
, LoopInvariantCodeMotion | |
, LoopClosedSingleStaticAssignment | |
, LoopUnswitch { optimizeForSize = False } | |
, LoopInstructionSimplify | |
, InstructionCombining | |
-- -scalar-evolution | |
-- -loop-simplify | |
, LoopClosedSingleStaticAssignment | |
, InductionVariableSimplify | |
, LoopIdiom | |
, LoopDeletion | |
, LoopUnroll { loopUnrollThreshold = Nothing | |
, count = Nothing | |
, allowPartial = Nothing } | |
-- -memdep | |
, GlobalValueNumbering { noLoads = False } -- loads?? | |
-- -memdep | |
-- -memcpyopt | |
, SparseConditionalConstantPropagation | |
, InstructionCombining | |
-- -lazy-value-info | |
, JumpThreading | |
, CorrelatedValuePropagation | |
-- -domtree | |
-- -memdep | |
, DeadStoreElimination | |
-- -loops | |
-- -scalar-evolution | |
-- -slp-vectorizer | |
-- , defaultVectorizeBasicBlocks -- instead of slp-vectorizer? | |
, AggressiveDeadCodeElimination | |
, SimplifyControlFlowGraph | |
, InstructionCombining | |
-- -barrier | |
-- -domtree | |
-- -loops | |
-- -loop-simplify | |
, LoopClosedSingleStaticAssignment | |
-- -scalar-evolution | |
-- -loop-simplify | |
-- LoopClosedSingleStaticAssignment | |
, LoopVectorize | |
, InstructionCombining | |
, SimplifyControlFlowGraph | |
-- -strip-dead-prototypes | |
, GlobalDeadCodeElimination | |
, ConstantMerge | |
-- -preverify | |
-- -domtree | |
-- -verify | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment