2
LLVM 중간 표현에서 루프에 대한 명령을 삽입 할 수 있습니까?이 명령은 해당 루프를 실행하기 전에 정확히 한 번 실행됩니까? 프리 헤더가 일부 루프에서는 NULL이기 때문에 명령을 프리 헤더에 삽입하면 작동하지 않습니다.루프 실행 전에 명령문을 삽입하십시오.
LLVM 중간 표현에서 루프에 대한 명령을 삽입 할 수 있습니까?이 명령은 해당 루프를 실행하기 전에 정확히 한 번 실행됩니까? 프리 헤더가 일부 루프에서는 NULL이기 때문에 명령을 프리 헤더에 삽입하면 작동하지 않습니다.루프 실행 전에 명령문을 삽입하십시오.
루프에 프리 헤더가 없으면 새 프리 헤더를 만들 수 있습니다.
여기에 예를 들어 http://www.cs.ucla.edu/classes/spring08/cs259/llvm-2.2/lib/Transforms/Utils/LoopSimplify.cpp 또는 http://www.opensource.apple.com/source/clang/clang-23/clang/lib/Transforms/Utils/LoopSimplify.cpp (기능을 InsertPreheaderForLoop
를 발견하고 그것에 전화)
/// InsertPreheaderForLoop - Once we discover that a loop doesn't have a
/// preheader, this method is called to insert one. This method has two phases:
/// preheader insertion and analysis updating.
///
void LoopSimplify::InsertPreheaderForLoop(Loop *L) {
BasicBlock *Header = L->getHeader();
// Compute the set of predecessors of the loop that are not in the loop.
std::vector<BasicBlock*> OutsideBlocks;
for (pred_iterator PI = pred_begin(Header), PE = pred_end(Header);
PI != PE; ++PI)
if (!L->contains(*PI)) // Coming in from outside the loop?
OutsideBlocks.push_back(*PI); // Keep track of it...
// Split out the loop pre-header.
BasicBlock *NewBB =
SplitBlockPredecessors(Header, ".preheader", OutsideBlocks);
//===--------------------------------------------------------------------===//
// Update analysis results now that we have performed the transformation
//
// We know that we have loop information to update... update it now.
if (Loop *Parent = L->getParentLoop())
Parent->addBasicBlockToLoop(NewBB, LI->getBase());
DT->splitBlock(NewBB);
if (DominanceFrontier *DF = getAnalysisToUpdate<DominanceFrontier>())
DF->splitBlock(NewBB);
// Make sure that NewBB is put someplace intelligent, which doesn't mess up
// code layout too horribly.
PlaceSplitBlockCarefully(NewBB, OutsideBlocks, L);
}
당신에게 너무 감사합니다! – dalibocai