How to create a Target Machine in LLVM?

1 day ago 3
ARTICLE AD BOX

I'm trying to create a TargetMachine for my TTI (TargetTransformInfo) Wrapper to query instruction costs and vector costs, but the LLVM documentation is scarce on how to instantiate one after initialization.

Below is the relevant portion of my code:

#include "llvm/Analysis/TargetTransformInfo.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Support/TargetSelect.h" #include <iostream> #include <memory> #include <cstdint> using namespace llvm; using namespace std; struct EncodedInstructionCost{ uint16_t instruction_cost; uint16_t vector_cost; }; static TargetMachine* create_target_machine() { InitializeNativeTarget(); // TargetMachine Constructor should be here }; // Cannot perform methods without TM: int get_instruction_cost() { }; int get_vector_instruction_cost() { };

I need this to work cross-platform (x86-64, ARM, etc.).

Read Entire Article