@@ -24,11 +24,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2424
2525======================= end_copyright_notice ==================================*/
2626
27- #include < sstream>
2827#include " common/LLVMWarningsPush.hpp"
2928#include < llvm/Support/ScaledNumber.h>
30- #include < llvm/Demangle/Demangle.h>
31- #include < llvm/IR/DebugInfo.h>
3229#include " common/LLVMWarningsPop.hpp"
3330#include " Compiler/CISACodeGen/ComputeShaderCodeGen.hpp"
3431#include " Compiler/CISACodeGen/ShaderCodeGen.hpp"
@@ -709,132 +706,15 @@ namespace IGC
709706 llvmCtxWrapper = nullptr ;
710707 }
711708
712- static const llvm::Function * getRelatedFunction (const llvm::Value *value )
709+ void CodeGenContext::EmitError (const char * errorstr )
713710 {
714- if (value == nullptr )
715- return nullptr ;
716-
717- if (const llvm::Function *F = llvm::dyn_cast<llvm::Function>(value)) {
718- return F;
719- }
720- if (const llvm::Argument *A = llvm::dyn_cast<llvm::Argument>(value)) {
721- return A->getParent ();
722- }
723- if (const llvm::BasicBlock *BB = llvm::dyn_cast<llvm::BasicBlock>(value)) {
724- return BB->getParent ();
725- }
726- if (const llvm::Instruction *I = llvm::dyn_cast<llvm::Instruction>(value)) {
727- return I->getParent ()->getParent ();
728- }
729-
730- return nullptr ;
731- }
732-
733- static bool isEntryPoint (CodeGenContext *ctx, const llvm::Function *F)
734- {
735- if (F == nullptr ) {
736- return false ;
737- }
738-
739- auto & FuncMD = ctx->getModuleMetaData ()->FuncMD ;
740- auto FuncInfo = FuncMD.find (const_cast <llvm::Function *>(F));
741- if (FuncInfo == FuncMD.end ()) {
742- return false ;
743- }
744-
745- const FunctionMetaData* MD = &FuncInfo->second ;
746- return MD->functionType == KernelFunction;
747- }
748-
749- static void findCallingKernles
750- (CodeGenContext *ctx, const llvm::Function *F, llvm::SmallPtrSetImpl<const llvm::Function *> *kernels)
751- {
752- if (F == nullptr || kernels->count (F))
753- return ;
754-
755- for (const llvm::User *U : F->users ()) {
756- auto *CI = llvm::dyn_cast<llvm::CallInst>(U);
757- if (CI == nullptr )
758- continue ;
759-
760- if (CI->getCalledFunction () != F)
761- continue ;
762-
763- const llvm::Function *caller = getRelatedFunction (CI);
764- if (isEntryPoint (ctx, caller)) {
765- kernels->insert (caller);
766- continue ;
767- }
768- // Caller is not a kernel, try to check which kerneles might
769- // be calling it:
770- findCallingKernles (ctx, caller, kernels);
771- }
772- }
773-
774- // TODO: remove this wrapper once we move to LLVM 11
775- static std::string demangle_wrapper (const std::string &name) {
776- #if LLVM_VERSION_MAJOR >= 11
777- return llvm::demangle (name);
778- #else
779- char *demangled = nullptr ;
780-
781- demangled = llvm::itaniumDemangle (name.c_str (), nullptr , nullptr , nullptr );
782- if (demangled == nullptr ) {
783- demangled = llvm::microsoftDemangle (name.c_str (), nullptr , nullptr , nullptr );
784- }
785-
786- if (demangled == nullptr ) {
787- return name;
788- }
789-
790- std::string result = demangled;
791- std::free (demangled);
792- return result;
793- #endif
794- }
795-
796- void CodeGenContext::EmitError (const char * errorstr, const llvm::Value *context)
797- {
798- std::stringstream ss;
799-
800- ss << " \n error :" ;
801- ss << errorstr;
802- // Try to get debug location to print out the relevant info.
803- if (const llvm::Instruction *I = llvm::dyn_cast<llvm::Instruction>(context)) {
804- if (const llvm::DILocation *DL = I->getDebugLoc ()) {
805- ss << " \n in file: " << DL->getFilename ().str () << " :" << DL->getLine () << " \n " ;
806- }
807- }
808- // Try to find function related to given context
809- // to print more informative error message.
810- if (const llvm::Function *F = getRelatedFunction (context)) {
811- // If the function is a kernel just print the kernel name.
812- if (isEntryPoint (this , F)) {
813- ss << " \n in kernel: '" << demangle_wrapper (F->getName ()) << " '" ;
814- // If the function is not a kernel try to print all kernels that
815- // might be using this function.
816- } else {
817- llvm::SmallPtrSet<const llvm::Function *, 16 > kernels;
818- findCallingKernles (this , F, &kernels);
819-
820- const size_t kernelsCount = kernels.size ();
821- ss << " \n in function: '" << demangle_wrapper (F->getName ()) << " ' " ;
822- if (kernelsCount == 0 ) {
823- ss << " called indirectly by at least one of the kernels.\n " ;
824- } else if (kernelsCount == 1 ) {
825- const llvm::Function *kernel = *kernels.begin ();
826- ss << " called by kernel: '" << demangle_wrapper (kernel->getName ()) << " '\n " ;
827- } else {
828- ss << " called by kernels:\n " ;
829- for (const llvm::Function *kernel : kernels) {
830- ss << " - '" << demangle_wrapper (kernel->getName ()) << " '\n " ;
831- }
832- }
833- }
834- }
835- ss << " \n error: backend compiler failed build.\n " ;
836-
837- this ->oclErrorMessage = ss.str ();// where to get this from
711+ std::string str (errorstr);
712+ std::string msg;
713+ msg += " \n error: " ;
714+ msg += str;
715+ msg += " \n error: backend compiler failed build.\n " ;
716+ str = msg;
717+ this ->oclErrorMessage = str;// where to get this from
838718 return ;
839719 }
840720
0 commit comments