Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollback JSON from llvm-17 to llvm-10 #55

Open
wants to merge 3 commits into
base: mlbridge-lib
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ LLVM/IR2Vec-Engine/IR2Vec-Binaries/*
!LLVM/IR2Vec-Engine/IR2Vec-Binaries/README.md
# Data
/data
install

# trained model
trained_model/
Expand Down
2 changes: 1 addition & 1 deletion MLCompilerBridge
2 changes: 1 addition & 1 deletion clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static json::Object createArtifactLocation(const FileEntry &FE,
auto I = llvm::find_if(Artifacts, [&](const json::Value &File) {
if (const json::Object *Obj = File.getAsObject()) {
if (const json::Object *FileLoc = Obj->getObject("location")) {
std::optional<StringRef> URI = FileLoc->getString("uri");
Optional<StringRef> URI = FileLoc->getString("uri");
return URI && URI->equals(FileURI);
}
}
Expand Down
30 changes: 19 additions & 11 deletions llvm/include/llvm/CodeGen/MLRegAlloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
#include "InterferenceCache.h"
#include "LiveDebugVariables.h"
#include "MLModelRunner/MLModelRunner.h"
#include "MLModelRunner/ONNXModelRunner/onnx.h"
#include "RegAllocBase.h"
#include "SpillPlacement.h"
#include "Spiller.h"
#include "SplitKit.h"
#include "grpc/RegisterAllocationInference/RegisterAllocationInference.pb.h"
#include "multi_agent_env.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/DenseMap.h"
Expand Down Expand Up @@ -64,9 +67,6 @@
#include "llvm/Support/Timer.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
#include "MLModelRunner/ONNXModelRunner/onnx.h"
#include "grpc/RegisterAllocationInference/RegisterAllocationInference.pb.h"
#include "multi_agent_env.h"
// gRPC includes
#include "grpc/RegisterAllocation/RegisterAllocation.grpc.pb.h"
#include "grpc/RegisterAllocationInference/RegisterAllocationInference.grpc.pb.h"
Expand All @@ -82,11 +82,10 @@
#include <memory>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <string>
#include <map>

#define DEBUG_TYPE "mlra-regalloc"

Expand Down Expand Up @@ -187,6 +186,7 @@ class MLRA : public RegAllocBase,
registerallocationinference::Data ServerModeRequest;
registerallocationinference::Data ClientModeResponse;
registerallocationinference::RegisterProfileList ClientModeRequest;

private:
struct PipeResponse {
std::string Action;
Expand All @@ -210,10 +210,10 @@ class MLRA : public RegAllocBase,
// };
// SmallMapVector<unsigned, RegisterProfile, 16> regProfMap;
// RegisterProfileMap regProfMap;
std::unique_ptr<MLModelRunner> MLRunner;
// std::unique_ptr<MLModelRunner> MLRunner;
json::Object JO;
std::vector<TensorSpec> FeatureSpecs;
std::vector<void*> InputBuffers;
std::vector<void *> InputBuffers;
SmallSetVector<unsigned, 8> regIdxs;
// TensorSpec AdviceSpec;
bool CommuResult;
Expand Down Expand Up @@ -277,11 +277,19 @@ class MLRA : public RegAllocBase,
//
unsigned getPhyRegForColor(LiveInterval &VirtReg, unsigned color,
SmallVector<unsigned, 4> &SplitVRegs);

Observation split_node_step(unsigned action) override;
void initPipeCommunication();
void processMLInputs(SmallSetVector<unsigned, 8> *updatedRegIdxs, bool IsStart = false, bool IsJson=false);
void processMLInputsProtobuf(SmallSetVector<unsigned, 8> *updatedRegIdxs, bool IsStart = false);

template <typename T> void initCommunication(T &);

template <typename T>
void processMLInputs(T &MLRunner, SmallSetVector<unsigned, 8> *updatedRegIdxs,
bool IsStart = false, bool IsJson = false);

template <typename T>
void processMLInputsProtobuf(T &MLRunner,
SmallSetVector<unsigned, 8> *updatedRegIdxs,
bool IsStart = false);
void printFeatures();
// void processMLAdvice();

Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/LinkAllPasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ namespace {
(void) llvm::createHardwareLoopsPass();
(void)llvm::createInjectTLIMappingsLegacyPass();
(void) llvm::createcustom_loop_distributionPass();
// (void)llvm::createRDGWrapperPass();
// (void) llvm::createLoopDistributionWrapperPassPass();
(void)llvm::createRDGWrapperPass();
(void) llvm::createLoopDistributionWrapperPassPass();

(void)new llvm::IntervalPartition();
(void)new llvm::ScalarEvolutionWrapperPass();
Expand Down
63 changes: 32 additions & 31 deletions llvm/include/llvm/Support/JSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ std::string fixUTF8(llvm::StringRef S);
class Array;
class ObjectKey;
class Value;
template <typename T> Value toJSON(const std::optional<T> &Opt);
template <typename T> Value toJSON(const llvm::Optional<T> &Opt);

/// An Object is a JSON object, which maps strings to heterogenous JSON values.
/// It simulates DenseMap<ObjectKey, Value>. ObjectKey is a maybe-owned string.
Expand Down Expand Up @@ -140,14 +140,14 @@ class Object {
// Look up a property, returning nullptr if it doesn't exist.
Value *get(StringRef K);
const Value *get(StringRef K) const;
// Typed accessors return std::nullopt/nullptr if
// Typed accessors return llvm::None/nullptr if
// - the property doesn't exist
// - or it has the wrong type
std::optional<std::nullptr_t> getNull(StringRef K) const;
std::optional<bool> getBoolean(StringRef K) const;
std::optional<double> getNumber(StringRef K) const;
std::optional<int64_t> getInteger(StringRef K) const;
std::optional<llvm::StringRef> getString(StringRef K) const;
llvm::Optional<std::nullptr_t> getNull(StringRef K) const;
llvm::Optional<bool> getBoolean(StringRef K) const;
llvm::Optional<double> getNumber(StringRef K) const;
llvm::Optional<int64_t> getInteger(StringRef K) const;
llvm::Optional<llvm::StringRef> getString(StringRef K) const;
const json::Object *getObject(StringRef K) const;
json::Object *getObject(StringRef K);
const json::Array *getArray(StringRef K) const;
Expand Down Expand Up @@ -238,14 +238,14 @@ inline bool operator!=(const Array &L, const Array &R) { return !(L == R); }
/// object (json::Object)
///
/// The kind can be queried directly, or implicitly via the typed accessors:
/// if (std::optional<StringRef> S = E.getAsString()
/// if (llvm::Optional<StringRef> S = E.getAsString()
/// assert(E.kind() == Value::String);
///
/// Array and Object also have typed indexing accessors for easy traversal:
/// Expected<Value> E = parse(R"( {"options": {"font": "sans-serif"}} )");
/// if (Object* O = E->getAsObject())
/// if (Object* Opts = O->getObject("options"))
/// if (std::optional<StringRef> Font = Opts->getString("font"))
/// if (llvm::Optional<StringRef> Font = Opts->getString("font"))
/// assert(Opts->at("font").kind() == Value::String);
///
/// === Converting JSON values to C++ types ===
Expand All @@ -266,13 +266,13 @@ inline bool operator!=(const Array &L, const Array &R) { return !(L == R); }
/// - std::string
/// - vector<T>, where T is deserializable
/// - map<string, T>, where T is deserializable
/// - std::optional<T>, where T is deserializable
/// - llvm::Optional<T>, where T is deserializable
/// ObjectMapper can help writing fromJSON() functions for object types.
///
/// For conversion in the other direction, the serializer function is:
/// toJSON(const T&) -> json::Value
/// If this exists, then it also allows constructing Value from T, and can
/// be used to serialize vector<T>, map<string, T>, and std::optional<T>.
/// be used to serialize vector<T>, map<string, T>, and llvm::Optional<T>.
///
/// === Serialization ===
///
Expand Down Expand Up @@ -401,29 +401,29 @@ class Value {
llvm_unreachable("Unknown kind");
}

// Typed accessors return std::nullopt/nullptr if the Value is not of this
// Typed accessors return llvm::None/nullptr if the Value is not of this
// type.
std::optional<std::nullptr_t> getAsNull() const {
llvm::Optional<std::nullptr_t> getAsNull() const {
if (LLVM_LIKELY(Type == T_Null))
return nullptr;
return std::nullopt;
return llvm::None;
}
std::optional<bool> getAsBoolean() const {
llvm::Optional<bool> getAsBoolean() const {
if (LLVM_LIKELY(Type == T_Boolean))
return as<bool>();
return std::nullopt;
return llvm::None;
}
std::optional<double> getAsNumber() const {
llvm::Optional<double> getAsNumber() const {
if (LLVM_LIKELY(Type == T_Double))
return as<double>();
if (LLVM_LIKELY(Type == T_Integer))
return as<int64_t>();
if (LLVM_LIKELY(Type == T_UINT64))
return as<uint64_t>();
return std::nullopt;
return llvm::None;
}
// Succeeds if the Value is a Number, and exactly representable as int64_t.
std::optional<int64_t> getAsInteger() const {
llvm::Optional<int64_t> getAsInteger() const {
if (LLVM_LIKELY(Type == T_Integer))
return as<int64_t>();
if (LLVM_LIKELY(Type == T_UINT64)) {
Expand All @@ -439,24 +439,24 @@ class Value {
D <= double(std::numeric_limits<int64_t>::max())))
return D;
}
return std::nullopt;
return llvm::None;
}
std::optional<uint64_t> getAsUINT64() const {
llvm::Optional<uint64_t> getAsUINT64() const {
if (Type == T_UINT64)
return as<uint64_t>();
else if (Type == T_Integer) {
int64_t N = as<int64_t>();
if (N >= 0)
return as<uint64_t>();
}
return std::nullopt;
return llvm::None;
}
std::optional<llvm::StringRef> getAsString() const {
llvm::Optional<llvm::StringRef> getAsString() const {
if (Type == T_String)
return llvm::StringRef(as<std::string>());
if (LLVM_LIKELY(Type == T_StringRef))
return as<llvm::StringRef>();
return std::nullopt;
return llvm::None;
}
const json::Object *getAsObject() const {
return LLVM_LIKELY(Type == T_Object) ? &as<json::Object>() : nullptr;
Expand Down Expand Up @@ -637,6 +637,7 @@ inline bool Object::erase(StringRef K) {
/// A "cursor" marking a position within a Value.
/// The Value is a tree, and this is the path from the root to the current node.
/// This is used to associate errors with particular subobjects.
class Path;
class Path {
public:
class Root;
Expand Down Expand Up @@ -770,9 +771,9 @@ inline bool fromJSON(const Value &E, std::nullptr_t &Out, Path P) {
return false;
}
template <typename T>
bool fromJSON(const Value &E, std::optional<T> &Out, Path P) {
bool fromJSON(const Value &E, llvm::Optional<T> &Out, Path P) {
if (E.getAsNull()) {
Out = std::nullopt;
Out = None;
return true;
}
T Result = {};
Expand Down Expand Up @@ -808,8 +809,8 @@ bool fromJSON(const Value &E, std::map<std::string, T> &Out, Path P) {
return false;
}

// Allow serialization of std::optional<T> for supported T.
template <typename T> Value toJSON(const std::optional<T> &Opt) {
// Allow serialization of llvm::Optional<T> for supported T.
template <typename T> Value toJSON(const llvm::Optional<T> &Opt) {
return Opt ? Value(*Opt) : Value(nullptr);
}

Expand Down Expand Up @@ -848,12 +849,12 @@ class ObjectMapper {

/// Maps a property to a field, if it exists.
/// If the property exists and is invalid, reports an error.
/// (Optional requires special handling, because missing keys are OK).
template <typename T> bool map(StringLiteral Prop, std::optional<T> &Out) {
/// (llvm::Optional requires special handling, because missing keys are OK).
template <typename T> bool map(StringLiteral Prop, llvm::Optional<T> &Out) {
assert(*this && "Must check this is an object before calling map()");
if (const Value *E = O->get(Prop))
return fromJSON(*E, Out, P.field(Prop));
Out = std::nullopt;
Out = llvm::None;
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class RDGWrapperPass : public FunctionPass {
DOTData &rdg);
};

// RDGWrapperPass *createRDGWrapperPass();
RDGWrapperPass *createRDGWrapperPass();

} // namespace llvm

Expand Down
20 changes: 10 additions & 10 deletions llvm/include/llvm/Transforms/Scalar/IR2Vec-LOF/LoopDistribution.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ class LoopDistribution {
void setLid(unsigned int lid) { this->lid = lid; }
void setPartition(std::string partition) { this->partition = partition; }

void computeDistribution(SmallVector<DataDependenceGraph *, 5> &SCCGraphs,
SmallVector<Loop *, 5> &loops,
SmallVector<std::string, 5> &dis_seqs);
// void computeDistribution(SmallVector<DataDependenceGraph *, 5> &SCCGraphs,
// SmallVector<Loop *, 5> &loops,
// SmallVector<std::string, 5> &dis_seqs);

void run(Function &F, FunctionAnalysisManager &fam,
SmallVector<DataDependenceGraph *, 5> &SCCGraphs,
SmallVector<Loop *, 5> &loops,
SmallVector<std::string, 5> &dis_seqs);
// void run(Function &F, FunctionAnalysisManager &fam,
// SmallVector<DataDependenceGraph *, 5> &SCCGraphs,
// SmallVector<Loop *, 5> &loops,
// SmallVector<std::string, 5> &dis_seqs);

bool
findLoopAndDistribute(Function &F, ScalarEvolution *SE_, LoopInfo *LI_,
Expand Down Expand Up @@ -117,9 +117,9 @@ class LoopDistributionWrapperPass : public FunctionPass {
}*/
bool runOnFunction(Function &F) override;

void run(SmallVector<DataDependenceGraph *, 5> &SCCGraphs,
SmallVector<Loop *, 5> &loops,
SmallVector<std::string, 5> &dis_seqs);
// void run(SmallVector<DataDependenceGraph *, 5> &SCCGraphs,
// SmallVector<Loop *, 5> &loops,
// SmallVector<std::string, 5> &dis_seqs);

void getAnalysisUsage(AnalysisUsage &AU) const;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ class custom_loop_distribution : public FunctionPass, public LDEnv {
private:
void canonicalizeLoopsWithLoads();

void initPipeCommunication(const std::vector<std::string> &RDG_List);
template <typename T>
void initCommunication(T &MLRunner,
const std::vector<std::string> &RDG_List);

std::unique_ptr<MLModelRunner> MLRunner;
// std::unique_ptr<MLModelRunner> MLRunner;
std::ofstream outfile;
};

Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Analysis/Analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ void llvm::initializeAnalysis(PassRegistry &Registry) {
initializeLCSSAVerificationPassPass(Registry);
initializeMemorySSAWrapperPassPass(Registry);
initializeMemorySSAPrinterLegacyPassPass(Registry);
initializeRDGWrapperPassPass(Registry);
initializeInnerMostLoopPassPass(Registry);
// initializeRDGWrapperPassPass(Registry);
// initializeInnerMostLoopPassPass(Registry);
}

void LLVMInitializeAnalysis(LLVMPassRegistryRef R) {
Expand Down
Loading