File tree Expand file tree Collapse file tree 3 files changed +43
-14
lines changed
SwiftCompilerSources/Sources/SIL Expand file tree Collapse file tree 3 files changed +43
-14
lines changed Original file line number Diff line number Diff line change @@ -157,18 +157,21 @@ extension Value {
157
157
extension BridgedValue {
158
158
public func getAs< T: AnyObject > ( _ valueType: T . Type ) -> T { obj. getAs ( T . self) }
159
159
160
+ public var value : Value { getAs ( AnyObject . self) as! Value }
161
+ }
162
+
163
+ extension BridgedClassifiedValue {
160
164
public var value : Value {
161
- // This is much faster than a conformance lookup with `as! Value`.
162
- let v = getAs ( AnyObject . self)
163
- switch v {
164
- case let inst as SingleValueInstruction :
165
- return inst
166
- case let arg as Argument :
167
- return arg
168
- case let mvr as MultipleValueInstructionResult :
169
- return mvr
170
- case let undef as Undef :
171
- return undef
165
+ // Doing the type check in C++ is much faster than a conformance lookup with `as! Value`.
166
+ switch kind {
167
+ case . SingleValueInstruction:
168
+ return obj. getAs ( SingleValueInstruction . self)
169
+ case . Argument:
170
+ return obj. getAs ( Argument . self)
171
+ case . MultipleValueInstructionResult:
172
+ return obj. getAs ( MultipleValueInstructionResult . self)
173
+ case . Undef:
174
+ return obj. getAs ( Undef . self)
172
175
default :
173
176
fatalError ( " unknown Value type " )
174
177
}
Original file line number Diff line number Diff line change @@ -133,6 +133,19 @@ typedef struct {
133
133
SwiftObject obj;
134
134
} BridgedValue;
135
135
136
+ // For fast SILValue -> Value briding.
137
+ // This is doing the type checks in C++ rather than in Swift.
138
+ // It's used for getting the value of an Operand, which is a time critical function.
139
+ typedef struct {
140
+ SwiftObject obj;
141
+ enum class Kind {
142
+ SingleValueInstruction,
143
+ Argument,
144
+ MultipleValueInstructionResult,
145
+ Undef
146
+ } kind;
147
+ } BridgedClassifiedValue;
148
+
136
149
typedef struct {
137
150
OptionalSwiftObject obj;
138
151
} OptionalBridgedValue;
@@ -305,7 +318,7 @@ OptionalBridgedSuccessor SILSuccessor_getNext(BridgedSuccessor succ);
305
318
BridgedBasicBlock SILSuccessor_getTargetBlock (BridgedSuccessor succ);
306
319
BridgedInstruction SILSuccessor_getContainingInst (BridgedSuccessor succ);
307
320
308
- BridgedValue Operand_getValue (BridgedOperand);
321
+ BridgedClassifiedValue Operand_getValue (BridgedOperand);
309
322
OptionalBridgedOperand Operand_nextUse (BridgedOperand);
310
323
BridgedInstruction Operand_getUser (BridgedOperand);
311
324
SwiftInt Operand_isTypeDependent (BridgedOperand);
Original file line number Diff line number Diff line change @@ -447,8 +447,21 @@ static Operand *castToOperand(BridgedOperand operand) {
447
447
return const_cast <Operand *>(static_cast <const Operand *>(operand.op ));
448
448
}
449
449
450
- BridgedValue Operand_getValue (BridgedOperand operand) {
451
- return {castToOperand (operand)->get ()};
450
+ BridgedClassifiedValue Operand_getValue (BridgedOperand operand) {
451
+ SILValue v = castToOperand (operand)->get ();
452
+ BridgedClassifiedValue::Kind k;
453
+ if (isa<SingleValueInstruction>(v)) {
454
+ k = BridgedClassifiedValue::Kind::SingleValueInstruction;
455
+ } else if (isa<SILArgument>(v)) {
456
+ k = BridgedClassifiedValue::Kind::Argument;
457
+ } else if (isa<MultipleValueInstructionResult>(v)) {
458
+ k = BridgedClassifiedValue::Kind::MultipleValueInstructionResult;
459
+ } else if (isa<SILUndef>(v)) {
460
+ k = BridgedClassifiedValue::Kind::Undef;
461
+ } else {
462
+ llvm_unreachable (" unknown SILValue" );
463
+ }
464
+ return {castToOperand (operand)->get (), k};
452
465
}
453
466
454
467
OptionalBridgedOperand Operand_nextUse (BridgedOperand operand) {
You can’t perform that action at this time.
0 commit comments