Turning sub-target features on/off (e.g. Altivec on PowerPC)


I’m using Mono with experimental LLVM backend support on PowerPC. I noticed that although LLVM’s IR contains SIMD instructions the assembly produced doesn’t contain any Altivec instructions and my PowerPC970 machine of course has Altivec support. Isn’t there some kind of autodetection? I searched in Target sources but only found out that Altivec is disabled by default.

Can I turn Altivec support on (and off, I need both cases) from the code? Some info: Mono’s utilizes LLVM in this way:

LLVMInitializePowerPCTarget ();
LLVMInitializePowerPCTargetInfo ();
ExecutionEngine *EE = ExecutionEngine::createJIT ( … );
fpm = new FunctionPassManager ( … );

fpm->add(new TargetData(*EE->getTargetData()));

and then uses ExecutionEngine object for compiling functions.

No there are no automatic autodetection for ppc.
AFAIK only the X86 backend currently have some autodetection code buried in the target backends. The habit to have autodetection code in the target backend are discouraged and X86 are currently moving code out from the backend into two new API found in LLVM 2.7 that can be used by clients to find out of the cpu capabilities.
This are the right place to add new PPC cpu/attributes autodetection code.
I you use the EngineBuilder instead of calling createJIT directly then you can set the cpu type and select cpu attributes using mattr easily, this are how lli does it: InitializeNativeTarget(); // use this instead of EngineBuilder builder(Mod); builder.setMArch(MArch); // set arch ppc_32 ppc_64 etc. builder.setMCPU(MCPU); // set desired cpu type for code generation builder.setMAttrs(MAttrs); // set desired cpu attributes (enable Altivec etc) EE = builder.create(); … Cheers Xerxes