Skip to content

Commit 3149ec0

Browse files
committed
[RISCV] Enable MCCodeEmitter instruction predicate verifier
This ensures that we never encode an instruction which is unavailable, such as if we explicitly insert a forbidden instruction when lowering. This is particularly important on RISC-V given its high degree of modularity, and will become increasingly important as new standard extensions appear. Reviewed By: asb, lenary Differential Revision: https://reviews.llvm.org/D85015
1 parent ea2e682 commit 3149ec0

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ class RISCVMCCodeEmitter : public MCCodeEmitter {
8484
unsigned getVMaskReg(const MCInst &MI, unsigned OpNo,
8585
SmallVectorImpl<MCFixup> &Fixups,
8686
const MCSubtargetInfo &STI) const;
87+
88+
private:
89+
FeatureBitset computeAvailableFeatures(const FeatureBitset &FB) const;
90+
void
91+
verifyInstructionPredicates(const MCInst &MI,
92+
const FeatureBitset &AvailableFeatures) const;
8793
};
8894
} // end anonymous namespace
8995

@@ -185,6 +191,9 @@ void RISCVMCCodeEmitter::expandAddTPRel(const MCInst &MI, raw_ostream &OS,
185191
void RISCVMCCodeEmitter::encodeInstruction(const MCInst &MI, raw_ostream &OS,
186192
SmallVectorImpl<MCFixup> &Fixups,
187193
const MCSubtargetInfo &STI) const {
194+
verifyInstructionPredicates(MI,
195+
computeAvailableFeatures(STI.getFeatureBits()));
196+
188197
const MCInstrDesc &Desc = MCII.get(MI.getOpcode());
189198
// Get byte count of instruction.
190199
unsigned Size = Desc.getSize();
@@ -397,4 +406,5 @@ unsigned RISCVMCCodeEmitter::getVMaskReg(const MCInst &MI, unsigned OpNo,
397406
}
398407
}
399408

409+
#define ENABLE_INSTR_PREDICATE_VERIFIER
400410
#include "RISCVGenMCCodeEmitter.inc"

0 commit comments

Comments
 (0)