Back to listC++
LLVM-style Value Class
Lv.5701@mukitaro0 playsJan 2, 2026
LLVM IR Value class pattern. The foundation of LLVM's intermediate representation.
preview.cpp
1#include <string>2#include <vector>3 4class Type;5class Use;6 7class Value {8public:9 enum ValueKind {10 ConstantVal,11 InstructionVal,12 ArgumentVal,13 BasicBlockVal14 };15 16private:17 Type* VTy;18 std::string Name;19 std::vector<Use*> Uses;20 ValueKind Kind;21 22public:23 Value(Type* Ty, ValueKind K) : VTy(Ty), Kind(K) {}24 virtual ~Value() = default;25 26 Type* getType() const { return VTy; }27 ValueKind getValueKind() const { return Kind; }28 29 bool hasName() const { return !Name.empty(); }30 std::string getName() const { return Name; }31 void setName(const std::string& N) { Name = N; }32 33 bool hasUses() const { return !Uses.empty(); }34 size_t getNumUses() const { return Uses.size(); }35};Custom problems are not included in rankings