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
6e415c06
Commit
6e415c06
authored
21 years ago
by
Chris Lattner
Browse files
Options
Downloads
Patches
Plain Diff
Add support for select constant expressions. Use reserve a bit more to avoid
memory wasteage. llvm-svn: 12323
parent
16375e30
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/VMCore/Constants.cpp
+35
-0
35 additions, 0 deletions
llvm/lib/VMCore/Constants.cpp
with
35 additions
and
0 deletions
llvm/lib/VMCore/Constants.cpp
+
35
−
0
View file @
6e415c06
...
@@ -267,14 +267,26 @@ ConstantStruct::ConstantStruct(const StructType *T,
...
@@ -267,14 +267,26 @@ ConstantStruct::ConstantStruct(const StructType *T,
ConstantPointerRef
::
ConstantPointerRef
(
GlobalValue
*
GV
)
ConstantPointerRef
::
ConstantPointerRef
(
GlobalValue
*
GV
)
:
Constant
(
GV
->
getType
())
{
:
Constant
(
GV
->
getType
())
{
Operands
.
reserve
(
1
);
Operands
.
push_back
(
Use
(
GV
,
this
));
Operands
.
push_back
(
Use
(
GV
,
this
));
}
}
ConstantExpr
::
ConstantExpr
(
unsigned
Opcode
,
Constant
*
C
,
const
Type
*
Ty
)
ConstantExpr
::
ConstantExpr
(
unsigned
Opcode
,
Constant
*
C
,
const
Type
*
Ty
)
:
Constant
(
Ty
),
iType
(
Opcode
)
{
:
Constant
(
Ty
),
iType
(
Opcode
)
{
Operands
.
reserve
(
1
);
Operands
.
push_back
(
Use
(
C
,
this
));
Operands
.
push_back
(
Use
(
C
,
this
));
}
}
// Select instruction creation ctor
ConstantExpr
::
ConstantExpr
(
Constant
*
C
,
Constant
*
V1
,
Constant
*
V2
)
:
Constant
(
V1
->
getType
()),
iType
(
Instruction
::
Select
)
{
Operands
.
reserve
(
3
);
Operands
.
push_back
(
Use
(
C
,
this
));
Operands
.
push_back
(
Use
(
V1
,
this
));
Operands
.
push_back
(
Use
(
V2
,
this
));
}
static
bool
isSetCC
(
unsigned
Opcode
)
{
static
bool
isSetCC
(
unsigned
Opcode
)
{
return
Opcode
==
Instruction
::
SetEQ
||
Opcode
==
Instruction
::
SetNE
||
return
Opcode
==
Instruction
::
SetEQ
||
Opcode
==
Instruction
::
SetNE
||
Opcode
==
Instruction
::
SetLT
||
Opcode
==
Instruction
::
SetGT
||
Opcode
==
Instruction
::
SetLT
||
Opcode
==
Instruction
::
SetGT
||
...
@@ -283,6 +295,7 @@ static bool isSetCC(unsigned Opcode) {
...
@@ -283,6 +295,7 @@ static bool isSetCC(unsigned Opcode) {
ConstantExpr
::
ConstantExpr
(
unsigned
Opcode
,
Constant
*
C1
,
Constant
*
C2
)
ConstantExpr
::
ConstantExpr
(
unsigned
Opcode
,
Constant
*
C1
,
Constant
*
C2
)
:
Constant
(
isSetCC
(
Opcode
)
?
Type
::
BoolTy
:
C1
->
getType
()),
iType
(
Opcode
)
{
:
Constant
(
isSetCC
(
Opcode
)
?
Type
::
BoolTy
:
C1
->
getType
()),
iType
(
Opcode
)
{
Operands
.
reserve
(
2
);
Operands
.
push_back
(
Use
(
C1
,
this
));
Operands
.
push_back
(
Use
(
C1
,
this
));
Operands
.
push_back
(
Use
(
C2
,
this
));
Operands
.
push_back
(
Use
(
C2
,
this
));
}
}
...
@@ -997,6 +1010,11 @@ namespace llvm {
...
@@ -997,6 +1010,11 @@ namespace llvm {
case
Instruction
::
Cast
:
case
Instruction
::
Cast
:
New
=
ConstantExpr
::
getCast
(
OldC
->
getOperand
(
0
),
NewTy
);
New
=
ConstantExpr
::
getCast
(
OldC
->
getOperand
(
0
),
NewTy
);
break
;
break
;
case
Instruction
::
Select
:
New
=
ConstantExpr
::
getSelectTy
(
NewTy
,
OldC
->
getOperand
(
0
),
OldC
->
getOperand
(
1
),
OldC
->
getOperand
(
2
));
break
;
case
Instruction
::
Shl
:
case
Instruction
::
Shl
:
case
Instruction
::
Shr
:
case
Instruction
::
Shr
:
New
=
ConstantExpr
::
getShiftTy
(
NewTy
,
OldC
->
getOpcode
(),
New
=
ConstantExpr
::
getShiftTy
(
NewTy
,
OldC
->
getOpcode
(),
...
@@ -1059,6 +1077,23 @@ Constant *ConstantExpr::getTy(const Type *ReqTy, unsigned Opcode,
...
@@ -1059,6 +1077,23 @@ Constant *ConstantExpr::getTy(const Type *ReqTy, unsigned Opcode,
return
ExprConstants
.
getOrCreate
(
ReqTy
,
Key
);
return
ExprConstants
.
getOrCreate
(
ReqTy
,
Key
);
}
}
Constant
*
ConstantExpr
::
getSelectTy
(
const
Type
*
ReqTy
,
Constant
*
C
,
Constant
*
V1
,
Constant
*
V2
)
{
assert
(
C
->
getType
()
==
Type
::
BoolTy
&&
"Select condition must be bool!"
);
assert
(
V1
->
getType
()
==
V2
->
getType
()
&&
"Select value types must match!"
);
assert
(
V1
->
getType
()
->
isFirstClassType
()
&&
"Cannot select aggregate type!"
);
if
(
ReqTy
==
V1
->
getType
())
if
(
Constant
*
SC
=
ConstantFoldSelectInstruction
(
C
,
V1
,
V2
))
return
SC
;
// Fold common cases
std
::
vector
<
Constant
*>
argVec
(
3
,
C
);
argVec
[
1
]
=
V1
;
argVec
[
2
]
=
V2
;
ExprMapKeyType
Key
=
std
::
make_pair
(
Instruction
::
Select
,
argVec
);
return
ExprConstants
.
getOrCreate
(
ReqTy
,
Key
);
}
/// getShiftTy - Return a shift left or shift right constant expr
/// getShiftTy - Return a shift left or shift right constant expr
Constant
*
ConstantExpr
::
getShiftTy
(
const
Type
*
ReqTy
,
unsigned
Opcode
,
Constant
*
ConstantExpr
::
getShiftTy
(
const
Type
*
ReqTy
,
unsigned
Opcode
,
Constant
*
C1
,
Constant
*
C2
)
{
Constant
*
C1
,
Constant
*
C2
)
{
...
...
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