bscarlet / llvm-general

Rich LLVM bindings for Haskell (with transfer of LLVM IR to and from C++, detailed compilation pass control, etc.)
http://hackage.haskell.org/package/llvm-general
132 stars 38 forks source link

CPUFeature functionality is broken #105

Closed dfoxfranke closed 9 years ago

dfoxfranke commented 10 years ago

The LLVM function llvm::sys::getHostCPUFeatures(StringMap<bool>& Features) is specified to provide

A string mapping feature names to either true (if enabled) or false (if disabled). This routine makes no guarantees about exactly which features may appear in this map, except that they are all valid LLVM feature names.

The current implementation of getHostCPUFeatures is of type IO (Set CPUFeature) and returns information only on enabled features. It ought to be IO (Map CPUFeature Bool) so that it can indicate disabled features as well.

withTargetMachine currently takes a Set CPUFeature argument and at LLVM.General.Internal.Target:80 turns it into a space-separated list which is ultimately passed to llvm::Target::createTargetMachine(). This function, however, expects a comma-separated list in which each item is prefixed by a '+' (to enable the feature) or '-' (to disable it). LLVM applies this list as diff against the set of features implicitly enabled by the cpu argument. withTargetMachine should take a Map CPUFeature Bool and convert it to this format.

bscarlet commented 10 years ago

Thanks for the report and diagnosis. Your changes sound right.