Steps for adding a new instruction to LLVM Backend

458 阅读1分钟

1. To add a new feature XXX to backend, which denotes the new added instruction.

def FeatureXXX
      : SubtargetFeature<"xxx", "HasXXX", "true", "Use xxx instruction">;

class XXXSubtarget {
  bool HasXXX = false;
  bool hasXXX() const {return HasXXX;}
};

2. Predicate for new feature.

def HasXXX 
      : Predicate<"Subtarget->hasXXX()">,AssemblerPredicate<(all_of FeatureXXX)>;

3. Update Scheduling model.

def II_XXX: InstrItinClass;
InstrItinData<II_XXX, [InstrStage<1, [ALU]>]>;
def : InstRW<[GenericWriteMul], (instrs MULT, MULTu, XXX)>;
list<Predicate> UnsupportedFeatures = [HasXXX];

4. Define the new XXX Instruction.

def XXX: Instruction<...>;

5. Define the matching Pattern for new XXX.

def :Pat<...>;

Now, it is done, if the new instruction does not need more customized handling.

6. Manual handling instruction selection for XXX if complext pattern is needed.

bool XXXDAGToDAGISel::selectXXX(...){...}