Skip to content

Commit 9416e96

Browse files
jaladreipsigcbot
authored andcommitted
Add a convenience function to insert setdebugreg instructions
This function will: * convert pointers to i32 and emit 2 instructions (for 64bit pointers) * try to bitcast 32bit data types to i32 (float) * will deal with nonuniform variables by reading only the first active lane
1 parent b234e04 commit 9416e96

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

IGC/Compiler/CISACodeGen/EmitVISAPass.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5472,6 +5472,9 @@ void EmitPass::emitSetDebugReg(llvm::Instruction* inst)
54725472
m_encoder->Push();
54735473
}
54745474

5475+
if (inst->use_empty())
5476+
return;
5477+
54755478
// read dbg0.1
54765479
m_encoder->SetSrcSubReg(0, 1);
54775480
m_encoder->SetSrcRegion(0, 0, 1, 0);

IGC/common/IGCIRBuilder.h

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,64 @@ namespace llvm {
176176
return this->CreateCall(func, Arg, Name);
177177
}
178178

179+
inline void SetDebugReg(Value* V, const Twine& Name = "")
180+
{
181+
Module *M = this->GetInsertBlock()->getParent()->getParent();
182+
Function *fn = GenISAIntrinsic::getDeclaration(
183+
M, GenISAIntrinsic::GenISA_SetDebugReg);
184+
185+
if (!isa<Constant>(V)) {
186+
187+
// read the first lane because debug register requires the value to
188+
// be uniform
189+
Function *waveBallotFn = GenISAIntrinsic::getDeclaration(
190+
M, GenISAIntrinsic::GenISA_WaveBallot);
191+
192+
Function *waveShuffleIndexFn = GenISAIntrinsic::getDeclaration(
193+
M, GenISAIntrinsic::GenISA_WaveShuffleIndex,
194+
V->getType());
195+
196+
Function *fblFn = GenISAIntrinsic::getDeclaration(
197+
M, GenISAIntrinsic::GenISA_firstbitLo);
198+
199+
CallInst *ballot = this->CreateCall2(waveBallotFn, this->getTrue(),
200+
this->getInt32(0));
201+
202+
auto *firstLaneId = this->CreateCall(fblFn, ballot);
203+
V = this->CreateCall3(waveShuffleIndexFn, V, firstLaneId,
204+
this->getInt32(0));
205+
}
206+
207+
if (V->getType() == this->getInt32Ty()) {
208+
this->CreateCall(fn, V, Name);
209+
return;
210+
}
211+
212+
if (V->getType()->isPointerTy()) {
213+
V = this->CreatePtrToInt(V, this->getInt64Ty());
214+
this->CreateCall(fn, this->CreateTrunc(V, this->getInt32Ty()),
215+
Name);
216+
this->CreateCall(
217+
fn,
218+
this->CreateTrunc(this->CreateLShr(V, 32), this->getInt32Ty()),
219+
Name);
220+
return;
221+
}
222+
223+
if (V->getType()->getPrimitiveSizeInBits() == 32) {
224+
this->CreateCall(fn, this->CreateBitCast(V, this->getInt32Ty()),
225+
Name);
226+
return;
227+
}
228+
229+
IGC_ASSERT_MESSAGE(0, "Unhandled?");
230+
}
231+
232+
inline void SetDebugReg(uint32_t V, const Twine& Name = "")
233+
{
234+
this->SetDebugReg(this->getInt32(V));
235+
}
236+
179237
private:
180238

181239
inline Value* CreateAllValuesAreConstantFP(Value** values,
@@ -195,5 +253,5 @@ namespace llvm {
195253
}
196254
};
197255

198-
} // end namespace llvm
256+
} // end namespace llvm
199257

0 commit comments

Comments
 (0)