Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
llvm-epi-0.8
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Roger Ferrer
llvm-epi-0.8
Commits
b17274eb
Commit
b17274eb
authored
22 years ago
by
Chris Lattner
Browse files
Options
Downloads
Patches
Plain Diff
Implement a new RemoveSuccessor function llvm-svn: 3131
parent
153ccdca
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+51
-4
51 additions, 4 deletions
llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
with
51 additions
and
4 deletions
llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+
51
−
4
View file @
b17274eb
...
...
@@ -7,7 +7,9 @@
#include
"llvm/Transforms/Utils/BasicBlockUtils.h"
#include
"llvm/Function.h"
#include
"llvm/Instruction.h"
#include
"llvm/iTerminators.h"
#include
"llvm/Constant.h"
#include
"llvm/Type.h"
#include
<algorithm>
// ReplaceInstWithValue - Replace all uses of an instruction (specified by BI)
...
...
@@ -50,11 +52,56 @@ void ReplaceInstWithInst(BasicBlock::InstListType &BIL,
}
// ReplaceInstWithInst - Replace the instruction specified by From with the
// instruction specified by To. Note that this is slower than providing an
// iterator directly, because the basic block containing From must be searched
// for the instruction.
// instruction specified by To.
//
void
ReplaceInstWithInst
(
Instruction
*
From
,
Instruction
*
To
)
{
BasicBlock
::
iterator
BI
(
From
);
ReplaceInstWithInst
(
From
->
getParent
()
->
getInstList
(),
BI
,
To
);
}
// RemoveSuccessor - Change the specified terminator instruction such that its
// successor #SuccNum no longer exists. Because this reduces the outgoing
// degree of the current basic block, the actual terminator instruction itself
// may have to be changed. In the case where the last successor of the block is
// deleted, a return instruction is inserted in its place which can cause a
// suprising change in program behavior if it is not expected.
//
void
RemoveSuccessor
(
TerminatorInst
*
TI
,
unsigned
SuccNum
)
{
assert
(
SuccNum
<
TI
->
getNumSuccessors
()
&&
"Trying to remove a nonexistant successor!"
);
// If our old successor block contains any PHI nodes, remove the entry in the
// PHI nodes that comes from this branch...
//
BasicBlock
*
BB
=
TI
->
getParent
();
TI
->
getSuccessor
(
SuccNum
)
->
removePredecessor
(
BB
);
TerminatorInst
*
NewTI
=
0
;
switch
(
TI
->
getOpcode
())
{
case
Instruction
::
Br
:
// If this is a conditional branch... convert to unconditional branch.
if
(
TI
->
getNumSuccessors
()
==
2
)
{
cast
<
BranchInst
>
(
TI
)
->
setUnconditionalDest
(
TI
->
getSuccessor
(
1
-
SuccNum
));
}
else
{
// Otherwise convert to a return instruction...
Value
*
RetVal
=
0
;
// Create a value to return... if the function doesn't return null...
if
(
BB
->
getParent
()
->
getReturnType
()
!=
Type
::
VoidTy
)
RetVal
=
Constant
::
getNullValue
(
BB
->
getParent
()
->
getReturnType
());
// Create the return...
NewTI
=
new
ReturnInst
(
RetVal
);
}
break
;
case
Instruction
::
Invoke
:
// Should convert to call
case
Instruction
::
Switch
:
// Should remove entry
default
:
case
Instruction
::
Ret
:
// Cannot happen, has no successors!
assert
(
0
&&
"Unhandled terminator instruction type in RemoveSuccessor!"
);
abort
();
}
if
(
NewTI
)
// If it's a different instruction, replace.
ReplaceInstWithInst
(
TI
,
NewTI
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment