[llvm-commits] [Patch] Use TargetTransformInfo to control switch-to-lookup table transform

Duncan Sands baldrick at free.fr
Mon Oct 29 09:50:12 PDT 2012


Hi Hal,

 >>> When the switch-to-lookup tables transform landed in SimplifyCFG,
>>> it
>>> was pointed out [1] that this could be inappropriate for some
>>> targets.
>>> Since there was no way at the time for the pass to know anything
>>> about
>>> the target, an awkward reverse-transform was added in
>>> CodeGenPrepare
>>> that turned lookup tables back into switches for some targets.
>>>
>>> The attached patch uses the new TargetTransformInfo to determine if
>>> a
>>> switch should be transformed, and removes
>>> CodeGenPrepare::ConvertLoadToSwitch. Please take a look!
>>
>> personally I think it is completely wrong to have codegen concepts
>> such as
>> ISD::BR_JT and ISD::BRIND leaking into the IR level:
>
> But these concepts are not leaking into the IR layer. These are contained in Target (in lib/Target/TargetTransformImpl.cpp

nope, Hans added it to Local.h, not to TargetTransformImpl.cpp.

Ciao, Duncan.

), and the IR layer does not see them. Also, a target could override this 
implementation and provide a different one. Nevertheless, the IR layer only sees 
an abstract interface, and if Target is not linked in, just gets a fixed generic 
answer.
>
>   -Hal
>
>>
>>> --- a/include/llvm/Transforms/Utils/Local.h
>>> +++ b/include/llvm/Transforms/Utils/Local.h
>>> @@ -49,6 +49,12 @@ unsigned
>>> ScalarTargetTransformImpl::getJumpBufSize() const {
>>>     return TLI->getJumpBufSize();
>>>   }
>>>
>>> +bool ScalarTargetTransformImpl::shouldBuildLookupTables() const {
>>> +  return TLI->supportJumpTables() &&
>>> +      (TLI->isOperationLegalOrCustom(ISD::BR_JT, MVT::Other) ||
>>> +       TLI->isOperationLegalOrCustom(ISD::BRIND, MVT::Other));
>>> +}
>>> +
>>>   //===----------------------------------------------------------------------===//
>>>   //
>>>   // Calls used by the vectorizers.
>>
>> Ciao, Duncan.
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>




More information about the llvm-commits mailing list