Skip to content

Commit 3bd5478

Browse files
pratikasharigcbot
authored andcommitted
Implement compareOperand() API for G4_Reloc_Imm
This is useful for checking equivalence of 2 relocatable imm operands. Without this change, we fall back to invoking G4_Imm::compareOperand() that returns Rel_eq for 2 relocatable immediates as they're always initialized to same imm magic value. This bug is fixed by checking symbol equivalence in G4_Reloc_Imm::compareOperand() now.
1 parent fabd05c commit 3bd5478

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

visa/G4_IR.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5580,6 +5580,22 @@ int64_t G4_Imm::typecastVals(int64_t value, G4_Type type) {
55805580
return retVal;
55815581
}
55825582

5583+
G4_CmpRelation G4_Reloc_Imm::compareOperand(G4_Operand *opnd,
5584+
const IR_Builder &builder) {
5585+
if (!opnd->isRelocImm())
5586+
return Rel_disjoint;
5587+
5588+
const auto *relocImmOpnd = opnd->asRelocImm();
5589+
if (llvm::StringRef(symbol) != llvm::StringRef(relocImmOpnd->symbol))
5590+
return Rel_disjoint;
5591+
if (relocKind != relocImmOpnd->relocKind)
5592+
return Rel_disjoint;
5593+
if (getType() != opnd->getType())
5594+
return Rel_disjoint;
5595+
5596+
return Rel_eq;
5597+
}
5598+
55835599
void G4_Reloc_Imm::emit(std::ostream &output) {
55845600
// @RelocTy(Symbol):OpType
55855601
// @RelocTy(Symbol+Imm):OpType

visa/G4_Operand.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ class G4_InstDpas;
121121
// Forward declarations for the concrete operand classes. We need them here
122122
// because the base class has APIs that perform downcasts to the concrete type.
123123
class G4_Imm;
124+
class G4_Reloc_Imm;
124125
class G4_Label;
125126
class G4_AddrExp;
126127
class G4_DstRegRegion;
@@ -303,6 +304,18 @@ class G4_Operand {
303304
return const_cast<G4_Imm *>(((const G4_Operand *)this)->asImm());
304305
}
305306

307+
const G4_Reloc_Imm *asRelocImm() const {
308+
#ifdef _DEBUG
309+
if (!isRelocImm()) {
310+
return nullptr;
311+
}
312+
#endif
313+
return reinterpret_cast<const G4_Reloc_Imm *>(this);
314+
}
315+
G4_Reloc_Imm *asRelocImm() {
316+
return const_cast<G4_Reloc_Imm *>(((const G4_Operand *)this)->asRelocImm());
317+
}
318+
306319
const G4_Predicate *asPredicate() const {
307320
#ifdef _DEBUG
308321
if (!isPredicate()) {
@@ -478,6 +491,9 @@ class G4_Reloc_Imm : public G4_Imm {
478491
void *operator new(size_t sz, Mem_Manager &m) { return m.alloc(sz); }
479492
public:
480493

494+
G4_CmpRelation compareOperand(G4_Operand *opnd,
495+
const IR_Builder &builder) override;
496+
481497
bool isRelocImm() const override { return true; }
482498

483499
void emit(std::ostream &output) override;

0 commit comments

Comments
 (0)