Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lgc/llpc][NFC] - Use starts_with and ends_with #2889

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lgc/builder/BuilderRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2161,13 +2161,13 @@ Instruction *Builder::record(BuilderOpcode opcode, Type *resultTy, ArrayRef<Valu
// @param name : Name of function declaration
// @returns : Opcode
BuilderOpcode BuilderRecorder::getOpcodeFromName(StringRef name) {
assert(name.startswith(BuilderCallPrefix));
assert(name.starts_with(BuilderCallPrefix));
name = name.drop_front(strlen(BuilderCallPrefix));
unsigned bestOpcode = 0;
unsigned bestLength = 0;
for (unsigned opcode = 0; opcode != BuilderOpcode::Count; ++opcode) {
StringRef opcodeName = getCallName(static_cast<BuilderOpcode>(opcode));
if (name.startswith(opcodeName)) {
if (name.starts_with(opcodeName)) {
if (opcodeName.size() > bestLength) {
bestLength = opcodeName.size();
bestOpcode = opcode;
Expand Down
6 changes: 3 additions & 3 deletions lgc/builder/BuilderReplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ bool BuilderReplayer::runImpl(Module &module, PipelineState *pipelineState) {
if (const MDNode *funcMeta = func.getMetadata(opcodeMetaKindId)) {
const ConstantAsMetadata *metaConst = cast<ConstantAsMetadata>(funcMeta->getOperand(0));
opcode = cast<ConstantInt>(metaConst->getValue())->getZExtValue();
assert(func.getName().startswith(BuilderCallPrefix));
assert(func.getName().starts_with(BuilderCallPrefix));
assert(func.getName()
.slice(strlen(BuilderCallPrefix), StringRef::npos)
.startswith(BuilderRecorder::getCallName(static_cast<BuilderOpcode>(opcode))) &&
.starts_with(BuilderRecorder::getCallName(static_cast<BuilderOpcode>(opcode))) &&
"lgc.create.* mismatch!");
} else {
if (!func.getName().startswith(BuilderCallPrefix))
if (!func.getName().starts_with(BuilderCallPrefix))
continue; // Not lgc.create.* call
opcode = BuilderRecorder::getOpcodeFromName(func.getName());
}
Expand Down
2 changes: 1 addition & 1 deletion lgc/disassembler/Disassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ static InstOp parseInstOp(StringRef op) {
return res;
}

if (op.startswith("s")) {
if (op.starts_with("s")) {
StringRef s = op.drop_front(1);
s.consume_front("[");
unsigned n;
Expand Down
2 changes: 1 addition & 1 deletion lgc/elfLinker/FetchShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void FetchShader::replaceShaderInputBuiltInFunctions(Function *fetchFunc) const
for (Function &func : *fetchFunc->getParent()) {
if (!func.isDeclaration())
continue;
if (func.getName().startswith(lgcName::SpecialUserData) || func.getName().startswith(lgcName::ShaderInput)) {
if (func.getName().starts_with(lgcName::SpecialUserData) || func.getName().starts_with(lgcName::ShaderInput)) {
while (!func.use_empty()) {
auto call = cast<CallInst>(func.use_begin()->getUser());
Value *replacement = nullptr;
Expand Down
36 changes: 18 additions & 18 deletions lgc/patch/CombineCooperativeMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ bool CooperativeMatrixCombiner::run() {
if (!fn.isDeclaration())
continue;

if (fn.getName().startswith(lgcName::CooperativeMatrixTranspose)) {
if (fn.getName().starts_with(lgcName::CooperativeMatrixTranspose)) {
for (User *user : fn.users()) {
if (auto *call = dyn_cast<CallInst>(user)) {
if (call->getFunction() == &m_function)
ops.push_back(call);
}
}
} else if (fn.getName().startswith(lgcName::CooperativeMatrixConvert)) {
} else if (fn.getName().starts_with(lgcName::CooperativeMatrixConvert)) {
for (User *user : fn.users()) {
if (auto *call = dyn_cast<CallInst>(user)) {
if (call->getFunction() == &m_function)
Expand Down Expand Up @@ -174,11 +174,11 @@ void CooperativeMatrixCombiner::foldTo(Value *from, Value *to) {
bool CooperativeMatrixCombiner::tryFold(CallInst *op) {
Value *src;
bool isConvert = false;
if (op->getCalledFunction()->getName().startswith(lgcName::CooperativeMatrixConvert)) {
if (op->getCalledFunction()->getName().starts_with(lgcName::CooperativeMatrixConvert)) {
src = op->getArgOperand(1);
isConvert = true;
} else {
assert(op->getCalledFunction()->getName().startswith(lgcName::CooperativeMatrixTranspose));
assert(op->getCalledFunction()->getName().starts_with(lgcName::CooperativeMatrixTranspose));
src = op->getArgOperand(0);
}

Expand Down Expand Up @@ -320,14 +320,14 @@ bool CooperativeMatrixCombiner::tryFoldComponentContaining(Value *start) {

if (auto *call = dyn_cast<CallInst>(input)) {
if (auto *callee = call->getCalledFunction()) {
if (callee->getName().startswith(lgcName::CooperativeMatrixLoad))
if (callee->getName().starts_with(lgcName::CooperativeMatrixLoad))
continue; // loads can be adjusted at zero cost
if (callee->getName().startswith(lgcName::CooperativeMatrixTranspose)) {
if (callee->getName().starts_with(lgcName::CooperativeMatrixTranspose)) {
foundComponentShape(getShapeOfTranspose(call));
++numTransposeInputs;
continue;
}
if (callee->getName().startswith(lgcName::CooperativeMatrixConvert)) {
if (callee->getName().starts_with(lgcName::CooperativeMatrixConvert)) {
auto srcElemType =
(Builder::CooperativeMatrixElementType)cast<ConstantInt>(call->getArgOperand(2))->getZExtValue();
auto dstElemType =
Expand Down Expand Up @@ -357,14 +357,14 @@ bool CooperativeMatrixCombiner::tryFoldComponentContaining(Value *start) {
for (Use *use : component.outputs) {
if (auto *call = dyn_cast<CallInst>(use->getUser())) {
if (auto *callee = call->getCalledFunction()) {
if (callee->getName().startswith(lgcName::CooperativeMatrixStore))
if (callee->getName().starts_with(lgcName::CooperativeMatrixStore))
continue; // stores can be adapted at zero cost
if (callee->getName().startswith(lgcName::CooperativeMatrixTranspose)) {
if (callee->getName().starts_with(lgcName::CooperativeMatrixTranspose)) {
foundComponentShape(getShapeOfTranspose(call));
transposeOutputs.insert(use->get());
continue;
}
if (callee->getName().startswith(lgcName::CooperativeMatrixConvert)) {
if (callee->getName().starts_with(lgcName::CooperativeMatrixConvert)) {
auto srcElemType =
(Builder::CooperativeMatrixElementType)cast<ConstantInt>(call->getArgOperand(2))->getZExtValue();
auto dstElemType =
Expand Down Expand Up @@ -403,15 +403,15 @@ bool CooperativeMatrixCombiner::tryFoldComponentContaining(Value *start) {
// Handle inputs that can be folded away / absorbed.
if (auto *call = dyn_cast<CallInst>(input)) {
if (auto *callee = call->getCalledFunction()) {
if (callee->getName().startswith(lgcName::CooperativeMatrixTranspose)) {
if (callee->getName().starts_with(lgcName::CooperativeMatrixTranspose)) {
Value *src = call->getArgOperand(0);
foldTo(input, src);

// Prepopulate the transpose cache to re-use the old transpose operation instead of creating a new one.
outTransposed.try_emplace(src, input);
continue;
}
if (callee->getName().startswith(lgcName::CooperativeMatrixLoad)) {
if (callee->getName().starts_with(lgcName::CooperativeMatrixLoad)) {
bool colMajor = cast<ConstantInt>(call->getArgOperand(2))->getZExtValue();
call->setArgOperand(2, b.getInt1(!colMajor));
continue;
Expand All @@ -437,11 +437,11 @@ bool CooperativeMatrixCombiner::tryFoldComponentContaining(Value *start) {
// Handle outputs that can be folded away / absorbed.
if (auto *call = dyn_cast<CallInst>(use->getUser())) {
if (auto *callee = call->getCalledFunction()) {
if (callee->getName().startswith(lgcName::CooperativeMatrixTranspose)) {
if (callee->getName().starts_with(lgcName::CooperativeMatrixTranspose)) {
foldTo(call, use->get());
continue;
}
if (callee->getName().startswith(lgcName::CooperativeMatrixStore)) {
if (callee->getName().starts_with(lgcName::CooperativeMatrixStore)) {
bool colMajor = cast<ConstantInt>(call->getArgOperand(2))->getZExtValue();
call->setArgOperand(2, b.getInt1(!colMajor));
continue;
Expand Down Expand Up @@ -505,7 +505,7 @@ bool CooperativeMatrixCombiner::tryFoldComponentContaining(Value *start) {
// Handle inputs for which the relayout can be folded or absorbed.
if (auto *call = dyn_cast<CallInst>(input)) {
if (auto *callee = call->getCalledFunction()) {
if (callee->getName().startswith(lgcName::CooperativeMatrixConvert)) {
if (callee->getName().starts_with(lgcName::CooperativeMatrixConvert)) {
unsigned srcElemType = cast<ConstantInt>(call->getArgOperand(2))->getZExtValue();
unsigned dstElemType = cast<ConstantInt>(call->getArgOperand(3))->getZExtValue();

Expand All @@ -527,7 +527,7 @@ bool CooperativeMatrixCombiner::tryFoldComponentContaining(Value *start) {
call->setArgOperand(5, b.getInt32((unsigned)*otherLayout));
continue;
}
if (callee->getName().startswith(lgcName::CooperativeMatrixLoad)) {
if (callee->getName().starts_with(lgcName::CooperativeMatrixLoad)) {
call->setArgOperand(4, b.getInt32((unsigned)*otherLayout));
continue;
}
Expand All @@ -553,7 +553,7 @@ bool CooperativeMatrixCombiner::tryFoldComponentContaining(Value *start) {
// Handle outputs for which the relayout can be folded or absorbed.
if (auto *call = dyn_cast<CallInst>(use->getUser())) {
if (auto *callee = call->getCalledFunction()) {
if (callee->getName().startswith(lgcName::CooperativeMatrixConvert)) {
if (callee->getName().starts_with(lgcName::CooperativeMatrixConvert)) {
unsigned srcElemType = cast<ConstantInt>(call->getArgOperand(2))->getZExtValue();
unsigned dstElemType = cast<ConstantInt>(call->getArgOperand(3))->getZExtValue();

Expand All @@ -567,7 +567,7 @@ bool CooperativeMatrixCombiner::tryFoldComponentContaining(Value *start) {
continue;
}
}
if (callee->getName().startswith(lgcName::CooperativeMatrixStore)) {
if (callee->getName().starts_with(lgcName::CooperativeMatrixStore)) {
call->setArgOperand(4, b.getInt32((unsigned)*otherLayout));
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions lgc/patch/FragColorExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ void LowerFragColorExport::collectExportInfoForGenericOutputs(Function *fragEntr

// Collect all of the exports in the fragment shader
for (auto &func : *fragEntryPoint->getParent()) {
if (!func.isDeclaration() || !func.getName().startswith(lgcName::OutputExportGeneric))
if (!func.isDeclaration() || !func.getName().starts_with(lgcName::OutputExportGeneric))
continue;
for (auto user : func.users()) {
auto callInst = cast<CallInst>(user);
Expand Down Expand Up @@ -652,7 +652,7 @@ void LowerFragColorExport::collectExportInfoForBuiltinOutput(Function *module, B
Value *m_fragStencilRef = nullptr;
Value *m_sampleMask = nullptr;
for (auto &func : *module->getParent()) {
if (!func.isDeclaration() || !func.getName().startswith(lgcName::OutputExportBuiltIn))
if (!func.isDeclaration() || !func.getName().starts_with(lgcName::OutputExportBuiltIn))
continue;
for (auto user : func.users()) {
auto callInst = cast<CallInst>(user);
Expand Down
22 changes: 11 additions & 11 deletions lgc/patch/LowerCooperativeMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ bool LowerCooperativeMatrix::runImpl(Module &module, PipelineShadersResult &pipe
SmallVector<Function *, 16> lowerCoopMatrixCallees;
for (auto &func : module) {
auto name = func.getName();
if (name.startswith(lgcName::CooperativeMatrix))
if (name.starts_with(lgcName::CooperativeMatrix))
lowerCoopMatrixCallees.push_back(&func);
}
if (lowerCoopMatrixCallees.empty())
Expand Down Expand Up @@ -127,11 +127,11 @@ void LowerCooperativeMatrix::visitCallInst(CallInst &callInst) {
builder.SetInsertPoint(&callInst);

auto mangledName = callee->getName();
if (mangledName.startswith(lgcName::CooperativeMatrixLength)) {
if (mangledName.starts_with(lgcName::CooperativeMatrixLength)) {
auto layout =
static_cast<Builder::CooperativeMatrixLayout>(cast<ConstantInt>(callInst.getOperand(1))->getZExtValue());
callInst.replaceAllUsesWith(builder.getInt32(getLength(layout)));
} else if (mangledName.startswith(lgcName::CooperativeMatrixExtract)) {
} else if (mangledName.starts_with(lgcName::CooperativeMatrixExtract)) {
Value *matrix = callInst.getOperand(0);
Value *index = callInst.getOperand(1);
auto elemType =
Expand All @@ -141,7 +141,7 @@ void LowerCooperativeMatrix::visitCallInst(CallInst &callInst) {
Value *result = cooperativeMatrixExtract(builder, matrix, index, elemType, layout);
result->takeName(&callInst);
callInst.replaceAllUsesWith(result);
} else if (mangledName.startswith(lgcName::CooperativeMatrixInsert)) {
} else if (mangledName.starts_with(lgcName::CooperativeMatrixInsert)) {
Value *matrix = callInst.getOperand(0);
Value *value = callInst.getOperand(1);
Value *index = callInst.getOperand(2);
Expand All @@ -152,7 +152,7 @@ void LowerCooperativeMatrix::visitCallInst(CallInst &callInst) {
Value *result = cooperativeMatrixInsert(builder, matrix, value, index, elemType, layout);
result->takeName(&callInst);
callInst.replaceAllUsesWith(result);
} else if (mangledName.startswith(lgcName::CooperativeMatrixLoad)) {
} else if (mangledName.starts_with(lgcName::CooperativeMatrixLoad)) {
Value *dataPtr = callInst.getOperand(0);
Value *stride = callInst.getOperand(1);
bool colMajor = cast<ConstantInt>(callInst.getOperand(2))->getZExtValue();
Expand All @@ -166,7 +166,7 @@ void LowerCooperativeMatrix::visitCallInst(CallInst &callInst) {
callInst.getName(), &callInst);
callInst.replaceAllUsesWith(loadVal);

} else if (mangledName.startswith(lgcName::CooperativeMatrixStore)) {
} else if (mangledName.starts_with(lgcName::CooperativeMatrixStore)) {
Value *dataPtr = callInst.getOperand(0);
Value *stride = callInst.getOperand(1);
bool colMajor = cast<ConstantInt>(callInst.getOperand(2))->getZExtValue();
Expand All @@ -180,7 +180,7 @@ void LowerCooperativeMatrix::visitCallInst(CallInst &callInst) {
cooperativeMatrixStoreInternal(dataPtr, stride, colMajor, elemType, layout, memoryAccess, vecVal,
callInst.getName(), &callInst);

} else if (mangledName.startswith(lgcName::CooperativeMatrixConvert)) {
} else if (mangledName.starts_with(lgcName::CooperativeMatrixConvert)) {
CastInst::CastOps castOp =
static_cast<CastInst::CastOps>(cast<ConstantInt>(callInst.getOperand(0))->getZExtValue());
Value *source = callInst.getOperand(1);
Expand All @@ -204,7 +204,7 @@ void LowerCooperativeMatrix::visitCallInst(CallInst &callInst) {
}
callInst.replaceAllUsesWith(resultVal);

} else if (mangledName.startswith(lgcName::CooperativeMatrixTranspose)) {
} else if (mangledName.starts_with(lgcName::CooperativeMatrixTranspose)) {
Value *matrix = callInst.getOperand(0);
Builder::CooperativeMatrixElementType elemType =
static_cast<Builder::CooperativeMatrixElementType>(cast<ConstantInt>(callInst.getOperand(1))->getZExtValue());
Expand All @@ -214,7 +214,7 @@ void LowerCooperativeMatrix::visitCallInst(CallInst &callInst) {
Value *resultVal = cooperativeMatrixTranspose(matrix, elemType, srcLayout, callInst.getName(), &callInst);
callInst.replaceAllUsesWith(resultVal);

} else if (mangledName.startswith(lgcName::CooperativeMatrixBinOp)) {
} else if (mangledName.starts_with(lgcName::CooperativeMatrixBinOp)) {
Builder::CooperativeMatrixArithOp coopMatArithOp =
static_cast<Builder::CooperativeMatrixArithOp>(cast<ConstantInt>(callInst.getOperand(0))->getZExtValue());
Value *lhs = callInst.getOperand(1);
Expand All @@ -228,7 +228,7 @@ void LowerCooperativeMatrix::visitCallInst(CallInst &callInst) {
cooperativeMatrixBinaryOp(coopMatArithOp, lhs, rhs, elemType, srcLayout, callInst.getName(), &callInst);
callInst.replaceAllUsesWith(resultVal);

} else if (mangledName.startswith(lgcName::CooperativeMatrixTimesScalar)) {
} else if (mangledName.starts_with(lgcName::CooperativeMatrixTimesScalar)) {
Value *matrix = callInst.getOperand(0);
Value *scalar = callInst.getOperand(1);
Builder::CooperativeMatrixElementType elemType =
Expand All @@ -239,7 +239,7 @@ void LowerCooperativeMatrix::visitCallInst(CallInst &callInst) {
Value *resultVal = coopMatrixTimesScalar(matrix, scalar, elemType, srcLayout, callInst.getName(), &callInst);
callInst.replaceAllUsesWith(resultVal);

} else if (mangledName.startswith(lgcName::CooperativeMatrixMulAdd)) {
} else if (mangledName.starts_with(lgcName::CooperativeMatrixMulAdd)) {
Value *matrixA = callInst.getOperand(0);
Value *matrixB = callInst.getOperand(1);
Value *matrixC = callInst.getOperand(2);
Expand Down
Loading