| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251 |
- // Copyright (c) 2019 Google LLC
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- #include "source/fuzz/transformation_outline_function.h"
- #include "gtest/gtest.h"
- #include "source/fuzz/counter_overflow_id_source.h"
- #include "source/fuzz/fuzzer_util.h"
- #include "test/fuzz/fuzz_test_util.h"
- namespace spvtools {
- namespace fuzz {
- namespace {
- TEST(TransformationOutlineFunctionTest, TrivialOutline) {
- // This tests outlining of a single, empty basic block.
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_4;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(5, 5, /* not relevant */ 200,
- 100, 101, 102, 103,
- /* not relevant */ 201, {}, {});
- ASSERT_TRUE(
- transformation.IsApplicable(context.get(), transformation_context));
- ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- std::string after_transformation = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- %103 = OpFunctionCall %2 %101
- OpReturn
- OpFunctionEnd
- %101 = OpFunction %2 None %3
- %102 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- ASSERT_TRUE(IsEqual(env, after_transformation, context.get()));
- }
- TEST(TransformationOutlineFunctionTest,
- DoNotOutlineIfRegionStartsWithOpVariable) {
- // This checks that we do not outline the first block of a function if it
- // contains OpVariable.
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %7 = OpTypeBool
- %8 = OpTypePointer Function %7
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- %6 = OpVariable %8 Function
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_4;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(5, 5, /* not relevant */ 200,
- 100, 101, 102, 103,
- /* not relevant */ 201, {}, {});
- ASSERT_FALSE(
- transformation.IsApplicable(context.get(), transformation_context));
- }
- TEST(TransformationOutlineFunctionTest, OutlineInterestingControlFlowNoState) {
- // This tests outlining of some non-trivial control flow, but such that the
- // basic blocks in the control flow do not actually do anything.
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- %2 = OpTypeVoid
- %20 = OpTypeBool
- %21 = OpConstantTrue %20
- %3 = OpTypeFunction %2
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpBranch %6
- %6 = OpLabel
- OpBranch %7
- %7 = OpLabel
- OpSelectionMerge %9 None
- OpBranchConditional %21 %8 %9
- %8 = OpLabel
- OpBranch %9
- %9 = OpLabel
- OpLoopMerge %12 %11 None
- OpBranch %10
- %10 = OpLabel
- OpBranchConditional %21 %11 %12
- %11 = OpLabel
- OpBranch %9
- %12 = OpLabel
- OpBranch %13
- %13 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_4;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(6, 13, /* not relevant */
- 200, 100, 101, 102, 103,
- /* not relevant */ 201, {}, {});
- ASSERT_TRUE(
- transformation.IsApplicable(context.get(), transformation_context));
- ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- std::string after_transformation = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- %2 = OpTypeVoid
- %20 = OpTypeBool
- %21 = OpConstantTrue %20
- %3 = OpTypeFunction %2
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpBranch %6
- %6 = OpLabel
- %103 = OpFunctionCall %2 %101
- OpReturn
- OpFunctionEnd
- %101 = OpFunction %2 None %3
- %102 = OpLabel
- OpBranch %7
- %7 = OpLabel
- OpSelectionMerge %9 None
- OpBranchConditional %21 %8 %9
- %8 = OpLabel
- OpBranch %9
- %9 = OpLabel
- OpLoopMerge %12 %11 None
- OpBranch %10
- %10 = OpLabel
- OpBranchConditional %21 %11 %12
- %11 = OpLabel
- OpBranch %9
- %12 = OpLabel
- OpBranch %13
- %13 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- ASSERT_TRUE(IsEqual(env, after_transformation, context.get()));
- }
- TEST(TransformationOutlineFunctionTest, OutlineCodeThatGeneratesUnusedIds) {
- // This tests outlining of a single basic block that does some computation,
- // but that does not use nor generate ids required outside of the outlined
- // region.
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- %2 = OpTypeVoid
- %20 = OpTypeInt 32 1
- %21 = OpConstant %20 5
- %3 = OpTypeFunction %2
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpBranch %6
- %6 = OpLabel
- %7 = OpCopyObject %20 %21
- %8 = OpCopyObject %20 %21
- %9 = OpIAdd %20 %7 %8
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_4;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(6, 6, /* not relevant */ 200,
- 100, 101, 102, 103,
- /* not relevant */ 201, {}, {});
- ASSERT_TRUE(
- transformation.IsApplicable(context.get(), transformation_context));
- ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- std::string after_transformation = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- %2 = OpTypeVoid
- %20 = OpTypeInt 32 1
- %21 = OpConstant %20 5
- %3 = OpTypeFunction %2
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpBranch %6
- %6 = OpLabel
- %103 = OpFunctionCall %2 %101
- OpReturn
- OpFunctionEnd
- %101 = OpFunction %2 None %3
- %102 = OpLabel
- %7 = OpCopyObject %20 %21
- %8 = OpCopyObject %20 %21
- %9 = OpIAdd %20 %7 %8
- OpReturn
- OpFunctionEnd
- )";
- ASSERT_TRUE(IsEqual(env, after_transformation, context.get()));
- }
- TEST(TransformationOutlineFunctionTest, OutlineCodeThatGeneratesSingleUsedId) {
- // This tests outlining of a block that generates an id that is used in a
- // later block.
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- %2 = OpTypeVoid
- %20 = OpTypeInt 32 1
- %21 = OpConstant %20 5
- %3 = OpTypeFunction %2
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpBranch %6
- %6 = OpLabel
- %7 = OpCopyObject %20 %21
- %8 = OpCopyObject %20 %21
- %9 = OpIAdd %20 %7 %8
- OpBranch %10
- %10 = OpLabel
- %11 = OpCopyObject %20 %9
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_4;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(6, 6, 99, 100, 101, 102, 103,
- 105, {}, {{9, 104}});
- ASSERT_TRUE(
- transformation.IsApplicable(context.get(), transformation_context));
- ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- std::string after_transformation = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- %2 = OpTypeVoid
- %20 = OpTypeInt 32 1
- %21 = OpConstant %20 5
- %3 = OpTypeFunction %2
- %99 = OpTypeStruct %20
- %100 = OpTypeFunction %99
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpBranch %6
- %6 = OpLabel
- %103 = OpFunctionCall %99 %101
- %9 = OpCompositeExtract %20 %103 0
- OpBranch %10
- %10 = OpLabel
- %11 = OpCopyObject %20 %9
- OpReturn
- OpFunctionEnd
- %101 = OpFunction %99 None %100
- %102 = OpLabel
- %7 = OpCopyObject %20 %21
- %8 = OpCopyObject %20 %21
- %104 = OpIAdd %20 %7 %8
- %105 = OpCompositeConstruct %99 %104
- OpReturnValue %105
- OpFunctionEnd
- )";
- ASSERT_TRUE(IsEqual(env, after_transformation, context.get()));
- }
- TEST(TransformationOutlineFunctionTest, OutlineDiamondThatGeneratesSeveralIds) {
- // This tests outlining of several blocks that generate a number of ids that
- // are used in later blocks.
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- %2 = OpTypeVoid
- %20 = OpTypeInt 32 1
- %21 = OpConstant %20 5
- %22 = OpTypeBool
- %3 = OpTypeFunction %2
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpBranch %6
- %6 = OpLabel
- %7 = OpCopyObject %20 %21
- %8 = OpCopyObject %20 %21
- %9 = OpSLessThan %22 %7 %8
- OpSelectionMerge %12 None
- OpBranchConditional %9 %10 %11
- %10 = OpLabel
- %13 = OpIAdd %20 %7 %8
- OpBranch %12
- %11 = OpLabel
- %14 = OpIAdd %20 %7 %7
- OpBranch %12
- %12 = OpLabel
- %15 = OpPhi %20 %13 %10 %14 %11
- OpBranch %80
- %80 = OpLabel
- OpBranch %16
- %16 = OpLabel
- %17 = OpCopyObject %20 %15
- %18 = OpCopyObject %22 %9
- %19 = OpIAdd %20 %7 %8
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_4;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(
- 6, 80, 100, 101, 102, 103, 104, 105, {},
- {{15, 106}, {9, 107}, {7, 108}, {8, 109}});
- ASSERT_TRUE(
- transformation.IsApplicable(context.get(), transformation_context));
- ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- std::string after_transformation = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- %2 = OpTypeVoid
- %20 = OpTypeInt 32 1
- %21 = OpConstant %20 5
- %22 = OpTypeBool
- %3 = OpTypeFunction %2
- %100 = OpTypeStruct %20 %20 %22 %20
- %101 = OpTypeFunction %100
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpBranch %6
- %6 = OpLabel
- %104 = OpFunctionCall %100 %102
- %7 = OpCompositeExtract %20 %104 0
- %8 = OpCompositeExtract %20 %104 1
- %9 = OpCompositeExtract %22 %104 2
- %15 = OpCompositeExtract %20 %104 3
- OpBranch %16
- %16 = OpLabel
- %17 = OpCopyObject %20 %15
- %18 = OpCopyObject %22 %9
- %19 = OpIAdd %20 %7 %8
- OpReturn
- OpFunctionEnd
- %102 = OpFunction %100 None %101
- %103 = OpLabel
- %108 = OpCopyObject %20 %21
- %109 = OpCopyObject %20 %21
- %107 = OpSLessThan %22 %108 %109
- OpSelectionMerge %12 None
- OpBranchConditional %107 %10 %11
- %10 = OpLabel
- %13 = OpIAdd %20 %108 %109
- OpBranch %12
- %11 = OpLabel
- %14 = OpIAdd %20 %108 %108
- OpBranch %12
- %12 = OpLabel
- %106 = OpPhi %20 %13 %10 %14 %11
- OpBranch %80
- %80 = OpLabel
- %105 = OpCompositeConstruct %100 %108 %109 %107 %106
- OpReturnValue %105
- OpFunctionEnd
- )";
- ASSERT_TRUE(IsEqual(env, after_transformation, context.get()));
- }
- TEST(TransformationOutlineFunctionTest, OutlineCodeThatUsesASingleId) {
- // This tests outlining of a block that uses an id defined earlier.
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- %2 = OpTypeVoid
- %20 = OpTypeInt 32 1
- %21 = OpConstant %20 5
- %3 = OpTypeFunction %2
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- %7 = OpCopyObject %20 %21
- OpBranch %6
- %6 = OpLabel
- %8 = OpCopyObject %20 %7
- OpBranch %10
- %10 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_4;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(6, 6, 100, 101, 102, 103, 104,
- 105, {{7, 106}}, {});
- ASSERT_TRUE(
- transformation.IsApplicable(context.get(), transformation_context));
- ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- std::string after_transformation = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- %2 = OpTypeVoid
- %20 = OpTypeInt 32 1
- %21 = OpConstant %20 5
- %3 = OpTypeFunction %2
- %101 = OpTypeFunction %2 %20
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- %7 = OpCopyObject %20 %21
- OpBranch %6
- %6 = OpLabel
- %104 = OpFunctionCall %2 %102 %7
- OpBranch %10
- %10 = OpLabel
- OpReturn
- OpFunctionEnd
- %102 = OpFunction %2 None %101
- %106 = OpFunctionParameter %20
- %103 = OpLabel
- %8 = OpCopyObject %20 %106
- OpReturn
- OpFunctionEnd
- )";
- ASSERT_TRUE(IsEqual(env, after_transformation, context.get()));
- }
- TEST(TransformationOutlineFunctionTest, OutlineCodeThatUsesAVariable) {
- // This tests outlining of a block that uses a variable.
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- %2 = OpTypeVoid
- %20 = OpTypeInt 32 1
- %21 = OpConstant %20 5
- %3 = OpTypeFunction %2
- %12 = OpTypePointer Function %20
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- %13 = OpVariable %12 Function
- OpBranch %6
- %6 = OpLabel
- %8 = OpLoad %20 %13
- OpBranch %10
- %10 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_4;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(6, 6, 100, 101, 102, 103, 104,
- 105, {{13, 106}}, {});
- ASSERT_TRUE(
- transformation.IsApplicable(context.get(), transformation_context));
- ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- std::string after_transformation = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- %2 = OpTypeVoid
- %20 = OpTypeInt 32 1
- %21 = OpConstant %20 5
- %3 = OpTypeFunction %2
- %12 = OpTypePointer Function %20
- %101 = OpTypeFunction %2 %12
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- %13 = OpVariable %12 Function
- OpBranch %6
- %6 = OpLabel
- %104 = OpFunctionCall %2 %102 %13
- OpBranch %10
- %10 = OpLabel
- OpReturn
- OpFunctionEnd
- %102 = OpFunction %2 None %101
- %106 = OpFunctionParameter %12
- %103 = OpLabel
- %8 = OpLoad %20 %106
- OpReturn
- OpFunctionEnd
- )";
- ASSERT_TRUE(IsEqual(env, after_transformation, context.get()));
- }
- TEST(TransformationOutlineFunctionTest, OutlineCodeThatUsesAParameter) {
- // This tests outlining of a block that uses a function parameter.
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- OpName %10 "foo(i1;"
- OpName %9 "x"
- OpName %18 "param"
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %6 = OpTypeInt 32 1
- %7 = OpTypePointer Function %6
- %8 = OpTypeFunction %6 %7
- %13 = OpConstant %6 1
- %17 = OpConstant %6 3
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- %18 = OpVariable %7 Function
- OpStore %18 %17
- %19 = OpFunctionCall %6 %10 %18
- OpReturn
- OpFunctionEnd
- %10 = OpFunction %6 None %8
- %9 = OpFunctionParameter %7
- %11 = OpLabel
- %12 = OpLoad %6 %9
- %14 = OpIAdd %6 %12 %13
- OpReturnValue %14
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_4;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(11, 11, 100, 101, 102, 103, 104,
- 105, {{9, 106}}, {{14, 107}});
- ASSERT_TRUE(
- transformation.IsApplicable(context.get(), transformation_context));
- ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- std::string after_transformation = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- OpName %10 "foo(i1;"
- OpName %9 "x"
- OpName %18 "param"
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %6 = OpTypeInt 32 1
- %7 = OpTypePointer Function %6
- %8 = OpTypeFunction %6 %7
- %13 = OpConstant %6 1
- %17 = OpConstant %6 3
- %100 = OpTypeStruct %6
- %101 = OpTypeFunction %100 %7
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- %18 = OpVariable %7 Function
- OpStore %18 %17
- %19 = OpFunctionCall %6 %10 %18
- OpReturn
- OpFunctionEnd
- %10 = OpFunction %6 None %8
- %9 = OpFunctionParameter %7
- %11 = OpLabel
- %104 = OpFunctionCall %100 %102 %9
- %14 = OpCompositeExtract %6 %104 0
- OpReturnValue %14
- OpFunctionEnd
- %102 = OpFunction %100 None %101
- %106 = OpFunctionParameter %7
- %103 = OpLabel
- %12 = OpLoad %6 %106
- %107 = OpIAdd %6 %12 %13
- %105 = OpCompositeConstruct %100 %107
- OpReturnValue %105
- OpFunctionEnd
- )";
- ASSERT_TRUE(IsEqual(env, after_transformation, context.get()));
- }
- TEST(TransformationOutlineFunctionTest,
- DoNotOutlineIfLoopMergeIsOutsideRegion) {
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %9 = OpTypeBool
- %10 = OpConstantTrue %9
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpBranch %6
- %6 = OpLabel
- OpLoopMerge %7 %8 None
- OpBranch %8
- %8 = OpLabel
- OpBranchConditional %10 %6 %7
- %7 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_4;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(6, 8, 100, 101, 102, 103, 104,
- 105, {}, {});
- ASSERT_FALSE(
- transformation.IsApplicable(context.get(), transformation_context));
- }
- TEST(TransformationOutlineFunctionTest, DoNotOutlineIfRegionInvolvesReturn) {
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- %2 = OpTypeVoid
- %20 = OpTypeBool
- %21 = OpConstantTrue %20
- %3 = OpTypeFunction %2
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpBranch %6
- %6 = OpLabel
- OpBranch %7
- %7 = OpLabel
- OpSelectionMerge %10 None
- OpBranchConditional %21 %8 %9
- %8 = OpLabel
- OpReturn
- %9 = OpLabel
- OpBranch %10
- %10 = OpLabel
- OpBranch %11
- %11 = OpLabel
- OpBranch %12
- %12 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_4;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(6, 11, /* not relevant */ 200,
- 100, 101, 102, 103,
- /* not relevant */ 201, {}, {});
- ASSERT_FALSE(
- transformation.IsApplicable(context.get(), transformation_context));
- }
- TEST(TransformationOutlineFunctionTest, DoNotOutlineIfRegionInvolvesKill) {
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- %2 = OpTypeVoid
- %20 = OpTypeBool
- %21 = OpConstantTrue %20
- %3 = OpTypeFunction %2
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpBranch %6
- %6 = OpLabel
- OpBranch %7
- %7 = OpLabel
- OpSelectionMerge %10 None
- OpBranchConditional %21 %8 %9
- %8 = OpLabel
- OpKill
- %9 = OpLabel
- OpBranch %10
- %10 = OpLabel
- OpBranch %11
- %11 = OpLabel
- OpBranch %12
- %12 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_4;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(6, 11, /* not relevant */ 200,
- 100, 101, 102, 103,
- /* not relevant */ 201, {}, {});
- ASSERT_FALSE(
- transformation.IsApplicable(context.get(), transformation_context));
- }
- TEST(TransformationOutlineFunctionTest,
- DoNotOutlineIfRegionInvolvesUnreachable) {
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- %2 = OpTypeVoid
- %20 = OpTypeBool
- %21 = OpConstantTrue %20
- %3 = OpTypeFunction %2
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpBranch %6
- %6 = OpLabel
- OpBranch %7
- %7 = OpLabel
- OpSelectionMerge %10 None
- OpBranchConditional %21 %8 %9
- %8 = OpLabel
- OpBranch %10
- %9 = OpLabel
- OpUnreachable
- %10 = OpLabel
- OpBranch %11
- %11 = OpLabel
- OpBranch %12
- %12 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_4;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(6, 11, /* not relevant */ 200,
- 100, 101, 102, 103,
- /* not relevant */ 201, {}, {});
- ASSERT_FALSE(
- transformation.IsApplicable(context.get(), transformation_context));
- }
- TEST(TransformationOutlineFunctionTest,
- DoNotOutlineIfSelectionMergeIsOutsideRegion) {
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %9 = OpTypeBool
- %10 = OpConstantTrue %9
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpBranch %6
- %6 = OpLabel
- OpSelectionMerge %7 None
- OpBranchConditional %10 %8 %7
- %8 = OpLabel
- OpBranch %7
- %7 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_4;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(6, 8, 100, 101, 102, 103, 104,
- 105, {}, {});
- ASSERT_FALSE(
- transformation.IsApplicable(context.get(), transformation_context));
- }
- TEST(TransformationOutlineFunctionTest, DoNotOutlineIfLoopHeadIsOutsideRegion) {
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %9 = OpTypeBool
- %10 = OpConstantTrue %9
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpBranch %6
- %6 = OpLabel
- OpLoopMerge %8 %11 None
- OpBranch %7
- %7 = OpLabel
- OpBranchConditional %10 %11 %8
- %11 = OpLabel
- OpBranch %6
- %8 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_4;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(7, 8, 100, 101, 102, 103, 104,
- 105, {}, {});
- ASSERT_FALSE(
- transformation.IsApplicable(context.get(), transformation_context));
- }
- TEST(TransformationOutlineFunctionTest,
- DoNotOutlineIfLoopContinueIsOutsideRegion) {
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %9 = OpTypeBool
- %10 = OpConstantTrue %9
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpBranch %6
- %6 = OpLabel
- OpLoopMerge %7 %8 None
- OpBranch %7
- %8 = OpLabel
- OpBranch %6
- %7 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_4;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(6, 7, 100, 101, 102, 103, 104,
- 105, {}, {});
- ASSERT_FALSE(
- transformation.IsApplicable(context.get(), transformation_context));
- }
- TEST(TransformationOutlineFunctionTest,
- DoNotOutlineWithLoopCarriedPhiDependence) {
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %9 = OpTypeBool
- %10 = OpConstantTrue %9
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpBranch %6
- %6 = OpLabel
- %12 = OpPhi %9 %10 %5 %13 %8
- OpLoopMerge %7 %8 None
- OpBranch %8
- %8 = OpLabel
- %13 = OpCopyObject %9 %10
- OpBranchConditional %10 %6 %7
- %7 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_4;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(6, 7, 100, 101, 102, 103, 104,
- 105, {}, {});
- ASSERT_FALSE(
- transformation.IsApplicable(context.get(), transformation_context));
- }
- TEST(TransformationOutlineFunctionTest,
- DoNotOutlineSelectionHeaderNotInRegion) {
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %6 = OpTypeBool
- %7 = OpConstantTrue %6
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpSelectionMerge %10 None
- OpBranchConditional %7 %8 %8
- %8 = OpLabel
- OpBranch %9
- %9 = OpLabel
- OpBranch %10
- %10 = OpLabel
- OpBranch %11
- %11 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_4;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(8, 11, 100, 101, 102, 103, 104,
- 105, {}, {});
- ASSERT_FALSE(
- transformation.IsApplicable(context.get(), transformation_context));
- }
- TEST(TransformationOutlineFunctionTest, OutlineRegionEndingWithReturnVoid) {
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- %20 = OpTypeInt 32 0
- %21 = OpConstant %20 1
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- %22 = OpCopyObject %20 %21
- OpBranch %54
- %54 = OpLabel
- OpBranch %57
- %57 = OpLabel
- %23 = OpCopyObject %20 %22
- OpBranch %58
- %58 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_5;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(
- /*entry_block*/ 54,
- /*exit_block*/ 58,
- /*new_function_struct_return_type_id*/ 200,
- /*new_function_type_id*/ 201,
- /*new_function_id*/ 202,
- /*new_function_region_entry_block*/ 203,
- /*new_caller_result_id*/ 204,
- /*new_callee_result_id*/ 205,
- /*input_id_to_fresh_id*/ {{22, 206}},
- /*output_id_to_fresh_id*/ {});
- ASSERT_TRUE(
- transformation.IsApplicable(context.get(), transformation_context));
- ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- std::string after_transformation = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- %20 = OpTypeInt 32 0
- %21 = OpConstant %20 1
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %201 = OpTypeFunction %2 %20
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- %22 = OpCopyObject %20 %21
- OpBranch %54
- %54 = OpLabel
- %204 = OpFunctionCall %2 %202 %22
- OpReturn
- OpFunctionEnd
- %202 = OpFunction %2 None %201
- %206 = OpFunctionParameter %20
- %203 = OpLabel
- OpBranch %57
- %57 = OpLabel
- %23 = OpCopyObject %20 %206
- OpBranch %58
- %58 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- ASSERT_TRUE(IsEqual(env, after_transformation, context.get()));
- }
- TEST(TransformationOutlineFunctionTest, OutlineRegionEndingWithReturnValue) {
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- %20 = OpTypeInt 32 0
- %21 = OpConstant %20 1
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %30 = OpTypeFunction %20
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- %6 = OpFunctionCall %20 %100
- OpReturn
- OpFunctionEnd
- %100 = OpFunction %20 None %30
- %8 = OpLabel
- %31 = OpCopyObject %20 %21
- OpBranch %9
- %9 = OpLabel
- %32 = OpCopyObject %20 %31
- OpBranch %10
- %10 = OpLabel
- OpReturnValue %32
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_5;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(
- /*entry_block*/ 9,
- /*exit_block*/ 10,
- /*new_function_struct_return_type_id*/ 200,
- /*new_function_type_id*/ 201,
- /*new_function_id*/ 202,
- /*new_function_region_entry_block*/ 203,
- /*new_caller_result_id*/ 204,
- /*new_callee_result_id*/ 205,
- /*input_id_to_fresh_id*/ {{31, 206}},
- /*output_id_to_fresh_id*/ {{32, 207}});
- ASSERT_TRUE(
- transformation.IsApplicable(context.get(), transformation_context));
- ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- std::string after_transformation = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- %20 = OpTypeInt 32 0
- %21 = OpConstant %20 1
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %30 = OpTypeFunction %20
- %200 = OpTypeStruct %20
- %201 = OpTypeFunction %200 %20
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- %6 = OpFunctionCall %20 %100
- OpReturn
- OpFunctionEnd
- %100 = OpFunction %20 None %30
- %8 = OpLabel
- %31 = OpCopyObject %20 %21
- OpBranch %9
- %9 = OpLabel
- %204 = OpFunctionCall %200 %202 %31
- %32 = OpCompositeExtract %20 %204 0
- OpReturnValue %32
- OpFunctionEnd
- %202 = OpFunction %200 None %201
- %206 = OpFunctionParameter %20
- %203 = OpLabel
- %207 = OpCopyObject %20 %206
- OpBranch %10
- %10 = OpLabel
- %205 = OpCompositeConstruct %200 %207
- OpReturnValue %205
- OpFunctionEnd
- )";
- ASSERT_TRUE(IsEqual(env, after_transformation, context.get()));
- }
- TEST(TransformationOutlineFunctionTest,
- OutlineRegionEndingWithConditionalBranch) {
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- %20 = OpTypeBool
- %21 = OpConstantTrue %20
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpBranch %54
- %54 = OpLabel
- %6 = OpCopyObject %20 %21
- OpSelectionMerge %8 None
- OpBranchConditional %6 %7 %8
- %7 = OpLabel
- OpBranch %8
- %8 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_5;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(
- /*entry_block*/ 54,
- /*exit_block*/ 54,
- /*new_function_struct_return_type_id*/ 200,
- /*new_function_type_id*/ 201,
- /*new_function_id*/ 202,
- /*new_function_region_entry_block*/ 203,
- /*new_caller_result_id*/ 204,
- /*new_callee_result_id*/ 205,
- /*input_id_to_fresh_id*/ {{}},
- /*output_id_to_fresh_id*/ {{6, 206}});
- ASSERT_TRUE(
- transformation.IsApplicable(context.get(), transformation_context));
- ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- std::string after_transformation = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- %20 = OpTypeBool
- %21 = OpConstantTrue %20
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %200 = OpTypeStruct %20
- %201 = OpTypeFunction %200
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpBranch %54
- %54 = OpLabel
- %204 = OpFunctionCall %200 %202
- %6 = OpCompositeExtract %20 %204 0
- OpSelectionMerge %8 None
- OpBranchConditional %6 %7 %8
- %7 = OpLabel
- OpBranch %8
- %8 = OpLabel
- OpReturn
- OpFunctionEnd
- %202 = OpFunction %200 None %201
- %203 = OpLabel
- %206 = OpCopyObject %20 %21
- %205 = OpCompositeConstruct %200 %206
- OpReturnValue %205
- OpFunctionEnd
- )";
- ASSERT_TRUE(IsEqual(env, after_transformation, context.get()));
- }
- TEST(TransformationOutlineFunctionTest,
- OutlineRegionEndingWithConditionalBranch2) {
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- %20 = OpTypeBool
- %21 = OpConstantTrue %20
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- %6 = OpCopyObject %20 %21
- OpBranch %54
- %54 = OpLabel
- OpSelectionMerge %8 None
- OpBranchConditional %6 %7 %8
- %7 = OpLabel
- OpBranch %8
- %8 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_5;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(
- /*entry_block*/ 54,
- /*exit_block*/ 54,
- /*new_function_struct_return_type_id*/ 200,
- /*new_function_type_id*/ 201,
- /*new_function_id*/ 202,
- /*new_function_region_entry_block*/ 203,
- /*new_caller_result_id*/ 204,
- /*new_callee_result_id*/ 205,
- /*input_id_to_fresh_id*/ {},
- /*output_id_to_fresh_id*/ {});
- ASSERT_TRUE(
- transformation.IsApplicable(context.get(), transformation_context));
- ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- std::string after_transformation = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- %20 = OpTypeBool
- %21 = OpConstantTrue %20
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- %6 = OpCopyObject %20 %21
- OpBranch %54
- %54 = OpLabel
- %204 = OpFunctionCall %2 %202
- OpSelectionMerge %8 None
- OpBranchConditional %6 %7 %8
- %7 = OpLabel
- OpBranch %8
- %8 = OpLabel
- OpReturn
- OpFunctionEnd
- %202 = OpFunction %2 None %3
- %203 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- ASSERT_TRUE(IsEqual(env, after_transformation, context.get()));
- }
- TEST(TransformationOutlineFunctionTest, DoNotOutlineRegionThatStartsWithOpPhi) {
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %6 = OpTypeBool
- %7 = OpConstantTrue %6
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpBranch %21
- %21 = OpLabel
- %22 = OpPhi %6 %7 %5
- %23 = OpCopyObject %6 %22
- OpBranch %24
- %24 = OpLabel
- %25 = OpCopyObject %6 %23
- %26 = OpCopyObject %6 %22
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_5;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(
- /*entry_block*/ 21,
- /*exit_block*/ 21,
- /*new_function_struct_return_type_id*/ 200,
- /*new_function_type_id*/ 201,
- /*new_function_id*/ 202,
- /*new_function_region_entry_block*/ 204,
- /*new_caller_result_id*/ 205,
- /*new_callee_result_id*/ 206,
- /*input_id_to_fresh_id*/ {{22, 207}},
- /*output_id_to_fresh_id*/ {{23, 208}});
- ASSERT_FALSE(
- transformation.IsApplicable(context.get(), transformation_context));
- }
- TEST(TransformationOutlineFunctionTest,
- DoNotOutlineRegionThatStartsWithLoopHeader) {
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %6 = OpTypeBool
- %7 = OpConstantTrue %6
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpBranch %21
- %21 = OpLabel
- OpLoopMerge %22 %23 None
- OpBranch %24
- %24 = OpLabel
- OpBranchConditional %7 %22 %23
- %23 = OpLabel
- OpBranch %21
- %22 = OpLabel
- OpBranch %25
- %25 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_5;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(
- /*entry_block*/ 21,
- /*exit_block*/ 24,
- /*new_function_struct_return_type_id*/ 200,
- /*new_function_type_id*/ 201,
- /*new_function_id*/ 202,
- /*new_function_region_entry_block*/ 204,
- /*new_caller_result_id*/ 205,
- /*new_callee_result_id*/ 206,
- /*input_id_to_fresh_id*/ {},
- /*output_id_to_fresh_id*/ {});
- ASSERT_FALSE(
- transformation.IsApplicable(context.get(), transformation_context));
- }
- TEST(TransformationOutlineFunctionTest,
- DoNotOutlineRegionThatEndsWithLoopMerge) {
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %6 = OpTypeBool
- %7 = OpConstantTrue %6
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpBranch %21
- %21 = OpLabel
- OpLoopMerge %22 %23 None
- OpBranch %24
- %24 = OpLabel
- OpBranchConditional %7 %22 %23
- %23 = OpLabel
- OpBranch %21
- %22 = OpLabel
- OpBranch %25
- %25 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_5;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(
- /*entry_block*/ 5,
- /*exit_block*/ 22,
- /*new_function_struct_return_type_id*/ 200,
- /*new_function_type_id*/ 201,
- /*new_function_id*/ 202,
- /*new_function_region_entry_block*/ 204,
- /*new_caller_result_id*/ 205,
- /*new_callee_result_id*/ 206,
- /*input_id_to_fresh_id*/ {},
- /*output_id_to_fresh_id*/ {});
- ASSERT_FALSE(
- transformation.IsApplicable(context.get(), transformation_context));
- }
- TEST(TransformationOutlineFunctionTest, DoNotOutlineRegionThatUsesAccessChain) {
- // An access chain result is a pointer, but it cannot be passed as a function
- // parameter, as it is not a memory object.
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %6 = OpTypeFloat 32
- %7 = OpTypeVector %6 4
- %8 = OpTypePointer Function %7
- %9 = OpTypePointer Function %6
- %18 = OpTypeInt 32 0
- %19 = OpConstant %18 0
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- %10 = OpVariable %8 Function
- OpBranch %11
- %11 = OpLabel
- %12 = OpAccessChain %9 %10 %19
- OpBranch %13
- %13 = OpLabel
- %14 = OpLoad %6 %12
- OpBranch %15
- %15 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_5;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(
- /*entry_block*/ 13,
- /*exit_block*/ 15,
- /*new_function_struct_return_type_id*/ 200,
- /*new_function_type_id*/ 201,
- /*new_function_id*/ 202,
- /*new_function_region_entry_block*/ 204,
- /*new_caller_result_id*/ 205,
- /*new_callee_result_id*/ 206,
- /*input_id_to_fresh_id*/ {{12, 207}},
- /*output_id_to_fresh_id*/ {});
- ASSERT_FALSE(
- transformation.IsApplicable(context.get(), transformation_context));
- }
- TEST(TransformationOutlineFunctionTest,
- DoNotOutlineRegionThatUsesCopiedObject) {
- // Copying a variable leads to a pointer, but one that cannot be passed as a
- // function parameter, as it is not a memory object.
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %6 = OpTypeFloat 32
- %7 = OpTypeVector %6 4
- %8 = OpTypePointer Function %7
- %9 = OpTypePointer Function %6
- %18 = OpTypeInt 32 0
- %19 = OpConstant %18 0
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- %10 = OpVariable %8 Function
- OpBranch %11
- %11 = OpLabel
- %20 = OpCopyObject %8 %10
- OpBranch %13
- %13 = OpLabel
- %12 = OpAccessChain %9 %20 %19
- %14 = OpLoad %6 %12
- OpBranch %15
- %15 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_5;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(
- /*entry_block*/ 13,
- /*exit_block*/ 15,
- /*new_function_struct_return_type_id*/ 200,
- /*new_function_type_id*/ 201,
- /*new_function_id*/ 202,
- /*new_function_region_entry_block*/ 204,
- /*new_caller_result_id*/ 205,
- /*new_callee_result_id*/ 206,
- /*input_id_to_fresh_id*/ {{20, 207}},
- /*output_id_to_fresh_id*/ {});
- ASSERT_FALSE(
- transformation.IsApplicable(context.get(), transformation_context));
- }
- TEST(TransformationOutlineFunctionTest,
- DoOutlineRegionThatUsesPointerParameter) {
- // The region being outlined reads from a function parameter of pointer type.
- // This is OK: the function parameter can itself be passed on as a function
- // parameter.
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %6 = OpTypeInt 32 1
- %7 = OpTypePointer Function %6
- %8 = OpTypeFunction %2 %7
- %13 = OpConstant %6 2
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- %15 = OpVariable %7 Function
- %16 = OpVariable %7 Function
- %17 = OpLoad %6 %15
- OpStore %16 %17
- %18 = OpFunctionCall %2 %10 %16
- %19 = OpLoad %6 %16
- OpStore %15 %19
- OpReturn
- OpFunctionEnd
- %10 = OpFunction %2 None %8
- %9 = OpFunctionParameter %7
- %11 = OpLabel
- %12 = OpLoad %6 %9
- %14 = OpIAdd %6 %12 %13
- OpBranch %20
- %20 = OpLabel
- OpStore %9 %14
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_5;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(
- /*entry_block*/ 11,
- /*exit_block*/ 11,
- /*new_function_struct_return_type_id*/ 200,
- /*new_function_type_id*/ 201,
- /*new_function_id*/ 202,
- /*new_function_region_entry_block*/ 204,
- /*new_caller_result_id*/ 205,
- /*new_callee_result_id*/ 206,
- /*input_id_to_fresh_id*/ {{9, 207}},
- /*output_id_to_fresh_id*/ {{14, 208}});
- ASSERT_TRUE(
- transformation.IsApplicable(context.get(), transformation_context));
- ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- std::string after_transformation = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %6 = OpTypeInt 32 1
- %7 = OpTypePointer Function %6
- %8 = OpTypeFunction %2 %7
- %13 = OpConstant %6 2
- %200 = OpTypeStruct %6
- %201 = OpTypeFunction %200 %7
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- %15 = OpVariable %7 Function
- %16 = OpVariable %7 Function
- %17 = OpLoad %6 %15
- OpStore %16 %17
- %18 = OpFunctionCall %2 %10 %16
- %19 = OpLoad %6 %16
- OpStore %15 %19
- OpReturn
- OpFunctionEnd
- %10 = OpFunction %2 None %8
- %9 = OpFunctionParameter %7
- %11 = OpLabel
- %205 = OpFunctionCall %200 %202 %9
- %14 = OpCompositeExtract %6 %205 0
- OpBranch %20
- %20 = OpLabel
- OpStore %9 %14
- OpReturn
- OpFunctionEnd
- %202 = OpFunction %200 None %201
- %207 = OpFunctionParameter %7
- %204 = OpLabel
- %12 = OpLoad %6 %207
- %208 = OpIAdd %6 %12 %13
- %206 = OpCompositeConstruct %200 %208
- OpReturnValue %206
- OpFunctionEnd
- )";
- ASSERT_TRUE(IsEqual(env, after_transformation, context.get()));
- }
- TEST(TransformationOutlineFunctionTest, OutlineLivesafe) {
- // In the following, %30 is a livesafe function, with irrelevant parameter
- // %200 and irrelevant local variable %201. Variable %100 is a loop limiter,
- // which is not irrelevant. The test checks that the outlined function is
- // livesafe, and that the parameters corresponding to %200 and %201 have the
- // irrelevant fact associated with them.
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %6 = OpTypeInt 32 0
- %7 = OpTypePointer Function %6
- %199 = OpTypeFunction %2 %7
- %8 = OpConstant %6 0
- %9 = OpConstant %6 1
- %10 = OpConstant %6 5
- %11 = OpTypeBool
- %12 = OpConstantTrue %11
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpReturn
- OpFunctionEnd
- %30 = OpFunction %2 None %199
- %200 = OpFunctionParameter %7
- %31 = OpLabel
- %100 = OpVariable %7 Function %8
- %201 = OpVariable %7 Function %8
- OpBranch %198
- %198 = OpLabel
- OpBranch %20
- %20 = OpLabel
- %101 = OpLoad %6 %100
- %102 = OpIAdd %6 %101 %9
- %202 = OpLoad %6 %200
- OpStore %201 %202
- OpStore %100 %102
- %103 = OpUGreaterThanEqual %11 %101 %10
- OpLoopMerge %21 %22 None
- OpBranchConditional %103 %21 %104
- %104 = OpLabel
- OpBranchConditional %12 %23 %21
- %23 = OpLabel
- %105 = OpLoad %6 %100
- %106 = OpIAdd %6 %105 %9
- OpStore %100 %106
- %107 = OpUGreaterThanEqual %11 %105 %10
- OpLoopMerge %25 %26 None
- OpBranchConditional %107 %25 %108
- %108 = OpLabel
- OpBranch %28
- %28 = OpLabel
- OpBranchConditional %12 %26 %25
- %26 = OpLabel
- OpBranch %23
- %25 = OpLabel
- %109 = OpLoad %6 %100
- %110 = OpIAdd %6 %109 %9
- OpStore %100 %110
- %111 = OpUGreaterThanEqual %11 %109 %10
- OpLoopMerge %24 %27 None
- OpBranchConditional %111 %24 %112
- %112 = OpLabel
- OpBranchConditional %12 %24 %27
- %27 = OpLabel
- OpBranch %25
- %24 = OpLabel
- OpBranch %22
- %22 = OpLabel
- OpBranch %20
- %21 = OpLabel
- OpBranch %197
- %197 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_5;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- transformation_context.GetFactManager()->AddFactFunctionIsLivesafe(30);
- transformation_context.GetFactManager()->AddFactValueOfPointeeIsIrrelevant(
- 200);
- transformation_context.GetFactManager()->AddFactValueOfPointeeIsIrrelevant(
- 201);
- TransformationOutlineFunction transformation(
- /*entry_block*/ 198,
- /*exit_block*/ 197,
- /*new_function_struct_return_type_id*/ 400,
- /*new_function_type_id*/ 401,
- /*new_function_id*/ 402,
- /*new_function_region_entry_block*/ 404,
- /*new_caller_result_id*/ 405,
- /*new_callee_result_id*/ 406,
- /*input_id_to_fresh_id*/ {{100, 407}, {200, 408}, {201, 409}},
- /*output_id_to_fresh_id*/ {});
- ASSERT_TRUE(
- transformation.IsApplicable(context.get(), transformation_context));
- ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- // The original function should still be livesafe.
- ASSERT_TRUE(transformation_context.GetFactManager()->FunctionIsLivesafe(30));
- // The outlined function should be livesafe.
- ASSERT_TRUE(transformation_context.GetFactManager()->FunctionIsLivesafe(402));
- // The variable and parameter that were originally irrelevant should still be.
- ASSERT_TRUE(
- transformation_context.GetFactManager()->PointeeValueIsIrrelevant(200));
- ASSERT_TRUE(
- transformation_context.GetFactManager()->PointeeValueIsIrrelevant(201));
- // The loop limiter should still be non-irrelevant.
- ASSERT_FALSE(
- transformation_context.GetFactManager()->PointeeValueIsIrrelevant(100));
- // The parameters for the original irrelevant variables should be irrelevant.
- ASSERT_TRUE(
- transformation_context.GetFactManager()->PointeeValueIsIrrelevant(408));
- ASSERT_TRUE(
- transformation_context.GetFactManager()->PointeeValueIsIrrelevant(409));
- // The parameter for the loop limiter should not be irrelevant.
- ASSERT_FALSE(
- transformation_context.GetFactManager()->PointeeValueIsIrrelevant(407));
- std::string after_transformation = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %6 = OpTypeInt 32 0
- %7 = OpTypePointer Function %6
- %199 = OpTypeFunction %2 %7
- %8 = OpConstant %6 0
- %9 = OpConstant %6 1
- %10 = OpConstant %6 5
- %11 = OpTypeBool
- %12 = OpConstantTrue %11
- %401 = OpTypeFunction %2 %7 %7 %7
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpReturn
- OpFunctionEnd
- %30 = OpFunction %2 None %199
- %200 = OpFunctionParameter %7
- %31 = OpLabel
- %100 = OpVariable %7 Function %8
- %201 = OpVariable %7 Function %8
- OpBranch %198
- %198 = OpLabel
- %405 = OpFunctionCall %2 %402 %200 %100 %201
- OpReturn
- OpFunctionEnd
- %402 = OpFunction %2 None %401
- %408 = OpFunctionParameter %7
- %407 = OpFunctionParameter %7
- %409 = OpFunctionParameter %7
- %404 = OpLabel
- OpBranch %20
- %20 = OpLabel
- %101 = OpLoad %6 %407
- %102 = OpIAdd %6 %101 %9
- %202 = OpLoad %6 %408
- OpStore %409 %202
- OpStore %407 %102
- %103 = OpUGreaterThanEqual %11 %101 %10
- OpLoopMerge %21 %22 None
- OpBranchConditional %103 %21 %104
- %104 = OpLabel
- OpBranchConditional %12 %23 %21
- %23 = OpLabel
- %105 = OpLoad %6 %407
- %106 = OpIAdd %6 %105 %9
- OpStore %407 %106
- %107 = OpUGreaterThanEqual %11 %105 %10
- OpLoopMerge %25 %26 None
- OpBranchConditional %107 %25 %108
- %108 = OpLabel
- OpBranch %28
- %28 = OpLabel
- OpBranchConditional %12 %26 %25
- %26 = OpLabel
- OpBranch %23
- %25 = OpLabel
- %109 = OpLoad %6 %407
- %110 = OpIAdd %6 %109 %9
- OpStore %407 %110
- %111 = OpUGreaterThanEqual %11 %109 %10
- OpLoopMerge %24 %27 None
- OpBranchConditional %111 %24 %112
- %112 = OpLabel
- OpBranchConditional %12 %24 %27
- %27 = OpLabel
- OpBranch %25
- %24 = OpLabel
- OpBranch %22
- %22 = OpLabel
- OpBranch %20
- %21 = OpLabel
- OpBranch %197
- %197 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- ASSERT_TRUE(IsEqual(env, after_transformation, context.get()));
- }
- TEST(TransformationOutlineFunctionTest, OutlineWithDeadBlocks1) {
- // This checks that if all blocks in the region being outlined were dead, all
- // blocks in the outlined function will be dead.
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- OpName %10 "foo(i1;"
- OpName %9 "x"
- OpName %12 "y"
- OpName %21 "i"
- OpName %46 "param"
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %6 = OpTypeInt 32 1
- %7 = OpTypePointer Function %6
- %8 = OpTypeFunction %2 %7
- %13 = OpConstant %6 2
- %14 = OpTypeBool
- %15 = OpConstantFalse %14
- %22 = OpConstant %6 0
- %29 = OpConstant %6 10
- %41 = OpConstant %6 1
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- %46 = OpVariable %7 Function
- OpStore %46 %13
- %47 = OpFunctionCall %2 %10 %46
- OpReturn
- OpFunctionEnd
- %10 = OpFunction %2 None %8
- %9 = OpFunctionParameter %7
- %11 = OpLabel
- %12 = OpVariable %7 Function
- %21 = OpVariable %7 Function
- OpStore %12 %13
- OpSelectionMerge %17 None
- OpBranchConditional %15 %16 %17
- %16 = OpLabel
- %18 = OpLoad %6 %9
- OpStore %12 %18
- %19 = OpLoad %6 %9
- %20 = OpIAdd %6 %19 %13
- OpStore %9 %20
- OpStore %21 %22
- OpBranch %23
- %23 = OpLabel
- OpLoopMerge %25 %26 None
- OpBranch %27
- %27 = OpLabel
- %28 = OpLoad %6 %21
- %30 = OpSLessThan %14 %28 %29
- OpBranchConditional %30 %24 %25
- %24 = OpLabel
- %31 = OpLoad %6 %9
- %32 = OpLoad %6 %21
- %33 = OpSGreaterThan %14 %31 %32
- OpSelectionMerge %35 None
- OpBranchConditional %33 %34 %35
- %34 = OpLabel
- OpBranch %26
- %35 = OpLabel
- %37 = OpLoad %6 %9
- %38 = OpLoad %6 %12
- %39 = OpIAdd %6 %38 %37
- OpStore %12 %39
- OpBranch %26
- %26 = OpLabel
- %40 = OpLoad %6 %21
- %42 = OpIAdd %6 %40 %41
- OpStore %21 %42
- OpBranch %23
- %25 = OpLabel
- OpBranch %50
- %50 = OpLabel
- OpBranch %17
- %17 = OpLabel
- %43 = OpLoad %6 %9
- %44 = OpLoad %6 %12
- %45 = OpIAdd %6 %44 %43
- OpStore %12 %45
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_5;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- for (uint32_t block_id : {16u, 23u, 24u, 26u, 27u, 34u, 35u, 50u}) {
- transformation_context.GetFactManager()->AddFactBlockIsDead(block_id);
- }
- TransformationOutlineFunction transformation(
- /*entry_block*/ 16,
- /*exit_block*/ 50,
- /*new_function_struct_return_type_id*/ 200,
- /*new_function_type_id*/ 201,
- /*new_function_id*/ 202,
- /*new_function_region_entry_block*/ 203,
- /*new_caller_result_id*/ 204,
- /*new_callee_result_id*/ 205,
- /*input_id_to_fresh_id*/ {{9, 206}, {12, 207}, {21, 208}},
- /*output_id_to_fresh_id*/ {});
- ASSERT_TRUE(
- transformation.IsApplicable(context.get(), transformation_context));
- ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- // All the original blocks, plus the new function entry block, should be dead.
- for (uint32_t block_id : {16u, 23u, 24u, 26u, 27u, 34u, 35u, 50u, 203u}) {
- ASSERT_TRUE(transformation_context.GetFactManager()->BlockIsDead(block_id));
- }
- }
- TEST(TransformationOutlineFunctionTest, OutlineWithDeadBlocks2) {
- // This checks that if some, but not all, blocks in the outlined region are
- // dead, those (but not others) will be dead in the outlined function.
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main" %8
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %6 = OpTypeBool
- %7 = OpTypePointer Private %6
- %8 = OpVariable %7 Private
- %9 = OpConstantFalse %6
- %10 = OpTypePointer Function %6
- %12 = OpConstantTrue %6
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- %11 = OpVariable %10 Function
- OpBranch %30
- %30 = OpLabel
- OpStore %8 %9
- OpBranch %31
- %31 = OpLabel
- OpStore %11 %12
- OpSelectionMerge %36 None
- OpBranchConditional %9 %32 %33
- %32 = OpLabel
- OpBranch %34
- %33 = OpLabel
- OpBranch %36
- %34 = OpLabel
- OpBranch %35
- %35 = OpLabel
- OpBranch %36
- %36 = OpLabel
- OpBranch %37
- %37 = OpLabel
- %13 = OpLoad %6 %8
- OpStore %11 %13
- %14 = OpLoad %6 %11
- OpStore %8 %14
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_5;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- for (uint32_t block_id : {32u, 34u, 35u}) {
- transformation_context.GetFactManager()->AddFactBlockIsDead(block_id);
- }
- TransformationOutlineFunction transformation(
- /*entry_block*/ 30,
- /*exit_block*/ 37,
- /*new_function_struct_return_type_id*/ 200,
- /*new_function_type_id*/ 201,
- /*new_function_id*/ 202,
- /*new_function_region_entry_block*/ 203,
- /*new_caller_result_id*/ 204,
- /*new_callee_result_id*/ 205,
- /*input_id_to_fresh_id*/ {{11, 206}},
- /*output_id_to_fresh_id*/ {});
- ASSERT_TRUE(
- transformation.IsApplicable(context.get(), transformation_context));
- ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- // The blocks that were originally dead, but not others, should be dead.
- for (uint32_t block_id : {32u, 34u, 35u}) {
- ASSERT_TRUE(transformation_context.GetFactManager()->BlockIsDead(block_id));
- }
- for (uint32_t block_id : {5u, 30u, 31u, 33u, 36u, 37u, 203u}) {
- ASSERT_FALSE(
- transformation_context.GetFactManager()->BlockIsDead(block_id));
- }
- }
- TEST(TransformationOutlineFunctionTest,
- OutlineWithIrrelevantVariablesAndParameters) {
- // This checks that if the outlined region uses a mixture of irrelevant and
- // non-irrelevant variables and parameters, these properties are preserved
- // during outlining.
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %6 = OpTypeInt 32 1
- %7 = OpTypePointer Function %6
- %8 = OpTypeFunction %2 %7 %7
- %13 = OpConstant %6 2
- %15 = OpConstant %6 3
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpReturn
- OpFunctionEnd
- %11 = OpFunction %2 None %8
- %9 = OpFunctionParameter %7
- %10 = OpFunctionParameter %7
- %12 = OpLabel
- %14 = OpVariable %7 Function
- %20 = OpVariable %7 Function
- OpBranch %50
- %50 = OpLabel
- OpStore %9 %13
- OpStore %14 %15
- %16 = OpLoad %6 %14
- OpStore %10 %16
- %17 = OpLoad %6 %9
- %18 = OpLoad %6 %10
- %19 = OpIAdd %6 %17 %18
- OpStore %14 %19
- %21 = OpLoad %6 %9
- OpStore %20 %21
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_5;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- transformation_context.GetFactManager()->AddFactValueOfPointeeIsIrrelevant(9);
- transformation_context.GetFactManager()->AddFactValueOfPointeeIsIrrelevant(
- 14);
- TransformationOutlineFunction transformation(
- /*entry_block*/ 50,
- /*exit_block*/ 50,
- /*new_function_struct_return_type_id*/ 200,
- /*new_function_type_id*/ 201,
- /*new_function_id*/ 202,
- /*new_function_region_entry_block*/ 203,
- /*new_caller_result_id*/ 204,
- /*new_callee_result_id*/ 205,
- /*input_id_to_fresh_id*/ {{9, 206}, {10, 207}, {14, 208}, {20, 209}},
- /*output_id_to_fresh_id*/ {});
- ASSERT_TRUE(
- transformation.IsApplicable(context.get(), transformation_context));
- ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- // The variables that were originally irrelevant, plus input parameters
- // corresponding to them, should be irrelevant. The rest should not be.
- for (uint32_t variable_id : {9u, 14u, 206u, 208u}) {
- ASSERT_TRUE(
- transformation_context.GetFactManager()->PointeeValueIsIrrelevant(
- variable_id));
- }
- for (uint32_t variable_id : {10u, 20u, 207u, 209u}) {
- ASSERT_FALSE(
- transformation_context.GetFactManager()->BlockIsDead(variable_id));
- }
- }
- TEST(TransformationOutlineFunctionTest,
- DoNotOutlineCodeThatProducesUsedPointer) {
- // This checks that we cannot outline a region of code if it produces a
- // pointer result id that gets used outside the region. This avoids creating
- // a struct with a pointer member.
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %6 "main"
- OpExecutionMode %6 OriginUpperLeft
- OpSource ESSL 310
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %21 = OpTypeBool
- %100 = OpTypeInt 32 0
- %99 = OpConstant %100 0
- %101 = OpTypeVector %100 2
- %102 = OpTypePointer Function %100
- %103 = OpTypePointer Function %101
- %6 = OpFunction %2 None %3
- %7 = OpLabel
- %104 = OpVariable %103 Function
- OpBranch %80
- %80 = OpLabel
- %105 = OpAccessChain %102 %104 %99
- OpBranch %106
- %106 = OpLabel
- OpStore %105 %99
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_5;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(
- /*entry_block*/ 80,
- /*exit_block*/ 80,
- /*new_function_struct_return_type_id*/ 300,
- /*new_function_type_id*/ 301,
- /*new_function_id*/ 302,
- /*new_function_region_entry_block*/ 304,
- /*new_caller_result_id*/ 305,
- /*new_callee_result_id*/ 306,
- /*input_id_to_fresh_id*/ {{104, 307}},
- /*output_id_to_fresh_id*/ {{105, 308}});
- ASSERT_FALSE(
- transformation.IsApplicable(context.get(), transformation_context));
- }
- TEST(TransformationOutlineFunctionTest, ExitBlockHeadsLoop) {
- // This checks that it is not possible outline a region that ends in a loop
- // head.
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %15 = OpTypeInt 32 1
- %35 = OpTypeBool
- %39 = OpConstant %15 1
- %40 = OpConstantTrue %35
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpBranch %22
- %22 = OpLabel
- OpBranch %23
- %23 = OpLabel
- %24 = OpPhi %15 %39 %22 %39 %25
- OpLoopMerge %26 %25 None
- OpBranchConditional %40 %25 %26
- %25 = OpLabel
- OpBranch %23
- %26 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_5;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(
- /*entry_block*/ 22,
- /*exit_block*/ 23,
- /*new_function_struct_return_type_id*/ 200,
- /*new_function_type_id*/ 201,
- /*new_function_id*/ 202,
- /*new_function_region_entry_block*/ 203,
- /*new_caller_result_id*/ 204,
- /*new_callee_result_id*/ 205,
- /*input_id_to_fresh_id*/ {},
- /*output_id_to_fresh_id*/ {});
- ASSERT_FALSE(
- transformation.IsApplicable(context.get(), transformation_context));
- ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
- }
- TEST(TransformationOutlineFunctionTest, Miscellaneous1) {
- // This tests outlining of some non-trivial code, and also tests the way
- // overflow ids are used by the transformation.
- std::string reference_shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main" %85
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- OpName %28 "buf"
- OpMemberName %28 0 "u1"
- OpMemberName %28 1 "u2"
- OpName %30 ""
- OpName %85 "color"
- OpMemberDecorate %28 0 Offset 0
- OpMemberDecorate %28 1 Offset 4
- OpDecorate %28 Block
- OpDecorate %30 DescriptorSet 0
- OpDecorate %30 Binding 0
- OpDecorate %85 Location 0
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %6 = OpTypeFloat 32
- %7 = OpTypeVector %6 4
- %10 = OpConstant %6 1
- %11 = OpConstant %6 2
- %12 = OpConstant %6 3
- %13 = OpConstant %6 4
- %14 = OpConstantComposite %7 %10 %11 %12 %13
- %15 = OpTypeInt 32 1
- %18 = OpConstant %15 0
- %28 = OpTypeStruct %6 %6
- %29 = OpTypePointer Uniform %28
- %30 = OpVariable %29 Uniform
- %31 = OpTypePointer Uniform %6
- %35 = OpTypeBool
- %39 = OpConstant %15 1
- %84 = OpTypePointer Output %7
- %85 = OpVariable %84 Output
- %114 = OpConstant %15 8
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpBranch %22
- %22 = OpLabel
- %103 = OpPhi %15 %18 %5 %106 %43
- %102 = OpPhi %7 %14 %5 %107 %43
- %101 = OpPhi %15 %18 %5 %40 %43
- %32 = OpAccessChain %31 %30 %18
- %33 = OpLoad %6 %32
- %34 = OpConvertFToS %15 %33
- %36 = OpSLessThan %35 %101 %34
- OpLoopMerge %24 %43 None
- OpBranchConditional %36 %23 %24
- %23 = OpLabel
- %40 = OpIAdd %15 %101 %39
- OpBranch %150
- %150 = OpLabel
- OpBranch %41
- %41 = OpLabel
- %107 = OpPhi %7 %102 %150 %111 %65
- %106 = OpPhi %15 %103 %150 %110 %65
- %104 = OpPhi %15 %40 %150 %81 %65
- %47 = OpAccessChain %31 %30 %39
- %48 = OpLoad %6 %47
- %49 = OpConvertFToS %15 %48
- %50 = OpSLessThan %35 %104 %49
- OpLoopMerge %1000 %65 None
- OpBranchConditional %50 %42 %1000
- %42 = OpLabel
- %60 = OpIAdd %15 %106 %114
- %63 = OpSGreaterThan %35 %104 %60
- OpBranchConditional %63 %64 %65
- %64 = OpLabel
- %71 = OpCompositeExtract %6 %107 0
- %72 = OpFAdd %6 %71 %11
- %97 = OpCompositeInsert %7 %72 %107 0
- %76 = OpCompositeExtract %6 %107 3
- %77 = OpConvertFToS %15 %76
- %79 = OpIAdd %15 %60 %77
- OpBranch %65
- %65 = OpLabel
- %111 = OpPhi %7 %107 %42 %97 %64
- %110 = OpPhi %15 %60 %42 %79 %64
- %81 = OpIAdd %15 %104 %39
- OpBranch %41
- %1000 = OpLabel
- OpBranch %1001
- %1001 = OpLabel
- OpBranch %43
- %43 = OpLabel
- OpBranch %22
- %24 = OpLabel
- %87 = OpCompositeExtract %6 %102 0
- %91 = OpConvertSToF %6 %103
- %92 = OpCompositeConstruct %7 %87 %11 %91 %10
- OpStore %85 %92
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_3;
- const auto consumer = nullptr;
- spvtools::ValidatorOptions validator_options;
- TransformationOutlineFunction transformation(
- /*entry_block*/ 150,
- /*exit_block*/ 1001,
- /*new_function_struct_return_type_id*/ 200,
- /*new_function_type_id*/ 201,
- /*new_function_id*/ 202,
- /*new_function_region_entry_block*/ 203,
- /*new_caller_result_id*/ 204,
- /*new_callee_result_id*/ 205,
- /*input_id_to_fresh_id*/ {{102, 300}, {103, 301}, {40, 302}},
- /*output_id_to_fresh_id*/ {{106, 400}, {107, 401}});
- TransformationOutlineFunction transformation_with_missing_input_id(
- /*entry_block*/ 150,
- /*exit_block*/ 1001,
- /*new_function_struct_return_type_id*/ 200,
- /*new_function_type_id*/ 201,
- /*new_function_id*/ 202,
- /*new_function_region_entry_block*/ 203,
- /*new_caller_result_id*/ 204,
- /*new_callee_result_id*/ 205,
- /*input_id_to_fresh_id*/ {{102, 300}, {40, 302}},
- /*output_id_to_fresh_id*/ {{106, 400}, {107, 401}});
- TransformationOutlineFunction transformation_with_missing_output_id(
- /*entry_block*/ 150,
- /*exit_block*/ 1001,
- /*new_function_struct_return_type_id*/ 200,
- /*new_function_type_id*/ 201,
- /*new_function_id*/ 202,
- /*new_function_region_entry_block*/ 203,
- /*new_caller_result_id*/ 204,
- /*new_callee_result_id*/ 205,
- /*input_id_to_fresh_id*/ {{102, 300}, {103, 301}, {40, 302}},
- /*output_id_to_fresh_id*/ {{106, 400}});
- TransformationOutlineFunction
- transformation_with_missing_input_and_output_ids(
- /*entry_block*/ 150,
- /*exit_block*/ 1001,
- /*new_function_struct_return_type_id*/ 200,
- /*new_function_type_id*/ 201,
- /*new_function_id*/ 202,
- /*new_function_region_entry_block*/ 203,
- /*new_caller_result_id*/ 204,
- /*new_callee_result_id*/ 205,
- /*input_id_to_fresh_id*/ {{102, 300}, {40, 302}},
- /*output_id_to_fresh_id*/ {{106, 400}});
- {
- const auto context =
- BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
- context.get(), validator_options, kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- #ifndef NDEBUG
- // We expect the following applicability checks to lead to assertion
- // failures since the transformations are missing input or output ids, and
- // the transformation context does not have a source of overflow ids.
- ASSERT_DEATH(transformation_with_missing_input_id.IsApplicable(
- context.get(), transformation_context),
- "Bad attempt to query whether overflow ids are available.");
- ASSERT_DEATH(transformation_with_missing_output_id.IsApplicable(
- context.get(), transformation_context),
- "Bad attempt to query whether overflow ids are available.");
- ASSERT_DEATH(transformation_with_missing_input_and_output_ids.IsApplicable(
- context.get(), transformation_context),
- "Bad attempt to query whether overflow ids are available.");
- #endif
- ASSERT_TRUE(
- transformation.IsApplicable(context.get(), transformation_context));
- ApplyAndCheckFreshIds(transformation, context.get(),
- &transformation_context);
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
- context.get(), validator_options, kConsoleMessageConsumer));
- std::string variant_shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main" %85
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- OpName %28 "buf"
- OpMemberName %28 0 "u1"
- OpMemberName %28 1 "u2"
- OpName %30 ""
- OpName %85 "color"
- OpMemberDecorate %28 0 Offset 0
- OpMemberDecorate %28 1 Offset 4
- OpDecorate %28 Block
- OpDecorate %30 DescriptorSet 0
- OpDecorate %30 Binding 0
- OpDecorate %85 Location 0
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %6 = OpTypeFloat 32
- %7 = OpTypeVector %6 4
- %10 = OpConstant %6 1
- %11 = OpConstant %6 2
- %12 = OpConstant %6 3
- %13 = OpConstant %6 4
- %14 = OpConstantComposite %7 %10 %11 %12 %13
- %15 = OpTypeInt 32 1
- %18 = OpConstant %15 0
- %28 = OpTypeStruct %6 %6
- %29 = OpTypePointer Uniform %28
- %30 = OpVariable %29 Uniform
- %31 = OpTypePointer Uniform %6
- %35 = OpTypeBool
- %39 = OpConstant %15 1
- %84 = OpTypePointer Output %7
- %85 = OpVariable %84 Output
- %114 = OpConstant %15 8
- %200 = OpTypeStruct %7 %15
- %201 = OpTypeFunction %200 %15 %7 %15
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpBranch %22
- %22 = OpLabel
- %103 = OpPhi %15 %18 %5 %106 %43
- %102 = OpPhi %7 %14 %5 %107 %43
- %101 = OpPhi %15 %18 %5 %40 %43
- %32 = OpAccessChain %31 %30 %18
- %33 = OpLoad %6 %32
- %34 = OpConvertFToS %15 %33
- %36 = OpSLessThan %35 %101 %34
- OpLoopMerge %24 %43 None
- OpBranchConditional %36 %23 %24
- %23 = OpLabel
- %40 = OpIAdd %15 %101 %39
- OpBranch %150
- %150 = OpLabel
- %204 = OpFunctionCall %200 %202 %103 %102 %40
- %107 = OpCompositeExtract %7 %204 0
- %106 = OpCompositeExtract %15 %204 1
- OpBranch %43
- %43 = OpLabel
- OpBranch %22
- %24 = OpLabel
- %87 = OpCompositeExtract %6 %102 0
- %91 = OpConvertSToF %6 %103
- %92 = OpCompositeConstruct %7 %87 %11 %91 %10
- OpStore %85 %92
- OpReturn
- OpFunctionEnd
- %202 = OpFunction %200 None %201
- %301 = OpFunctionParameter %15
- %300 = OpFunctionParameter %7
- %302 = OpFunctionParameter %15
- %203 = OpLabel
- OpBranch %41
- %41 = OpLabel
- %401 = OpPhi %7 %300 %203 %111 %65
- %400 = OpPhi %15 %301 %203 %110 %65
- %104 = OpPhi %15 %302 %203 %81 %65
- %47 = OpAccessChain %31 %30 %39
- %48 = OpLoad %6 %47
- %49 = OpConvertFToS %15 %48
- %50 = OpSLessThan %35 %104 %49
- OpLoopMerge %1000 %65 None
- OpBranchConditional %50 %42 %1000
- %42 = OpLabel
- %60 = OpIAdd %15 %400 %114
- %63 = OpSGreaterThan %35 %104 %60
- OpBranchConditional %63 %64 %65
- %64 = OpLabel
- %71 = OpCompositeExtract %6 %401 0
- %72 = OpFAdd %6 %71 %11
- %97 = OpCompositeInsert %7 %72 %401 0
- %76 = OpCompositeExtract %6 %401 3
- %77 = OpConvertFToS %15 %76
- %79 = OpIAdd %15 %60 %77
- OpBranch %65
- %65 = OpLabel
- %111 = OpPhi %7 %401 %42 %97 %64
- %110 = OpPhi %15 %60 %42 %79 %64
- %81 = OpIAdd %15 %104 %39
- OpBranch %41
- %1000 = OpLabel
- OpBranch %1001
- %1001 = OpLabel
- %205 = OpCompositeConstruct %200 %401 %400
- OpReturnValue %205
- OpFunctionEnd
- )";
- ASSERT_TRUE(IsEqual(env, variant_shader, context.get()));
- }
- {
- const auto context =
- BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
- context.get(), validator_options, kConsoleMessageConsumer));
- auto overflow_ids_unique_ptr = MakeUnique<CounterOverflowIdSource>(2000);
- auto overflow_ids_ptr = overflow_ids_unique_ptr.get();
- TransformationContext new_transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options,
- std::move(overflow_ids_unique_ptr));
- ASSERT_TRUE(transformation_with_missing_input_id.IsApplicable(
- context.get(), new_transformation_context));
- ASSERT_TRUE(transformation_with_missing_output_id.IsApplicable(
- context.get(), new_transformation_context));
- ASSERT_TRUE(transformation_with_missing_input_and_output_ids.IsApplicable(
- context.get(), new_transformation_context));
- ApplyAndCheckFreshIds(transformation_with_missing_input_and_output_ids,
- context.get(), &new_transformation_context,
- overflow_ids_ptr->GetIssuedOverflowIds());
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
- context.get(), validator_options, kConsoleMessageConsumer));
- std::string variant_shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main" %85
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- OpName %28 "buf"
- OpMemberName %28 0 "u1"
- OpMemberName %28 1 "u2"
- OpName %30 ""
- OpName %85 "color"
- OpMemberDecorate %28 0 Offset 0
- OpMemberDecorate %28 1 Offset 4
- OpDecorate %28 Block
- OpDecorate %30 DescriptorSet 0
- OpDecorate %30 Binding 0
- OpDecorate %85 Location 0
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %6 = OpTypeFloat 32
- %7 = OpTypeVector %6 4
- %10 = OpConstant %6 1
- %11 = OpConstant %6 2
- %12 = OpConstant %6 3
- %13 = OpConstant %6 4
- %14 = OpConstantComposite %7 %10 %11 %12 %13
- %15 = OpTypeInt 32 1
- %18 = OpConstant %15 0
- %28 = OpTypeStruct %6 %6
- %29 = OpTypePointer Uniform %28
- %30 = OpVariable %29 Uniform
- %31 = OpTypePointer Uniform %6
- %35 = OpTypeBool
- %39 = OpConstant %15 1
- %84 = OpTypePointer Output %7
- %85 = OpVariable %84 Output
- %114 = OpConstant %15 8
- %200 = OpTypeStruct %7 %15
- %201 = OpTypeFunction %200 %15 %7 %15
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpBranch %22
- %22 = OpLabel
- %103 = OpPhi %15 %18 %5 %106 %43
- %102 = OpPhi %7 %14 %5 %107 %43
- %101 = OpPhi %15 %18 %5 %40 %43
- %32 = OpAccessChain %31 %30 %18
- %33 = OpLoad %6 %32
- %34 = OpConvertFToS %15 %33
- %36 = OpSLessThan %35 %101 %34
- OpLoopMerge %24 %43 None
- OpBranchConditional %36 %23 %24
- %23 = OpLabel
- %40 = OpIAdd %15 %101 %39
- OpBranch %150
- %150 = OpLabel
- %204 = OpFunctionCall %200 %202 %103 %102 %40
- %107 = OpCompositeExtract %7 %204 0
- %106 = OpCompositeExtract %15 %204 1
- OpBranch %43
- %43 = OpLabel
- OpBranch %22
- %24 = OpLabel
- %87 = OpCompositeExtract %6 %102 0
- %91 = OpConvertSToF %6 %103
- %92 = OpCompositeConstruct %7 %87 %11 %91 %10
- OpStore %85 %92
- OpReturn
- OpFunctionEnd
- %202 = OpFunction %200 None %201
- %2000 = OpFunctionParameter %15
- %300 = OpFunctionParameter %7
- %302 = OpFunctionParameter %15
- %203 = OpLabel
- OpBranch %41
- %41 = OpLabel
- %2001 = OpPhi %7 %300 %203 %111 %65
- %400 = OpPhi %15 %2000 %203 %110 %65
- %104 = OpPhi %15 %302 %203 %81 %65
- %47 = OpAccessChain %31 %30 %39
- %48 = OpLoad %6 %47
- %49 = OpConvertFToS %15 %48
- %50 = OpSLessThan %35 %104 %49
- OpLoopMerge %1000 %65 None
- OpBranchConditional %50 %42 %1000
- %42 = OpLabel
- %60 = OpIAdd %15 %400 %114
- %63 = OpSGreaterThan %35 %104 %60
- OpBranchConditional %63 %64 %65
- %64 = OpLabel
- %71 = OpCompositeExtract %6 %2001 0
- %72 = OpFAdd %6 %71 %11
- %97 = OpCompositeInsert %7 %72 %2001 0
- %76 = OpCompositeExtract %6 %2001 3
- %77 = OpConvertFToS %15 %76
- %79 = OpIAdd %15 %60 %77
- OpBranch %65
- %65 = OpLabel
- %111 = OpPhi %7 %2001 %42 %97 %64
- %110 = OpPhi %15 %60 %42 %79 %64
- %81 = OpIAdd %15 %104 %39
- OpBranch %41
- %1000 = OpLabel
- OpBranch %1001
- %1001 = OpLabel
- %205 = OpCompositeConstruct %200 %2001 %400
- OpReturnValue %205
- OpFunctionEnd
- )";
- ASSERT_TRUE(IsEqual(env, variant_shader, context.get()));
- }
- }
- TEST(TransformationOutlineFunctionTest, Miscellaneous2) {
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %21 = OpTypeBool
- %167 = OpConstantTrue %21
- %168 = OpConstantFalse %21
- %4 = OpFunction %2 None %3
- %5 = OpLabel
- OpBranch %34
- %34 = OpLabel
- OpLoopMerge %36 %37 None
- OpBranchConditional %168 %37 %38
- %38 = OpLabel
- OpBranchConditional %168 %37 %36
- %37 = OpLabel
- OpBranch %34
- %36 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_5;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(
- /*entry_block*/ 38,
- /*exit_block*/ 36,
- /*new_function_struct_return_type_id*/ 200,
- /*new_function_type_id*/ 201,
- /*new_function_id*/ 202,
- /*new_function_region_entry_block*/ 203,
- /*new_caller_result_id*/ 204,
- /*new_callee_result_id*/ 205,
- /*input_id_to_fresh_id*/ {},
- /*output_id_to_fresh_id*/ {});
- ASSERT_FALSE(
- transformation.IsApplicable(context.get(), transformation_context));
- }
- TEST(TransformationOutlineFunctionTest, Miscellaneous3) {
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %6 "main"
- OpExecutionMode %6 OriginUpperLeft
- OpSource ESSL 310
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %21 = OpTypeBool
- %167 = OpConstantTrue %21
- %6 = OpFunction %2 None %3
- %7 = OpLabel
- OpBranch %80
- %80 = OpLabel
- OpBranch %14
- %14 = OpLabel
- OpLoopMerge %16 %17 None
- OpBranch %18
- %18 = OpLabel
- OpBranchConditional %167 %15 %16
- %15 = OpLabel
- OpBranch %17
- %16 = OpLabel
- OpBranch %81
- %81 = OpLabel
- OpReturn
- %17 = OpLabel
- OpBranch %14
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_5;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(
- /*entry_block*/ 80,
- /*exit_block*/ 81,
- /*new_function_struct_return_type_id*/ 300,
- /*new_function_type_id*/ 301,
- /*new_function_id*/ 302,
- /*new_function_region_entry_block*/ 304,
- /*new_caller_result_id*/ 305,
- /*new_callee_result_id*/ 306,
- /*input_id_to_fresh_id*/ {},
- /*output_id_to_fresh_id*/ {});
- ASSERT_TRUE(
- transformation.IsApplicable(context.get(), transformation_context));
- ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- std::string after_transformation = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %6 "main"
- OpExecutionMode %6 OriginUpperLeft
- OpSource ESSL 310
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %21 = OpTypeBool
- %167 = OpConstantTrue %21
- %6 = OpFunction %2 None %3
- %7 = OpLabel
- OpBranch %80
- %80 = OpLabel
- %305 = OpFunctionCall %2 %302
- OpReturn
- OpFunctionEnd
- %302 = OpFunction %2 None %3
- %304 = OpLabel
- OpBranch %14
- %14 = OpLabel
- OpLoopMerge %16 %17 None
- OpBranch %18
- %18 = OpLabel
- OpBranchConditional %167 %15 %16
- %15 = OpLabel
- OpBranch %17
- %16 = OpLabel
- OpBranch %81
- %81 = OpLabel
- OpReturn
- %17 = OpLabel
- OpBranch %14
- OpFunctionEnd
- )";
- ASSERT_TRUE(IsEqual(env, after_transformation, context.get()));
- }
- TEST(TransformationOutlineFunctionTest, Miscellaneous4) {
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %6 "main"
- OpExecutionMode %6 OriginUpperLeft
- OpSource ESSL 310
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %21 = OpTypeBool
- %100 = OpTypeInt 32 0
- %101 = OpTypePointer Function %100
- %102 = OpTypePointer Function %100
- %103 = OpTypeFunction %2 %101
- %6 = OpFunction %2 None %3
- %7 = OpLabel
- %104 = OpVariable %102 Function
- OpBranch %80
- %80 = OpLabel
- %105 = OpLoad %100 %104
- OpBranch %106
- %106 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_5;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(
- /*entry_block*/ 80,
- /*exit_block*/ 106,
- /*new_function_struct_return_type_id*/ 300,
- /*new_function_type_id*/ 301,
- /*new_function_id*/ 302,
- /*new_function_region_entry_block*/ 304,
- /*new_caller_result_id*/ 305,
- /*new_callee_result_id*/ 306,
- /*input_id_to_fresh_id*/ {{104, 307}},
- /*output_id_to_fresh_id*/ {});
- ASSERT_TRUE(
- transformation.IsApplicable(context.get(), transformation_context));
- ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- std::string after_transformation = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %6 "main"
- OpExecutionMode %6 OriginUpperLeft
- OpSource ESSL 310
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %21 = OpTypeBool
- %100 = OpTypeInt 32 0
- %101 = OpTypePointer Function %100
- %102 = OpTypePointer Function %100
- %103 = OpTypeFunction %2 %101
- %301 = OpTypeFunction %2 %102
- %6 = OpFunction %2 None %3
- %7 = OpLabel
- %104 = OpVariable %102 Function
- OpBranch %80
- %80 = OpLabel
- %305 = OpFunctionCall %2 %302 %104
- OpReturn
- OpFunctionEnd
- %302 = OpFunction %2 None %301
- %307 = OpFunctionParameter %102
- %304 = OpLabel
- %105 = OpLoad %100 %307
- OpBranch %106
- %106 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- ASSERT_TRUE(IsEqual(env, after_transformation, context.get()));
- }
- TEST(TransformationOutlineFunctionTest, NoOutlineWithUnreachableBlocks) {
- // This checks that outlining will not be performed if a node in the region
- // has an unreachable predecessor.
- std::string shader = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %4 "main"
- OpExecutionMode %4 OriginUpperLeft
- OpSource ESSL 310
- OpName %4 "main"
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %4 = OpFunction %2 None %3
- %7 = OpLabel
- OpBranch %5
- %5 = OpLabel
- OpReturn
- %6 = OpLabel
- OpBranch %5
- OpFunctionEnd
- )";
- const auto env = SPV_ENV_UNIVERSAL_1_4;
- const auto consumer = nullptr;
- const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
- spvtools::ValidatorOptions validator_options;
- ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
- kConsoleMessageConsumer));
- TransformationContext transformation_context(
- MakeUnique<FactManager>(context.get()), validator_options);
- TransformationOutlineFunction transformation(5, 5, /* not relevant */ 200,
- 100, 101, 102, 103,
- /* not relevant */ 201, {}, {});
- ASSERT_FALSE(
- transformation.IsApplicable(context.get(), transformation_context));
- }
- } // namespace
- } // namespace fuzz
- } // namespace spvtools
|