[PATCH] Changing the Back-end when Target Options Change
Bill Wendling
wendling at apple.com
Fri Jun 21 11:14:25 PDT 2013
On Jun 20, 2013, at 6:48 AM, "Du Toit, Stefanus" <stefanus.du.toit at intel.com> wrote:
> Hi Bill,
>
> From: Bill Wendling <wendling at apple.com>
>> For those not interested in slugging their way through a ton of
>> refactoring code, here's a cleaner patch.
>>
>> The executive summary:
>>
>> This regenerates the TargetMachine object if the any of the values in
>> TargetOptions changes. The regeneration is recursive, because creating
>> TargetMachine pretty much creates all of the other back-end objects that
>> are needed for code generation.
>
> You could use the "curiously recurring template pattern" and add an
> instance of a class template in the middle of the inheritance hierarchy,
> e.g. something alone the lines of:
>
> template<typename Derived>
> class TargetMachineHelper : public TargetMachine {
> TargetMachine *
> regenerateWithOptionsImpl(const TargetOptions &Opts,
> Reloc::Model RM,
> CodeModel::Model CM,
> CodeGenOpt::Level OptLvl,
> std::string &targetTriple,
> std::string &targetCPU,
> std::string &targetFS) {
> TargetPassConfig *TPC = PassConfig;
>
> this->~Derived();
> Derived *NewTM = new (this)
> Derived(TheTarget, targetTriple, targetCPU, targetFS,
> Opts, RM, CM, OptLvl);
>
> if (TPC)
> NewTM->PassConfig = TPC->regenerateWithTargetMachine(NewTM);
>
> return NewTM;
> }
> };
>
> // Then, for each backend, change the inheritance like so:
>
> class MyTargetMachine : public TargetMachineHelper<MyTargetMachine> {
> // ...
>
> (I'm sure there are errors in the above, but hopefully it gets the idea
> across)
>
> This would remove the need to define all of these similar-looking
> functions in the backends. Should work for PassConfig too.
>
Not a bad idea. I'll look into it. Thanks!
-bw
More information about the llvm-commits
mailing list