@@ -3683,24 +3683,26 @@ namespace IGC
36833683 }
36843684 }
36853685
3686- void CEncoder::InitBuildParams (llvm::SmallVector<const char * , 10 >& params)
3686+ void CEncoder::InitBuildParams (llvm::SmallVector<std::unique_ptr< char , std::function< void ( char *)>> , 10>& params)
36873687 {
36883688 CodeGenContext* context = m_program->GetContext ();
36893689 bool isOptDisabled = context->getModuleMetaData ()->compOpt .OptDisable ;
3690-
3690+ typedef std::unique_ptr< char , std::function<void (char *)>> param_uptr;
3691+ auto literal_deleter = [](char * val) {};
3692+ auto dup_deleter = [](char * val) {free (val); };
36913693 // create vbuilder->Compile() params
36923694 if (IGC_IS_FLAG_ENABLED (EnableVISADotAll))
36933695 {
3694- params.push_back (" -dotAll" );
3696+ params.push_back (param_uptr ( " -dotAll" , literal_deleter) );
36953697 }
36963698 if (IGC_IS_FLAG_ENABLED (EnableVISADebug) || isOptDisabled)
36973699 {
3698- params.push_back (" -debug" );
3700+ params.push_back (param_uptr ( " -debug" , literal_deleter) );
36993701 }
37003702 if (context->getModuleMetaData ()->compOpt .FastVISACompile )
37013703 {
3702- params.push_back (" -fasterRA" );
3703- params.push_back (" -noLocalSplit" );
3704+ params.push_back (param_uptr ( " -fasterRA" , literal_deleter) );
3705+ params.push_back (param_uptr ( " -noLocalSplit" , literal_deleter) );
37043706 }
37053707 // Ensure VISA_Opts has the same scope as CreateVISABuilder so that valid
37063708 // strings are checked by vISA and freed out of this function.
@@ -3724,7 +3726,7 @@ namespace IGC
37243726 // note that the memory should be freed once
37253727 // params has been read, but since this is only for
37263728 // debugging, do not bother freeing memory.
3727- params.push_back (_strdup (opt.c_str ()));
3729+ params.push_back (param_uptr ( _strdup (opt.c_str ()), dup_deleter ));
37283730 if (opt == " -output" || opt == " -binary" || opt == " -dumpvisa" || opt == " -dumpcommonisa" )
37293731 {
37303732 m_enableVISAdump = true ;
@@ -3736,11 +3738,11 @@ namespace IGC
37363738 {
37373739 QWORD AssemblyHash = { 0 };
37383740 AssemblyHash = context->hash .getAsmHash ();
3739- params.push_back (" -hashmovs" );
3741+ params.push_back (param_uptr ( " -hashmovs" , literal_deleter) );
37403742 std::string Low = std::to_string ((DWORD)AssemblyHash);
37413743 std::string High = std::to_string ((DWORD)(AssemblyHash >> 32 ));
3742- params.push_back (_strdup (Low.c_str ()));
3743- params.push_back (_strdup (High.c_str ()));
3744+ params.push_back (param_uptr ( _strdup (Low.c_str ()), dup_deleter ));
3745+ params.push_back (param_uptr ( _strdup (High.c_str ()), dup_deleter ));
37443746
37453747 QWORD NosHash = { 0 };
37463748 NosHash = context->hash .getNosHash ();
@@ -3749,11 +3751,11 @@ namespace IGC
37493751 QWORD hashToUse = NosHash != 0 ? NosHash : PsoHash;
37503752 if (hashToUse)
37513753 {
3752- params.push_back (" -hashmovs1" );
3754+ params.push_back (param_uptr ( " -hashmovs1" , literal_deleter) );
37533755 std::string Low = std::to_string ((DWORD)hashToUse);
37543756 std::string High = std::to_string ((DWORD)(hashToUse >> 32 ));
3755- params.push_back (_strdup (Low.c_str ()));
3756- params.push_back (_strdup (High.c_str ()));
3757+ params.push_back (param_uptr ( _strdup (Low.c_str ()), dup_deleter ));
3758+ params.push_back (param_uptr ( _strdup (High.c_str ()), dup_deleter ));
37573759 }
37583760 }
37593761 }
@@ -4305,10 +4307,15 @@ namespace IGC
43054307 SetVISAWaTable (m_program->m_Platform ->getWATable ());
43064308
43074309 llvm::SmallVector<const char *, 10 > params;
4310+ llvm::SmallVector<std::unique_ptr< char , std::function<void (char *)>>, 10 > params2;
43084311 if (!m_hasInlineAsm)
43094312 {
43104313 // Asm text writer mode doesnt need dump params
4311- InitBuildParams (params);
4314+ InitBuildParams (params2);
4315+ for (size_t i = 0 ; i < params2.size (); i++)
4316+ {
4317+ params.push_back ((params2[i].get ()));
4318+ }
43124319 }
43134320
43144321 COMPILER_TIME_START (m_program->GetContext (), TIME_CG_vISACompile);
@@ -4845,7 +4852,12 @@ namespace IGC
48454852 V (vbuilder->WriteVISAHeader ());
48464853
48474854 llvm::SmallVector<const char *, 10 > params;
4848- InitBuildParams (params);
4855+ llvm::SmallVector<std::unique_ptr< char , std::function<void ( char *)>>, 10 > params2;
4856+ InitBuildParams (params2);
4857+ for (size_t i = 0 ; i < params2.size (); i++)
4858+ {
4859+ params.push_back ((params2[i].get ()));
4860+ }
48494861
48504862 // Create a new builder for parsing the visaasm
48514863 TARGET_PLATFORM VISAPlatform = GetVISAPlatform (&(context->platform ));
0 commit comments