Small cleanup.
    * Use `cast` rather than `dyn_cast` to get an assertion failure rather than a segfault in case of a type mismatch.
    * Use stream operators to `emitOpError`s.

--

PiperOrigin-RevId: 249208135
diff --git a/lib/GPU/IR/GPUDialect.cpp b/lib/GPU/IR/GPUDialect.cpp
index bd882c9..a7554c2 100644
--- a/lib/GPU/IR/GPUDialect.cpp
+++ b/lib/GPU/IR/GPUDialect.cpp
@@ -303,7 +303,7 @@
 }
 
 Function *LaunchFuncOp::kernel() {
-  return this->getAttr(getKernelAttrName()).dyn_cast<FunctionAttr>().getValue();
+  return this->getAttr(getKernelAttrName()).cast<FunctionAttr>().getValue();
 }
 
 unsigned LaunchFuncOp::getNumKernelOperands() {
@@ -324,20 +324,20 @@
   Function *kernelFunc = this->kernel();
   if (!kernelFunc->getAttrOfType<mlir::UnitAttr>(
           GPUDialect::getKernelFuncAttrName())) {
-    return emitError("kernel function is missing the '" +
-                     GPUDialect::getKernelFuncAttrName() + "' attribute");
+    return emitError("kernel function is missing the '")
+           << GPUDialect::getKernelFuncAttrName() << "' attribute";
   }
   unsigned numKernelFuncArgs = kernelFunc->getNumArguments();
   if (getNumKernelOperands() != numKernelFuncArgs) {
-    return emitOpError("got " + Twine(getNumKernelOperands()) +
-                       " kernel operands but expected " +
-                       Twine(numKernelFuncArgs));
+    return emitOpError("got ")
+           << getNumKernelOperands() << " kernel operands but expected "
+           << numKernelFuncArgs;
   }
   for (unsigned i = 0; i < numKernelFuncArgs; ++i) {
     if (getKernelOperand(i)->getType() !=
         kernelFunc->getArgument(i)->getType()) {
-      return emitOpError("type of function argument " + Twine(i) +
-                         " does not match");
+      return emitOpError("type of function argument ")
+             << i << " does not match";
     }
   }
   return success();