@@ -76,7 +76,8 @@ class Instruction;
76
76
class User ;
77
77
class Value ;
78
78
79
- // / Returns the operand edge when dereferenced.
79
+ // / Iterator for the `Use` edges of a User's operands.
80
+ // / \Returns the operand `Use` when dereferenced.
80
81
class OperandUseIterator {
81
82
sandboxir::Use Use;
82
83
// / Don't let the user create a non-empty OperandUseIterator.
@@ -103,7 +104,8 @@ class OperandUseIterator {
103
104
}
104
105
};
105
106
106
- // / Returns user edge when dereferenced.
107
+ // / Iterator for the `Use` edges of a Value's users.
108
+ // / \Returns a `Use` when dereferenced.
107
109
class UserUseIterator {
108
110
sandboxir::Use Use;
109
111
// / Don't let the user create a non-empty UserUseIterator.
@@ -162,7 +164,9 @@ class Value {
162
164
unsigned UID;
163
165
#endif
164
166
// / The LLVM Value that corresponds to this SandboxIR Value.
165
- // / NOTE: Some SBInstructions, like Packs, may include more than one value.
167
+ // / NOTE: Some sandboxir Instructions, like Packs, may include more than one
168
+ // / value and in these cases `Val` points to the last instruction in program
169
+ // / order.
166
170
llvm::Value *Val = nullptr ;
167
171
168
172
friend class Context ; // For getting `Val`.
@@ -300,6 +304,7 @@ class Argument : public sandboxir::Value {
300
304
#endif
301
305
};
302
306
307
+ // / A sandboxir::User has operands.
303
308
class User : public Value {
304
309
protected:
305
310
User (ClassID ID, llvm::Value *V, Context &Ctx) : Value(ID, V, Ctx) {}
@@ -309,6 +314,9 @@ class User : public Value {
309
314
// / match the underlying LLVM instruction. All others should use a different
310
315
// / implementation.
311
316
Use getOperandUseDefault (unsigned OpIdx, bool Verify) const ;
317
+ // / \Returns the Use for the \p OpIdx'th operand. This is virtual to allow
318
+ // / instructions to deviate from the LLVM IR operands, which is a requirement
319
+ // / for sandboxir Instructions that consist of more than one LLVM Instruction.
312
320
virtual Use getOperandUseInternal (unsigned OpIdx, bool Verify) const = 0;
313
321
friend class OperandUseIterator ; // for getOperandUseInternal()
314
322
@@ -414,7 +422,8 @@ class Constant : public sandboxir::User {
414
422
#endif
415
423
};
416
424
417
- // / The BasicBlock::iterator.
425
+ // / Iterator for `Instruction`s in a `BasicBlock.
426
+ // / \Returns an sandboxir::Instruction & when derereferenced.
418
427
class BBIterator {
419
428
public:
420
429
using difference_type = std::ptrdiff_t ;
@@ -456,7 +465,8 @@ class BBIterator {
456
465
pointer get () const { return getInstr (It); }
457
466
};
458
467
459
- // / A sandboxir::User with operands and opcode.
468
+ // / A sandboxir::User with operands, opcode and linked with previous/next
469
+ // / instructions in an instruction list.
460
470
class Instruction : public sandboxir ::User {
461
471
public:
462
472
enum class Opcode {
@@ -577,6 +587,7 @@ class OpaqueInst : public sandboxir::Instruction {
577
587
#endif
578
588
};
579
589
590
+ // / Contains a list of sandboxir::Instruction's.
580
591
class BasicBlock : public Value {
581
592
// / Builds a graph that contains all values in \p BB in their original form
582
593
// / i.e., no vectorization is taking place here.
@@ -643,9 +654,10 @@ class Context {
643
654
friend void Instruction::eraseFromParent (); // For detach().
644
655
// / Take ownership of VPtr and store it in `LLVMValueToValueMap`.
645
656
Value *registerValue (std::unique_ptr<Value> &&VPtr);
646
-
657
+ // / This is the actual function that creates sandboxir values for \p V,
658
+ // / and among others handles all instruction types.
647
659
Value *getOrCreateValueInternal (llvm::Value *V, llvm::User *U = nullptr );
648
-
660
+ // / Get or create a sandboxir::Argument for an existing LLVM IR \p LLVMArg.
649
661
Argument *getOrCreateArgument (llvm::Argument *LLVMArg) {
650
662
auto Pair = LLVMValueToValueMap.insert ({LLVMArg, nullptr });
651
663
auto It = Pair.first ;
@@ -655,11 +667,12 @@ class Context {
655
667
}
656
668
return cast<Argument>(It->second .get ());
657
669
}
658
-
670
+ // / Get or create a sandboxir::Value for an existing LLVM IR \p LLVMV.
659
671
Value *getOrCreateValue (llvm::Value *LLVMV) {
660
672
return getOrCreateValueInternal (LLVMV, 0 );
661
673
}
662
-
674
+ // / Create a sandboxir::BasicBlock for an existing LLVM IR \p BB. This will
675
+ // / also create all contents of the block.
663
676
BasicBlock *createBasicBlock (llvm::BasicBlock *BB);
664
677
665
678
friend class BasicBlock ; // For getOrCreateValue().
@@ -671,7 +684,9 @@ class Context {
671
684
const sandboxir::Value *getValue (const llvm::Value *V) const {
672
685
return getValue (const_cast <llvm::Value *>(V));
673
686
}
674
-
687
+ // / Create a sandboxir::Function for an existing LLVM IR \p F, including all
688
+ // / blocks and instructions.
689
+ // / This is the main API function for creating Sandbox IR.
675
690
Function *createFunction (llvm::Function *F);
676
691
677
692
// / \Returns the number of values registered with Context.
0 commit comments